Skip to content

Commit 28ddda7

Browse files
committed
add compile-fail test for &mut promotion
1 parent 720293b commit 28ddda7

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/test/ui/consts/promote-no-mut.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// ignore-tidy-linelength
2+
// We do not promote mutable references.
3+
static mut TEST1: Option<&mut [i32]> = Some(&mut [1, 2, 3]); //~ ERROR temporary value dropped while borrowed
4+
5+
static mut TEST2: &'static mut [i32] = {
6+
let x = &mut [1,2,3]; //~ ERROR temporary value dropped while borrowed
7+
x
8+
};
9+
10+
fn main() {}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0716]: temporary value dropped while borrowed
2+
--> $DIR/promote-no-mut.rs:3:50
3+
|
4+
LL | static mut TEST1: Option<&mut [i32]> = Some(&mut [1, 2, 3]);
5+
| ----------^^^^^^^^^-
6+
| | | |
7+
| | | temporary value is freed at the end of this statement
8+
| | creates a temporary which is freed while still in use
9+
| using this value as a static requires that borrow lasts for `'static`
10+
11+
error[E0716]: temporary value dropped while borrowed
12+
--> $DIR/promote-no-mut.rs:6:18
13+
|
14+
LL | let x = &mut [1,2,3];
15+
| ^^^^^^^ creates a temporary which is freed while still in use
16+
LL | x
17+
| - using this value as a static requires that borrow lasts for `'static`
18+
LL | };
19+
| - temporary value is freed at the end of this statement
20+
21+
error: aborting due to 2 previous errors
22+
23+
For more information about this error, try `rustc --explain E0716`.

src/test/ui/consts/promotion-mutable-ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(const_mut_refs)]
33

44
static mut TEST: i32 = {
5-
// We cannot promote this, as CTFE needs to be able to mutate it later.
5+
// We must not promote this, as CTFE needs to be able to mutate it later.
66
let x = &mut [1,2,3];
77
x[0] += 1;
88
x[0]

0 commit comments

Comments
 (0)