Skip to content

Commit 5387b24

Browse files
authored
Rollup merge of #86280 - JohnTitor:issue-76510, r=oli-obk
Add a regression test for issue-76510 Fixed by #78407, closes #76510 r? ``@oli-obk``
2 parents 9fcbbbb + d7db969 commit 5387b24

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0764]: mutable references are not allowed in the final value of constants
2+
--> $DIR/issue-76510.rs:5:29
3+
|
4+
LL | const S: &'static mut str = &mut " hello ";
5+
| ^^^^^^^^^^^^^^
6+
7+
error[E0658]: mutation through a reference is not allowed in constants
8+
--> $DIR/issue-76510.rs:5:29
9+
|
10+
LL | const S: &'static mut str = &mut " hello ";
11+
| ^^^^^^^^^^^^^^
12+
|
13+
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
14+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
15+
16+
error[E0596]: cannot borrow data in a `&` reference as mutable
17+
--> $DIR/issue-76510.rs:5:29
18+
|
19+
LL | const S: &'static mut str = &mut " hello ";
20+
| ^^^^^^^^^^^^^^ cannot borrow as mutable
21+
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+
╾─alloc2──╼ 07 00 00 00 │ ╾──╼....
31+
}
32+
33+
error: aborting due to 4 previous errors
34+
35+
Some errors have detailed explanations: E0080, E0596, E0658, E0764.
36+
For more information about an error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0764]: mutable references are not allowed in the final value of constants
2+
--> $DIR/issue-76510.rs:5:29
3+
|
4+
LL | const S: &'static mut str = &mut " hello ";
5+
| ^^^^^^^^^^^^^^
6+
7+
error[E0658]: mutation through a reference is not allowed in constants
8+
--> $DIR/issue-76510.rs:5:29
9+
|
10+
LL | const S: &'static mut str = &mut " hello ";
11+
| ^^^^^^^^^^^^^^
12+
|
13+
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
14+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
15+
16+
error[E0596]: cannot borrow data in a `&` reference as mutable
17+
--> $DIR/issue-76510.rs:5:29
18+
|
19+
LL | const S: &'static mut str = &mut " hello ";
20+
| ^^^^^^^^^^^^^^ cannot borrow as mutable
21+
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+
╾───────alloc2────────╼ 07 00 00 00 00 00 00 00 │ ╾──────╼........
31+
}
32+
33+
error: aborting due to 4 previous errors
34+
35+
Some errors have detailed explanations: E0080, E0596, E0658, E0764.
36+
For more information about an error, try `rustc --explain E0080`.

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

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// stderr-per-bitwidth
2+
3+
use std::mem::{transmute, ManuallyDrop};
4+
5+
const S: &'static mut str = &mut " hello ";
6+
//~^ ERROR: mutable references are not allowed in the final value of constants
7+
//~| ERROR: mutation through a reference is not allowed in constants
8+
//~| ERROR: cannot borrow data in a `&` reference as mutable
9+
//~| ERROR: it is undefined behavior to use this value
10+
11+
const fn trigger() -> [(); unsafe {
12+
let s = transmute::<(*const u8, usize), &ManuallyDrop<str>>((S.as_ptr(), 3));
13+
0
14+
}] {
15+
[(); 0]
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)