]> git.lizzy.rs Git - rust.git/commitdiff
simplify `AnonTypeDecl` in the impl trait code
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 6 Dec 2017 22:11:41 +0000 (17:11 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 20 Dec 2017 19:04:50 +0000 (14:04 -0500)
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
src/librustc_typeck/check/regionck.rs

index 7ebdb876ed02f54ce20de59cfead13cc0b26a893..3da71d1c0c5d72b2a84f32ad63e25e5b81df3035 100644 (file)
@@ -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<ty::Region<'tcx>>,
+    /// 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 @@ fn instantiate_anon_types<T: TypeFoldable<'tcx>>(&self, value: &T) -> T {
                 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);
 
index 7ef6027772be2deeb5658a60f84f40096f37ff06..63c77a893c964c75f6fab66463e16811f1271dbb 100644 (file)
@@ -451,7 +451,7 @@ fn constrain_anon_types(&mut self) {
             // 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;
             }