Auto merge of #54802 - davidtwco:issue-53040, r=pnkfelix
[nll] better error message when returning refs to upvars Fixes #53040. r? @nikomatsakis
This commit is contained in:
commit
e1041c6cd1
12 changed files with 214 additions and 68 deletions
|
|
@ -20,24 +20,22 @@ LL | //[mir]~^ ERROR cannot borrow `x` as mutable more than o
|
|||
LL | *y = 1;
|
||||
| ------ first borrow later used here
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
error: captured variable cannot escape `FnMut` closure body
|
||||
--> $DIR/borrowck-describe-lvalue.rs:305:16
|
||||
|
|
||||
LL | || {
|
||||
| --
|
||||
| ||
|
||||
| |return type of closure is [closure@$DIR/borrowck-describe-lvalue.rs:305:16: 311:18 x:&'2 mut i32]
|
||||
| lifetime `'1` represents this closure's body
|
||||
LL | / || { //[mir]~ ERROR unsatisfied lifetime constraints
|
||||
| - inferred to be a `FnMut` closure
|
||||
LL | / || { //[mir]~ ERROR captured variable cannot escape `FnMut` closure body
|
||||
LL | | let y = &mut x;
|
||||
LL | | &mut x; //[ast]~ ERROR cannot borrow `**x` as mutable more than once at a time
|
||||
LL | | //[mir]~^ ERROR cannot borrow `x` as mutable more than once at a time
|
||||
LL | | *y = 1;
|
||||
LL | | drop(y);
|
||||
LL | | }
|
||||
| |_________________^ returning this value requires that `'1` must outlive `'2`
|
||||
| |_________________^ returns a closure that contains a reference to a captured variable, which then escapes the closure body
|
||||
|
|
||||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
|
||||
= note: `FnMut` closures only have access to their captured variables while they are executing...
|
||||
= note: ...therefore, they cannot allow references to captured variables to escape
|
||||
|
||||
error[E0503]: cannot use `f.x` because it was mutably borrowed
|
||||
--> $DIR/borrowck-describe-lvalue.rs:53:9
|
||||
|
|
|
|||
|
|
@ -20,24 +20,22 @@ LL | //[mir]~^ ERROR cannot borrow `x` as mutable more than o
|
|||
LL | *y = 1;
|
||||
| ------ first borrow later used here
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
error: captured variable cannot escape `FnMut` closure body
|
||||
--> $DIR/borrowck-describe-lvalue.rs:305:16
|
||||
|
|
||||
LL | || {
|
||||
| --
|
||||
| ||
|
||||
| |return type of closure is [closure@$DIR/borrowck-describe-lvalue.rs:305:16: 311:18 x:&'2 mut i32]
|
||||
| lifetime `'1` represents this closure's body
|
||||
LL | / || { //[mir]~ ERROR unsatisfied lifetime constraints
|
||||
| - inferred to be a `FnMut` closure
|
||||
LL | / || { //[mir]~ ERROR captured variable cannot escape `FnMut` closure body
|
||||
LL | | let y = &mut x;
|
||||
LL | | &mut x; //[ast]~ ERROR cannot borrow `**x` as mutable more than once at a time
|
||||
LL | | //[mir]~^ ERROR cannot borrow `x` as mutable more than once at a time
|
||||
LL | | *y = 1;
|
||||
LL | | drop(y);
|
||||
LL | | }
|
||||
| |_________________^ returning this value requires that `'1` must outlive `'2`
|
||||
| |_________________^ returns a closure that contains a reference to a captured variable, which then escapes the closure body
|
||||
|
|
||||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
|
||||
= note: `FnMut` closures only have access to their captured variables while they are executing...
|
||||
= note: ...therefore, they cannot allow references to captured variables to escape
|
||||
|
||||
error[E0503]: cannot use `f.x` because it was mutably borrowed
|
||||
--> $DIR/borrowck-describe-lvalue.rs:53:9
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ fn main() {
|
|||
// FIXME(#49824) -- the free region error below should probably not be there
|
||||
let mut x = 0;
|
||||
|| {
|
||||
|| { //[mir]~ ERROR unsatisfied lifetime constraints
|
||||
|| { //[mir]~ ERROR captured variable cannot escape `FnMut` closure body
|
||||
let y = &mut x;
|
||||
&mut x; //[ast]~ ERROR cannot borrow `**x` as mutable more than once at a time
|
||||
//[mir]~^ ERROR cannot borrow `x` as mutable more than once at a time
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
error: captured variable cannot escape `FnMut` closure body
|
||||
--> $DIR/issue-40510-1.rs:18:9
|
||||
|
|
||||
LL | || {
|
||||
| --
|
||||
| ||
|
||||
| |return type of closure is &'2 mut std::boxed::Box<()>
|
||||
| lifetime `'1` represents this closure's body
|
||||
| - inferred to be a `FnMut` closure
|
||||
LL | &mut x
|
||||
| ^^^^^^ returning this value requires that `'1` must outlive `'2`
|
||||
| ^^^^^^ returns a reference to a captured variable which escapes the closure body
|
||||
|
|
||||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
|
||||
= note: `FnMut` closures only have access to their captured variables while they are executing...
|
||||
= note: ...therefore, they cannot allow references to captured variables to escape
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
error: captured variable cannot escape `FnMut` closure body
|
||||
--> $DIR/issue-40510-3.rs:18:9
|
||||
|
|
||||
LL | || {
|
||||
| --
|
||||
| ||
|
||||
| |return type of closure is [closure@$DIR/issue-40510-3.rs:18:9: 20:10 x:&'2 mut std::vec::Vec<()>]
|
||||
| lifetime `'1` represents this closure's body
|
||||
| - inferred to be a `FnMut` closure
|
||||
LL | / || {
|
||||
LL | | x.push(())
|
||||
LL | | }
|
||||
| |_________^ returning this value requires that `'1` must outlive `'2`
|
||||
| |_________^ returns a closure that contains a reference to a captured variable, which then escapes the closure body
|
||||
|
|
||||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
|
||||
= note: `FnMut` closures only have access to their captured variables while they are executing...
|
||||
= note: ...therefore, they cannot allow references to captured variables to escape
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
error: captured variable cannot escape `FnMut` closure body
|
||||
--> $DIR/issue-49824.rs:22:9
|
||||
|
|
||||
LL | || {
|
||||
| --
|
||||
| ||
|
||||
| |return type of closure is [closure@$DIR/issue-49824.rs:22:9: 24:10 x:&'2 mut i32]
|
||||
| lifetime `'1` represents this closure's body
|
||||
| - inferred to be a `FnMut` closure
|
||||
LL | / || {
|
||||
LL | | let _y = &mut x;
|
||||
LL | | }
|
||||
| |_________^ returning this value requires that `'1` must outlive `'2`
|
||||
| |_________^ returns a closure that contains a reference to a captured variable, which then escapes the closure body
|
||||
|
|
||||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
|
||||
= note: `FnMut` closures only have access to their captured variables while they are executing...
|
||||
= note: ...therefore, they cannot allow references to captured variables to escape
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
16
src/test/ui/nll/issue-53040.rs
Normal file
16
src/test/ui/nll/issue-53040.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
#![feature(nll)]
|
||||
|
||||
fn main() {
|
||||
let mut v: Vec<()> = Vec::new();
|
||||
|| &mut v;
|
||||
}
|
||||
13
src/test/ui/nll/issue-53040.stderr
Normal file
13
src/test/ui/nll/issue-53040.stderr
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
error: captured variable cannot escape `FnMut` closure body
|
||||
--> $DIR/issue-53040.rs:15:8
|
||||
|
|
||||
LL | || &mut v;
|
||||
| - ^^^^^^ returns a reference to a captured variable which escapes the closure body
|
||||
| |
|
||||
| inferred to be a `FnMut` closure
|
||||
|
|
||||
= note: `FnMut` closures only have access to their captured variables while they are executing...
|
||||
= note: ...therefore, they cannot allow references to captured variables to escape
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
error: captured variable cannot escape `FnMut` closure body
|
||||
--> $DIR/regions-return-ref-to-upvar-issue-17403.rs:17:24
|
||||
|
|
||||
LL | let mut f = || &mut x; //~ ERROR cannot infer
|
||||
| -- ^^^^^^ returning this value requires that `'1` must outlive `'2`
|
||||
| ||
|
||||
| |return type of closure is &'2 mut i32
|
||||
| lifetime `'1` represents this closure's body
|
||||
| - ^^^^^^ returns a reference to a captured variable which escapes the closure body
|
||||
| |
|
||||
| inferred to be a `FnMut` closure
|
||||
|
|
||||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
|
||||
= note: `FnMut` closures only have access to their captured variables while they are executing...
|
||||
= note: ...therefore, they cannot allow references to captured variables to escape
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue