Skip to content

Commit

Permalink
Unit tests for rust-lang#57464 ICE.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Mar 1, 2019
1 parent 9f75f51 commit 88801bf
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
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`.
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

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`.
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)
}

0 comments on commit 88801bf

Please sign in to comment.