diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-01-16 12:12:28 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-01-16 12:13:27 +0100 |
| commit | 169e2ab55b490a2b3103372b97a5d315ce8438e7 (patch) | |
| tree | d002ef8414452ef95073a40a81186428fb10cb2d | |
| parent | 37947ffc405c573c075e0471692e5b13332b22a6 (diff) | |
| download | rust-169e2ab55b490a2b3103372b97a5d315ce8438e7.tar.gz rust-169e2ab55b490a2b3103372b97a5d315ce8438e7.zip | |
Correctly handle type relative in `trait_duplication_in_bounds` lint
| -rw-r--r-- | clippy_lints/src/trait_bounds.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index e4054393d0a..768623b5d03 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -390,6 +390,14 @@ fn get_trait_info_from_bound<'a>(bound: &'a GenericBound<'_>) -> Option<(Res, &' } } +fn get_ty_res(ty: Ty<'_>) -> Option<Res> { + match ty.kind { + TyKind::Path(QPath::Resolved(_, path)) => Some(path.res), + TyKind::Path(QPath::TypeRelative(ty, _)) => get_ty_res(*ty), + _ => None, + } +} + // FIXME: ComparableTraitRef does not support nested bounds needed for associated_type_bounds fn into_comparable_trait_ref(trait_ref: &TraitRef<'_>) -> ComparableTraitRef { ComparableTraitRef( @@ -401,10 +409,8 @@ fn into_comparable_trait_ref(trait_ref: &TraitRef<'_>) -> ComparableTraitRef { .filter_map(|segment| { // get trait bound type arguments Some(segment.args?.args.iter().filter_map(|arg| { - if let GenericArg::Type(ty) = arg - && let TyKind::Path(QPath::Resolved(_, path)) = ty.kind - { - return Some(path.res); + if let GenericArg::Type(ty) = arg { + return get_ty_res(**ty); } None })) |
