Skip to content

Commit

Permalink
Consider imitation
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Aug 19, 2024
1 parent 84b6d98 commit a544509
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
8 changes: 6 additions & 2 deletions impl/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions tests/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,19 @@ mod type_variables {
elem: Option<I::Item>,
}

#[derive(derive_more::Debug)]
struct CollidedPathName<Item> {
item: Item,
elem: Option<some_path::Item>,
}

mod some_path {
use super::Debug;

#[derive(Debug)]
pub struct Item;
}

#[test]
fn assert() {
assert_eq!(
Expand Down Expand Up @@ -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 }",
);
}
}
21 changes: 21 additions & 0 deletions tests/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,18 @@ mod type_variables {
elem: Option<I::Item>,
}

#[derive(Display)]
#[display("{item:?} with {elem:?}")]
struct CollidedPathName<Item> {
item: Item,
elem: Option<some_path::Item>,
}

mod some_path {
#[derive(Debug)]
pub struct Item;
}

#[test]
fn assert() {
assert_eq!(
Expand Down Expand Up @@ -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)",
);
}
}

0 comments on commit a544509

Please sign in to comment.