Update tests

This commit is contained in:
Matthew Jasper 2020-05-20 18:58:41 +01:00
parent 3d8a0733ae
commit f9f3063cfa
50 changed files with 468 additions and 889 deletions

View File

@ -1,12 +0,0 @@
error: borrowed data cannot be stored outside of its closure
--> $DIR/issue-45983.rs:20:27
|
LL | let x = None;
| - borrowed data cannot be stored into here...
LL | give_any(|y| x = Some(y));
| --- ^ cannot be stored outside of its closure
| |
| ...because it cannot outlive this closure
error: aborting due to previous error

View File

@ -1,21 +0,0 @@
error[E0521]: borrowed data escapes outside of closure
--> $DIR/issue-45983.rs:20:18
|
LL | let x = None;
| - `x` declared here, outside of the closure body
LL | give_any(|y| x = Some(y));
| - ^^^^^^^^^^^ `y` escapes the closure body here
| |
| `y` is a reference that is only valid in the closure body
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/issue-45983.rs:20:18
|
LL | let x = None;
| - help: consider changing this to be mutable: `mut x`
LL | give_any(|y| x = Some(y));
| ^^^^^^^^^^^ cannot assign
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0594`.

View File

@ -1,24 +1,12 @@
// As documented in Issue #45983, this test is evaluating the quality // As documented in Issue #45983, this test is evaluating the quality
// of our diagnostics on erroneous code using higher-ranked closures. // of our diagnostics on erroneous code using higher-ranked closures.
// revisions: migrate nll
// Since we are testing nll (and migration) explicitly as a separate
// revisions, don't worry about the --compare-mode=nll on this test.
// ignore-compare-mode-nll
// ignore-compare-mode-polonius
//[nll]compile-flags: -Z borrowck=mir
fn give_any<F: for<'r> FnOnce(&'r ())>(f: F) { fn give_any<F: for<'r> FnOnce(&'r ())>(f: F) {
f(&()); f(&());
} }
fn main() { fn main() {
let x = None; let mut x = None;
give_any(|y| x = Some(y)); give_any(|y| x = Some(y));
//[migrate]~^ ERROR borrowed data cannot be stored outside of its closure //~^ ERROR borrowed data escapes outside of closure
//[nll]~^^ ERROR borrowed data escapes outside of closure
//[nll]~| ERROR cannot assign to `x`, as it is not declared as mutable
} }

View File

@ -1,9 +1,9 @@
error[E0521]: borrowed data escapes outside of closure error[E0521]: borrowed data escapes outside of closure
--> $DIR/regions-escape-bound-fn-2.rs:8:18 --> $DIR/issue-45983.rs:10:18
| |
LL | let mut x = None; LL | let mut x = None;
| ----- `x` declared here, outside of the closure body | ----- `x` declared here, outside of the closure body
LL | with_int(|y| x = Some(y)); LL | give_any(|y| x = Some(y));
| - ^^^^^^^^^^^ `y` escapes the closure body here | - ^^^^^^^^^^^ `y` escapes the closure body here
| | | |
| `y` is a reference that is only valid in the closure body | `y` is a reference that is only valid in the closure body

View File

@ -1,14 +0,0 @@
error[E0521]: borrowed data escapes outside of closure
--> $DIR/issue-7573.rs:21:9
|
LL | let mut lines_to_use: Vec<&CrateId> = Vec::new();
| ---------------- `lines_to_use` declared here, outside of the closure body
LL |
LL | let push_id = |installed_id: &CrateId| {
| ------------ `installed_id` is a reference that is only valid in the closure body
...
LL | lines_to_use.push(installed_id);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `installed_id` escapes the closure body here
error: aborting due to previous error

View File

@ -1,36 +1,34 @@
pub struct CrateId { pub struct CrateId {
local_path: String, local_path: String,
junk: String junk: String,
} }
impl CrateId { impl CrateId {
fn new(s: &str) -> CrateId { fn new(s: &str) -> CrateId {
CrateId { CrateId { local_path: s.to_string(), junk: "wutevs".to_string() }
local_path: s.to_string(),
junk: "wutevs".to_string()
}
} }
} }
pub fn remove_package_from_database() { pub fn remove_package_from_database() {
let mut lines_to_use: Vec<&CrateId> = Vec::new(); let mut lines_to_use: Vec<&CrateId> = Vec::new();
//~^ NOTE cannot infer an appropriate lifetime //~^ NOTE `lines_to_use` declared here, outside of the closure body
let push_id = |installed_id: &CrateId| { let push_id = |installed_id: &CrateId| {
//~^ NOTE borrowed data cannot outlive this closure //~^ NOTE `installed_id` is a reference that is only valid in the closure body
//~| NOTE ...so that variable is valid at time of its declaration
lines_to_use.push(installed_id); lines_to_use.push(installed_id);
//~^ ERROR borrowed data cannot be stored outside of its closure //~^ ERROR borrowed data escapes outside of closure
//~| NOTE cannot be stored outside of its closure //~| NOTE `installed_id` escapes the closure body here
}; };
list_database(push_id); list_database(push_id);
for l in &lines_to_use { for l in &lines_to_use {
println!("{}", l.local_path); println!("{}", l.local_path);
} }
} }
pub fn list_database<F>(mut f: F) where F: FnMut(&CrateId) { pub fn list_database<F>(mut f: F)
where
F: FnMut(&CrateId),
{
let stuff = ["foo", "bar"]; let stuff = ["foo", "bar"];
for l in &stuff { for l in &stuff {

View File

@ -1,16 +1,14 @@
error: borrowed data cannot be stored outside of its closure error[E0521]: borrowed data escapes outside of closure
--> $DIR/issue-7573.rs:21:27 --> $DIR/issue-7573.rs:17:9
| |
LL | let mut lines_to_use: Vec<&CrateId> = Vec::new(); LL | let mut lines_to_use: Vec<&CrateId> = Vec::new();
| - cannot infer an appropriate lifetime... | ---------------- `lines_to_use` declared here, outside of the closure body
LL | LL |
LL | let push_id = |installed_id: &CrateId| { LL | let push_id = |installed_id: &CrateId| {
| ------- ------------------------ borrowed data cannot outlive this closure | ------------ `installed_id` is a reference that is only valid in the closure body
| | LL |
| ...so that variable is valid at time of its declaration
...
LL | lines_to_use.push(installed_id); LL | lines_to_use.push(installed_id);
| ^^^^^^^^^^^^ cannot be stored outside of its closure | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `installed_id` escapes the closure body here
error: aborting due to previous error error: aborting due to previous error

View File

@ -1,4 +1,7 @@
fn with_int<F>(f: F) where F: FnOnce(&isize) { fn with_int<F>(f: F)
where
F: FnOnce(&isize),
{
let x = 3; let x = 3;
f(&x); f(&x);
} }
@ -6,5 +9,5 @@ fn with_int<F>(f: F) where F: FnOnce(&isize) {
fn main() { fn main() {
let mut x = None; let mut x = None;
with_int(|y| x = Some(y)); with_int(|y| x = Some(y));
//~^ ERROR borrowed data cannot be stored outside of its closure //~^ ERROR borrowed data escapes outside of closure
} }

View File

@ -1,12 +1,12 @@
error: borrowed data cannot be stored outside of its closure error[E0521]: borrowed data escapes outside of closure
--> $DIR/regions-escape-bound-fn-2.rs:8:27 --> $DIR/regions-escape-bound-fn-2.rs:11:18
| |
LL | let mut x = None; LL | let mut x = None;
| ----- borrowed data cannot be stored into here... | ----- `x` declared here, outside of the closure body
LL | with_int(|y| x = Some(y)); LL | with_int(|y| x = Some(y));
| --- ^ cannot be stored outside of its closure | - ^^^^^^^^^^^ `y` escapes the closure body here
| | | |
| ...because it cannot outlive this closure | `y` is a reference that is only valid in the closure body
error: aborting due to previous error error: aborting due to previous error

View File

@ -1,12 +0,0 @@
error[E0521]: borrowed data escapes outside of closure
--> $DIR/regions-escape-bound-fn.rs:8:18
|
LL | let mut x: Option<&isize> = None;
| ----- `x` declared here, outside of the closure body
LL | with_int(|y| x = Some(y));
| - ^^^^^^^^^^^ `y` escapes the closure body here
| |
| `y` is a reference that is only valid in the closure body
error: aborting due to previous error

View File

@ -1,4 +1,7 @@
fn with_int<F>(f: F) where F: FnOnce(&isize) { fn with_int<F>(f: F)
where
F: FnOnce(&isize),
{
let x = 3; let x = 3;
f(&x); f(&x);
} }
@ -6,5 +9,5 @@ fn with_int<F>(f: F) where F: FnOnce(&isize) {
fn main() { fn main() {
let mut x: Option<&isize> = None; let mut x: Option<&isize> = None;
with_int(|y| x = Some(y)); with_int(|y| x = Some(y));
//~^ ERROR borrowed data cannot be stored outside of its closure //~^ ERROR borrowed data escapes outside of closure
} }

View File

@ -1,12 +1,12 @@
error: borrowed data cannot be stored outside of its closure error[E0521]: borrowed data escapes outside of closure
--> $DIR/regions-escape-bound-fn.rs:8:27 --> $DIR/regions-escape-bound-fn.rs:11:18
| |
LL | let mut x: Option<&isize> = None; LL | let mut x: Option<&isize> = None;
| ----- borrowed data cannot be stored into here... | ----- `x` declared here, outside of the closure body
LL | with_int(|y| x = Some(y)); LL | with_int(|y| x = Some(y));
| --- ^ cannot be stored outside of its closure | - ^^^^^^^^^^^ `y` escapes the closure body here
| | | |
| ...because it cannot outlive this closure | `y` is a reference that is only valid in the closure body
error: aborting due to previous error error: aborting due to previous error

View File

@ -1,12 +0,0 @@
error[E0521]: borrowed data escapes outside of closure
--> $DIR/regions-escape-unboxed-closure.rs:6:23
|
LL | let mut x: Option<&isize> = None;
| ----- `x` declared here, outside of the closure body
LL | with_int(&mut |y| x = Some(y));
| - ^^^^^^^^^^^ `y` escapes the closure body here
| |
| `y` is a reference that is only valid in the closure body
error: aborting due to previous error

View File

@ -1,8 +1,7 @@
fn with_int(f: &mut dyn FnMut(&isize)) { fn with_int(f: &mut dyn FnMut(&isize)) {}
}
fn main() { fn main() {
let mut x: Option<&isize> = None; let mut x: Option<&isize> = None;
with_int(&mut |y| x = Some(y)); with_int(&mut |y| x = Some(y));
//~^ ERROR borrowed data cannot be stored outside of its closure //~^ ERROR borrowed data escapes outside of closure
} }

View File

@ -1,12 +1,12 @@
error: borrowed data cannot be stored outside of its closure error[E0521]: borrowed data escapes outside of closure
--> $DIR/regions-escape-unboxed-closure.rs:6:32 --> $DIR/regions-escape-unboxed-closure.rs:5:23
| |
LL | let mut x: Option<&isize> = None; LL | let mut x: Option<&isize> = None;
| ----- borrowed data cannot be stored into here... | ----- `x` declared here, outside of the closure body
LL | with_int(&mut |y| x = Some(y)); LL | with_int(&mut |y| x = Some(y));
| --- ^ cannot be stored outside of its closure | - ^^^^^^^^^^^ `y` escapes the closure body here
| | | |
| ...because it cannot outlive this closure | `y` is a reference that is only valid in the closure body
error: aborting due to previous error error: aborting due to previous error

View File

@ -1,123 +0,0 @@
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:8:5
|
LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
| -- -- has type `core::ffi::VaListImpl<'1>`
| |
| lifetime `'f` defined here
LL | ap
| ^^ function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'f`
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:8:5
|
LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
| -- -- has type `core::ffi::VaListImpl<'1>`
| |
| lifetime `'f` defined here
LL | ap
| ^^ returning this value requires that `'1` must outlive `'f`
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:12:5
|
LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> {
| -- has type `core::ffi::VaListImpl<'1>`
LL | ap
| ^^ returning this value requires that `'1` must outlive `'static`
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:16:33
|
LL | let _ = ap.with_copy(|ap| { ap });
| --- ^^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of closure is core::ffi::VaList<'2, '_>
| has type `core::ffi::VaList<'1, '_>`
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:20:5
|
LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | *ap0 = ap1;
| ^^^^ assignment requires that `'1` must outlive `'2`
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:20:5
|
LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | *ap0 = ap1;
| ^^^^ assignment requires that `'2` must outlive `'1`
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:24:5
|
LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
| --- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | ap0 = &mut ap1;
| ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:24:5
|
LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
| --- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | ap0 = &mut ap1;
| ^^^^^^^^^^^^^^ assignment requires that `'2` must outlive `'1`
error[E0384]: cannot assign to immutable argument `ap0`
--> $DIR/variadic-ffi-4.rs:24:5
|
LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
| --- help: make this binding mutable: `mut ap0`
LL | ap0 = &mut ap1;
| ^^^^^^^^^^^^^^ cannot assign to immutable argument
error[E0597]: `ap1` does not live long enough
--> $DIR/variadic-ffi-4.rs:24:11
|
LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
| - let's call the lifetime of this reference `'3`
LL | ap0 = &mut ap1;
| ------^^^^^^^^
| | |
| | borrowed value does not live long enough
| assignment requires that `ap1` is borrowed for `'3`
...
LL | }
| - `ap1` dropped here while still borrowed
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:31:12
|
LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | *ap0 = ap1.clone();
| ^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:31:12
|
LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | *ap0 = ap1.clone();
| ^^^^^^^^^^^ argument requires that `'2` must outlive `'1`
error: aborting due to 12 previous errors
Some errors have detailed explanations: E0384, E0597.
For more information about an error, try `rustc --explain E0384`.

View File

@ -1,32 +1,38 @@
#![crate_type="lib"] #![crate_type = "lib"]
#![no_std] #![no_std]
#![feature(c_variadic)] #![feature(c_variadic)]
use core::ffi::{VaList, VaListImpl}; use core::ffi::{VaList, VaListImpl};
pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
ap //~ ERROR: mismatched types ap
//~^ ERROR: lifetime may not live long enough
//~| ERROR: lifetime may not live long enough
} }
pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> { pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> {
ap //~ ERROR: mismatched types ap //~ ERROR: lifetime may not live long enough
} }
pub unsafe extern "C" fn no_escape2(_: usize, ap: ...) { pub unsafe extern "C" fn no_escape2(_: usize, ap: ...) {
let _ = ap.with_copy(|ap| { ap }); //~ ERROR: cannot infer an appropriate lifetime let _ = ap.with_copy(|ap| ap); //~ ERROR: lifetime may not live long enough
} }
pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
*ap0 = ap1; //~ ERROR: mismatched types *ap0 = ap1;
//~^ ERROR: lifetime may not live long enough
//~| ERROR: lifetime may not live long enough
} }
pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
ap0 = &mut ap1; ap0 = &mut ap1;
//~^ ERROR: a value of type `core::ffi::VaListImpl<'_>` is borrowed for too long //~^ ERROR: `ap1` does not live long enough
//~| ERROR: mismatched types //~| ERROR: lifetime may not live long enough
//~| ERROR: cannot infer an appropriate lifetime //~| ERROR: lifetime may not live long enough
} }
pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
*ap0 = ap1.clone(); //~ ERROR: mismatched types *ap0 = ap1.clone();
//~^ ERROR: lifetime may not live long enough
//~| ERROR: lifetime may not live long enough
} }

View File

@ -1,217 +1,114 @@
error[E0308]: mismatched types error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:8:5 --> $DIR/variadic-ffi-4.rs:8:5
| |
LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
| -- -- has type `core::ffi::VaListImpl<'1>`
| |
| lifetime `'f` defined here
LL | ap LL | ap
| ^^ lifetime mismatch | ^^ function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'f`
|
= note: expected struct `core::ffi::VaListImpl<'f>` error: lifetime may not live long enough
found struct `core::ffi::VaListImpl<'_>` --> $DIR/variadic-ffi-4.rs:8:5
note: the scope of call-site for function at 7:78...
--> $DIR/variadic-ffi-4.rs:7:78
|
LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
| ______________________________________________________________________________^
LL | | ap
LL | | }
| |_^
note: ...does not necessarily outlive the lifetime `'f` as defined on the function body at 7:37
--> $DIR/variadic-ffi-4.rs:7:37
| |
LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
| ^^ | -- -- has type `core::ffi::VaListImpl<'1>`
| |
error[E0308]: mismatched types | lifetime `'f` defined here
--> $DIR/variadic-ffi-4.rs:12:5
|
LL | ap LL | ap
| ^^ lifetime mismatch | ^^ returning this value requires that `'1` must outlive `'f`
|
= note: expected struct `core::ffi::VaListImpl<'static>`
found struct `core::ffi::VaListImpl<'_>`
note: the scope of call-site for function at 11:79...
--> $DIR/variadic-ffi-4.rs:11:79
|
LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> {
| _______________________________________________________________________________^
LL | | ap
LL | | }
| |_^
= note: ...does not necessarily outlive the static lifetime
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:16:33 --> $DIR/variadic-ffi-4.rs:14:5
| |
LL | let _ = ap.with_copy(|ap| { ap }); LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> {
| ^^ | -- has type `core::ffi::VaListImpl<'1>`
| LL | ap
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 16:26... | ^^ returning this value requires that `'1` must outlive `'static`
--> $DIR/variadic-ffi-4.rs:16:26
|
LL | let _ = ap.with_copy(|ap| { ap });
| ^^^^^^^^^^^
note: ...so that the expression is assignable
--> $DIR/variadic-ffi-4.rs:16:33
|
LL | let _ = ap.with_copy(|ap| { ap });
| ^^
= note: expected `core::ffi::VaList<'_, '_>`
found `core::ffi::VaList<'_, '_>`
note: but, the lifetime must be valid for the method call at 16:13...
--> $DIR/variadic-ffi-4.rs:16:13
|
LL | let _ = ap.with_copy(|ap| { ap });
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so type `core::ffi::VaList<'_, '_>` of expression is valid during the expression
--> $DIR/variadic-ffi-4.rs:16:13
|
LL | let _ = ap.with_copy(|ap| { ap });
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0308]: mismatched types error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:20:12 --> $DIR/variadic-ffi-4.rs:18:31
| |
LL | let _ = ap.with_copy(|ap| ap);
| --- ^^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of closure is core::ffi::VaList<'2, '_>
| has type `core::ffi::VaList<'1, '_>`
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:22:5
|
LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | *ap0 = ap1; LL | *ap0 = ap1;
| ^^^ lifetime mismatch | ^^^^ assignment requires that `'1` must outlive `'2`
|
= note: expected struct `core::ffi::VaListImpl<'_>`
found struct `core::ffi::VaListImpl<'_>`
note: the scope of call-site for function at 19:87...
--> $DIR/variadic-ffi-4.rs:19:87
|
LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| _______________________________________________________________________________________^
LL | | *ap0 = ap1;
LL | | }
| |_^
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 19:1
--> $DIR/variadic-ffi-4.rs:19:1
|
LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
LL | | *ap0 = ap1;
LL | | }
| |_^
error[E0490]: a value of type `core::ffi::VaListImpl<'_>` is borrowed for too long error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:24:11 --> $DIR/variadic-ffi-4.rs:22:5
| |
LL | ap0 = &mut ap1; LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ^^^^^^^^ | ------- ------- has type `core::ffi::VaListImpl<'2>`
| | |
note: the type is valid for the anonymous lifetime #1 defined on the function body at 23:1 | has type `&mut core::ffi::VaListImpl<'1>`
--> $DIR/variadic-ffi-4.rs:23:1 LL | *ap0 = ap1;
| | ^^^^ assignment requires that `'2` must outlive `'1`
LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
LL | | ap0 = &mut ap1;
LL | |
LL | |
LL | |
LL | | }
| |_^
note: but the borrow lasts for the scope of call-site for function at 23:83
--> $DIR/variadic-ffi-4.rs:23:83
|
LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
| ___________________________________________________________________________________^
LL | | ap0 = &mut ap1;
LL | |
LL | |
LL | |
LL | | }
| |_^
error[E0308]: mismatched types error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:24:11 --> $DIR/variadic-ffi-4.rs:28:5
| |
LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | ap0 = &mut ap1; LL | ap0 = &mut ap1;
| ^^^^^^^^ lifetime mismatch | ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
|
= note: expected mutable reference `&mut core::ffi::VaListImpl<'_>`
found mutable reference `&mut core::ffi::VaListImpl<'_>`
note: the scope of call-site for function at 23:83...
--> $DIR/variadic-ffi-4.rs:23:83
|
LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
| ___________________________________________________________________________________^
LL | | ap0 = &mut ap1;
LL | |
LL | |
LL | |
LL | | }
| |_^
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 23:1
--> $DIR/variadic-ffi-4.rs:23:1
|
LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
LL | | ap0 = &mut ap1;
LL | |
LL | |
LL | |
LL | | }
| |_^
error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:24:11 --> $DIR/variadic-ffi-4.rs:28:5
| |
LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | ap0 = &mut ap1; LL | ap0 = &mut ap1;
| ^^^^^^^^ | ^^^^^^^^^^^^^^ assignment requires that `'2` must outlive `'1`
|
note: first, the lifetime cannot outlive the scope of call-site for function at 23:83...
--> $DIR/variadic-ffi-4.rs:23:83
|
LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
| ___________________________________________________________________________________^
LL | | ap0 = &mut ap1;
LL | |
LL | |
LL | |
LL | | }
| |_^
note: ...so that the type `core::ffi::VaListImpl<'_>` is not borrowed for too long
--> $DIR/variadic-ffi-4.rs:24:11
|
LL | ap0 = &mut ap1;
| ^^^^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #1 defined on the function body at 23:1...
--> $DIR/variadic-ffi-4.rs:23:1
|
LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
LL | | ap0 = &mut ap1;
LL | |
LL | |
LL | |
LL | | }
| |_^
note: ...so that reference does not outlive borrowed content
--> $DIR/variadic-ffi-4.rs:24:11
|
LL | ap0 = &mut ap1;
| ^^^^^^^^
error[E0308]: mismatched types error[E0597]: `ap1` does not live long enough
--> $DIR/variadic-ffi-4.rs:31:12 --> $DIR/variadic-ffi-4.rs:28:11
| |
LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| - let's call the lifetime of this reference `'3`
LL | ap0 = &mut ap1;
| ------^^^^^^^^
| | |
| | borrowed value does not live long enough
| assignment requires that `ap1` is borrowed for `'3`
...
LL | }
| - `ap1` dropped here while still borrowed
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:35:12
|
LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | *ap0 = ap1.clone(); LL | *ap0 = ap1.clone();
| ^^^^^^^^^^^ lifetime mismatch | ^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: expected struct `core::ffi::VaListImpl<'_>`
found struct `core::ffi::VaListImpl<'_>`
note: the scope of call-site for function at 30:87...
--> $DIR/variadic-ffi-4.rs:30:87
|
LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| _______________________________________________________________________________________^
LL | | *ap0 = ap1.clone();
LL | | }
| |_^
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 30:1
--> $DIR/variadic-ffi-4.rs:30:1
|
LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
LL | | *ap0 = ap1.clone();
LL | | }
| |_^
error: aborting due to 8 previous errors error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:35:12
|
LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `core::ffi::VaListImpl<'2>`
| |
| has type `&mut core::ffi::VaListImpl<'1>`
LL | *ap0 = ap1.clone();
| ^^^^^^^^^^^ argument requires that `'2` must outlive `'1`
Some errors have detailed explanations: E0308, E0495. error: aborting due to 11 previous errors
For more information about an error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0597`.

View File

@ -0,0 +1,24 @@
error: lifetime may not live long enough
--> $DIR/expect-region-supply-region-2.rs:14:30
|
LL | fn expect_bound_supply_named<'x>() {
| -- lifetime `'x` defined here
...
LL | closure_expecting_bound(|x: &'x u32| {
| ^ - let's call the lifetime of this reference `'1`
| |
| requires that `'1` must outlive `'x`
error: lifetime may not live long enough
--> $DIR/expect-region-supply-region-2.rs:14:30
|
LL | fn expect_bound_supply_named<'x>() {
| -- lifetime `'x` defined here
...
LL | closure_expecting_bound(|x: &'x u32| {
| ^ requires that `'x` must outlive `'static`
|
= help: consider replacing `'x` with `'static`
error: aborting due to 2 previous errors

View File

@ -0,0 +1,24 @@
#![allow(warnings)]
fn closure_expecting_bound<F>(_: F)
where
F: FnOnce(&u32),
{
}
fn expect_bound_supply_named<'x>() {
let mut f: Option<&u32> = None;
// Here we give a type annotation that `x` should be free. We get
// an error because of that.
closure_expecting_bound(|x: &'x u32| {
//~^ ERROR mismatched types
//~| ERROR mismatched types
// Borrowck doesn't get a chance to run, but if it did it should error
// here.
f = Some(x);
});
}
fn main() {}

View File

@ -0,0 +1,55 @@
error[E0308]: mismatched types
--> $DIR/expect-region-supply-region-2.rs:14:33
|
LL | closure_expecting_bound(|x: &'x u32| {
| ^^^^^^^ lifetime mismatch
|
= note: expected reference `&u32`
found reference `&'x u32`
note: the anonymous lifetime #2 defined on the body at 14:29...
--> $DIR/expect-region-supply-region-2.rs:14:29
|
LL | closure_expecting_bound(|x: &'x u32| {
| _____________________________^
LL | |
LL | |
LL | |
... |
LL | | f = Some(x);
LL | | });
| |_____^
note: ...does not necessarily outlive the lifetime `'x` as defined on the function body at 9:30
--> $DIR/expect-region-supply-region-2.rs:9:30
|
LL | fn expect_bound_supply_named<'x>() {
| ^^
error[E0308]: mismatched types
--> $DIR/expect-region-supply-region-2.rs:14:33
|
LL | closure_expecting_bound(|x: &'x u32| {
| ^^^^^^^ lifetime mismatch
|
= note: expected reference `&u32`
found reference `&'x u32`
note: the lifetime `'x` as defined on the function body at 9:30...
--> $DIR/expect-region-supply-region-2.rs:9:30
|
LL | fn expect_bound_supply_named<'x>() {
| ^^
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 14:29
--> $DIR/expect-region-supply-region-2.rs:14:29
|
LL | closure_expecting_bound(|x: &'x u32| {
| _____________________________^
LL | |
LL | |
LL | |
... |
LL | | f = Some(x);
LL | | });
| |_____^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -1,44 +0,0 @@
error[E0521]: borrowed data escapes outside of closure
--> $DIR/expect-region-supply-region.rs:18:9
|
LL | let mut f: Option<&u32> = None;
| ----- `f` declared here, outside of the closure body
LL | closure_expecting_bound(|x| {
| - `x` is a reference that is only valid in the closure body
LL | f = Some(x);
| ^^^^^^^^^^^ `x` escapes the closure body here
error[E0521]: borrowed data escapes outside of closure
--> $DIR/expect-region-supply-region.rs:28:9
|
LL | let mut f: Option<&u32> = None;
| ----- `f` declared here, outside of the closure body
LL | closure_expecting_bound(|x: &u32| {
| - `x` is a reference that is only valid in the closure body
LL | f = Some(x);
| ^^^^^^^^^^^ `x` escapes the closure body here
error: lifetime may not live long enough
--> $DIR/expect-region-supply-region.rs:37:30
|
LL | fn expect_bound_supply_named<'x>() {
| -- lifetime `'x` defined here
...
LL | closure_expecting_bound(|x: &'x u32| {
| ^ - let's call the lifetime of this reference `'1`
| |
| requires that `'1` must outlive `'x`
error: lifetime may not live long enough
--> $DIR/expect-region-supply-region.rs:37:30
|
LL | fn expect_bound_supply_named<'x>() {
| -- lifetime `'x` defined here
...
LL | closure_expecting_bound(|x: &'x u32| {
| ^ requires that `'x` must outlive `'static`
|
= help: consider replacing `'x` with `'static`
error: aborting due to 4 previous errors

View File

@ -1,12 +1,14 @@
#![allow(warnings)] #![allow(warnings)]
fn closure_expecting_bound<F>(_: F) fn closure_expecting_bound<F>(_: F)
where F: FnOnce(&u32) where
F: FnOnce(&u32),
{ {
} }
fn closure_expecting_free<'a, F>(_: F) fn closure_expecting_free<'a, F>(_: F)
where F: FnOnce(&'a u32) where
F: FnOnce(&'a u32),
{ {
} }
@ -15,7 +17,7 @@ fn expect_bound_supply_nothing() {
// it to escape into `f`: // it to escape into `f`:
let mut f: Option<&u32> = None; let mut f: Option<&u32> = None;
closure_expecting_bound(|x| { closure_expecting_bound(|x| {
f = Some(x); //~ ERROR borrowed data cannot be stored outside of its closure f = Some(x); //~ ERROR borrowed data escapes outside of closure
}); });
} }
@ -25,22 +27,7 @@ fn expect_bound_supply_bound() {
// closure: // closure:
let mut f: Option<&u32> = None; let mut f: Option<&u32> = None;
closure_expecting_bound(|x: &u32| { closure_expecting_bound(|x: &u32| {
f = Some(x); //~ ERROR borrowed data cannot be stored outside of its closure f = Some(x); //~ ERROR borrowed data escapes outside of closure
});
}
fn expect_bound_supply_named<'x>() {
let mut f: Option<&u32> = None;
// Here we give a type annotation that `x` should be free. We get
// an error because of that.
closure_expecting_bound(|x: &'x u32| {
//~^ ERROR mismatched types
//~| ERROR mismatched types
// And we still cannot let `x` escape into `f`.
f = Some(x);
//~^ ERROR borrowed data cannot be stored outside of its closure
}); });
} }
@ -67,4 +54,4 @@ fn expect_free_supply_named<'x>() {
closure_expecting_free(|x: &'x u32| f = Some(x)); // OK closure_expecting_free(|x: &'x u32| f = Some(x)); // OK
} }
fn main() { } fn main() {}

View File

@ -1,87 +1,22 @@
error: borrowed data cannot be stored outside of its closure error[E0521]: borrowed data escapes outside of closure
--> $DIR/expect-region-supply-region.rs:18:18 --> $DIR/expect-region-supply-region.rs:20:9
| |
LL | let mut f: Option<&u32> = None; LL | let mut f: Option<&u32> = None;
| ----- borrowed data cannot be stored into here... | ----- `f` declared here, outside of the closure body
LL | closure_expecting_bound(|x| { LL | closure_expecting_bound(|x| {
| --- ...because it cannot outlive this closure | - `x` is a reference that is only valid in the closure body
LL | f = Some(x); LL | f = Some(x);
| ^ cannot be stored outside of its closure | ^^^^^^^^^^^ `x` escapes the closure body here
error: borrowed data cannot be stored outside of its closure error[E0521]: borrowed data escapes outside of closure
--> $DIR/expect-region-supply-region.rs:28:18 --> $DIR/expect-region-supply-region.rs:30:9
| |
LL | let mut f: Option<&u32> = None; LL | let mut f: Option<&u32> = None;
| ----- borrowed data cannot be stored into here... | ----- `f` declared here, outside of the closure body
LL | closure_expecting_bound(|x: &u32| { LL | closure_expecting_bound(|x: &u32| {
| --------- ...because it cannot outlive this closure | - `x` is a reference that is only valid in the closure body
LL | f = Some(x); LL | f = Some(x);
| ^ cannot be stored outside of its closure | ^^^^^^^^^^^ `x` escapes the closure body here
error[E0308]: mismatched types error: aborting due to 2 previous errors
--> $DIR/expect-region-supply-region.rs:37:33
|
LL | closure_expecting_bound(|x: &'x u32| {
| ^^^^^^^ lifetime mismatch
|
= note: expected reference `&u32`
found reference `&'x u32`
note: the anonymous lifetime #2 defined on the body at 37:29...
--> $DIR/expect-region-supply-region.rs:37:29
|
LL | closure_expecting_bound(|x: &'x u32| {
| _____________________________^
LL | |
LL | |
LL | |
... |
LL | |
LL | | });
| |_____^
note: ...does not necessarily outlive the lifetime `'x` as defined on the function body at 32:30
--> $DIR/expect-region-supply-region.rs:32:30
|
LL | fn expect_bound_supply_named<'x>() {
| ^^
error[E0308]: mismatched types
--> $DIR/expect-region-supply-region.rs:37:33
|
LL | closure_expecting_bound(|x: &'x u32| {
| ^^^^^^^ lifetime mismatch
|
= note: expected reference `&u32`
found reference `&'x u32`
note: the lifetime `'x` as defined on the function body at 32:30...
--> $DIR/expect-region-supply-region.rs:32:30
|
LL | fn expect_bound_supply_named<'x>() {
| ^^
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 37:29
--> $DIR/expect-region-supply-region.rs:37:29
|
LL | closure_expecting_bound(|x: &'x u32| {
| _____________________________^
LL | |
LL | |
LL | |
... |
LL | |
LL | | });
| |_____^
error: borrowed data cannot be stored outside of its closure
--> $DIR/expect-region-supply-region.rs:42:18
|
LL | let mut f: Option<&u32> = None;
| ----- borrowed data cannot be stored into here...
...
LL | closure_expecting_bound(|x: &'x u32| {
| ------------ ...because it cannot outlive this closure
...
LL | f = Some(x);
| ^ cannot be stored outside of its closure
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -0,0 +1,28 @@
error: lifetime may not live long enough
--> $DIR/E0490.rs:2:12
|
LL | fn f<'a, 'b>(y: &'b ()) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | let x: &'a _ = &y;
| ^^^^^ type annotation requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
error[E0597]: `y` does not live long enough
--> $DIR/E0490.rs:2:20
|
LL | fn f<'a, 'b>(y: &'b ()) {
| -- lifetime `'a` defined here
LL | let x: &'a _ = &y;
| ----- ^^ borrowed value does not live long enough
| |
| type annotation requires that `y` is borrowed for `'a`
...
LL | }
| - `y` dropped here while still borrowed
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0597`.

View File

@ -0,0 +1,8 @@
fn f<'a, 'b>(y: &'b ()) {
let x: &'a _ = &y;
//~^ E0490
//~| E0495
//~| E0495
}
fn main() {}

View File

@ -0,0 +1,76 @@
error[E0490]: a value of type `&'b ()` is borrowed for too long
--> $DIR/E0490.rs:2:20
|
LL | let x: &'a _ = &y;
| ^^
|
note: the type is valid for the lifetime `'a` as defined on the function body at 1:6
--> $DIR/E0490.rs:1:6
|
LL | fn f<'a, 'b>(y: &'b ()) {
| ^^
note: but the borrow lasts for the lifetime `'b` as defined on the function body at 1:10
--> $DIR/E0490.rs:1:10
|
LL | fn f<'a, 'b>(y: &'b ()) {
| ^^
error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
--> $DIR/E0490.rs:2:20
|
LL | let x: &'a _ = &y;
| ^^
|
note: first, the lifetime cannot outlive the lifetime `'b` as defined on the function body at 1:10...
--> $DIR/E0490.rs:1:10
|
LL | fn f<'a, 'b>(y: &'b ()) {
| ^^
note: ...so that the type `&'b ()` is not borrowed for too long
--> $DIR/E0490.rs:2:20
|
LL | let x: &'a _ = &y;
| ^^
note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 1:6...
--> $DIR/E0490.rs:1:6
|
LL | fn f<'a, 'b>(y: &'b ()) {
| ^^
note: ...so that reference does not outlive borrowed content
--> $DIR/E0490.rs:2:20
|
LL | let x: &'a _ = &y;
| ^^
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> $DIR/E0490.rs:2:20
|
LL | let x: &'a _ = &y;
| ^^
|
note: first, the lifetime cannot outlive the lifetime `'b` as defined on the function body at 1:10...
--> $DIR/E0490.rs:1:10
|
LL | fn f<'a, 'b>(y: &'b ()) {
| ^^
note: ...so that the expression is assignable
--> $DIR/E0490.rs:2:20
|
LL | let x: &'a _ = &y;
| ^^
= note: expected `&'a &()`
found `&'a &'b ()`
note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 1:6...
--> $DIR/E0490.rs:1:6
|
LL | fn f<'a, 'b>(y: &'b ()) {
| ^^
note: ...so that the reference type `&'a &()` does not outlive the data it points at
--> $DIR/E0490.rs:2:12
|
LL | let x: &'a _ = &y;
| ^^^^^
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0495`.

View File

@ -1,11 +0,0 @@
error: lifetime may not live long enough
--> $DIR/E0621-does-not-trigger-for-closures.rs:15:45
|
LL | invoke(&x, |a, b| if a > b { a } else { b });
| -- ^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is &'2 i32
| has type `&'1 i32`
error: aborting due to previous error

View File

@ -1,9 +1,7 @@
// Test that we give the generic E0495 when one of the free regions is // Test that we give the generic error when one of the free regions is
// bound in a closure (rather than suggesting a change to the signature // bound in a closure (rather than suggesting a change to the signature
// of the closure, which is not specified in `foo` but rather in `invoke`). // of the closure, which is not specified in `foo` but rather in `invoke`).
// FIXME - This might be better as a UI test, but the finer details
// of the error seem to vary on different machines.
fn invoke<'a, F>(x: &'a i32, f: F) -> &'a i32 fn invoke<'a, F>(x: &'a i32, f: F) -> &'a i32
where F: FnOnce(&'a i32, &i32) -> &'a i32 where F: FnOnce(&'a i32, &i32) -> &'a i32
{ {
@ -12,7 +10,7 @@ where F: FnOnce(&'a i32, &i32) -> &'a i32
} }
fn foo<'a>(x: &'a i32) { fn foo<'a>(x: &'a i32) {
invoke(&x, |a, b| if a > b { a } else { b }); //~ ERROR E0495 invoke(&x, |a, b| if a > b { a } else { b }); //~ ERROR lifetime may not live long enough
} }
fn main() {} fn main() {}

View File

@ -1,30 +1,11 @@
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements error: lifetime may not live long enough
--> $DIR/E0621-does-not-trigger-for-closures.rs:15:5 --> $DIR/E0621-does-not-trigger-for-closures.rs:13:45
| |
LL | invoke(&x, |a, b| if a > b { a } else { b }); LL | invoke(&x, |a, b| if a > b { a } else { b });
| ^^^^^^ | -- ^ returning this value requires that `'1` must outlive `'2`
| | ||
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 15:16... | |return type of closure is &'2 i32
--> $DIR/E0621-does-not-trigger-for-closures.rs:15:16 | has type `&'1 i32`
|
LL | invoke(&x, |a, b| if a > b { a } else { b });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that reference does not outlive borrowed content
--> $DIR/E0621-does-not-trigger-for-closures.rs:15:45
|
LL | invoke(&x, |a, b| if a > b { a } else { b });
| ^
note: but, the lifetime must be valid for the call at 15:5...
--> $DIR/E0621-does-not-trigger-for-closures.rs:15:5
|
LL | invoke(&x, |a, b| if a > b { a } else { b });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so type `&i32` of expression is valid during the expression
--> $DIR/E0621-does-not-trigger-for-closures.rs:15:5
|
LL | invoke(&x, |a, b| if a > b { a } else { b });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.

View File

@ -4,17 +4,11 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e>
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
| |
note: hidden type `Ordinary<'_>` captures the scope of call-site for function at 23:1 note: hidden type `Ordinary<'_>` captures lifetime smaller than the function body
--> $DIR/ordinary-bounds-unrelated.rs:23:1 --> $DIR/ordinary-bounds-unrelated.rs:18:74
| |
LL | / { LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e>
LL | | // Hidden type `Ordinary<'0>` with constraints: | ^^^^^^^^^^^^^^^^^^
LL | | //
LL | | // ```
... |
LL | | if condition() { a } else { b }
LL | | }
| |_^
error: aborting due to previous error error: aborting due to previous error

View File

@ -4,17 +4,11 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b>
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
| |
note: hidden type `Ordinary<'_>` captures the scope of call-site for function at 22:1 note: hidden type `Ordinary<'_>` captures lifetime smaller than the function body
--> $DIR/ordinary-bounds-unsuited.rs:22:1 --> $DIR/ordinary-bounds-unsuited.rs:20:62
| |
LL | / { LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b>
LL | | // We return a value: | ^^^^^^^^^^^^^^^^^^
LL | | //
LL | | // ```
... |
LL | | if condition() { a } else { b }
LL | | }
| |_^
error: aborting due to previous error error: aborting due to previous error

View File

@ -6,22 +6,21 @@ trait A<T>
fn get(&self) -> T { panic!() } fn get(&self) -> T { panic!() }
} }
struct B<'a, T:'a>(&'a (A<T>+'a)); struct B<'a, T: 'a>(&'a (A<T> + 'a));
trait X { fn foo(&self) {} } trait X { fn foo(&self) {} }
impl<'a, T> X for B<'a, T> {} impl<'a, T> X for B<'a, T> {}
fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> { fn f<'a, T, U>(v: Box<A<T> + 'static>) -> Box<X + 'static> {
// oh dear! // oh dear!
box B(&*v) as Box<X> box B(&*v) as Box<X>
//~^ ERROR the parameter type `T` may not live long enough //~^ ERROR the parameter type `T` may not live long enough
//~| ERROR the parameter type `T` may not live long enough //~| ERROR the parameter type `T` may not live long enough
//~| ERROR the parameter type `T` may not live long enough //~| ERROR the parameter type `T` may not live long enough
//~| ERROR the parameter type `T` may not live long enough //~| ERROR the parameter type `T` may not live long enough
//~| ERROR the parameter type `T` may not live long enough //~| ERROR the parameter type `T` may not live long enough
//~| ERROR the parameter type `T` may not live long enough //~| ERROR the parameter type `T` may not live long enough
//~| ERROR the parameter type `T` may not live long enough
} }
fn main() {} fn main() {}

View File

@ -1,7 +1,7 @@
error[E0310]: the parameter type `T` may not live long enough error[E0310]: the parameter type `T` may not live long enough
--> $DIR/regions-close-object-into-object-5.rs:17:5 --> $DIR/regions-close-object-into-object-5.rs:17:5
| |
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> { LL | fn f<'a, T, U>(v: Box<A<T> + 'static>) -> Box<X + 'static> {
| - help: consider adding an explicit lifetime bound...: `T: 'static` | - help: consider adding an explicit lifetime bound...: `T: 'static`
LL | // oh dear! LL | // oh dear!
LL | box B(&*v) as Box<X> LL | box B(&*v) as Box<X>
@ -13,25 +13,10 @@ note: ...so that the type `B<'_, T>` will meet its required lifetime bounds
LL | box B(&*v) as Box<X> LL | box B(&*v) as Box<X>
| ^^^^^^^^^^ | ^^^^^^^^^^
error[E0310]: the parameter type `T` may not live long enough
--> $DIR/regions-close-object-into-object-5.rs:17:5
|
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
| - help: consider adding an explicit lifetime bound...: `T: 'static`
LL | // oh dear!
LL | box B(&*v) as Box<X>
| ^^^^^^^^^^^^^^^^^^^^
|
note: ...so that it can be closed over into an object
--> $DIR/regions-close-object-into-object-5.rs:17:5
|
LL | box B(&*v) as Box<X>
| ^^^^^^^^^^^^^^^^^^^^
error[E0310]: the parameter type `T` may not live long enough error[E0310]: the parameter type `T` may not live long enough
--> $DIR/regions-close-object-into-object-5.rs:17:9 --> $DIR/regions-close-object-into-object-5.rs:17:9
| |
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> { LL | fn f<'a, T, U>(v: Box<A<T> + 'static>) -> Box<X + 'static> {
| - help: consider adding an explicit lifetime bound...: `T: 'static` | - help: consider adding an explicit lifetime bound...: `T: 'static`
LL | // oh dear! LL | // oh dear!
LL | box B(&*v) as Box<X> LL | box B(&*v) as Box<X>
@ -46,7 +31,7 @@ LL | box B(&*v) as Box<X>
error[E0310]: the parameter type `T` may not live long enough error[E0310]: the parameter type `T` may not live long enough
--> $DIR/regions-close-object-into-object-5.rs:17:9 --> $DIR/regions-close-object-into-object-5.rs:17:9
| |
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> { LL | fn f<'a, T, U>(v: Box<A<T> + 'static>) -> Box<X + 'static> {
| - help: consider adding an explicit lifetime bound...: `T: 'static` | - help: consider adding an explicit lifetime bound...: `T: 'static`
LL | // oh dear! LL | // oh dear!
LL | box B(&*v) as Box<X> LL | box B(&*v) as Box<X>
@ -61,7 +46,7 @@ LL | box B(&*v) as Box<X>
error[E0310]: the parameter type `T` may not live long enough error[E0310]: the parameter type `T` may not live long enough
--> $DIR/regions-close-object-into-object-5.rs:17:11 --> $DIR/regions-close-object-into-object-5.rs:17:11
| |
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> { LL | fn f<'a, T, U>(v: Box<A<T> + 'static>) -> Box<X + 'static> {
| - help: consider adding an explicit lifetime bound...: `T: 'static` | - help: consider adding an explicit lifetime bound...: `T: 'static`
LL | // oh dear! LL | // oh dear!
LL | box B(&*v) as Box<X> LL | box B(&*v) as Box<X>
@ -76,7 +61,7 @@ LL | box B(&*v) as Box<X>
error[E0310]: the parameter type `T` may not live long enough error[E0310]: the parameter type `T` may not live long enough
--> $DIR/regions-close-object-into-object-5.rs:17:11 --> $DIR/regions-close-object-into-object-5.rs:17:11
| |
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> { LL | fn f<'a, T, U>(v: Box<A<T> + 'static>) -> Box<X + 'static> {
| - help: consider adding an explicit lifetime bound...: `T: 'static` | - help: consider adding an explicit lifetime bound...: `T: 'static`
LL | // oh dear! LL | // oh dear!
LL | box B(&*v) as Box<X> LL | box B(&*v) as Box<X>
@ -91,7 +76,7 @@ LL | box B(&*v) as Box<X>
error[E0310]: the parameter type `T` may not live long enough error[E0310]: the parameter type `T` may not live long enough
--> $DIR/regions-close-object-into-object-5.rs:17:11 --> $DIR/regions-close-object-into-object-5.rs:17:11
| |
LL | fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> { LL | fn f<'a, T, U>(v: Box<A<T> + 'static>) -> Box<X + 'static> {
| - help: consider adding an explicit lifetime bound...: `T: 'static` | - help: consider adding an explicit lifetime bound...: `T: 'static`
LL | // oh dear! LL | // oh dear!
LL | box B(&*v) as Box<X> LL | box B(&*v) as Box<X>
@ -103,6 +88,6 @@ note: ...so that the type `(dyn A<T> + 'static)` is not borrowed for too long
LL | box B(&*v) as Box<X> LL | box B(&*v) as Box<X>
| ^^^ | ^^^
error: aborting due to 7 previous errors error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0310`. For more information about this error, try `rustc --explain E0310`.

View File

@ -1,5 +1,5 @@
error[E0310]: the parameter type `A` may not live long enough error[E0310]: the parameter type `A` may not live long enough
--> $DIR/regions-close-over-type-parameter-1.rs:10:5 --> $DIR/regions-close-over-type-parameter-1.rs:12:5
| |
LL | box v as Box<dyn SomeTrait + 'static> LL | box v as Box<dyn SomeTrait + 'static>
| ^^^^^ | ^^^^^
@ -7,7 +7,7 @@ LL | box v as Box<dyn SomeTrait + 'static>
= help: consider adding an explicit lifetime bound `A: 'static`... = help: consider adding an explicit lifetime bound `A: 'static`...
error[E0309]: the parameter type `A` may not live long enough error[E0309]: the parameter type `A` may not live long enough
--> $DIR/regions-close-over-type-parameter-1.rs:20:5 --> $DIR/regions-close-over-type-parameter-1.rs:21:5
| |
LL | box v as Box<dyn SomeTrait + 'b> LL | box v as Box<dyn SomeTrait + 'b>
| ^^^^^ | ^^^^^

View File

@ -4,22 +4,22 @@
// an object. This should yield errors unless `A` (and the object) // an object. This should yield errors unless `A` (and the object)
// both have suitable bounds. // both have suitable bounds.
trait SomeTrait { fn get(&self) -> isize; } trait SomeTrait {
fn get(&self) -> isize;
fn make_object1<A:SomeTrait>(v: A) -> Box<dyn SomeTrait + 'static> {
box v as Box<dyn SomeTrait + 'static>
//~^ ERROR the parameter type `A` may not live long enough
//~| ERROR the parameter type `A` may not live long enough
} }
fn make_object2<'a,A:SomeTrait+'a>(v: A) -> Box<dyn SomeTrait + 'a> { fn make_object1<A: SomeTrait>(v: A) -> Box<dyn SomeTrait + 'static> {
box v as Box<dyn SomeTrait + 'static>
//~^ ERROR the parameter type `A` may not live long enough
}
fn make_object2<'a, A: SomeTrait + 'a>(v: A) -> Box<dyn SomeTrait + 'a> {
box v as Box<dyn SomeTrait + 'a> box v as Box<dyn SomeTrait + 'a>
} }
fn make_object3<'a,'b,A:SomeTrait+'a>(v: A) -> Box<dyn SomeTrait + 'b> { fn make_object3<'a, 'b, A: SomeTrait + 'a>(v: A) -> Box<dyn SomeTrait + 'b> {
box v as Box<dyn SomeTrait + 'b> box v as Box<dyn SomeTrait + 'b>
//~^ ERROR the parameter type `A` may not live long enough //~^ ERROR the parameter type `A` may not live long enough
//~| ERROR the parameter type `A` may not live long enough
} }
fn main() { } fn main() {}

View File

@ -1,60 +1,32 @@
error[E0310]: the parameter type `A` may not live long enough error[E0310]: the parameter type `A` may not live long enough
--> $DIR/regions-close-over-type-parameter-1.rs:10:5 --> $DIR/regions-close-over-type-parameter-1.rs:12:5
| |
LL | fn make_object1<A:SomeTrait>(v: A) -> Box<dyn SomeTrait + 'static> { LL | fn make_object1<A: SomeTrait>(v: A) -> Box<dyn SomeTrait + 'static> {
| -- help: consider adding an explicit lifetime bound...: `A: 'static +` | -- help: consider adding an explicit lifetime bound...: `A: 'static +`
LL | box v as Box<dyn SomeTrait + 'static> LL | box v as Box<dyn SomeTrait + 'static>
| ^^^^^ | ^^^^^
| |
note: ...so that the type `A` will meet its required lifetime bounds note: ...so that the type `A` will meet its required lifetime bounds
--> $DIR/regions-close-over-type-parameter-1.rs:10:5 --> $DIR/regions-close-over-type-parameter-1.rs:12:5
| |
LL | box v as Box<dyn SomeTrait + 'static> LL | box v as Box<dyn SomeTrait + 'static>
| ^^^^^ | ^^^^^
error[E0310]: the parameter type `A` may not live long enough
--> $DIR/regions-close-over-type-parameter-1.rs:10:5
|
LL | fn make_object1<A:SomeTrait>(v: A) -> Box<dyn SomeTrait + 'static> {
| -- help: consider adding an explicit lifetime bound...: `A: 'static +`
LL | box v as Box<dyn SomeTrait + 'static>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...so that it can be closed over into an object
--> $DIR/regions-close-over-type-parameter-1.rs:10:5
|
LL | box v as Box<dyn SomeTrait + 'static>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0309]: the parameter type `A` may not live long enough error[E0309]: the parameter type `A` may not live long enough
--> $DIR/regions-close-over-type-parameter-1.rs:20:5 --> $DIR/regions-close-over-type-parameter-1.rs:21:5
| |
LL | fn make_object3<'a,'b,A:SomeTrait+'a>(v: A) -> Box<dyn SomeTrait + 'b> { LL | fn make_object3<'a, 'b, A: SomeTrait + 'a>(v: A) -> Box<dyn SomeTrait + 'b> {
| -- help: consider adding an explicit lifetime bound...: `A: 'b +` | -- help: consider adding an explicit lifetime bound...: `A: 'b +`
LL | box v as Box<dyn SomeTrait + 'b> LL | box v as Box<dyn SomeTrait + 'b>
| ^^^^^ | ^^^^^
| |
note: ...so that the type `A` will meet its required lifetime bounds note: ...so that the type `A` will meet its required lifetime bounds
--> $DIR/regions-close-over-type-parameter-1.rs:20:5 --> $DIR/regions-close-over-type-parameter-1.rs:21:5
| |
LL | box v as Box<dyn SomeTrait + 'b> LL | box v as Box<dyn SomeTrait + 'b>
| ^^^^^ | ^^^^^
error[E0309]: the parameter type `A` may not live long enough error: aborting due to 2 previous errors
--> $DIR/regions-close-over-type-parameter-1.rs:20:5
|
LL | fn make_object3<'a,'b,A:SomeTrait+'a>(v: A) -> Box<dyn SomeTrait + 'b> {
| -- help: consider adding an explicit lifetime bound...: `A: 'b +`
LL | box v as Box<dyn SomeTrait + 'b>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...so that it can be closed over into an object
--> $DIR/regions-close-over-type-parameter-1.rs:20:5
|
LL | box v as Box<dyn SomeTrait + 'b>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0309, E0310. Some errors have detailed explanations: E0309, E0310.
For more information about an error, try `rustc --explain E0309`. For more information about an error, try `rustc --explain E0309`.

View File

@ -1,11 +0,0 @@
error: lifetime may not live long enough
--> $DIR/regions-escape-method.rs:15:13
|
LL | s.f(|p| p)
| -- ^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is &'2 i32
| has type `&'1 i32`
error: aborting due to previous error

View File

@ -12,5 +12,5 @@ impl S {
fn main() { fn main() {
let s = S; let s = S;
s.f(|p| p) //~ ERROR cannot infer s.f(|p| p) //~ ERROR lifetime may not live long enough
} }

View File

@ -1,32 +1,11 @@
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements error: lifetime may not live long enough
--> $DIR/regions-escape-method.rs:15:13 --> $DIR/regions-escape-method.rs:15:13
| |
LL | s.f(|p| p) LL | s.f(|p| p)
| ^ | -- ^ returning this value requires that `'1` must outlive `'2`
| | ||
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 15:9... | |return type of closure is &'2 i32
--> $DIR/regions-escape-method.rs:15:9 | has type `&'1 i32`
|
LL | s.f(|p| p)
| ^^^^^
note: ...so that the expression is assignable
--> $DIR/regions-escape-method.rs:15:13
|
LL | s.f(|p| p)
| ^
= note: expected `&i32`
found `&i32`
note: but, the lifetime must be valid for the method call at 15:5...
--> $DIR/regions-escape-method.rs:15:5
|
LL | s.f(|p| p)
| ^^^^^^^^^^
note: ...so that a type/lifetime parameter is in scope here
--> $DIR/regions-escape-method.rs:15:5
|
LL | s.f(|p| p)
| ^^^^^^^^^^
error: aborting due to previous error error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.

View File

@ -1,11 +0,0 @@
error: lifetime may not live long enough
--> $DIR/regions-escape-via-trait-or-not.rs:18:14
|
LL | with(|o| o)
| -- ^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is &'2 isize
| has type `&'1 isize`
error: aborting due to previous error

View File

@ -15,7 +15,7 @@ fn with<R:Deref, F>(f: F) -> isize where F: FnOnce(&isize) -> R {
} }
fn return_it() -> isize { fn return_it() -> isize {
with(|o| o) //~ ERROR cannot infer with(|o| o) //~ ERROR lifetime may not live long enough
} }
fn main() { fn main() {

View File

@ -1,32 +1,11 @@
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements error: lifetime may not live long enough
--> $DIR/regions-escape-via-trait-or-not.rs:18:14 --> $DIR/regions-escape-via-trait-or-not.rs:18:14
| |
LL | with(|o| o) LL | with(|o| o)
| ^ | -- ^ returning this value requires that `'1` must outlive `'2`
| | ||
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 18:10... | |return type of closure is &'2 isize
--> $DIR/regions-escape-via-trait-or-not.rs:18:10 | has type `&'1 isize`
|
LL | with(|o| o)
| ^^^^^
note: ...so that the expression is assignable
--> $DIR/regions-escape-via-trait-or-not.rs:18:14
|
LL | with(|o| o)
| ^
= note: expected `&isize`
found `&isize`
note: but, the lifetime must be valid for the expression at 18:5...
--> $DIR/regions-escape-via-trait-or-not.rs:18:5
|
LL | with(|o| o)
| ^^^^
note: ...so type `fn([closure@$DIR/regions-escape-via-trait-or-not.rs:18:10: 18:15]) -> isize {with::<&isize, [closure@$DIR/regions-escape-via-trait-or-not.rs:18:10: 18:15]>}` of expression is valid during the expression
--> $DIR/regions-escape-via-trait-or-not.rs:18:5
|
LL | with(|o| o)
| ^^^^
error: aborting due to previous error error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.

View File

@ -1,11 +0,0 @@
error: lifetime may not live long enough
--> $DIR/regions-infer-call-3.rs:8:24
|
LL | let z = with(|y| { select(x, y) });
| -- ^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is &'2 isize
| has type `&'1 isize`
error: aborting due to previous error

View File

@ -6,7 +6,7 @@ fn with<T, F>(f: F) -> T where F: FnOnce(&isize) -> T {
fn manip<'a>(x: &'a isize) -> isize { fn manip<'a>(x: &'a isize) -> isize {
let z = with(|y| { select(x, y) }); let z = with(|y| { select(x, y) });
//~^ ERROR cannot infer //~^ ERROR lifetime may not live long enough
*z *z
} }

View File

@ -1,30 +1,11 @@
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter 'r in function call due to conflicting requirements error: lifetime may not live long enough
--> $DIR/regions-infer-call-3.rs:8:24 --> $DIR/regions-infer-call-3.rs:8:24
| |
LL | let z = with(|y| { select(x, y) }); LL | let z = with(|y| { select(x, y) });
| ^^^^^^^^^^^^ | -- ^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
| | ||
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 8:18... | |return type of closure is &'2 isize
--> $DIR/regions-infer-call-3.rs:8:18 | has type `&'1 isize`
|
LL | let z = with(|y| { select(x, y) });
| ^^^^^^^^^^^^^^^^^^^^
note: ...so that reference does not outlive borrowed content
--> $DIR/regions-infer-call-3.rs:8:34
|
LL | let z = with(|y| { select(x, y) });
| ^
note: but, the lifetime must be valid for the call at 8:13...
--> $DIR/regions-infer-call-3.rs:8:13
|
LL | let z = with(|y| { select(x, y) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so type `&isize` of expression is valid during the expression
--> $DIR/regions-infer-call-3.rs:8:13
|
LL | let z = with(|y| { select(x, y) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.

View File

@ -1,13 +0,0 @@
error: captured variable cannot escape `FnMut` closure body
--> $DIR/regions-return-ref-to-upvar-issue-17403.rs:7:24
|
LL | let mut f = || &mut x;
| - ^^^^^^ 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

View File

@ -4,7 +4,7 @@ fn main() {
// Unboxed closure case // Unboxed closure case
{ {
let mut x = 0; let mut x = 0;
let mut f = || &mut x; //~ ERROR cannot infer let mut f = || &mut x; //~ ERROR captured variable cannot escape `FnMut` closure body
let x = f(); let x = f();
let y = f(); let y = f();
} }

View File

@ -1,30 +1,13 @@
error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements error: captured variable cannot escape `FnMut` closure body
--> $DIR/regions-return-ref-to-upvar-issue-17403.rs:7:24 --> $DIR/regions-return-ref-to-upvar-issue-17403.rs:7:24
| |
LL | let mut f = || &mut x; LL | let mut f = || &mut x;
| ^^^^^^ | - ^^^^^^ returns a reference to a captured variable which escapes the closure body
| |
| inferred to be a `FnMut` closure
| |
note: first, the lifetime cannot outlive the lifetime `'_` as defined on the body at 7:21... = note: `FnMut` closures only have access to their captured variables while they are executing...
--> $DIR/regions-return-ref-to-upvar-issue-17403.rs:7:21 = note: ...therefore, they cannot allow references to captured variables to escape
|
LL | let mut f = || &mut x;
| ^^^^^^^^^
note: ...so that closure can access `x`
--> $DIR/regions-return-ref-to-upvar-issue-17403.rs:7:24
|
LL | let mut f = || &mut x;
| ^^^^^^
note: but, the lifetime must be valid for the call at 9:17...
--> $DIR/regions-return-ref-to-upvar-issue-17403.rs:9:17
|
LL | let y = f();
| ^^^
note: ...so type `&mut i32` of expression is valid during the expression
--> $DIR/regions-return-ref-to-upvar-issue-17403.rs:9:17
|
LL | let y = f();
| ^^^
error: aborting due to previous error error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.

View File

@ -3,8 +3,8 @@
// revisions: legacy v0 // revisions: legacy v0
//[legacy]compile-flags: -Z symbol-mangling-version=legacy //[legacy]compile-flags: -Z symbol-mangling-version=legacy
//[v0]compile-flags: -Z symbol-mangling-version=v0 //[v0]compile-flags: -Z symbol-mangling-version=v0
//[legacy]normalize-stderr-32bit: "hdb62078998ce7ea8" -> "SYMBOL_HASH" //[legacy]normalize-stderr-32bit: "h5ef5dfc14aeecbfc" -> "SYMBOL_HASH"
//[legacy]normalize-stderr-64bit: "h62e540f14f879d56" -> "SYMBOL_HASH" //[legacy]normalize-stderr-64bit: "h9e54d216f70fcbc5" -> "SYMBOL_HASH"
#![feature(optin_builtin_traits, rustc_attrs)] #![feature(optin_builtin_traits, rustc_attrs)]
#![allow(dead_code)] #![allow(dead_code)]