]> git.lizzy.rs Git - rust.git/commitdiff
Eliminate ty::Generics::lifetimes()
authorvarkor <github@varkor.com>
Fri, 13 Apr 2018 23:07:25 +0000 (00:07 +0100)
committervarkor <github@varkor.com>
Tue, 15 May 2018 13:21:03 +0000 (14:21 +0100)
Begone lazy lifetime code!

src/librustc/infer/anon_types/mod.rs
src/librustc/ty/mod.rs
src/librustc_typeck/impl_wf_check.rs
src/librustdoc/clean/mod.rs

index 06af6d16c3006b9e9832bc3b888abb489f4794c7..a83eb7fd354a376d9c5dd85cf75aa8cae36ffe5f 100644 (file)
@@ -14,7 +14,7 @@
 use rustc_data_structures::fx::FxHashMap;
 use syntax::ast;
 use traits::{self, PredicateObligation};
-use ty::{self, Ty, TyCtxt};
+use ty::{self, Ty, TyCtxt, GenericParamDef};
 use ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
 use ty::outlives::Component;
 use ty::subst::{Kind, Substs, UnpackedKind};
@@ -313,7 +313,13 @@ fn constrain_anon_type<FRR: FreeRegionRelations<'tcx>>(
         // `['a]` for the first impl trait and `'b` for the
         // second.
         let mut least_region = None;
-        for region_def in abstract_type_generics.lifetimes_depr() {
+        for region_def in abstract_type_generics.params.iter().filter_map(|param| {
+            if let GenericParamDef::Lifetime(lt) = param {
+                Some(lt)
+            } else {
+                None
+            }
+        }) {
             // Find the index of this region in the list of substitutions.
             let index = region_def.index as usize;
 
index eabff9a9124137fd8d4e294911e6f5bcaccdf1bf..680c03f02e1d5f6df3ec808de37e18e8688ca509 100644 (file)
@@ -847,16 +847,6 @@ pub fn type_params_without_defaults(&self) -> usize {
         count
     }
 
-    pub fn lifetimes_depr(&self) -> impl DoubleEndedIterator<Item = &RegionParamDef> {
-        self.params.iter().filter_map(|p| {
-            if let GenericParamDef::Lifetime(lt) = p {
-                Some(lt)
-            } else {
-                None
-            }
-        })
-    }
-
     pub fn types_depr(&self) -> impl DoubleEndedIterator<Item = &TypeParamDef> {
         self.params.iter().filter_map(|p| {
             if let GenericParamDef::Type(ty) = p {
index e0786ea8b3c6fff62ea681bbefed16a5538b1adb..01e2bc3137433eadf53ef0df626c20cdd39736e1 100644 (file)
@@ -104,14 +104,6 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     ctp::identify_constrained_type_params(
         tcx, &impl_predicates.predicates.as_slice(), impl_trait_ref, &mut input_parameters);
 
-    // Disallow ANY unconstrained type parameters.
-    for (ty_param, param) in impl_generics.types_depr().zip(impl_hir_generics.ty_params()) {
-        let param_ty = ty::ParamTy::for_def(ty_param);
-        if !input_parameters.contains(&ctp::Parameter::from(param_ty)) {
-            report_unused_parameter(tcx, param.span, "type", &param_ty.to_string());
-        }
-    }
-
     // Disallow unconstrained lifetimes, but only if they appear in assoc types.
     let lifetimes_in_associated_types: FxHashSet<_> = impl_item_refs.iter()
         .map(|item_ref| tcx.hir.local_def_id(item_ref.id.node_id))
@@ -122,13 +114,27 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         .flat_map(|def_id| {
             ctp::parameters_for(&tcx.type_of(def_id), true)
         }).collect();
-    for (ty_lt, lt) in impl_generics.lifetimes_depr().zip(impl_hir_generics.lifetimes()) {
-        let param = ctp::Parameter::from(ty_lt.to_early_bound_region_data());
 
-        if lifetimes_in_associated_types.contains(&param) && // (*)
-            !input_parameters.contains(&param) {
-            report_unused_parameter(tcx, lt.lifetime.span,
-                                    "lifetime", &lt.lifetime.name.name().to_string());
+    for (ty_param, hir_param) in impl_generics.params.iter()
+                                              .zip(impl_hir_generics.params.iter()) {
+        match (ty_param, hir_param) {
+            // Disallow ANY unconstrained type parameters.
+            (ty::GenericParamDef::Type(ty_ty), hir::GenericParamDef::Type(hir_ty)) => {
+                let param_ty = ty::ParamTy::for_def(ty_ty);
+                if !input_parameters.contains(&ctp::Parameter::from(param_ty)) {
+                    report_unused_parameter(tcx, hir_ty.span, "type", &param_ty.to_string());
+                }
+            }
+            (ty::GenericParamDef::Lifetime(ty_lt), hir::GenericParamDef::Lifetime(hir_lt)) => {
+                let param = ctp::Parameter::from(ty_lt.to_early_bound_region_data());
+                if lifetimes_in_associated_types.contains(&param) && // (*)
+                    !input_parameters.contains(&param) {
+                    report_unused_parameter(tcx, hir_lt.lifetime.span,
+                                            "lifetime", &hir_lt.lifetime.name.name().to_string());
+                }
+            }
+            (ty::GenericParamDef::Type(_), _) => continue,
+            (ty::GenericParamDef::Lifetime(_), _) => continue,
         }
     }
 
index 7f6da5414c63757ad1417184f91ffaf14d0cd4ae..6848b25097b8d7e7a6e978773bebf78a24247a41 100644 (file)
@@ -1849,10 +1849,15 @@ fn clean(&self, cx: &DocContext) -> Generics {
         // and instead see `where T: Foo + Bar + Sized + 'a`
 
         Generics {
-            params: gens.lifetimes_depr()
-                        .into_iter()
-                        .map(|lp| GenericParamDef::Lifetime(lp.clean(cx)))
-                        .chain(
+            params: gens.params
+                        .iter()
+                        .flat_map(|param| {
+                            if let ty::GenericParamDef::Lifetime(lt) = param {
+                                Some(GenericParamDef::Lifetime(lt.clean(cx)))
+                            } else {
+                                None
+                            }
+                        }).chain(
                             simplify::ty_params(stripped_typarams)
                                 .into_iter()
                                 .map(|tp| GenericParamDef::Type(tp))