]> git.lizzy.rs Git - rust.git/commitdiff
Remove a field that is computed later anyway
authorOli Scherer <github35764891676564198441@oli-obk.de>
Mon, 26 Jul 2021 17:09:05 +0000 (17:09 +0000)
committerOli Scherer <github35764891676564198441@oli-obk.de>
Fri, 6 Aug 2021 10:18:31 +0000 (10:18 +0000)
compiler/rustc_infer/src/infer/opaque_types.rs
compiler/rustc_trait_selection/src/opaque_types.rs

index 4a1cbf597db3544f3c1c8dad5e0f881100e858a9..d0883f23a4e6bb9237a7c8b83aa17f0dca6beb2c 100644 (file)
@@ -42,29 +42,6 @@ pub struct OpaqueTypeDecl<'tcx> {
     /// lifetime parameter on `foo`.)
     pub concrete_ty: Ty<'tcx>,
 
-    /// Returns `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.)
-    pub has_required_region_bounds: bool,
-
     /// The origin of the opaque type.
     pub origin: hir::OpaqueTyOrigin,
 }
index 5ff1cf777f95c34feff3d68af91c4370901cb9c4..4268fa0358439001003395dbedbffc16f0bdca4d 100644 (file)
@@ -330,19 +330,36 @@ fn constrain_opaque_type<FRR: FreeRegionRelations<'tcx>>(
 
         let span = tcx.def_span(def_id);
 
-        // If there are required region bounds, we can use them.
-        if opaque_defn.has_required_region_bounds {
-            let bounds = tcx.explicit_item_bounds(def_id);
-            debug!("{:#?}", bounds);
-            let bounds: Vec<_> =
-                bounds.iter().map(|(bound, _)| bound.subst(tcx, opaque_type_key.substs)).collect();
-            debug!("{:#?}", bounds);
-            let opaque_type = tcx.mk_opaque(def_id, opaque_type_key.substs);
-
-            let required_region_bounds =
-                required_region_bounds(tcx, opaque_type, bounds.into_iter());
-            debug_assert!(!required_region_bounds.is_empty());
+        // Check 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.)
+        let bounds = tcx.explicit_item_bounds(def_id);
+        debug!("{:#?}", bounds);
+        let bounds: Vec<_> =
+            bounds.iter().map(|(bound, _)| bound.subst(tcx, opaque_type_key.substs)).collect();
+        debug!("{:#?}", bounds);
+        let opaque_type = tcx.mk_opaque(def_id, opaque_type_key.substs);
 
+        let required_region_bounds = required_region_bounds(tcx, opaque_type, bounds.into_iter());
+        if !required_region_bounds.is_empty() {
             for required_region in required_region_bounds {
                 concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
                     op: |r| self.sub_regions(infer::CallReturn(span), required_region, r),
@@ -979,9 +996,6 @@ fn fold_opaque_ty(
 
         debug!("instantiate_opaque_types: bounds={:?}", bounds);
 
-        let required_region_bounds = required_region_bounds(tcx, ty, bounds.iter().copied());
-        debug!("instantiate_opaque_types: required_region_bounds={:?}", required_region_bounds);
-
         // Make sure that we are in fact defining the *entire* type
         // (e.g., `type Foo<T: Bound> = impl Bar;` needs to be
         // defined by a function like `fn foo<T: Bound>() -> Foo<T>`).
@@ -997,13 +1011,7 @@ fn fold_opaque_ty(
 
         self.opaque_types.insert(
             OpaqueTypeKey { def_id, substs },
-            OpaqueTypeDecl {
-                opaque_type: ty,
-                definition_span,
-                concrete_ty: ty_var,
-                has_required_region_bounds: !required_region_bounds.is_empty(),
-                origin,
-            },
+            OpaqueTypeDecl { opaque_type: ty, definition_span, concrete_ty: ty_var, origin },
         );
         debug!("instantiate_opaque_types: ty_var={:?}", ty_var);