Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
roxelo committed Oct 14, 2020
1 parent 3c46fd6 commit a64ad51
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 42 deletions.
20 changes: 4 additions & 16 deletions compiler/rustc_middle/src/ty/outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,14 @@ fn compute_components(
}

ty::Closure(_, ref substs) => {
if substs.as_closure().is_valid() {
for upvar_ty in substs.as_closure().upvar_tys() {
compute_components(tcx, upvar_ty, out, visited);
}
} else {
let tupled_ty = substs.as_closure().tupled_upvars_ty();
compute_components(tcx, tupled_ty, out, visited);
}
let tupled_ty = substs.as_closure().tupled_upvars_ty();
compute_components(tcx, tupled_ty, out, visited);
}

ty::Generator(_, ref substs, _) => {
// Same as the closure case
if substs.as_generator().is_valid() {
for upvar_ty in substs.as_generator().upvar_tys() {
compute_components(tcx, upvar_ty, out, visited);
}
} else {
let tupled_ty = substs.as_generator().tupled_upvars_ty();
compute_components(tcx, tupled_ty, out, visited);
}
let tupled_ty = substs.as_generator().tupled_upvars_ty();
compute_components(tcx, tupled_ty, out, visited);

// We ignore regions in the generator interior as we don't
// want these to affect region inference
Expand Down
40 changes: 14 additions & 26 deletions compiler/rustc_trait_selection/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {

for required_region in required_region_bounds {
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
infcx: self,
op: |r| self.sub_regions(infer::CallReturn(span), required_region, r),
});
}
Expand Down Expand Up @@ -510,7 +509,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
}
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
infcx: self,
op: |r| self.sub_regions(infer::CallReturn(span), least_region, r),
});
}
Expand Down Expand Up @@ -545,7 +543,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
);

concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
infcx: self,
op: |r| {
self.member_constraint(
opaque_type_def_id,
Expand Down Expand Up @@ -686,12 +683,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
//
// We ignore any type parameters because impl trait values are assumed to
// capture all the in-scope type parameters.
struct ConstrainOpaqueTypeRegionVisitor<'cx, 'tcx, OP> {
infcx: &'cx InferCtxt<'cx, 'tcx>,
struct ConstrainOpaqueTypeRegionVisitor<OP> {
op: OP,
}

impl<'cx, 'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor<'cx, 'tcx, OP>
impl<'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor<OP>
where
OP: FnMut(ty::Region<'tcx>),
{
Expand Down Expand Up @@ -721,36 +717,28 @@ where
ty::Closure(_, ref substs) => {
// Skip lifetime parameters of the enclosing item(s)

let ty = self.infcx.shallow_resolve(substs.as_closure().tupled_upvars_ty());
if let ty::Infer(ty::TyVar(_)) = ty.kind() {
// Not yet resolved.
ty.super_visit_with(self);
} else {
for upvar_ty in substs.as_closure().upvar_tys() {
upvar_ty.visit_with(self);
}
substs.as_closure().tupled_upvars_ty().visit_with(self);

substs.as_closure().sig_as_fn_ptr_ty().visit_with(self);
for upvar_ty in substs.as_closure().upvar_tys() {
upvar_ty.visit_with(self);
}

substs.as_closure().sig_as_fn_ptr_ty().visit_with(self);
}

ty::Generator(_, ref substs, _) => {
// Skip lifetime parameters of the enclosing item(s)
// Also skip the witness type, because that has no free regions.

let ty = self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());
if let ty::Infer(ty::TyVar(_)) = ty.kind() {
// Not yet resolved.
ty.super_visit_with(self);
} else {
for upvar_ty in substs.as_generator().upvar_tys() {
upvar_ty.visit_with(self);
}
substs.as_generator().tupled_upvars_ty().visit_with(self);

substs.as_generator().return_ty().visit_with(self);
substs.as_generator().yield_ty().visit_with(self);
substs.as_generator().resume_ty().visit_with(self);
for upvar_ty in substs.as_generator().upvar_tys() {
upvar_ty.visit_with(self);
}

substs.as_generator().return_ty().visit_with(self);
substs.as_generator().yield_ty().visit_with(self);
substs.as_generator().resume_ty().visit_with(self);
}
_ => {
ty.super_visit_with(self);
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_traits/src/dropck_outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ fn dtorck_constraint_for_ty<'tcx>(
if !substs.as_closure().is_valid() {
// By the time this code runs, all type variables ought to
// be fully resolved.

tcx.sess.delay_span_bug(
span,
&format!("upvar_tys for closure not found. Expected capture information for closure {}", ty,),
);
return Err(NoSolution);
}

Expand Down Expand Up @@ -252,6 +257,10 @@ fn dtorck_constraint_for_ty<'tcx>(
if !substs.as_generator().is_valid() {
// By the time this code runs, all type variables ought to
// be fully resolved.
tcx.sess.delay_span_bug(
span,
&format!("upvar_tys for generator not found. Expected capture information for generator {}", ty,),
);
return Err(NoSolution);
}

Expand Down

0 comments on commit a64ad51

Please sign in to comment.