Skip to content

Commit 89b888d

Browse files
committed
Account for trait alias when looking for defid
1 parent 7a11843 commit 89b888d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,8 @@ impl SelfKind {
27992799
hir::Mutability::MutMutable => &paths::ASMUT_TRAIT,
28002800
};
28012801

2802-
let trait_def_id = get_trait_def_id(cx, trait_path).expect("trait def id not found");
2802+
let trait_def_id =
2803+
get_trait_def_id(cx, trait_path).unwrap_or_else(|| panic!("trait def id not found: {:?}", &trait_path));
28032804
implements_trait(cx, ty, trait_def_id, &[parent_ty.into()])
28042805
}
28052806

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)