Auto merge of #53109 - nikomatsakis:nll-escaping-into-return-revert, r=nikomatsakis
revert #52991 Reverts https://github.com/rust-lang/rust/pull/52991 which is flawed. I have an idea how to fix it but might as well revert first since it is so wildly flawed. That's what I get for opening PRs while on PTO =) r? @pnkfelix
This commit is contained in:
commit
ccb550fb45
11 changed files with 108 additions and 331 deletions
29
src/test/ui/borrowck/issue-52713-bug.rs
Normal file
29
src/test/ui/borrowck/issue-52713-bug.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// 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.
|
||||
|
||||
// Regression test for a bug in #52713: this was an optimization for
|
||||
// computing liveness that wound up accidentally causing the program
|
||||
// below to be accepted.
|
||||
|
||||
#![feature(nll)]
|
||||
|
||||
fn foo<'a>(x: &'a mut u32) -> u32 {
|
||||
let mut x = 22;
|
||||
let y = &x;
|
||||
if false {
|
||||
return x;
|
||||
}
|
||||
|
||||
x += 1; //~ ERROR
|
||||
println!("{}", y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
14
src/test/ui/borrowck/issue-52713-bug.stderr
Normal file
14
src/test/ui/borrowck/issue-52713-bug.stderr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
error[E0506]: cannot assign to `x` because it is borrowed
|
||||
--> $DIR/issue-52713-bug.rs:24:5
|
||||
|
|
||||
LL | let y = &x;
|
||||
| -- borrow of `x` occurs here
|
||||
...
|
||||
LL | x += 1; //~ ERROR
|
||||
| ^^^^^^ assignment to borrowed `x` occurs here
|
||||
LL | println!("{}", y);
|
||||
| - borrow later used here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0506`.
|
||||
|
|
@ -1,24 +1,30 @@
|
|||
error[E0597]: borrowed value does not live long enough
|
||||
--> $DIR/promote-ref-mut-in-let-issue-46557.rs:15:21
|
||||
|
|
||||
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...
|
||||
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 | 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...
|
||||
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
|
||||
|
|
|
|||
|
|
@ -63,18 +63,9 @@ LL | match map.get() {
|
|||
LL | Some(v) => {
|
||||
LL | map.set(String::new()); // Both AST and MIR error here
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
|
||||
|
|
||||
note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 41:1...
|
||||
--> $DIR/get_default.rs:41:1
|
||||
|
|
||||
LL | / fn err(map: &mut Map) -> &String {
|
||||
LL | | loop {
|
||||
LL | | match map.get() {
|
||||
LL | | Some(v) => {
|
||||
... |
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_^
|
||||
...
|
||||
LL | return v;
|
||||
| - borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable (Mir)
|
||||
--> $DIR/get_default.rs:51:17
|
||||
|
|
|
|||
|
|
@ -63,18 +63,9 @@ LL | match map.get() {
|
|||
LL | Some(v) => {
|
||||
LL | map.set(String::new()); // Both AST and MIR error here
|
||||
| ^^^ mutable borrow occurs here
|
||||
|
|
||||
note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 41:1...
|
||||
--> $DIR/get_default.rs:41:1
|
||||
|
|
||||
LL | / fn err(map: &mut Map) -> &String {
|
||||
LL | | loop {
|
||||
LL | | match map.get() {
|
||||
LL | | Some(v) => {
|
||||
... |
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_^
|
||||
...
|
||||
LL | return v;
|
||||
| - borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable (Mir)
|
||||
--> $DIR/get_default.rs:51:17
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
error[E0597]: borrowed value does not live long enough
|
||||
--> $DIR/return-ref-mut-issue-46557.rs:17:21
|
||||
|
|
||||
LL | let ref mut x = 1234543; //~ ERROR borrowed value does not live long enough [E0597]
|
||||
| ^^^^^^^ 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...
|
||||
LL | fn gimme_static_mut() -> &'static mut u32 {
|
||||
| ___________________________________________-
|
||||
LL | | let ref mut x = 1234543; //~ ERROR borrowed value does not live long enough [E0597]
|
||||
| | ^^^^^^^ temporary value does not live long enough
|
||||
LL | | x
|
||||
LL | | }
|
||||
| | -
|
||||
| | |
|
||||
| |_temporary value only lives until here
|
||||
| borrow later used here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue