diff options
| author | Lzu Tao <taolzu@gmail.com> | 2019-08-22 10:03:26 +0700 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2019-08-25 20:36:11 +0700 |
| commit | dac2509bacd9e4c3f7cc27a4aeff38c5b0388840 (patch) | |
| tree | 24f143ac85d8a24762b49043a813b05ec006aafa | |
| parent | 05f603e6cec63d0b2681a84d4a64a51bccac1624 (diff) | |
| download | rust-dac2509bacd9e4c3f7cc27a4aeff38c5b0388840.tar.gz rust-dac2509bacd9e4c3f7cc27a4aeff38c5b0388840.zip | |
Account for trait alias when looking for defid
| -rw-r--r-- | clippy_lints/src/methods/mod.rs | 5 | ||||
| -rw-r--r-- | clippy_lints/src/utils/mod.rs | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index f7544e095b8..0eaec449dc4 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2781,7 +2781,10 @@ impl SelfKind { hir::Mutability::MutMutable => &paths::ASMUT_TRAIT, }; - let trait_def_id = get_trait_def_id(cx, trait_path).expect("trait def id not found"); + let trait_def_id = match get_trait_def_id(cx, trait_path) { + Some(did) => did, + None => return false, + }; implements_trait(cx, ty, trait_def_id, &[parent_ty.into()]) } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 2d772d77ed1..408deb1b402 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -261,6 +261,7 @@ pub fn path_to_res(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<(def::Res) } /// Convenience function to get the `DefId` of a trait by path. +/// It could be a trait or trait alias. pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<DefId> { let res = match path_to_res(cx, path) { Some(res) => res, @@ -268,7 +269,8 @@ pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<DefId }; match res { - def::Res::Def(DefKind::Trait, trait_id) => Some(trait_id), + Res::Def(DefKind::Trait, trait_id) | Res::Def(DefKind::TraitAlias, trait_id) => Some(trait_id), + Res::Err => unreachable!("this trait resolution is impossible: {:?}", &path), _ => None, } } |
