Skip to content

Commit f39b6fd

Browse files
committed
Delay a bug on non-ADT field access to prevent ICEs on const eval fails in tys
1 parent cb4d9a1 commit f39b6fd

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

compiler/rustc_passes/src/dead.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
142142
self.insert_def_id(def.non_enum_variant().fields[index].did);
143143
}
144144
ty::Tuple(..) => {}
145-
_ => span_bug!(lhs.span, "named field access on non-ADT"),
145+
ty => {
146+
self.tcx
147+
.dcx()
148+
.span_delayed_bug(lhs.span, format!("named field access on non-ADT `{ty:?}`"));
149+
}
146150
}
147151
}
148152

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Regression test for issue #120615.
2+
3+
fn main() {
4+
[(); loop {}].field; //~ ERROR constant evaluation is taking a long time
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: constant evaluation is taking a long time
2+
--> $DIR/field-access-after-const-eval-fail-in-ty.rs:4:10
3+
|
4+
LL | [(); loop {}].field;
5+
| ^^^^^^^
6+
|
7+
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
8+
If your compilation actually takes a long time, you can safely allow the lint.
9+
help: the constant being evaluated
10+
--> $DIR/field-access-after-const-eval-fail-in-ty.rs:4:10
11+
|
12+
LL | [(); loop {}].field;
13+
| ^^^^^^^
14+
= note: `#[deny(long_running_const_eval)]` on by default
15+
16+
error: aborting due to 1 previous error
17+

0 commit comments

Comments
 (0)