]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/utils/mod.rs
Auto merge of #4551 - mikerite:fix-ice-reporting, r=llogiq
[rust.git] / clippy_lints / src / utils / mod.rs
index 41b472b2764aee26604bed007617f83cc6b91ec6..9165f8d74d7831bc1f2e453a2b58100db5d1260f 100644 (file)
@@ -273,6 +273,19 @@ pub fn path_to_res(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<(def::Res)
     }
 }
 
+pub fn qpath_res(cx: &LateContext<'_, '_>, qpath: &hir::QPath, id: hir::HirId) -> Res {
+    match qpath {
+        hir::QPath::Resolved(_, path) => path.res,
+        hir::QPath::TypeRelative(..) => {
+            if cx.tcx.has_typeck_tables(id.owner_def_id()) {
+                cx.tcx.typeck_tables_of(id.owner_def_id()).qpath_res(qpath, id)
+            } else {
+                Res::Err
+            }
+        },
+    }
+}
+
 /// 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> {