Skip to content

Commit

Permalink
Rollup merge of rust-lang#55638 - pnkfelix:issue-55608-ice-reempty-ms…
Browse files Browse the repository at this point in the history
…g_span_from_free_region, r=estebank

Fix ICE in msg_span_from_free_region on ReEmpty

On an example like this:

```rust
#![feature(conservative_impl_trait)]

fn server() -> impl FilterBase2 {
    segment2(|| { loop { } }).map2(|| "")
}

trait FilterBase2 {
    fn map2<F>(self, _fn: F) -> Map2<F> where Self: Sized { loop { } }
}

struct Map2<F> { _func: F }

impl<F> FilterBase2 for Map2<F> { }

fn segment2<F>(_fn: F) -> Map2<F> where F: Fn() -> Result<(), ()> {
    loop { }
}
```

we now, instead of ICE'ing, get a diagnostic like:

```
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
 --> issue-55608.rs:3:16
  |
3 | fn server() -> impl FilterBase2 {
  |                ^^^^^^^^^^^^^^^^
  |
  = note: hidden type `Map2<[closure@issue-55608.rs:4:36: 4:41]>` captures an empty lifetime
```

Fix rust-lang#55608
  • Loading branch information
Mark-Simulacrum committed Nov 9, 2018
2 parents 78cab36 + cc33aec commit 4805a97
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.msg_span_from_early_bound_and_free_regions(region)
}
ty::ReStatic => ("the static lifetime".to_owned(), None),
ty::ReEmpty => ("an empty lifetime".to_owned(), None),
_ => bug!("{:?}", region),
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/ui/impl-trait/issue-55608-captures-empty-region.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This used to ICE because it creates an `impl Trait` that captures a
// hidden empty region.

#![feature(conservative_impl_trait)]

fn server() -> impl FilterBase2 { //~ ERROR [E0700]
segment2(|| { loop { } }).map2(|| "")
}

trait FilterBase2 {
fn map2<F>(self, _fn: F) -> Map2<F> where Self: Sized { loop { } }
}

struct Map2<F> { _func: F }

impl<F> FilterBase2 for Map2<F> { }

fn segment2<F>(_fn: F) -> Map2<F> where F: Fn() -> Result<(), ()> {
loop { }
}

fn main() { server(); }
11 changes: 11 additions & 0 deletions src/test/ui/impl-trait/issue-55608-captures-empty-region.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> $DIR/issue-55608-captures-empty-region.rs:6:16
|
LL | fn server() -> impl FilterBase2 { //~ ERROR [E0700]
| ^^^^^^^^^^^^^^^^
|
= note: hidden type `Map2<[closure@$DIR/issue-55608-captures-empty-region.rs:7:36: 7:41]>` captures an empty lifetime

error: aborting due to previous error

For more information about this error, try `rustc --explain E0700`.

0 comments on commit 4805a97

Please sign in to comment.