From 47ad24be161f22b1b931fd6d1da050682a70cf0f Mon Sep 17 00:00:00 2001 From: David Crossman <22548398+DavidCrossman@users.noreply.github.com> Date: Wed, 10 Jun 2026 15:28:08 +0100 Subject: [PATCH 1/3] Improve macro hygiene --- impl/src/error.rs | 9 ++++++--- impl/src/is_variant.rs | 2 +- impl/src/try_unwrap.rs | 6 +++--- impl/src/unwrap.rs | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/impl/src/error.rs b/impl/src/error.rs index a801dc20..5ee3d887 100644 --- a/impl/src/error.rs +++ b/impl/src/error.rs @@ -40,7 +40,7 @@ pub fn expand( // Not using `#[inline]` here on purpose, since this is almost never part // of a hot codepath. quote! { - fn source(&self) -> Option<&(dyn derive_more::core::error::Error + 'static)> { + fn source(&self) -> derive_more::core::option::Option<&(dyn derive_more::core::error::Error + 'static)> { use derive_more::__private::AsDynError as _; #source } @@ -166,7 +166,10 @@ fn render_enum( }) }; - let source = render(&mut source_match_arms, quote! { None }); + let source = render( + &mut source_match_arms, + quote! { derive_more::core::option::Option::None }, + ); let provide = render(&mut provide_match_arms, quote! { () }); Ok((bounds, source, provide)) @@ -287,7 +290,7 @@ fn render_some(mut expr: TokenStream, unpack: bool) -> TokenStream { if unpack { expr = quote! { derive_more::core::option::Option::as_ref(#expr)? } } - quote! { Some(#expr.__derive_more_as_dyn_error()) } + quote! { derive_more::core::option::Option::Some(#expr.__derive_more_as_dyn_error()) } } fn parse_fields<'input, 'state>( diff --git a/impl/src/is_variant.rs b/impl/src/is_variant.rs index 4ca7ebbb..d04a23b2 100644 --- a/impl/src/is_variant.rs +++ b/impl/src/is_variant.rs @@ -41,7 +41,7 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result TokenStr let error = quote! { derive_more::TryUnwrapError::<_>::new( val, - stringify!(#enum_name), - stringify!(#variant_ident), - stringify!(#func_name), + derive_more::core::stringify!(#enum_name), + derive_more::core::stringify!(#variant_ident), + derive_more::core::stringify!(#func_name), ) }; quote! { diff --git a/impl/src/unwrap.rs b/impl/src/unwrap.rs index 2df7732b..294ad96b 100644 --- a/impl/src/unwrap.rs +++ b/impl/src/unwrap.rs @@ -160,7 +160,7 @@ fn failed_block(state: &State, enum_name: &Ident, fn_name: &Ident) -> TokenStrea let panic_msg = format!( "called `{enum_name}::{fn_name}()` on a `{enum_name}::{variant_ident}` value" ); - quote! { #enum_name :: #variant_ident #data_pattern => panic!(#panic_msg) } + quote! { #enum_name :: #variant_ident #data_pattern => derive_more::core::panic!(#panic_msg) } }); quote! { From de5a30eba777b75bbde0a1b77348132188828182 Mon Sep 17 00:00:00 2001 From: David Crossman <22548398+DavidCrossman@users.noreply.github.com> Date: Thu, 11 Jun 2026 17:21:48 +0100 Subject: [PATCH 2/3] Update `compile_fail` tests --- tests/compile_fail/as_mut/renamed_generic.stderr | 3 +++ tests/compile_fail/as_ref/renamed_generic.stderr | 3 +++ tests/compile_fail/eq/non_eq_field.stderr | 1 - tests/compile_fail/eq/non_eq_field_recursive.stderr | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/compile_fail/as_mut/renamed_generic.stderr b/tests/compile_fail/as_mut/renamed_generic.stderr index 44bc9df0..9b440346 100644 --- a/tests/compile_fail/as_mut/renamed_generic.stderr +++ b/tests/compile_fail/as_mut/renamed_generic.stderr @@ -17,6 +17,9 @@ note: trait bound `Foo: AsMut>` was not satisfied | ^^^^^^^^^^^^^^^^^^ type parameter would need to implement `AsMut` note: the trait `AsMut` must be implemented --> $RUST/core/src/convert/mod.rs + | + | pub const trait AsMut: PointeeSized { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: consider manually implementing the trait to avoid undesired bounds = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `as_mut`, perhaps you need to implement it: diff --git a/tests/compile_fail/as_ref/renamed_generic.stderr b/tests/compile_fail/as_ref/renamed_generic.stderr index 3ece6ac8..a2d46150 100644 --- a/tests/compile_fail/as_ref/renamed_generic.stderr +++ b/tests/compile_fail/as_ref/renamed_generic.stderr @@ -17,6 +17,9 @@ note: trait bound `Foo: AsRef>` was not satisfied | ^^^^^^^^^^^^^^^^^^ type parameter would need to implement `AsRef` note: the trait `AsRef` must be implemented --> $RUST/core/src/convert/mod.rs + | + | pub const trait AsRef: PointeeSized { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: consider manually implementing the trait to avoid undesired bounds = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `as_ref`, perhaps you need to implement it: diff --git a/tests/compile_fail/eq/non_eq_field.stderr b/tests/compile_fail/eq/non_eq_field.stderr index ae02e14a..e93c539b 100644 --- a/tests/compile_fail/eq/non_eq_field.stderr +++ b/tests/compile_fail/eq/non_eq_field.stderr @@ -14,5 +14,4 @@ error[E0277]: the trait bound `f32: Eq` is not satisfied u128 u16 and $N others - = help: see issue #48214 = note: this error originates in the derive macro `derive_more::Eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/compile_fail/eq/non_eq_field_recursive.stderr b/tests/compile_fail/eq/non_eq_field_recursive.stderr index 0119f739..89fff75c 100644 --- a/tests/compile_fail/eq/non_eq_field_recursive.stderr +++ b/tests/compile_fail/eq/non_eq_field_recursive.stderr @@ -11,6 +11,9 @@ help: the trait `Eq` is not implemented for `NotEq` | ^^^^^^^^^^^^^^^ help: the trait `Eq` is implemented for `Box` --> $RUST/alloc/src/boxed.rs + | + | impl Eq for Box {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: required for `Box>` to implement `Eq` note: required by a bound in `derive_more::__private::AssertParamIsEq` --> src/cmp.rs From 21488b7b56f55da43795162105dde1f6076cf88b Mon Sep 17 00:00:00 2001 From: David Crossman <22548398+DavidCrossman@users.noreply.github.com> Date: Thu, 11 Jun 2026 17:59:36 +0100 Subject: [PATCH 3/3] Fix CI --- tests/compile_fail/as_mut/renamed_generic.stderr | 3 --- tests/compile_fail/as_ref/renamed_generic.stderr | 3 --- tests/compile_fail/eq/non_eq_field_recursive.stderr | 3 --- 3 files changed, 9 deletions(-) diff --git a/tests/compile_fail/as_mut/renamed_generic.stderr b/tests/compile_fail/as_mut/renamed_generic.stderr index 9b440346..44bc9df0 100644 --- a/tests/compile_fail/as_mut/renamed_generic.stderr +++ b/tests/compile_fail/as_mut/renamed_generic.stderr @@ -17,9 +17,6 @@ note: trait bound `Foo: AsMut>` was not satisfied | ^^^^^^^^^^^^^^^^^^ type parameter would need to implement `AsMut` note: the trait `AsMut` must be implemented --> $RUST/core/src/convert/mod.rs - | - | pub const trait AsMut: PointeeSized { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: consider manually implementing the trait to avoid undesired bounds = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `as_mut`, perhaps you need to implement it: diff --git a/tests/compile_fail/as_ref/renamed_generic.stderr b/tests/compile_fail/as_ref/renamed_generic.stderr index a2d46150..3ece6ac8 100644 --- a/tests/compile_fail/as_ref/renamed_generic.stderr +++ b/tests/compile_fail/as_ref/renamed_generic.stderr @@ -17,9 +17,6 @@ note: trait bound `Foo: AsRef>` was not satisfied | ^^^^^^^^^^^^^^^^^^ type parameter would need to implement `AsRef` note: the trait `AsRef` must be implemented --> $RUST/core/src/convert/mod.rs - | - | pub const trait AsRef: PointeeSized { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: consider manually implementing the trait to avoid undesired bounds = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `as_ref`, perhaps you need to implement it: diff --git a/tests/compile_fail/eq/non_eq_field_recursive.stderr b/tests/compile_fail/eq/non_eq_field_recursive.stderr index 89fff75c..0119f739 100644 --- a/tests/compile_fail/eq/non_eq_field_recursive.stderr +++ b/tests/compile_fail/eq/non_eq_field_recursive.stderr @@ -11,9 +11,6 @@ help: the trait `Eq` is not implemented for `NotEq` | ^^^^^^^^^^^^^^^ help: the trait `Eq` is implemented for `Box` --> $RUST/alloc/src/boxed.rs - | - | impl Eq for Box {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: required for `Box>` to implement `Eq` note: required by a bound in `derive_more::__private::AssertParamIsEq` --> src/cmp.rs