Auto merge of #51274 - nikomatsakis:issue-46557-promote-ref-mut, r=eddyb

also check `let` arms and nested patterns for mutable borrows

Fixes #46557

r? @eddyb
This commit is contained in:
bors 2018-06-02 13:22:38 +00:00
commit d830f46b77
5 changed files with 211 additions and 5 deletions

View file

@ -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`.

View file

@ -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() {
}

View file

@ -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`.