diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 9dccd4a0552c3..a7ae709f712ee 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -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) diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index f77e1db42d4d2..39b8d6a12643a 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -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; diff --git a/tests/crashes/125323.rs b/tests/crashes/125323.rs deleted file mode 100644 index 180b7bbad097d..0000000000000 --- a/tests/crashes/125323.rs +++ /dev/null @@ -1,6 +0,0 @@ -//@ known-bug: rust-lang/rust#125323 -fn main() { - for _ in 0..0 { - [(); loop {}]; - } -} diff --git a/tests/ui/consts/do-not-ice-long-constant-evaluation-in-for-loop.rs b/tests/ui/consts/do-not-ice-long-constant-evaluation-in-for-loop.rs new file mode 100644 index 0000000000000..e5a45f032f285 --- /dev/null +++ b/tests/ui/consts/do-not-ice-long-constant-evaluation-in-for-loop.rs @@ -0,0 +1,6 @@ +// Issue-125323 +fn main() { + for _ in 0..0 { + [(); loop {}]; //~ ERROR constant evaluation is taking a long time + } +} diff --git a/tests/ui/consts/do-not-ice-long-constant-evaluation-in-for-loop.stderr b/tests/ui/consts/do-not-ice-long-constant-evaluation-in-for-loop.stderr new file mode 100644 index 0000000000000..dd4578b7f72a5 --- /dev/null +++ b/tests/ui/consts/do-not-ice-long-constant-evaluation-in-for-loop.stderr @@ -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 +