diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-06-01 09:41:44 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-06-01 10:06:02 -0400 |
| commit | a667049c33753dec2ea236fcca3dbf3a7540a5df (patch) | |
| tree | 1d541f1d98a6328b59d9df5815207eb24dfeed0b /src/test | |
| parent | 577a5b2703d97e5408664e409f35768944360fea (diff) | |
| download | rust-a667049c33753dec2ea236fcca3dbf3a7540a5df.tar.gz rust-a667049c33753dec2ea236fcca3dbf3a7540a5df.zip | |
also check `let` arms and nested patterns for mutable borrows
Diffstat (limited to 'src/test')
3 files changed, 161 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.nll.stderr b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.nll.stderr new file mode 100644 index 00000000000..95acdab3e80 --- /dev/null +++ b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.rs b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.rs new file mode 100644 index 00000000000..4c5f458d6a3 --- /dev/null +++ b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.rs @@ -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() { +} diff --git a/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.stderr b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.stderr new file mode 100644 index 00000000000..931eb7da744 --- /dev/null +++ b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.stderr @@ -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`. |
