Skip to content

Commit fcb9e92

Browse files
spastorinonikomatsakis
authored andcommitted
Integrate generators to universal region setup
1 parent 5d259b2 commit fcb9e92

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

src/librustc/mir/visit.rs

+9
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ macro_rules! make_mir_visitor {
277277

278278
fn super_mir(&mut self,
279279
mir: & $($mutability)* Mir<'tcx>) {
280+
if let Some(yield_ty) = &$($mutability)* mir.yield_ty {
281+
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
282+
span: mir.span,
283+
scope: ARGUMENT_VISIBILITY_SCOPE,
284+
}));
285+
}
286+
280287
// for best performance, we want to use an iterator rather
281288
// than a for-loop, to avoid calling Mir::invalidate for
282289
// each basic block.
@@ -852,6 +859,8 @@ pub enum TyContext {
852859
/// The return type of the function.
853860
ReturnTy(SourceInfo),
854861

862+
YieldTy(SourceInfo),
863+
855864
/// A type found at some location.
856865
Location(Location),
857866
}

src/librustc_mir/borrow_check/nll/constraint_generation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
6969
fn visit_ty(&mut self, ty: &ty::Ty<'tcx>, ty_context: TyContext) {
7070
match ty_context {
7171
TyContext::ReturnTy(source_info) |
72+
TyContext::YieldTy(source_info) |
7273
TyContext::LocalDecl { source_info, .. } => {
7374
span_bug!(source_info.span,
7475
"should not be visiting outside of the CFG: {:?}",

src/librustc_mir/borrow_check/nll/type_check/input_output.rs

+9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
6060
self.equate_normalized_input_or_output(start_position, input_ty, mir_input_ty);
6161
}
6262

63+
assert!(
64+
mir.yield_ty.is_some() && universal_regions.yield_ty.is_some() ||
65+
mir.yield_ty.is_none() && universal_regions.yield_ty.is_none()
66+
);
67+
if let Some(mir_yield_ty) = mir.yield_ty {
68+
let ur_yield_ty = universal_regions.yield_ty.unwrap();
69+
self.equate_normalized_input_or_output(start_position, ur_yield_ty, mir_yield_ty);
70+
}
71+
6372
// Return types are a bit more complex. They may contain existential `impl Trait`
6473
// types.
6574
debug!(

src/librustc_mir/borrow_check/nll/universal_regions.rs

+10
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ pub struct UniversalRegions<'tcx> {
9696
/// our special inference variable there, we would mess that up.
9797
pub region_bound_pairs: Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>,
9898

99+
pub yield_ty: Option<Ty<'tcx>>,
100+
99101
relations: UniversalRegionRelations,
100102
}
101103

@@ -505,6 +507,13 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
505507
num_universals
506508
);
507509

510+
let yield_ty = match defining_ty {
511+
DefiningTy::Generator(def_id, substs, _) => {
512+
Some(substs.generator_yield_ty(def_id, self.infcx.tcx))
513+
}
514+
_ => None,
515+
};
516+
508517
UniversalRegions {
509518
indices,
510519
fr_static,
@@ -516,6 +525,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
516525
unnormalized_output_ty,
517526
unnormalized_input_tys,
518527
region_bound_pairs: self.region_bound_pairs,
528+
yield_ty: yield_ty,
519529
relations: self.relations,
520530
}
521531
}

0 commit comments

Comments
 (0)