Skip to content

Commit

Permalink
Use revisions for NLL in lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackh726 committed May 22, 2022
1 parent fe91cfd commit 383fbee
Show file tree
Hide file tree
Showing 108 changed files with 398 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
error[E0308]: mismatched types
--> $DIR/issue-79187-2.rs:8:5
--> $DIR/issue-79187-2.rs:12:5
|
LL | take_foo(|a| a);
| ^^^^^^^^ lifetime mismatch
|
= note: expected type `for<'r> Fn<(&'r i32,)>`
found type `Fn<(&i32,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-79187-2.rs:8:14
--> $DIR/issue-79187-2.rs:12:14
|
LL | take_foo(|a| a);
| ^^^^^
note: the lifetime requirement is introduced here
--> $DIR/issue-79187-2.rs:5:21
--> $DIR/issue-79187-2.rs:9:21
|
LL | fn take_foo(_: impl Foo) {}
| ^^^

error[E0308]: mismatched types
--> $DIR/issue-79187-2.rs:9:5
--> $DIR/issue-79187-2.rs:16:5
|
LL | take_foo(|a: &i32| a);
| ^^^^^^^^ lifetime mismatch
|
= note: expected reference `&i32`
found reference `&i32`
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
--> $DIR/issue-79187-2.rs:9:14
--> $DIR/issue-79187-2.rs:16:14
|
LL | take_foo(|a: &i32| a);
| ^^^^^^^^^^^
note: the lifetime requirement is introduced here
--> $DIR/issue-79187-2.rs:5:21
--> $DIR/issue-79187-2.rs:9:21
|
LL | fn take_foo(_: impl Foo) {}
| ^^^

error[E0308]: mismatched types
--> $DIR/issue-79187-2.rs:10:5
--> $DIR/issue-79187-2.rs:20:5
|
LL | take_foo(|a: &i32| -> &i32 { a });
| ^^^^^^^^ lifetime mismatch
|
= note: expected reference `&i32`
found reference `&i32`
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
--> $DIR/issue-79187-2.rs:10:14
--> $DIR/issue-79187-2.rs:20:14
|
LL | take_foo(|a: &i32| -> &i32 { a });
| ^^^^^^^^^^^^^^^^^^^^^^^
note: the lifetime requirement is introduced here
--> $DIR/issue-79187-2.rs:5:21
--> $DIR/issue-79187-2.rs:9:21
|
LL | fn take_foo(_: impl Foo) {}
| ^^^
Expand Down
20 changes: 10 additions & 10 deletions src/test/ui/lifetimes/issue-79187-2.nll.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: lifetime may not live long enough
--> $DIR/issue-79187-2.rs:9:24
--> $DIR/issue-79187-2.rs:16:24
|
LL | take_foo(|a: &i32| a);
| - - ^ returning this value requires that `'1` must outlive `'2`
Expand All @@ -8,7 +8,7 @@ LL | take_foo(|a: &i32| a);
| let's call the lifetime of this reference `'1`

error: lifetime may not live long enough
--> $DIR/issue-79187-2.rs:10:34
--> $DIR/issue-79187-2.rs:20:34
|
LL | take_foo(|a: &i32| -> &i32 { a });
| - - ^ returning this value requires that `'1` must outlive `'2`
Expand All @@ -17,7 +17,7 @@ LL | take_foo(|a: &i32| -> &i32 { a });
| let's call the lifetime of this reference `'1`

error: implementation of `FnOnce` is not general enough
--> $DIR/issue-79187-2.rs:8:5
--> $DIR/issue-79187-2.rs:12:5
|
LL | take_foo(|a| a);
| ^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
Expand All @@ -26,48 +26,48 @@ LL | take_foo(|a| a);
= note: ...but it actually implements `FnOnce<(&'2 i32,)>`, for some specific lifetime `'2`

error[E0308]: mismatched types
--> $DIR/issue-79187-2.rs:8:5
--> $DIR/issue-79187-2.rs:12:5
|
LL | take_foo(|a| a);
| ^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected type `for<'r> Fn<(&'r i32,)>`
found type `Fn<(&i32,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-79187-2.rs:8:14
--> $DIR/issue-79187-2.rs:12:14
|
LL | take_foo(|a| a);
| ^^^^^
note: the lifetime requirement is introduced here
--> $DIR/issue-79187-2.rs:5:21
--> $DIR/issue-79187-2.rs:9:21
|
LL | fn take_foo(_: impl Foo) {}
| ^^^

error[E0308]: mismatched types
--> $DIR/issue-79187-2.rs:9:5
--> $DIR/issue-79187-2.rs:16:5
|
LL | take_foo(|a: &i32| a);
| ^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected reference `&i32`
found reference `&i32`
note: the lifetime requirement is introduced here
--> $DIR/issue-79187-2.rs:5:21
--> $DIR/issue-79187-2.rs:9:21
|
LL | fn take_foo(_: impl Foo) {}
| ^^^

error[E0308]: mismatched types
--> $DIR/issue-79187-2.rs:10:5
--> $DIR/issue-79187-2.rs:20:5
|
LL | take_foo(|a: &i32| -> &i32 { a });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected reference `&i32`
found reference `&i32`
note: the lifetime requirement is introduced here
--> $DIR/issue-79187-2.rs:5:21
--> $DIR/issue-79187-2.rs:9:21
|
LL | fn take_foo(_: impl Foo) {}
| ^^^
Expand Down
19 changes: 16 additions & 3 deletions src/test/ui/lifetimes/issue-79187-2.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
// revisions: base nll
// ignore-compare-mode-nll
//[nll] compile-flags: -Z borrowck=mir

trait Foo {}

impl<F> Foo for F where F: Fn(&i32) -> &i32 {}

fn take_foo(_: impl Foo) {}

fn main() {
take_foo(|a| a); //~ ERROR mismatched types
take_foo(|a: &i32| a); //~ ERROR mismatched types
take_foo(|a: &i32| -> &i32 { a }); //~ ERROR mismatched types
take_foo(|a| a);
//[base]~^ ERROR mismatched types
//[nll]~^^ ERROR implementation of `FnOnce` is not general enough
//[nll]~| ERROR mismatched types
take_foo(|a: &i32| a);
//[base]~^ ERROR mismatched types
//[nll]~^^ ERROR lifetime may not live long enough
//[nll]~| ERROR mismatched types
take_foo(|a: &i32| -> &i32 { a });
//[base]~^ ERROR mismatched types
//[nll]~^^ ERROR lifetime may not live long enough
//[nll]~| ERROR mismatched types

// OK
take_foo(identity(|a| a));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: implementation of `FnOnce` is not general enough
--> $DIR/issue-79187.rs:5:5
--> $DIR/issue-79187.rs:9:5
|
LL | thing(f);
| ^^^^^ implementation of `FnOnce` is not general enough
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/lifetimes/issue-79187.nll.stderr
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
error[E0308]: mismatched types
--> $DIR/issue-79187.rs:5:5
--> $DIR/issue-79187.rs:9:5
|
LL | thing(f);
| ^^^^^^^^ one type is more general than the other
|
= note: expected type `for<'r> FnOnce<(&'r u32,)>`
found type `FnOnce<(&u32,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-79187.rs:4:13
--> $DIR/issue-79187.rs:8:13
|
LL | let f = |_| ();
| ^^^^^^
note: the lifetime requirement is introduced here
--> $DIR/issue-79187.rs:1:18
--> $DIR/issue-79187.rs:5:18
|
LL | fn thing(x: impl FnOnce(&u32)) {}
| ^^^^^^^^^^^^

error: implementation of `FnOnce` is not general enough
--> $DIR/issue-79187.rs:5:5
--> $DIR/issue-79187.rs:9:5
|
LL | thing(f);
| ^^^^^^^^ implementation of `FnOnce` is not general enough
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/lifetimes/issue-79187.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// revisions: base nll
// ignore-compare-mode-nll
//[nll] compile-flags: -Z borrowck=mir

fn thing(x: impl FnOnce(&u32)) {}

fn main() {
let f = |_| ();
thing(f); //~ERROR implementation of `FnOnce` is not general enough
thing(f);
//[nll]~^ ERROR mismatched types
//~^^ ERROR implementation of `FnOnce` is not general enough
}
15 changes: 15 additions & 0 deletions src/test/ui/lifetimes/issue-90170-elision-mismatch-nll.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// FIXME(nll): On NLL stabilization, this should be replace
// `issue-90170-elision-mismatch.rs`. Compiletest has
// problems with rustfix and revisions.
// ignore-compare-mode-nll
// compile-flags: -Zborrowck=mir

// run-rustfix

pub fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } //~ ERROR lifetime may not live long enough

pub fn foo2<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } //~ ERROR lifetime may not live long enough

pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } //~ ERROR lifetime may not live long enough

fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/lifetimes/issue-90170-elision-mismatch-nll.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// FIXME(nll): On NLL stabilization, this should be replace
// `issue-90170-elision-mismatch.rs`. Compiletest has
// problems with rustfix and revisions.
// ignore-compare-mode-nll
// compile-flags: -Zborrowck=mir

// run-rustfix

pub fn foo(x: &mut Vec<&u8>, y: &u8) { x.push(y); } //~ ERROR lifetime may not live long enough

pub fn foo2(x: &mut Vec<&'_ u8>, y: &u8) { x.push(y); } //~ ERROR lifetime may not live long enough

pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&u8>, y: &u8) { x.push(y); } //~ ERROR lifetime may not live long enough

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: lifetime may not live long enough
--> $DIR/issue-90170-elision-mismatch.rs:3:40
--> $DIR/issue-90170-elision-mismatch-nll.rs:9:40
|
LL | pub fn foo(x: &mut Vec<&u8>, y: &u8) { x.push(y); }
| - - ^^^^^^^^^ argument requires that `'1` must outlive `'2`
Expand All @@ -13,7 +13,7 @@ LL | pub fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); }
| ++++ ++ ++

error: lifetime may not live long enough
--> $DIR/issue-90170-elision-mismatch.rs:5:44
--> $DIR/issue-90170-elision-mismatch-nll.rs:11:44
|
LL | pub fn foo2(x: &mut Vec<&'_ u8>, y: &u8) { x.push(y); }
| - - ^^^^^^^^^ argument requires that `'1` must outlive `'2`
Expand All @@ -27,7 +27,7 @@ LL | pub fn foo2<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); }
| ++++ ~~ ++

error: lifetime may not live long enough
--> $DIR/issue-90170-elision-mismatch.rs:7:63
--> $DIR/issue-90170-elision-mismatch-nll.rs:13:63
|
LL | pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&u8>, y: &u8) { x.push(y); }
| - - ^^^^^^^^^ argument requires that `'1` must outlive `'2`
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/lifetimes/issue-90170-elision-mismatch.fixed
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// FIXME(nll): On NLL stabilization, this should be replaced by
// `issue-90170-elision-mismatch-nll.rs`. Compiletest has
// problems with rustfix and revisions.
// ignore-compare-mode-nll

// run-rustfix

pub fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); } //~ ERROR lifetime mismatch
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/lifetimes/issue-90170-elision-mismatch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// FIXME(nll): On NLL stabilization, this should be replaced by
// `issue-90170-elision-mismatch-nll.rs`. Compiletest has
// problems with rustfix and revisions.
// ignore-compare-mode-nll

// run-rustfix

pub fn foo(x: &mut Vec<&u8>, y: &u8) { x.push(y); } //~ ERROR lifetime mismatch
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/lifetimes/issue-90170-elision-mismatch.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0623]: lifetime mismatch
--> $DIR/issue-90170-elision-mismatch.rs:3:47
--> $DIR/issue-90170-elision-mismatch.rs:8:47
|
LL | pub fn foo(x: &mut Vec<&u8>, y: &u8) { x.push(y); }
| --- --- ^ ...but data from `y` flows into `x` here
Expand All @@ -13,7 +13,7 @@ LL | pub fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); }
| ++++ ++ ++

error[E0623]: lifetime mismatch
--> $DIR/issue-90170-elision-mismatch.rs:5:51
--> $DIR/issue-90170-elision-mismatch.rs:10:51
|
LL | pub fn foo2(x: &mut Vec<&'_ u8>, y: &u8) { x.push(y); }
| ------ --- ^ ...but data from `y` flows into `x` here
Expand All @@ -27,7 +27,7 @@ LL | pub fn foo2<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); }
| ++++ ~~ ++

error[E0623]: lifetime mismatch
--> $DIR/issue-90170-elision-mismatch.rs:7:70
--> $DIR/issue-90170-elision-mismatch.rs:12:70
|
LL | pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&u8>, y: &u8) { x.push(y); }
| --- --- ^ ...but data from `y` flows into `x` here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0759]: `foo` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/issue-90600-expected-return-static-indirect.rs:7:32
--> $DIR/issue-90600-expected-return-static-indirect.rs:11:32
|
LL | fn inner(mut foo: &[u8]) {
| ----- this data with an anonymous lifetime `'_`...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0597]: `foo` does not live long enough
--> $DIR/issue-90600-expected-return-static-indirect.rs:7:32
--> $DIR/issue-90600-expected-return-static-indirect.rs:11:32
|
LL | let refcell = RefCell::new(&mut foo);
| ^^^^^^^^ borrowed value does not live long enough
LL |
...
LL | let read = &refcell as &RefCell<dyn Read>;
| -------- cast requires that `foo` is borrowed for `'static`
...
LL | }
| - `foo` dropped here while still borrowed

error: lifetime may not live long enough
--> $DIR/issue-90600-expected-return-static-indirect.rs:9:16
--> $DIR/issue-90600-expected-return-static-indirect.rs:14:16
|
LL | fn inner(mut foo: &[u8]) {
| - let's call the lifetime of this reference `'1`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// revisions: base nll
// ignore-compare-mode-nll
//[nll] compile-flags: -Z borrowck=mir

use std::cell::RefCell;
use std::io::Read;

fn main() {}

fn inner(mut foo: &[u8]) {
let refcell = RefCell::new(&mut foo);
//~^ ERROR `foo` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement [E0759]
//[base]~^ ERROR `foo` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement [E0759]
//[nll]~^^ ERROR `foo` does not live long enough
let read = &refcell as &RefCell<dyn Read>;
//[nll]~^ ERROR lifetime may not live long enough

read_thing(read);
}
Expand Down
Loading

0 comments on commit 383fbee

Please sign in to comment.