-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add compile-fail test for &mut promotion
- Loading branch information
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// ignore-tidy-linelength | ||
// We do not promote mutable references. | ||
static mut TEST1: Option<&mut [i32]> = Some(&mut [1, 2, 3]); //~ ERROR temporary value dropped while borrowed | ||
|
||
static mut TEST2: &'static mut [i32] = { | ||
let x = &mut [1,2,3]; //~ ERROR temporary value dropped while borrowed | ||
x | ||
}; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/promote-no-mut.rs:3:50 | ||
| | ||
LL | static mut TEST1: Option<&mut [i32]> = Some(&mut [1, 2, 3]); | ||
| ----------^^^^^^^^^- | ||
| | | | | ||
| | | temporary value is freed at the end of this statement | ||
| | creates a temporary which is freed while still in use | ||
| using this value as a static requires that borrow lasts for `'static` | ||
|
||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/promote-no-mut.rs:6:18 | ||
| | ||
LL | let x = &mut [1,2,3]; | ||
| ^^^^^^^ creates a temporary which is freed while still in use | ||
LL | x | ||
| - using this value as a static requires that borrow lasts for `'static` | ||
LL | }; | ||
| - temporary value is freed at the end of this statement | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0716`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters