Skip to content

Commit 9074427

Browse files
committed
Do not ICE in privacy when type inference fails.
1 parent 55cac26 commit 9074427

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

Diff for: compiler/rustc_privacy/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,12 @@ impl<'tcx> NamePrivacyVisitor<'tcx> {
973973

974974
impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
975975
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
976-
let old_maybe_typeck_results =
977-
self.maybe_typeck_results.replace(self.tcx.typeck_body(body_id));
976+
let new_typeck_results = self.tcx.typeck_body(body_id);
977+
// Do not try reporting privacy violations if we failed to infer types.
978+
if new_typeck_results.tainted_by_errors.is_some() {
979+
return;
980+
}
981+
let old_maybe_typeck_results = self.maybe_typeck_results.replace(new_typeck_results);
978982
self.visit_body(self.tcx.hir().body(body_id));
979983
self.maybe_typeck_results = old_maybe_typeck_results;
980984
}

Diff for: tests/crashes/122736.rs renamed to tests/ui/privacy/no-ice-on-inference-failure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//@ known-bug: #122736
21
fn main_ref() {
32
let array = [(); {
43
let mut x = &0;
54
let mut n = 0;
65
while n < 5 {
6+
//~^ ERROR constant evaluation is taking a long time
77
x = &0;
88
}
99
0

Diff for: tests/ui/privacy/no-ice-on-inference-failure.stderr

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: constant evaluation is taking a long time
2+
--> $DIR/no-ice-on-inference-failure.rs:5:9
3+
|
4+
LL | / while n < 5 {
5+
LL | |
6+
LL | | x = &0;
7+
LL | | }
8+
| |_________^
9+
|
10+
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
11+
If your compilation actually takes a long time, you can safely allow the lint.
12+
help: the constant being evaluated
13+
--> $DIR/no-ice-on-inference-failure.rs:2:22
14+
|
15+
LL | let array = [(); {
16+
| ______________________^
17+
LL | | let mut x = &0;
18+
LL | | let mut n = 0;
19+
LL | | while n < 5 {
20+
... |
21+
LL | | 0
22+
LL | | }];
23+
| |_____^
24+
= note: `#[deny(long_running_const_eval)]` on by default
25+
26+
error: aborting due to 1 previous error
27+

0 commit comments

Comments
 (0)