Skip to content

Commit c297753

Browse files
Rollup merge of #120020 - oli-obk:long_const_eval_err_taint, r=compiler-errors
Gracefully handle missing typeck information if typeck errored fixes #116893 I created some logs and the typeck of `fn main` is exactly the same, no matter whether the constant's body is what it is, or if it is replaced with `panic!()`. The latter will cause the ICE not to be emitted though. The reason for that is that we abort compilation if *errors* were emitted, but not if *lint errors* were emitted. This took me way too long to debug, and is another reason why I would have liked rust-lang/compiler-team#633
2 parents f92cee2 + 3599c18 commit c297753

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1526,13 +1526,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15261526

15271527
self.check_repeat_element_needs_copy_bound(element, count, element_ty);
15281528

1529-
self.register_wf_obligation(
1530-
Ty::new_array_with_const_len(tcx, t, count).into(),
1531-
expr.span,
1532-
traits::WellFormed(None),
1533-
);
1529+
let ty = Ty::new_array_with_const_len(tcx, t, count);
1530+
1531+
self.register_wf_obligation(ty.into(), expr.span, traits::WellFormed(None));
15341532

1535-
Ty::new_array_with_const_len(tcx, t, count)
1533+
ty
15361534
}
15371535

15381536
fn check_repeat_element_needs_copy_bound(

compiler/rustc_passes/src/dead.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
128128
if let Some(def_id) = self.typeck_results().type_dependent_def_id(id) {
129129
self.check_def_id(def_id);
130130
} else {
131-
bug!("no type-dependent def for method");
131+
assert!(
132+
self.typeck_results().tainted_by_errors.is_some(),
133+
"no type-dependent def for method"
134+
);
132135
}
133136
}
134137

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
//! This test tests two things at once:
2+
//! 1. we error if a const evaluation hits the deny-by-default lint limit
3+
//! 2. we do not ICE on invalid follow-up code
4+
5+
// compile-flags: -Z tiny-const-eval-limit
6+
17
fn main() {
28
// Tests the Collatz conjecture with an incorrect base case (0 instead of 1).
39
// The value of `n` will loop indefinitely (4 - 2 - 1 - 4).
4-
let _ = [(); {
10+
let s = [(); {
511
let mut n = 113383; // #20 in https://oeis.org/A006884
612
while n != 0 {
713
//~^ ERROR is taking a long time
814
n = if n % 2 == 0 { n / 2 } else { 3 * n + 1 };
915
}
1016
n
1117
}];
18+
19+
s.nonexistent_method();
1220
}

tests/ui/consts/const-eval/infinite_loop.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: constant evaluation is taking a long time
2-
--> $DIR/infinite_loop.rs:6:9
2+
--> $DIR/infinite_loop.rs:12:9
33
|
44
LL | / while n != 0 {
55
LL | |
@@ -10,9 +10,9 @@ LL | | }
1010
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
1111
If your compilation actually takes a long time, you can safely allow the lint.
1212
help: the constant being evaluated
13-
--> $DIR/infinite_loop.rs:4:18
13+
--> $DIR/infinite_loop.rs:10:18
1414
|
15-
LL | let _ = [(); {
15+
LL | let s = [(); {
1616
| __________________^
1717
LL | | let mut n = 113383; // #20 in https://oeis.org/A006884
1818
LL | | while n != 0 {

0 commit comments

Comments
 (0)