Skip to content

Commit bdeec5d

Browse files
committed
Use TypeckResults::expr_ty instead of TyCtxt::type_of to fix "Not a type" ICE
1 parent 7154b23 commit bdeec5d

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

clippy_lints/src/default_numeric_fallback.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
130130
}
131131
},
132132

133-
ExprKind::Struct(qpath, fields, base) => {
133+
ExprKind::Struct(_, fields, base) => {
134134
if_chain! {
135-
if let Some(def_id) = self.cx.qpath_res(qpath, expr.hir_id).opt_def_id();
136-
let ty = self.cx.tcx.type_of(def_id);
135+
let ty = self.cx.typeck_results().expr_ty(expr);
137136
if let Some(adt_def) = ty.ty_adt_def();
138137
if adt_def.is_struct();
139138
if let Some(variant) = adt_def.variants.iter().next();

clippy_lints/src/inconsistent_struct_constructor.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ impl LateLintPass<'_> for InconsistentStructConstructor {
6666
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
6767
if_chain! {
6868
if let ExprKind::Struct(qpath, fields, base) = expr.kind;
69-
if let Some(def_id) = cx.qpath_res(qpath, expr.hir_id).opt_def_id();
70-
let ty = cx.tcx.type_of(def_id);
69+
let ty = cx.typeck_results().expr_ty(expr);
7170
if let Some(adt_def) = ty.ty_adt_def();
7271
if adt_def.is_struct();
7372
if let Some(variant) = adt_def.variants.iter().next();

tests/ui/crashes/ice-6792.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! This is a reproducer for the ICE 6792: https://github.com/rust-lang/rust-clippy/issues/6792.
2+
//! The ICE is caused by using `TyCtxt::type_of(assoc_type_id)`.
3+
4+
trait Trait {
5+
type Ty;
6+
7+
fn broken() -> Self::Ty;
8+
}
9+
10+
struct Foo {}
11+
12+
impl Trait for Foo {
13+
type Ty = Foo;
14+
15+
fn broken() -> Self::Ty {
16+
Self::Ty {}
17+
}
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)