make sure we do not promote things with interior mutability
This commit is contained in:
parent
a68864b688
commit
bd837e899b
2 changed files with 22 additions and 7 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#![allow(unconditional_panic, const_err)]
|
||||
#![feature(const_fn, const_fn_union)]
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
// We do not promote mutable references.
|
||||
static mut TEST1: Option<&mut [i32]> = Some(&mut [1, 2, 3]); //~ ERROR temporary value dropped while borrowed
|
||||
|
||||
|
|
@ -32,4 +34,7 @@ const TEST_UNION: () = {
|
|||
let _x: &'static i32 = &unsafe { U { x: 0 }.x }; //~ ERROR temporary value dropped while borrowed
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
fn main() {
|
||||
// We must not promote things with interior mutability.
|
||||
let _val: &'static _ = &(Cell::new(1), 2).0; //~ ERROR temporary value dropped while borrowed
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promote-not.rs:7:50
|
||||
--> $DIR/promote-not.rs:9:50
|
||||
|
|
||||
LL | static mut TEST1: Option<&mut [i32]> = Some(&mut [1, 2, 3]);
|
||||
| ----------^^^^^^^^^-
|
||||
|
|
@ -9,7 +9,7 @@ LL | static mut TEST1: Option<&mut [i32]> = Some(&mut [1, 2, 3]);
|
|||
| using this value as a static requires that borrow lasts for `'static`
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promote-not.rs:10:18
|
||||
--> $DIR/promote-not.rs:12:18
|
||||
|
|
||||
LL | let x = &mut [1,2,3];
|
||||
| ^^^^^^^ creates a temporary which is freed while still in use
|
||||
|
|
@ -19,7 +19,7 @@ LL | };
|
|||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promote-not.rs:19:32
|
||||
--> $DIR/promote-not.rs:21:32
|
||||
|
|
||||
LL | let _x: &'static () = &foo();
|
||||
| ----------- ^^^^^ creates a temporary which is freed while still in use
|
||||
|
|
@ -29,7 +29,7 @@ LL | }
|
|||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promote-not.rs:27:29
|
||||
--> $DIR/promote-not.rs:29:29
|
||||
|
|
||||
LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x };
|
||||
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
|
|
@ -39,7 +39,7 @@ LL | }
|
|||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promote-not.rs:32:29
|
||||
--> $DIR/promote-not.rs:34:29
|
||||
|
|
||||
LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x };
|
||||
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
|
|
@ -48,6 +48,16 @@ LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x };
|
|||
LL | };
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promote-not.rs:39:29
|
||||
|
|
||||
LL | let _val: &'static _ = &(Cell::new(1), 2).0;
|
||||
| ---------- ^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
| |
|
||||
| type annotation requires that borrow lasts for `'static`
|
||||
LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0716`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue