forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/test/ui/issues/issue-57464-avoid-eager-conversion-to-region-vid.ast.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0373]: closure may outlive the current function, but it borrows `local`, which is owned by the current function | ||
--> $DIR/issue-57464-avoid-eager-conversion-to-region-vid.rs:45:13 | ||
| | ||
LL | let m = |_: ()| poll_fn(|| { local; }); | ||
| ^^^^^^^ ----- `local` is borrowed here | ||
| | | ||
| may outlive borrowed value `local` | ||
help: to force the closure to take ownership of `local` (and any other referenced variables), use the `move` keyword | ||
| | ||
LL | let m = move |_: ()| poll_fn(|| { local; }); | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0373`. |
14 changes: 14 additions & 0 deletions
14
src/test/ui/issues/issue-57464-avoid-eager-conversion-to-region-vid.mig.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0373]: closure may outlive the current function, but it borrows `local`, which is owned by the current function | ||
--> $DIR/issue-57464-avoid-eager-conversion-to-region-vid.rs:46:13 | ||
| | ||
LL | let m = |_: ()| poll_fn(|| { local; }); | ||
| ^^^^^^^ ----- `local` is borrowed here | ||
| | | ||
| may outlive borrowed value `local` | ||
help: to force the closure to take ownership of `local` (and any other referenced variables), use the `move` keyword | ||
| | ||
LL | let m = move |_: ()| poll_fn(|| { local; }); | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
21 changes: 21 additions & 0 deletions
21
src/test/ui/issues/issue-57464-avoid-eager-conversion-to-region-vid.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0373]: closure may outlive the current function, but it borrows `local`, which is owned by the current function | ||
--> $DIR/issue-57464-avoid-eager-conversion-to-region-vid.rs:45:13 | ||
| | ||
LL | let m = |_: ()| poll_fn(|| { local; }); | ||
| ^^^^^^^ ----- `local` is borrowed here | ||
| | | ||
| may outlive borrowed value `local` | ||
| | ||
note: closure is returned here | ||
--> $DIR/issue-57464-avoid-eager-conversion-to-region-vid.rs:51:5 | ||
| | ||
LL | and_then(f) | ||
| ^^^^^^^^^^^ | ||
help: to force the closure to take ownership of `local` (and any other referenced variables), use the `move` keyword | ||
| | ||
LL | let m = move |_: ()| poll_fn(|| { local; }); | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0373`. |
52 changes: 52 additions & 0 deletions
52
src/test/ui/issues/issue-57464-avoid-eager-conversion-to-region-vid.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// This test managed to tickle a part of the compiler where a region | ||
// representing a static scope (a call-site scope, to be precise) was | ||
// leaking the where clause of a type underlying an `impl Trait`. This | ||
// caused an ICE in spots where we assume that all regions must be | ||
// region_vid's (unique representatives used in NLL) and then | ||
// attempted to eagerly convert the region to its region_vid, which | ||
// does not work for scopes which do not have region_vids (apart from | ||
// the 'static region). | ||
// | ||
// This regression test is just meant to check that we do not ICE, | ||
// regardless of whether NLL is turned on or not. | ||
|
||
// revisions: ast nll | ||
//[ast]compile-flags: -Z borrowck=ast | ||
//[mig]compile-flags: -Z borrowck=migrate -Z two-phase-borrows | ||
//[nll]compile-flags: -Z borrowck=mir -Z two-phase-borrows | ||
|
||
// don't worry about the --compare-mode=nll on this test. | ||
// ignore-compare-mode-nll | ||
|
||
pub struct AndThen<B, F>(B, F); | ||
fn and_then<F, B>(_: F) -> AndThen<B, F> where F: FnOnce() -> B { unimplemented!() } | ||
|
||
pub trait Trait { } | ||
impl<B, F> Trait for AndThen<B, F> { } | ||
|
||
pub struct JoinAll<I> where I: Iterator { _elem: std::marker::PhantomData<I::Item> } | ||
pub fn join_all<I>(_i: I) -> JoinAll<I> where I: Iterator { unimplemented!() } | ||
|
||
pub struct PollFn<F, T>(F, std::marker::PhantomData<fn () -> T>); | ||
pub fn poll_fn<T, F>(_f: F) -> PollFn<F, T> where F: FnMut() -> T { unimplemented!() } | ||
|
||
impl<B, I: Iterator, F> Iterator for Map<I, F> where F: FnMut(I::Item) -> B { | ||
type Item = B; | ||
fn next(&mut self) -> Option<B> { unimplemented!() } | ||
} | ||
|
||
struct Map<I, F> { iter: I, f: F } | ||
|
||
fn main() { let _b: Box<Trait + Send> = Box::new(graphql()); } | ||
|
||
fn graphql() -> impl Trait | ||
{ | ||
let local = (); | ||
let m = |_: ()| poll_fn(|| { local; }); | ||
//[ast]~^ ERROR closure may outlive the current function, but it borrows `local` | ||
//[mig]~^^ ERROR closure may outlive the current function, but it borrows `local` | ||
//[nll]~^^^ ERROR closure may outlive the current function, but it borrows `local` | ||
let v = Map { iter: std::iter::once(()), f: m }; | ||
let f = || join_all(v); | ||
and_then(f) | ||
} |