Skip to content

Commit 58b98ba

Browse files
committed
Fix: early return if typeck_results is tainted by errors
1 parent 7479dd2 commit 58b98ba

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

compiler/rustc_lint/src/builtin.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ declare_lint_pass!(NonShorthandFieldPatterns => [NON_SHORTHAND_FIELD_PATTERNS]);
153153

154154
impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
155155
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &hir::Pat<'_>) {
156-
if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind {
156+
// The result shouldn't be tainted, otherwise it will cause ICE.
157+
if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind
158+
&& cx.typeck_results().tainted_by_errors.is_none()
159+
{
157160
let variant = cx
158161
.typeck_results()
159162
.pat_ty(pat)

compiler/rustc_passes/src/dead.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,14 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
521521

522522
impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
523523
fn visit_nested_body(&mut self, body: hir::BodyId) {
524-
let old_maybe_typeck_results =
525-
self.maybe_typeck_results.replace(self.tcx.typeck_body(body));
524+
let typeck_results = self.tcx.typeck_body(body);
525+
526+
// The result shouldn't be tainted, otherwise it will cause ICE.
527+
if typeck_results.tainted_by_errors.is_some() {
528+
return;
529+
}
530+
531+
let old_maybe_typeck_results = self.maybe_typeck_results.replace(typeck_results);
526532
let body = self.tcx.hir_body(body);
527533
self.visit_body(body);
528534
self.maybe_typeck_results = old_maybe_typeck_results;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Issue-125323
22
fn main() {
3-
for _ in 0..0 { //~ ERROR type annotations needed [E0282]
3+
for _ in 0..0 {
44
[(); loop {}]; //~ ERROR constant evaluation is taking a long time
55
}
66
}

tests/ui/consts/do-not-ice-long-constant-evaluation-in-for-loop.stderr

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,5 @@ LL | [(); loop {}];
1313
| ^^^^^^^
1414
= note: `#[deny(long_running_const_eval)]` on by default
1515

16-
error[E0282]: type annotations needed
17-
--> $DIR/do-not-ice-long-constant-evaluation-in-for-loop.rs:3:14
18-
|
19-
LL | for _ in 0..0 {
20-
| ^^^^ cannot infer type for struct `std::ops::Range<{integer}>`
21-
22-
error: aborting due to 2 previous errors
16+
error: aborting due to 1 previous error
2317

24-
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)