Skip to content

Commit cd7a8f5

Browse files
committed
Fix: early return if typeck_results is tainted by errors
1 parent 07dca96 commit cd7a8f5

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
@@ -151,7 +151,10 @@ declare_lint_pass!(NonShorthandFieldPatterns => [NON_SHORTHAND_FIELD_PATTERNS]);
151151

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

compiler/rustc_passes/src/dead.rs

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

558558
impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
559559
fn visit_nested_body(&mut self, body: hir::BodyId) {
560-
let old_maybe_typeck_results =
561-
self.maybe_typeck_results.replace(self.tcx.typeck_body(body));
560+
let typeck_results = self.tcx.typeck_body(body);
561+
562+
// The result shouldn't be tainted, otherwise it will cause ICE.
563+
if typeck_results.tainted_by_errors.is_some() {
564+
return;
565+
}
566+
567+
let old_maybe_typeck_results = self.maybe_typeck_results.replace(typeck_results);
562568
let body = self.tcx.hir_body(body);
563569
self.visit_body(body);
564570
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)