about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYoshitomo Nakanishi <yurayura.rounin.3@gmail.com>2021-02-27 21:52:15 +0900
committerYoshitomo Nakanishi <yurayura.rounin.3@gmail.com>2021-02-27 22:57:29 +0900
commitbdeec5dbd6e484cec26039cb795193ab044cf4d9 (patch)
tree70bea6f06c2025cddafe38255b820c162055e27c
parent7154b2360114977cd67bb844114cf429fa9cdb88 (diff)
downloadrust-bdeec5dbd6e484cec26039cb795193ab044cf4d9.tar.gz
rust-bdeec5dbd6e484cec26039cb795193ab044cf4d9.zip
Use TypeckResults::expr_ty instead of TyCtxt::type_of to fix "Not a type" ICE
-rw-r--r--clippy_lints/src/default_numeric_fallback.rs5
-rw-r--r--clippy_lints/src/inconsistent_struct_constructor.rs3
-rw-r--r--tests/ui/crashes/ice-6792.rs20
3 files changed, 23 insertions, 5 deletions
diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs
index 6ace9aa6bdf..369efacc9bc 100644
--- a/clippy_lints/src/default_numeric_fallback.rs
+++ b/clippy_lints/src/default_numeric_fallback.rs
@@ -130,10 +130,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
                 }
             },
 
-            ExprKind::Struct(qpath, fields, base) => {
+            ExprKind::Struct(_, fields, base) => {
                 if_chain! {
-                    if let Some(def_id) = self.cx.qpath_res(qpath, expr.hir_id).opt_def_id();
-                    let ty = self.cx.tcx.type_of(def_id);
+                    let ty = self.cx.typeck_results().expr_ty(expr);
                     if let Some(adt_def) = ty.ty_adt_def();
                     if adt_def.is_struct();
                     if let Some(variant) = adt_def.variants.iter().next();
diff --git a/clippy_lints/src/inconsistent_struct_constructor.rs b/clippy_lints/src/inconsistent_struct_constructor.rs
index c5afdf530eb..4f35e13c85a 100644
--- a/clippy_lints/src/inconsistent_struct_constructor.rs
+++ b/clippy_lints/src/inconsistent_struct_constructor.rs
@@ -66,8 +66,7 @@ impl LateLintPass<'_> for InconsistentStructConstructor {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
         if_chain! {
             if let ExprKind::Struct(qpath, fields, base) = expr.kind;
-            if let Some(def_id)  = cx.qpath_res(qpath, expr.hir_id).opt_def_id();
-            let ty = cx.tcx.type_of(def_id);
+            let ty = cx.typeck_results().expr_ty(expr);
             if let Some(adt_def) = ty.ty_adt_def();
             if adt_def.is_struct();
             if let Some(variant) = adt_def.variants.iter().next();
diff --git a/tests/ui/crashes/ice-6792.rs b/tests/ui/crashes/ice-6792.rs
new file mode 100644
index 00000000000..0e2ab1a39b8
--- /dev/null
+++ b/tests/ui/crashes/ice-6792.rs
@@ -0,0 +1,20 @@
+//! This is a reproducer for the ICE 6792: https://github.com/rust-lang/rust-clippy/issues/6792.
+//! The ICE is caused by using `TyCtxt::type_of(assoc_type_id)`.
+
+trait Trait {
+    type Ty;
+
+    fn broken() -> Self::Ty;
+}
+
+struct Foo {}
+
+impl Trait for Foo {
+    type Ty = Foo;
+
+    fn broken() -> Self::Ty {
+        Self::Ty {}
+    }
+}
+
+fn main() {}