Skip to content

Commit 06eb912

Browse files
fix tests, add new tests checking borrowck CFTE ICE
1 parent 77dae2d commit 06eb912

File tree

7 files changed

+23
-40
lines changed

7 files changed

+23
-40
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
struct X<const N: usize = {
2+
let s: &'static str; s.len()
3+
//~^ ERROR borrow of possibly-uninitialized variable
4+
}>;
5+
6+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0381]: borrow of possibly-uninitialized variable: `s`
2+
--> $DIR/const-generic-default-wont-borrowck.rs:2:26
3+
|
4+
LL | let s: &'static str; s.len()
5+
| ^^^^^^^ use of possibly-uninitialized `*s`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0381`.

src/test/ui/consts/const-mut-refs/issue-76510.32bit.stderr

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,7 @@ error[E0596]: cannot borrow data in a `&` reference as mutable
1919
LL | const S: &'static mut str = &mut " hello ";
2020
| ^^^^^^^^^^^^^^ cannot borrow as mutable
2121

22-
error[E0080]: it is undefined behavior to use this value
23-
--> $DIR/issue-76510.rs:5:1
24-
|
25-
LL | const S: &'static mut str = &mut " hello ";
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered mutable reference in a `const`
27-
|
28-
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
29-
= note: the raw bytes of the constant (size: 8, align: 4) {
30-
╾─alloc3──╼ 07 00 00 00 │ ╾──╼....
31-
}
32-
33-
error: aborting due to 4 previous errors
22+
error: aborting due to 3 previous errors
3423

35-
Some errors have detailed explanations: E0080, E0596, E0658, E0764.
36-
For more information about an error, try `rustc --explain E0080`.
24+
Some errors have detailed explanations: E0596, E0658, E0764.
25+
For more information about an error, try `rustc --explain E0596`.

src/test/ui/consts/const-mut-refs/issue-76510.64bit.stderr

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,7 @@ error[E0596]: cannot borrow data in a `&` reference as mutable
1919
LL | const S: &'static mut str = &mut " hello ";
2020
| ^^^^^^^^^^^^^^ cannot borrow as mutable
2121

22-
error[E0080]: it is undefined behavior to use this value
23-
--> $DIR/issue-76510.rs:5:1
24-
|
25-
LL | const S: &'static mut str = &mut " hello ";
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered mutable reference in a `const`
27-
|
28-
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
29-
= note: the raw bytes of the constant (size: 16, align: 8) {
30-
╾───────alloc3────────╼ 07 00 00 00 00 00 00 00 │ ╾──────╼........
31-
}
32-
33-
error: aborting due to 4 previous errors
22+
error: aborting due to 3 previous errors
3423

35-
Some errors have detailed explanations: E0080, E0596, E0658, E0764.
36-
For more information about an error, try `rustc --explain E0080`.
24+
Some errors have detailed explanations: E0596, E0658, E0764.
25+
For more information about an error, try `rustc --explain E0596`.

src/test/ui/consts/const-mut-refs/issue-76510.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const S: &'static mut str = &mut " hello ";
66
//~^ ERROR: mutable references are not allowed in the final value of constants
77
//~| ERROR: mutation through a reference is not allowed in constants
88
//~| ERROR: cannot borrow data in a `&` reference as mutable
9-
//~| ERROR: it is undefined behavior to use this value
109

1110
const fn trigger() -> [(); unsafe {
1211
let s = transmute::<(*const u8, usize), &ManuallyDrop<str>>((S.as_ptr(), 3));

src/test/ui/consts/issue-78655.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const FOO: *const u32 = { //~ ERROR encountered dangling pointer in final constant
1+
const FOO: *const u32 = {
22
let x;
33
&x //~ ERROR borrow of possibly-uninitialized variable: `x`
44
};

src/test/ui/consts/issue-78655.stderr

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ error[E0381]: borrow of possibly-uninitialized variable: `x`
44
LL | &x
55
| ^^ use of possibly-uninitialized `x`
66

7-
error: encountered dangling pointer in final constant
8-
--> $DIR/issue-78655.rs:1:1
9-
|
10-
LL | / const FOO: *const u32 = {
11-
LL | | let x;
12-
LL | | &x
13-
LL | | };
14-
| |__^
15-
167
error: could not evaluate constant pattern
178
--> $DIR/issue-78655.rs:7:9
189
|
@@ -25,6 +16,6 @@ error: could not evaluate constant pattern
2516
LL | let FOO = FOO;
2617
| ^^^
2718

28-
error: aborting due to 4 previous errors
19+
error: aborting due to 3 previous errors
2920

3021
For more information about this error, try `rustc --explain E0381`.

0 commit comments

Comments
 (0)