Use revisions for NLL in closures

This commit is contained in:
Jack Huey 2022-05-21 14:22:42 -04:00
parent eb222bf943
commit f1a7f9ab40
6 changed files with 36 additions and 18 deletions

View file

@ -1,22 +1,24 @@
error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:9
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:9:9
|
LL | fn foo(x: &()) {
| --- this data with an anonymous lifetime `'_`...
LL | bar(|| {
| _________^
LL | |
LL | |
LL | |
LL | | let _ = x;
LL | | })
| |_____^ ...is used here...
|
note: ...and is required to live as long as `'static` here
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:9:5
|
LL | bar(|| {
| ^^^
note: `'static` lifetime requirement introduced by this bound
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:1:39
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:39
|
LL | fn bar<F>(blk: F) where F: FnOnce() + 'static {
| ^^^^^^^

View file

@ -1,5 +1,5 @@
error[E0521]: borrowed data escapes outside of function
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:9:5
|
LL | fn foo(x: &()) {
| - - let's call the lifetime of this reference `'1`
@ -7,6 +7,8 @@ LL | fn foo(x: &()) {
| `x` is a reference that is only valid in the function body
LL | / bar(|| {
LL | |
LL | |
LL | |
LL | | let _ = x;
LL | | })
| | ^
@ -15,19 +17,21 @@ LL | | })
| argument requires that `'1` must outlive `'static`
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:9
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:9:9
|
LL | bar(|| {
| ^^ may outlive borrowed value `x`
LL |
...
LL | let _ = x;
| - `x` is borrowed here
|
note: function requires argument type to outlive `'static`
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:5:5
--> $DIR/closure-bounds-static-cant-capture-borrowed.rs:9:5
|
LL | / bar(|| {
LL | |
LL | |
LL | |
LL | | let _ = x;
LL | | })
| |______^

View file

@ -1,9 +1,15 @@
// ignore-compare-mode-nll
// revisions: base nll
// [nll]compile-flags: -Zborrowck=mir
fn bar<F>(blk: F) where F: FnOnce() + 'static {
}
fn foo(x: &()) {
bar(|| {
//~^ ERROR `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement [E0759]
//[base]~^ ERROR `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement [E0759]
//[nll]~^^ ERROR borrowed data escapes
//[nll]~| ERROR closure may outlive
let _ = x;
})
}

View file

@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/expect-region-supply-region-2.rs:14:33
--> $DIR/expect-region-supply-region-2.rs:18:33
|
LL | closure_expecting_bound(|x: &'x u32| {
| ^^^^^^^ lifetime mismatch
@ -7,7 +7,7 @@ LL | closure_expecting_bound(|x: &'x u32| {
= note: expected reference `&u32`
found reference `&'x u32`
note: the anonymous lifetime #1 defined here...
--> $DIR/expect-region-supply-region-2.rs:14:29
--> $DIR/expect-region-supply-region-2.rs:18:29
|
LL | closure_expecting_bound(|x: &'x u32| {
| _____________________________^
@ -19,13 +19,13 @@ LL | | f = Some(x);
LL | | });
| |_____^
note: ...does not necessarily outlive the lifetime `'x` as defined here
--> $DIR/expect-region-supply-region-2.rs:9:30
--> $DIR/expect-region-supply-region-2.rs:13:30
|
LL | fn expect_bound_supply_named<'x>() {
| ^^
error[E0308]: mismatched types
--> $DIR/expect-region-supply-region-2.rs:14:33
--> $DIR/expect-region-supply-region-2.rs:18:33
|
LL | closure_expecting_bound(|x: &'x u32| {
| ^^^^^^^ lifetime mismatch
@ -33,12 +33,12 @@ LL | closure_expecting_bound(|x: &'x u32| {
= note: expected reference `&u32`
found reference `&'x u32`
note: the lifetime `'x` as defined here...
--> $DIR/expect-region-supply-region-2.rs:9:30
--> $DIR/expect-region-supply-region-2.rs:13:30
|
LL | fn expect_bound_supply_named<'x>() {
| ^^
note: ...does not necessarily outlive the anonymous lifetime #1 defined here
--> $DIR/expect-region-supply-region-2.rs:14:29
--> $DIR/expect-region-supply-region-2.rs:18:29
|
LL | closure_expecting_bound(|x: &'x u32| {
| _____________________________^

View file

@ -1,5 +1,5 @@
error: lifetime may not live long enough
--> $DIR/expect-region-supply-region-2.rs:14:30
--> $DIR/expect-region-supply-region-2.rs:18:30
|
LL | fn expect_bound_supply_named<'x>() {
| -- lifetime `'x` defined here
@ -10,7 +10,7 @@ LL | closure_expecting_bound(|x: &'x u32| {
| requires that `'1` must outlive `'x`
error: lifetime may not live long enough
--> $DIR/expect-region-supply-region-2.rs:14:30
--> $DIR/expect-region-supply-region-2.rs:18:30
|
LL | fn expect_bound_supply_named<'x>() {
| -- lifetime `'x` defined here

View file

@ -1,3 +1,7 @@
// ignore-compare-mode-nll
// revisions: base nll
// [nll]compile-flags: -Zborrowck=mir
#![allow(warnings)]
fn closure_expecting_bound<F>(_: F)
@ -12,8 +16,10 @@ fn expect_bound_supply_named<'x>() {
// 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
//[base]~^ ERROR mismatched types
//[base]~| ERROR mismatched types
//[nll]~^^^ ERROR lifetime may not live long enough
//[nll]~| ERROR lifetime may not live long enough
// Borrowck doesn't get a chance to run, but if it did it should error
// here.