Skip to content

Issue-125323: ICE non-ADT in struct pattern when long time constant evaluation is in for loop #138679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ declare_lint_pass!(NonShorthandFieldPatterns => [NON_SHORTHAND_FIELD_PATTERNS]);

impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &hir::Pat<'_>) {
if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind {
// The result shouldn't be tainted, otherwise it will cause ICE.
if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind
&& cx.typeck_results().tainted_by_errors.is_none()
{
let variant = cx
.typeck_results()
.pat_ty(pat)
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,14 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {

impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_maybe_typeck_results =
self.maybe_typeck_results.replace(self.tcx.typeck_body(body));
let typeck_results = self.tcx.typeck_body(body);

// The result shouldn't be tainted, otherwise it will cause ICE.
if typeck_results.tainted_by_errors.is_some() {
return;
}

let old_maybe_typeck_results = self.maybe_typeck_results.replace(typeck_results);
let body = self.tcx.hir_body(body);
self.visit_body(body);
self.maybe_typeck_results = old_maybe_typeck_results;
Expand Down
6 changes: 0 additions & 6 deletions tests/crashes/125323.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Issue-125323
fn main() {
for _ in 0..0 {
[(); loop {}]; //~ 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/do-not-ice-long-constant-evaluation-in-for-loop.rs:4:14
|
LL | [(); loop {}];
| ^^^^^^^
|
= 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/do-not-ice-long-constant-evaluation-in-for-loop.rs:4:14
|
LL | [(); loop {}];
| ^^^^^^^
= note: `#[deny(long_running_const_eval)]` on by default

error: aborting due to 1 previous error

Loading