From a5445096551e111cbe952de9abc8e8f260f2157d Mon Sep 17 00:00:00 2001 From: tyranron Date: Mon, 19 Aug 2024 16:08:24 +0300 Subject: [PATCH] Consider imitation --- impl/src/fmt/mod.rs | 8 ++++++-- tests/debug.rs | 24 ++++++++++++++++++++++++ tests/display.rs | 21 +++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/impl/src/fmt/mod.rs b/impl/src/fmt/mod.rs index 9afd0cce..e09d3d68 100644 --- a/impl/src/fmt/mod.rs +++ b/impl/src/fmt/mod.rs @@ -632,8 +632,12 @@ impl ContainsGenericsExt for syn::Path { } self.segments .iter() - .any(|segment| match &segment.arguments { - syn::PathArguments::None => type_params.contains(&&segment.ident), + .enumerate() + .any(|(n, segment)| match &segment.arguments { + syn::PathArguments::None => { + // `TypeParam::AssocType` case. + (n == 0) && type_params.contains(&&segment.ident) + } syn::PathArguments::AngleBracketed( syn::AngleBracketedGenericArguments { args, .. }, ) => args.iter().any(|generic| match generic { diff --git a/tests/debug.rs b/tests/debug.rs index 3967a31c..68e01042 100644 --- a/tests/debug.rs +++ b/tests/debug.rs @@ -2116,6 +2116,19 @@ mod type_variables { elem: Option, } + #[derive(derive_more::Debug)] + struct CollidedPathName { + item: Item, + elem: Option, + } + + mod some_path { + use super::Debug; + + #[derive(Debug)] + pub struct Item; + } + #[test] fn assert() { assert_eq!( @@ -2166,5 +2179,16 @@ mod type_variables { ), "AssocType { iter: Empty, elem: None }", ); + + assert_eq!( + format!( + "{:?}", + CollidedPathName { + item: true, + elem: None, + }, + ), + "CollidedPathName { item: true, elem: None }", + ); } } diff --git a/tests/display.rs b/tests/display.rs index 16876a8c..10f11281 100644 --- a/tests/display.rs +++ b/tests/display.rs @@ -2519,6 +2519,18 @@ mod type_variables { elem: Option, } + #[derive(Display)] + #[display("{item:?} with {elem:?}")] + struct CollidedPathName { + item: Item, + elem: Option, + } + + mod some_path { + #[derive(Debug)] + pub struct Item; + } + #[test] fn assert() { assert_eq!( @@ -2577,5 +2589,14 @@ mod type_variables { .to_string(), "Empty with None", ); + + assert_eq!( + CollidedPathName { + item: false, + elem: Some(some_path::Item), + } + .to_string(), + "false with Some(Item)", + ); } }