From b2df5d55ec626bc02b1c4706608bbadaa530e283 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 4 Nov 2024 16:29:55 -0500 Subject: [PATCH] Add test of r#source that is not Error::source Without r#source: error[E0599]: the method `as_dyn_error` exists for type `char`, but its trait bounds were not satisfied --> tests/test_source.rs:72:9 | 72 | source: char, | ^^^^^^ method cannot be called on `char` due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `char: std::error::Error` which is required by `char: AsDynError<'_>` --- tests/test_source.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_source.rs b/tests/test_source.rs index 637f4ac0..29968bee 100644 --- a/tests/test_source.rs +++ b/tests/test_source.rs @@ -63,3 +63,20 @@ error_from_macro! { #[error("Something")] Variant(#[from] io::Error) } + +#[test] +fn test_not_source() { + #[derive(Error, Debug)] + #[error("{source} ==> {destination}")] + pub struct NotSource { + r#source: char, + destination: char, + } + + let error = NotSource { + source: 'S', + destination: 'D', + }; + assert_eq!(error.to_string(), "S ==> D"); + assert!(error.source().is_none()); +}