Skip to content

Commit b571264

Browse files
Auto merge of #147876 - Shunpoco:lint-check-tainted-error, r=<try>
Check tainted_by_error in LateLint
2 parents d85276b + f61c361 commit b571264

File tree

7 files changed

+33
-12
lines changed

7 files changed

+33
-12
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ 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 typeck_result shouldn't be tainted, otherwise it will cause ICE.
93+
// If rustdoc is the caller of this function, we shouldn't run typeck_body here.
94+
if !self.context.tcx.sess.opts.actually_rustdoc
95+
&& self.context.tcx.typeck_body(body_id).tainted_by_errors.is_some()
96+
{
97+
return;
98+
}
99+
92100
let old_enclosing_body = self.context.enclosing_body.replace(body_id);
93101
let old_cached_typeck_results = self.context.cached_typeck_results.get();
94102

tests/crashes/138361.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/ui/consts/do-not-ice-long-constant-evaluation-in-for-loop.stderr renamed to tests/ui/consts/long-constant-evaluation-cause-dead-code.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: constant evaluation is taking a long time
2-
--> $DIR/do-not-ice-long-constant-evaluation-in-for-loop.rs:10:14
2+
--> $DIR/long-constant-evaluation-cause-dead-code.rs:10:14
33
|
44
LL | [(); loop {}];
55
| ^^^^^^^
66
|
77
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
88
If your compilation actually takes a long time, you can safely allow the lint.
99
help: the constant being evaluated
10-
--> $DIR/do-not-ice-long-constant-evaluation-in-for-loop.rs:10:14
10+
--> $DIR/long-constant-evaluation-cause-dead-code.rs:10:14
1111
|
1212
LL | [(); loop {}];
1313
| ^^^^^^^
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)