Skip to content

Commit dac2509

Browse files
committed
Account for trait alias when looking for defid
1 parent 05f603e commit dac2509

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,10 @@ impl SelfKind {
27812781
hir::Mutability::MutMutable => &paths::ASMUT_TRAIT,
27822782
};
27832783

2784-
let trait_def_id = get_trait_def_id(cx, trait_path).expect("trait def id not found");
2784+
let trait_def_id = match get_trait_def_id(cx, trait_path) {
2785+
Some(did) => did,
2786+
None => return false,
2787+
};
27852788
implements_trait(cx, ty, trait_def_id, &[parent_ty.into()])
27862789
}
27872790

clippy_lints/src/utils/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,16 @@ pub fn path_to_res(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<(def::Res)
261261
}
262262

263263
/// Convenience function to get the `DefId` of a trait by path.
264+
/// It could be a trait or trait alias.
264265
pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<DefId> {
265266
let res = match path_to_res(cx, path) {
266267
Some(res) => res,
267268
None => return None,
268269
};
269270

270271
match res {
271-
def::Res::Def(DefKind::Trait, trait_id) => Some(trait_id),
272+
Res::Def(DefKind::Trait, trait_id) | Res::Def(DefKind::TraitAlias, trait_id) => Some(trait_id),
273+
Res::Err => unreachable!("this trait resolution is impossible: {:?}", &path),
272274
_ => None,
273275
}
274276
}

0 commit comments

Comments
 (0)