diff options
| author | bors <bors@rust-lang.org> | 2018-06-02 13:22:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-06-02 13:22:38 +0000 |
| commit | d830f46b77bbb97fbff6397f0d9c352a880f796d (patch) | |
| tree | e3bf6ba27aa205b6c59d2f1fa3daa9bfab00f485 /src/test | |
| parent | 1b3d737716a4ae40709da627fc3e726ce539e405 (diff) | |
| parent | a667049c33753dec2ea236fcca3dbf3a7540a5df (diff) | |
| download | rust-d830f46b77bbb97fbff6397f0d9c352a880f796d.tar.gz rust-d830f46b77bbb97fbff6397f0d9c352a880f796d.zip | |
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
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`. |
