Skip to content

Commit d951d5d

Browse files
committed
Handle ReEmpty for impl Trait
Closes #35668
1 parent cf0cdc4 commit d951d5d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/librustc_typeck/check/writeback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
319319
let outside_ty = gcx.fold_regions(&inside_ty, &mut false, |r, _| {
320320
match *r {
321321
// 'static is valid everywhere.
322-
ty::ReStatic => gcx.mk_region(ty::ReStatic),
322+
ty::ReStatic |
323+
ty::ReEmpty => gcx.mk_region(*r),
323324

324325
// Free regions that come from early-bound regions are valid.
325326
ty::ReFree(ty::FreeRegion {
@@ -341,7 +342,6 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
341342
}
342343

343344
ty::ReVar(_) |
344-
ty::ReEmpty |
345345
ty::ReErased => {
346346
let span = reason.span(self.tcx());
347347
span_bug!(span, "invalid region in impl Trait: {:?}", r);

src/test/compile-fail/issue-35668.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2016 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+
#![feature(conservative_impl_trait)]
12+
13+
fn func<'a, T>(a: &'a [T]) -> impl Iterator<Item=&'a T> {
14+
a.iter().map(|a| a*a)
15+
//~^ ERROR binary operation `*` cannot be applied to type `&T`
16+
}
17+
18+
fn main() {
19+
let a = (0..30).collect::<Vec<_>>();
20+
21+
for k in func(&a) {
22+
println!("{}", k);
23+
}
24+
}

0 commit comments

Comments
 (0)