From 51ca022b1f2191b7bf56f86691e2111548bf1bb7 Mon Sep 17 00:00:00 2001 From: Daniel Levin Date: Fri, 26 Sep 2025 06:11:28 +0200 Subject: [PATCH] docs: Include #[diagnostic(forward(..)] in documentation (#446) --- README.md | 11 +++++++++++ src/lib.rs | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 4829d03..d77bda1 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,17 @@ pub enum MyLibError { // Use `#[diagnostic(transparent)]` to wrap another [`Diagnostic`]. You won't see labels otherwise #[diagnostic(transparent)] AnotherError(#[from] AnotherError), + + /// Forward the diagnostic to a particular field. + #[error("other error")] + #[diagnostic(forward(the_actual_diagnostic))] + EvenMoreData { + unrelated_field_1: String, + unrelated_field_2: usize, + + #[source] + the_actual_diagnostic: AnotherError, + } } #[derive(Error, Diagnostic, Debug)] diff --git a/src/lib.rs b/src/lib.rs index 2e07663..3d9f327 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -211,6 +211,17 @@ //! // Use `#[diagnostic(transparent)]` to wrap another [`Diagnostic`]. You won't see labels otherwise //! #[diagnostic(transparent)] //! AnotherError(#[from] AnotherError), +//! +//! /// Forward the diagnostic to a particular field. +//! #[error("other error")] +//! #[diagnostic(forward(the_actual_diagnostic))] +//! EvenMoreData { +//! unrelated_field_1: String, +//! unrelated_field_2: usize, +//! +//! #[source] +//! the_actual_diagnostic: AnotherError, +//! } //! } //! //! #[derive(Error, Diagnostic, Debug)]