Skip to content

Commit 2bd9479

Browse files
committedAug 9, 2022
compare with-flag to without-flag
1 parent 7b2a5f2 commit 2bd9479

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed
 

‎src/test/ui/consts/extra-const-ub/detect-extra-ub.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1-
// compile-flags: -Zextra-const-ub-checks
1+
// revisions: no_flag with_flag
2+
// [no_flag] check-pass
3+
// [with_flag] compile-flags: -Zextra-const-ub-checks
24
#![feature(const_ptr_read)]
35

46
use std::mem::transmute;
57

68
const INVALID_BOOL: () = unsafe {
79
let _x: bool = transmute(3u8);
8-
//~^ ERROR: evaluation of constant value failed
9-
//~| invalid value
10+
//[with_flag]~^ ERROR: evaluation of constant value failed
11+
//[with_flag]~| invalid value
1012
};
1113

1214
const INVALID_PTR_IN_INT: () = unsafe {
1315
let _x: usize = transmute(&3u8);
14-
//~^ ERROR: evaluation of constant value failed
15-
//~| invalid value
16+
//[with_flag]~^ ERROR: evaluation of constant value failed
17+
//[with_flag]~| invalid value
1618
};
1719

1820
const INVALID_SLICE_TO_USIZE_TRANSMUTE: () = unsafe {
1921
let x: &[u8] = &[0; 32];
2022
let _x: (usize, usize) = transmute(x);
21-
//~^ ERROR: evaluation of constant value failed
22-
//~| invalid value
23+
//[with_flag]~^ ERROR: evaluation of constant value failed
24+
//[with_flag]~| invalid value
2325
};
2426

2527
const UNALIGNED_PTR: () = unsafe {
2628
let _x: &u32 = transmute(&[0u8; 4]);
27-
//~^ ERROR: evaluation of constant value failed
28-
//~| invalid value
29+
//[with_flag]~^ ERROR: evaluation of constant value failed
30+
//[with_flag]~| invalid value
2931
};
3032

3133
const UNALIGNED_READ: () = {
32-
INNER; //~ERROR any use of this value will cause an error
33-
//~| previously accepted
34+
INNER; //[with_flag]~ERROR any use of this value will cause an error
35+
//[with_flag]~| previously accepted
3436
// There is an error here but its span is in the standard library so we cannot match it...
3537
// so we have this in a *nested* const, such that the *outer* const fails to use it.
3638
const INNER: () = unsafe {

‎src/test/ui/consts/extra-const-ub/detect-extra-ub.stderr ‎src/test/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/detect-extra-ub.rs:7:20
2+
--> $DIR/detect-extra-ub.rs:9:20
33
|
44
LL | let _x: bool = transmute(3u8);
55
| ^^^^^^^^^^^^^^ constructing invalid value: encountered 0x03, but expected a boolean
66

77
error[E0080]: evaluation of constant value failed
8-
--> $DIR/detect-extra-ub.rs:13:21
8+
--> $DIR/detect-extra-ub.rs:15:21
99
|
1010
LL | let _x: usize = transmute(&3u8);
1111
| ^^^^^^^^^^^^^^^ constructing invalid value: encountered (potentially part of) a pointer, but expected plain (non-pointer) bytes
1212

1313
error[E0080]: evaluation of constant value failed
14-
--> $DIR/detect-extra-ub.rs:20:30
14+
--> $DIR/detect-extra-ub.rs:22:30
1515
|
1616
LL | let _x: (usize, usize) = transmute(x);
1717
| ^^^^^^^^^^^^ constructing invalid value at .0: encountered (potentially part of) a pointer, but expected plain (non-pointer) bytes
1818

1919
error[E0080]: evaluation of constant value failed
20-
--> $DIR/detect-extra-ub.rs:26:20
20+
--> $DIR/detect-extra-ub.rs:28:20
2121
|
2222
LL | let _x: &u32 = transmute(&[0u8; 4]);
2323
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 4 byte alignment but found 1)
@@ -36,13 +36,13 @@ LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
3636
LL | unsafe { read(self) }
3737
| ---------- inside `ptr::const_ptr::<impl *const u32>::read` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
3838
|
39-
::: $DIR/detect-extra-ub.rs:39:9
39+
::: $DIR/detect-extra-ub.rs:41:9
4040
|
4141
LL | ptr.read();
42-
| ---------- inside `INNER` at $DIR/detect-extra-ub.rs:39:9
42+
| ---------- inside `INNER` at $DIR/detect-extra-ub.rs:41:9
4343

4444
error: any use of this value will cause an error
45-
--> $DIR/detect-extra-ub.rs:32:5
45+
--> $DIR/detect-extra-ub.rs:34:5
4646
|
4747
LL | const UNALIGNED_READ: () = {
4848
| ------------------------
@@ -58,7 +58,7 @@ error: aborting due to 6 previous errors
5858
For more information about this error, try `rustc --explain E0080`.
5959
Future incompatibility report: Future breakage diagnostic:
6060
error: any use of this value will cause an error
61-
--> $DIR/detect-extra-ub.rs:32:5
61+
--> $DIR/detect-extra-ub.rs:34:5
6262
|
6363
LL | const UNALIGNED_READ: () = {
6464
| ------------------------

0 commit comments

Comments
 (0)
Please sign in to comment.