Skip to content

Commit 6971b0d

Browse files
committed
Auto merge of #6812 - Y-Nak:fix-6792, r=matthiaskrgr
Fix ICEs 6792 and 6793 fixes #6792, fixes #6793. r? `@matthiaskrgr` Fixes the ICEs by replacing `TyCtxt::type_of` with `TypeckResults::expr_ty`. changelog: none
2 parents 7154b23 + e51bb0e commit 6971b0d

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-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() {}

tests/ui/crashes/ice-6793.rs

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

0 commit comments

Comments
 (0)