File tree 3 files changed +17
-6
lines changed
compiler/rustc_passes/src
tests/ui/consts/const-eval
3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -423,8 +423,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
423
423
424
424
impl < ' tcx > Visitor < ' tcx > for MarkSymbolVisitor < ' tcx > {
425
425
fn visit_nested_body ( & mut self , body : hir:: BodyId ) {
426
- let old_maybe_typeck_results =
427
- self . maybe_typeck_results . replace ( self . tcx . typeck_body ( body) ) ;
426
+ let typeck_results = self . tcx . typeck_body ( body) ;
427
+ if typeck_results. tainted_by_errors . is_some ( ) {
428
+ return ;
429
+ }
430
+ let old_maybe_typeck_results = self . maybe_typeck_results . replace ( typeck_results) ;
428
431
let body = self . tcx . hir ( ) . body ( body) ;
429
432
self . visit_body ( body) ;
430
433
self . maybe_typeck_results = old_maybe_typeck_results;
Original file line number Diff line number Diff line change
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
+
1
7
fn main ( ) {
2
8
// Tests the Collatz conjecture with an incorrect base case (0 instead of 1).
3
9
// The value of `n` will loop indefinitely (4 - 2 - 1 - 4).
4
- let _ = [ ( ) ; {
10
+ let s = [ ( ) ; {
5
11
let mut n = 113383 ; // #20 in https://oeis.org/A006884
6
12
while n != 0 {
7
13
//~^ ERROR is taking a long time
8
14
n = if n % 2 == 0 { n / 2 } else { 3 * n + 1 } ;
9
15
}
10
16
n
11
17
} ] ;
18
+
19
+ s. nonexistent_method ( ) ;
12
20
}
Original file line number Diff line number Diff line change 1
1
error: constant evaluation is taking a long time
2
- --> $DIR/infinite_loop.rs:6 :9
2
+ --> $DIR/infinite_loop.rs:12 :9
3
3
|
4
4
LL | / while n != 0 {
5
5
LL | |
@@ -10,9 +10,9 @@ LL | | }
10
10
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
11
11
If your compilation actually takes a long time, you can safely allow the lint.
12
12
help: the constant being evaluated
13
- --> $DIR/infinite_loop.rs:4 :18
13
+ --> $DIR/infinite_loop.rs:10 :18
14
14
|
15
- LL | let _ = [(); {
15
+ LL | let s = [(); {
16
16
| __________________^
17
17
LL | | let mut n = 113383; // #20 in https://oeis.org/A006884
18
18
LL | | while n != 0 {
You can’t perform that action at this time.
0 commit comments