Skip to content

Commit 484e6f0

Browse files
committed
Rollup merge of #49730 - sinkuu:fix_ice_49556, r=cramertj
Fix ICE with impl Trait Fixes #49556 (comment). May or may not fix 49556 itself. Closures like `|x: &'a _| x` has `ClosureSubsts` of `fn(&'a _) -> &'(ReScope) _`, so `tcx.note_and_explain_free_region` (called [here](https://github.com/rust-lang/rust/blob/a143462783cec88b7b733e8aa09990bfeb59f754/src/librustc/infer/anon_types/mod.rs#L572)) panics.
2 parents 574c050 + b9e04e5 commit 484e6f0

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/librustc/infer/anon_types/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,14 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
533533
match r {
534534
// ignore bound regions that appear in the type (e.g., this
535535
// would ignore `'r` in a type like `for<'r> fn(&'r u32)`.
536-
ty::ReLateBound(..) => return r,
536+
ty::ReLateBound(..) |
537537

538538
// ignore `'static`, as that can appear anywhere
539-
ty::ReStatic => return r,
539+
ty::ReStatic |
540+
541+
// ignore `ReScope`, as that can appear anywhere
542+
// See `src/test/run-pass/issue-49556.rs` for example.
543+
ty::ReScope(..) => return r,
540544

541545
_ => { }
542546
}

src/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
181181
self.msg_span_from_early_bound_and_free_regions(region)
182182
},
183183
ty::ReStatic => ("the static lifetime".to_owned(), None),
184-
_ => bug!(),
184+
_ => bug!("{:?}", region),
185185
}
186186
}
187187

src/test/run-pass/issue-49556.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn iter<'a>(data: &'a [usize]) -> impl Iterator<Item = usize> + 'a {
12+
data.iter()
13+
.map(
14+
|x| x // fn(&'a usize) -> &'(ReScope) usize
15+
)
16+
.map(
17+
|x| *x // fn(&'(ReScope) usize) -> usize
18+
)
19+
}
20+
21+
fn main() {
22+
}

0 commit comments

Comments
 (0)