Address comments

This commit is contained in:
Roxane 2020-10-14 00:17:42 -04:00
parent 3c46fd67f8
commit a64ad51ff7
3 changed files with 27 additions and 42 deletions

View File

@ -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

View File

@ -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),
});
}
@ -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),
});
}
@ -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,
@ -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>),
{
@ -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);

View File

@ -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);
}
@ -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);
}