Skip to content

Commit 11c5ecd

Browse files
committed
visit_nested_body for LateLint should return earlier if there is an error
We started to check typeck result's tainted_by_errors in check_pat for LateLint, But ideally the check should be in a better place which all lints profit from it. visit_nested_body is the place because it's the starting point of linting body.
1 parent e124355 commit 11c5ecd

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,7 @@ declare_lint_pass!(NonShorthandFieldPatterns => [NON_SHORTHAND_FIELD_PATTERNS]);
152152

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

compiler/rustc_lint/src/late.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
8989
}
9090

9191
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
92+
// The result shouldn't be tainted, otherwise it will cause ICE.
93+
if self.context.tcx.typeck_body(body_id).tainted_by_errors.is_some() {
94+
return;
95+
}
96+
9297
let old_enclosing_body = self.context.enclosing_body.replace(body_id);
9398
let old_cached_typeck_results = self.context.cached_typeck_results.get();
9499

tests/crashes/138361.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// The test confirms ICE-138361 is fixed.
2+
fn main() {
3+
[0; loop{}]; //~ ERROR constant evaluation is taking a long time
4+
std::mem::transmute(4)
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: constant evaluation is taking a long time
2+
--> $DIR/long-constant-evaluation-cause-ice-in-sty.rs:3:7
3+
|
4+
LL | [0; loop{}];
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/long-constant-evaluation-cause-ice-in-sty.rs:3:7
11+
|
12+
LL | [0; loop{}];
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)