From a64ad51ff7ae2f82d4aed5bc4d3a7c3d3b7c7117 Mon Sep 17 00:00:00 2001 From: Roxane Date: Wed, 14 Oct 2020 00:17:42 -0400 Subject: [PATCH] Address comments --- compiler/rustc_middle/src/ty/outlives.rs | 20 ++-------- .../rustc_trait_selection/src/opaque_types.rs | 40 +++++++------------ compiler/rustc_traits/src/dropck_outlives.rs | 9 +++++ 3 files changed, 27 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_middle/src/ty/outlives.rs b/compiler/rustc_middle/src/ty/outlives.rs index 708c92af146..86750d5c081 100644 --- a/compiler/rustc_middle/src/ty/outlives.rs +++ b/compiler/rustc_middle/src/ty/outlives.rs @@ -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 diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 087f6a0deec..ecaafee77e2 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -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, } -impl<'cx, 'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor<'cx, 'tcx, OP> +impl<'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor 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); diff --git a/compiler/rustc_traits/src/dropck_outlives.rs b/compiler/rustc_traits/src/dropck_outlives.rs index bbd3a7229a9..6cffa6d02a4 100644 --- a/compiler/rustc_traits/src/dropck_outlives.rs +++ b/compiler/rustc_traits/src/dropck_outlives.rs @@ -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); }