File tree 4 files changed +38
-16
lines changed
src/test/ui/consts/const-eval 4 files changed +38
-16
lines changed Original file line number Diff line number Diff line change 1
1
warning: any use of this value will cause an error
2
- --> $DIR/promoted_errors.rs:13 :5
2
+ --> $DIR/promoted_errors.rs:15 :5
3
3
|
4
4
LL | 0 - 1
5
5
| ^^^^^
6
6
| |
7
7
| attempt to compute `0_u32 - 1_u32`, which would overflow
8
- | inside `overflow` at $DIR/promoted_errors.rs:13 :5
9
- | inside `X` at $DIR/promoted_errors.rs:33 :29
8
+ | inside `overflow` at $DIR/promoted_errors.rs:15 :5
9
+ | inside `X` at $DIR/promoted_errors.rs:38 :29
10
10
...
11
11
LL | / const X: () = {
12
12
LL | | let _x: &'static u32 = &overflow();
@@ -18,15 +18,15 @@ LL | | };
18
18
| |__-
19
19
|
20
20
note: the lint level is defined here
21
- --> $DIR/promoted_errors.rs:9 :9
21
+ --> $DIR/promoted_errors.rs:11 :9
22
22
|
23
23
LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
24
24
| ^^^^^^^^^
25
25
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
26
26
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
27
27
28
28
warning: any use of this value will cause an error
29
- --> $DIR/promoted_errors.rs:33 :28
29
+ --> $DIR/promoted_errors.rs:38 :28
30
30
|
31
31
LL | / const X: () = {
32
32
LL | | let _x: &'static u32 = &overflow();
Original file line number Diff line number Diff line change 1
1
warning: any use of this value will cause an error
2
- --> $DIR/promoted_errors.rs:18 :5
2
+ --> $DIR/promoted_errors.rs:20 :5
3
3
|
4
4
LL | 1 / 0
5
5
| ^^^^^
6
6
| |
7
7
| attempt to divide `1_i32` by zero
8
- | inside `div_by_zero1` at $DIR/promoted_errors.rs:18 :5
9
- | inside `X` at $DIR/promoted_errors.rs:36 :29
8
+ | inside `div_by_zero1` at $DIR/promoted_errors.rs:20 :5
9
+ | inside `X` at $DIR/promoted_errors.rs:41 :29
10
10
...
11
11
LL | / const X: () = {
12
12
LL | | let _x: &'static u32 = &overflow();
@@ -18,15 +18,15 @@ LL | | };
18
18
| |__-
19
19
|
20
20
note: the lint level is defined here
21
- --> $DIR/promoted_errors.rs:9 :9
21
+ --> $DIR/promoted_errors.rs:11 :9
22
22
|
23
23
LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
24
24
| ^^^^^^^^^
25
25
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
26
26
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
27
27
28
28
warning: any use of this value will cause an error
29
- --> $DIR/promoted_errors.rs:36 :28
29
+ --> $DIR/promoted_errors.rs:41 :28
30
30
|
31
31
LL | / const X: () = {
32
32
LL | | let _x: &'static u32 = &overflow();
Original file line number Diff line number Diff line change 1
1
warning: any use of this value will cause an error
2
- --> $DIR/promoted_errors.rs:13 :5
2
+ --> $DIR/promoted_errors.rs:15 :5
3
3
|
4
4
LL | 0 - 1
5
5
| ^^^^^
6
6
| |
7
7
| attempt to compute `0_u32 - 1_u32`, which would overflow
8
- | inside `overflow` at $DIR/promoted_errors.rs:13 :5
9
- | inside `X` at $DIR/promoted_errors.rs:33 :29
8
+ | inside `overflow` at $DIR/promoted_errors.rs:15 :5
9
+ | inside `X` at $DIR/promoted_errors.rs:38 :29
10
10
...
11
11
LL | / const X: () = {
12
12
LL | | let _x: &'static u32 = &overflow();
@@ -18,15 +18,15 @@ LL | | };
18
18
| |__-
19
19
|
20
20
note: the lint level is defined here
21
- --> $DIR/promoted_errors.rs:9 :9
21
+ --> $DIR/promoted_errors.rs:11 :9
22
22
|
23
23
LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
24
24
| ^^^^^^^^^
25
25
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
26
26
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
27
27
28
28
warning: any use of this value will cause an error
29
- --> $DIR/promoted_errors.rs:33 :28
29
+ --> $DIR/promoted_errors.rs:38 :28
30
30
|
31
31
LL | / const X: () = {
32
32
LL | | let _x: &'static u32 = &overflow();
Original file line number Diff line number Diff line change 6
6
// build-pass
7
7
// ignore-pass (test emits codegen-time warnings and verifies that they are not errors)
8
8
9
+ //! This test ensures that when we promote code that fails to evaluate, the build still succeeds.
10
+
9
11
#![ warn( const_err, arithmetic_overflow, unconditional_panic) ]
10
12
11
13
// The only way to have promoteds that fail is in `const fn` called from `const`/`static`.
@@ -29,6 +31,9 @@ const fn oob() -> i32 {
29
31
[ 1 , 2 , 3 ] [ 4 ]
30
32
}
31
33
34
+ // An unused constant containing failing promoteds.
35
+ // This should work as long as `const_err` can be turned into just a warning;
36
+ // once it turns into a hard error, just remove `X`.
32
37
const X : ( ) = {
33
38
let _x: & ' static u32 = & overflow ( ) ;
34
39
//[opt_with_overflow_checks,noopt]~^ WARN any use of this value will cause an error
@@ -41,4 +46,21 @@ const X: () = {
41
46
let _x: & ' static i32 = & oob ( ) ;
42
47
} ;
43
48
44
- fn main ( ) { }
49
+ const fn mk_false ( ) -> bool { false }
50
+
51
+ // An actually used constant referencing failing promoteds in dead code.
52
+ // This needs to always work.
53
+ const Y : ( ) = {
54
+ if mk_false ( ) {
55
+ let _x: & ' static u32 = & overflow ( ) ;
56
+ let _x: & ' static i32 = & div_by_zero1 ( ) ;
57
+ let _x: & ' static i32 = & div_by_zero2 ( ) ;
58
+ let _x: & ' static i32 = & div_by_zero3 ( ) ;
59
+ let _x: & ' static i32 = & oob ( ) ;
60
+ }
61
+ ( )
62
+ } ;
63
+
64
+ fn main ( ) {
65
+ let _y = Y ;
66
+ }
You can’t perform that action at this time.
0 commit comments