Skip to content

Commit 4f773af

Browse files
Check for presence of field in typeck results before visiting it
Co-authored-by: Michael Goulet <michael@errs.io>
1 parent cb4d9a1 commit 4f773af

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
@@ -464,7 +464,11 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
464464
self.lookup_and_handle_method(expr.hir_id);
465465
}
466466
hir::ExprKind::Field(ref lhs, ..) => {
467-
self.handle_field_access(lhs, expr.hir_id);
467+
if self.typeck_results().opt_field_index(expr.hir_id).is_some() {
468+
self.handle_field_access(lhs, expr.hir_id);
469+
} else {
470+
self.tcx.dcx().span_delayed_bug(expr.span, "couldn't resolve index for field");
471+
}
468472
}
469473
hir::ExprKind::Struct(qpath, fields, _) => {
470474
let res = self.typeck_results().qpath_res(qpath, expr.hir_id);
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)