Skip to content

Commit

Permalink
Rollup merge of rust-lang#120616 - fmease:fix-ice-const-eval-fail-und…
Browse files Browse the repository at this point in the history
…ef-field-access, r=compiler-errors

Fix ICE on field access on a tainted type after const-eval failure

Fixes rust-lang#120615.

r? oli-obk or compiler
  • Loading branch information
matthiaskrgr authored Feb 3, 2024
2 parents 2a8fc94 + 4f773af commit 326839b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,11 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
self.lookup_and_handle_method(expr.hir_id);
}
hir::ExprKind::Field(ref lhs, ..) => {
self.handle_field_access(lhs, expr.hir_id);
if self.typeck_results().opt_field_index(expr.hir_id).is_some() {
self.handle_field_access(lhs, expr.hir_id);
} else {
self.tcx.dcx().span_delayed_bug(expr.span, "couldn't resolve index for field");
}
}
hir::ExprKind::Struct(qpath, fields, _) => {
let res = self.typeck_results().qpath_res(qpath, expr.hir_id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Regression test for issue #120615.

fn main() {
[(); loop {}].field; //~ ERROR constant evaluation is taking a long time
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: constant evaluation is taking a long time
--> $DIR/field-access-after-const-eval-fail-in-ty.rs:4:10
|
LL | [(); loop {}].field;
| ^^^^^^^
|
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
If your compilation actually takes a long time, you can safely allow the lint.
help: the constant being evaluated
--> $DIR/field-access-after-const-eval-fail-in-ty.rs:4:10
|
LL | [(); loop {}].field;
| ^^^^^^^
= note: `#[deny(long_running_const_eval)]` on by default

error: aborting due to 1 previous error

0 comments on commit 326839b

Please sign in to comment.