Skip to content

Commit

Permalink
address comments and rebase on master
Browse files Browse the repository at this point in the history
  • Loading branch information
roxelo committed Jul 22, 2020
1 parent de57093 commit 349f23e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/librustc_middle/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,10 @@ impl<'tcx> UpvarSubsts<'tcx> {
#[inline]
pub fn upvar_tuple_ty(self) -> Ty<'tcx> {
let tupled_upvars_ty = match self {
UpvarSubsts::Closure(substs) => substs.as_closure().split().tupled_upvars_ty,
UpvarSubsts::Generator(substs) => substs.as_generator().split().tupled_upvars_ty,
UpvarSubsts::Closure(substs) => substs.as_closure().upvar_tuple_ty(),
UpvarSubsts::Generator(substs) => substs.as_generator().upvar_tuple_ty(),
};
tupled_upvars_ty.expect_ty()
tupled_upvars_ty
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/librustc_trait_selection/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
for required_region in required_region_bounds {
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
op: |r| self.sub_regions(infer::CallReturn(span), required_region, r),
infcx: self,
});
}
if let GenerateMemberConstraints::IfNoStaticBound = mode {
Expand Down Expand Up @@ -509,6 +510,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
op: |r| self.sub_regions(infer::CallReturn(span), least_region, r),
infcx: self,
});
}

Expand Down Expand Up @@ -551,6 +553,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
&choice_regions,
)
},
infcx: self,
});
}

Expand Down Expand Up @@ -682,11 +685,12 @@ 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<OP> {
struct ConstrainOpaqueTypeRegionVisitor<'cx, 'tcx, OP> {
op: OP,
infcx: &'cx InferCtxt<'cx, 'tcx>,
}

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

if !substs.as_closure().is_valid() {
let ty = self.infcx.shallow_resolve(substs.as_closure().upvar_tuple_ty());
if let ty::Infer(ty::TyVar(_)) = ty.kind {
// Not yet resolved.
ty.super_visit_with(self);
} else {
Expand All @@ -732,7 +737,8 @@ where
// Skip lifetime parameters of the enclosing item(s)
// Also skip the witness type, because that has no free regions.

if !substs.as_generator().is_valid() {
let ty = self.infcx.shallow_resolve(substs.as_generator().upvar_tuple_ty());
if let ty::Infer(ty::TyVar(_)) = ty.kind {
// Not yet resolved.
ty.super_visit_with(self);
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trait_selection/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,12 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
// are not directly inspecting closure types
// anyway, except via auto trait matching (which
// only inspects the upvar types).
walker.skip_current_subtree(); // subtree handled below
let ty = self.infcx.shallow_resolve(substs.as_closure().upvar_tuple_ty());
if let ty::Infer(ty::TyVar(_)) = ty.kind {
// Not yet resolved.
walker.skip_current_subtree();
self.compute(ty.into());
} else {
walker.skip_current_subtree(); // subtree handled below
for upvar_ty in substs.as_closure().upvar_tys() {
// FIXME(eddyb) add the type to `walker` instead of recursing.
self.compute(upvar_ty.into());
Expand Down
9 changes: 2 additions & 7 deletions src/librustc_typeck/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Function items or non-capturing closures of differing IDs or InternalSubsts.
let (a_sig, b_sig) = {
let is_capturing_closure = |ty| {
if let &ty::Closure(_, substs) = ty {
let ty = self.infcx.shallow_resolve(substs.as_closure().upvar_tuple_ty());
if let ty::Infer(ty::TyVar(_)) = ty.kind {
substs.as_closure().upvar_tys().next().is_some()
} else {
false
}
if let &ty::Closure(closure_def_id_a, _substs) = ty {
self.tcx.upvars_mentioned(closure_def_id_a.expect_local()).is_some()
} else {
false
}
Expand Down

0 comments on commit 349f23e

Please sign in to comment.