-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #51274 - nikomatsakis:issue-46557-promote-ref-mut, r=eddyb
- Loading branch information
Showing
5 changed files
with
211 additions
and
5 deletions.
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
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
63 changes: 63 additions & 0 deletions
63
src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.nll.stderr
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,63 @@ | ||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:15:21 | ||
| | ||
LL | fn gimme_static_mut_let() -> &'static mut u32 { | ||
| _______________________________________________- | ||
LL | | let ref mut x = 1234543; //~ ERROR | ||
| | ^^^^^^^ temporary value does not live long enough | ||
LL | | x | ||
LL | | } | ||
| | - | ||
| | | | ||
| |_temporary value only lives until here | ||
| borrow later used here | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:20:25 | ||
| | ||
LL | fn gimme_static_mut_let_nested() -> &'static mut u32 { | ||
| ______________________________________________________- | ||
LL | | let (ref mut x, ) = (1234543, ); //~ ERROR | ||
| | ^^^^^^^^^^^ temporary value does not live long enough | ||
LL | | x | ||
LL | | } | ||
| | - | ||
| | | | ||
| |_temporary value only lives until here | ||
| borrow later used here | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:25:11 | ||
| | ||
LL | match 1234543 { | ||
| ^^^^^^^ temporary value does not live long enough | ||
... | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:31:11 | ||
| | ||
LL | match (123443,) { | ||
| ^^^^^^^^^ temporary value does not live long enough | ||
... | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:37:10 | ||
| | ||
LL | &mut 1234543 //~ ERROR | ||
| ^^^^^^^ temporary value does not live long enough | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0597`. |
41 changes: 41 additions & 0 deletions
41
src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.rs
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,41 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that we fail to promote the constant here which has a `ref | ||
// mut` borrow. | ||
|
||
fn gimme_static_mut_let() -> &'static mut u32 { | ||
let ref mut x = 1234543; //~ ERROR | ||
x | ||
} | ||
|
||
fn gimme_static_mut_let_nested() -> &'static mut u32 { | ||
let (ref mut x, ) = (1234543, ); //~ ERROR | ||
x | ||
} | ||
|
||
fn gimme_static_mut_match() -> &'static mut u32 { | ||
match 1234543 { | ||
ref mut x => x //~ ERROR | ||
} | ||
} | ||
|
||
fn gimme_static_mut_match_nested() -> &'static mut u32 { | ||
match (123443,) { | ||
(ref mut x,) => x, //~ ERROR | ||
} | ||
} | ||
|
||
fn gimme_static_mut_ampersand() -> &'static mut u32 { | ||
&mut 1234543 //~ ERROR | ||
} | ||
|
||
fn main() { | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.stderr
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,57 @@ | ||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:15:9 | ||
| | ||
LL | let ref mut x = 1234543; //~ ERROR | ||
| ^^^^^^^^^ temporary value does not live long enough | ||
LL | x | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:20:10 | ||
| | ||
LL | let (ref mut x, ) = (1234543, ); //~ ERROR | ||
| ^^^^^^^^^ borrowed value does not live long enough | ||
LL | x | ||
LL | } | ||
| - borrowed value only lives until here | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:26:9 | ||
| | ||
LL | ref mut x => x //~ ERROR | ||
| ^^^^^^^^^ temporary value does not live long enough | ||
LL | } | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:32:10 | ||
| | ||
LL | (ref mut x,) => x, //~ ERROR | ||
| ^^^^^^^^^ borrowed value does not live long enough | ||
LL | } | ||
LL | } | ||
| - borrowed value only lives until here | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:37:10 | ||
| | ||
LL | &mut 1234543 //~ ERROR | ||
| ^^^^^^^ temporary value does not live long enough | ||
LL | } | ||
| - temporary value only lives until here | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0597`. |