From f3335c61693135cb92ec659e04e4a542eabef874 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 6 Dec 2017 17:11:41 -0500 Subject: [PATCH] simplify `AnonTypeDecl` in the impl trait code We don't need to know the vector of region bounds; we only care if there were any region bounds at all. --- src/librustc_typeck/check/mod.rs | 27 +++++++++++++++++++++++---- src/librustc_typeck/check/regionck.rs | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 7ebdb876ed0..3da71d1c0c5 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -257,9 +257,28 @@ struct AnonTypeDecl<'tcx> { /// lifetime parameter on `foo`.) concrete_ty: Ty<'tcx>, - /// A list of all required region bounds on the impl Trait type, - /// e.g. `'a` and `'b` in `fn foo<'a, 'b, 'c>() -> impl Trait<'c> + 'a + 'b`. - required_region_bounds: Vec>, + /// True if the `impl Trait` bounds include region bounds. + /// For example, this would be true for: + /// + /// fn foo<'a, 'b, 'c>() -> impl Trait<'c> + 'a + 'b + /// + /// but false for: + /// + /// fn foo<'c>() -> impl Trait<'c> + /// + /// unless `Trait` was declared like: + /// + /// trait Trait<'c>: 'c + /// + /// in which case it would be true. + /// + /// This is used during regionck to decide whether we need to + /// impose any additional constraints to ensure that region + /// variables in `concrete_ty` wind up being constrained to + /// something from `substs` (or, at minimum, things that outlive + /// the fn body). (Ultimately, writeback is responsible for this + /// check.) + has_required_region_bounds: bool, } impl<'a, 'gcx, 'tcx> Deref for Inherited<'a, 'gcx, 'tcx> { @@ -1942,7 +1961,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.anon_types.borrow_mut().insert(def_id, AnonTypeDecl { substs, concrete_ty: ty_var, - required_region_bounds, + has_required_region_bounds: !required_region_bounds.is_empty(), }); debug!("instantiate_anon_types: ty_var={:?}", ty_var); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 7ef6027772b..63c77a893c9 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -451,7 +451,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { // If there are required region bounds, we can just skip // ahead. There will already be a registered region // obligation related `concrete_ty` to those regions. - if anon_defn.required_region_bounds.len() != 0 { + if anon_defn.has_required_region_bounds { continue; }