about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Hansch <dev@phansch.net>2020-04-12 10:41:25 +0200
committerPhilipp Hansch <dev@phansch.net>2020-04-15 07:23:13 +0200
commit9ec95af7023634474f2ebfafe353624174af4d10 (patch)
tree3acbf771536bc7be80f10c20dd8f0dd15506eb91
parent97aa8dc778031f929a9563980b7766da0f8b9cf5 (diff)
downloadrust-9ec95af7023634474f2ebfafe353624174af4d10.tar.gz
rust-9ec95af7023634474f2ebfafe353624174af4d10.zip
Refactor: Use rustc's `match_def_path`
This replaces our match_def_path implementation with the rustc one.

Note that we can't just use it in all call sites because of the
`&[&str]` / `&[Symbol]` difference in Clippy/rustc.
-rw-r--r--clippy_lints/src/utils/mod.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs
index bf55e82f96f..f7a91fcdd21 100644
--- a/clippy_lints/src/utils/mod.rs
+++ b/clippy_lints/src/utils/mod.rs
@@ -1222,8 +1222,10 @@ pub fn is_normalizable<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, param_env: ty::Para
 }
 
 pub fn match_def_path<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, did: DefId, syms: &[&str]) -> bool {
-    let path = cx.get_def_path(did);
-    path.len() == syms.len() && path.into_iter().zip(syms.iter()).all(|(a, &b)| a.as_str() == b)
+    // We have to convert `syms` to `&[Symbol]` here because rustc's `match_def_path`
+    // accepts only that. We should probably move to Symbols in Clippy as well.
+    let syms = syms.iter().map(|p| Symbol::intern(p)).collect::<Vec<Symbol>>();
+    cx.match_def_path(did, &syms)
 }
 
 /// Returns the list of condition expressions and the list of blocks in a