Skip to content

Commit 1f5145e

Browse files
committed
Treat generators the same as closure for escaping lifetimes
1 parent 664c8ed commit 1f5145e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/librustc/infer/opaque_types/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,23 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
705705
self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs })
706706
}
707707

708+
ty::Generator(def_id, substs, movability) => {
709+
let generics = self.tcx.generics_of(def_id);
710+
let substs = self.tcx.mk_substs(substs.substs.iter().enumerate().map(
711+
|(index, &kind)| {
712+
if index < generics.parent_count {
713+
// Accommodate missing regions in the parent kinds...
714+
self.fold_kind_mapping_missing_regions_to_empty(kind)
715+
} else {
716+
// ...but not elsewhere.
717+
self.fold_kind_normally(kind)
718+
}
719+
},
720+
));
721+
722+
self.tcx.mk_generator(def_id, ty::GeneratorSubsts { substs }, movability)
723+
}
724+
708725
_ => ty.super_fold_with(self),
709726
}
710727
}

src/test/run-pass/impl-trait/lifetimes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-pass
22

33
#![allow(warnings)]
4+
#![feature(generators)]
45

56
use std::fmt::Debug;
67

@@ -112,6 +113,11 @@ impl<'unnecessary_lifetime> MyVec {
112113
fn iter_doesnt_capture_unnecessary_lifetime<'s>(&'s self) -> impl Iterator<Item = &'s u8> {
113114
self.0.iter().flat_map(|inner_vec| inner_vec.iter())
114115
}
116+
117+
fn generator_doesnt_capture_unnecessary_lifetime<'s: 's>() -> impl Sized {
118+
|| yield
119+
}
115120
}
116121

122+
117123
fn main() {}

0 commit comments

Comments
 (0)