about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-04-14 19:20:51 +0100
committervarkor <github@varkor.com>2018-05-15 14:21:03 +0100
commit0b8b14f6f50575a515e1f9472eff410c6e140e9c (patch)
treed4961178d1e7fd05d0a9737a5aa4253adac445ca
parentd557ff983f75ad21a90240dea0a80e318175b504 (diff)
downloadrust-0b8b14f6f50575a515e1f9472eff410c6e140e9c.tar.gz
rust-0b8b14f6f50575a515e1f9472eff410c6e140e9c.zip
Eliminate ty::Generics::types()
And with one final incanation, the specific kind iterators were banished from ty::Generics, never to be seen again!
-rw-r--r--src/librustc/middle/resolve_lifetime.rs7
-rw-r--r--src/librustc/traits/error_reporting.rs4
-rw-r--r--src/librustc/traits/on_unimplemented.rs8
-rw-r--r--src/librustc/ty/mod.rs10
-rw-r--r--src/librustc/util/ppaux.rs25
-rw-r--r--src/librustc_trans/debuginfo/mod.rs2
-rw-r--r--src/librustc_typeck/check/compare_method.rs4
-rw-r--r--src/librustc_typeck/check/wfcheck.rs14
-rw-r--r--src/librustdoc/clean/mod.rs14
9 files changed, 52 insertions, 36 deletions
diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs
index b450ef81c91..f6d13c2a72f 100644
--- a/src/librustc/middle/resolve_lifetime.rs
+++ b/src/librustc/middle/resolve_lifetime.rs
@@ -1659,8 +1659,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
                     .entry(def_id)
                     .or_insert_with(|| {
                         tcx.generics_of(def_id)
-                            .types_depr()
-                            .map(|def| def.object_lifetime_default)
+                            .params
+                            .iter()
+                            .filter_map(|param| {
+                                param.get_type().and_then(|ty| Some(ty.object_lifetime_default))
+                            })
                             .collect()
                     })
             };
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index b7f0e6a32ea..d0166393f01 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -378,9 +378,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
             flags.push(("_Self".to_string(), Some(self.tcx.type_of(def.did).to_string())));
         }
 
-        for param in generics.types_depr() {
+        for param in generics.params.iter().filter_map(|param| param.get_type()) {
             let name = param.name.to_string();
-            let ty = trait_ref.substs.type_for_def(param);
+            let ty = trait_ref.substs.type_for_def(&param);
             let ty_str = ty.to_string();
             flags.push((name.clone(), Some(ty_str.clone())));
         }
diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs
index cee63e2ecc1..9fdbac49496 100644
--- a/src/librustc/traits/on_unimplemented.rs
+++ b/src/librustc/traits/on_unimplemented.rs
@@ -291,8 +291,12 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
         let name = tcx.item_name(trait_ref.def_id);
         let trait_str = tcx.item_path_str(trait_ref.def_id);
         let generics = tcx.generics_of(trait_ref.def_id);
-        let generic_map = generics.types_depr().map(|param| {
-            (param.name.to_string(), trait_ref.substs.type_for_def(param).to_string())
+        let generic_map = generics.params.iter().filter_map(|param| {
+            if let Some(ty) = param.get_type() {
+                Some((ty.name.to_string(), trait_ref.substs.type_for_def(&ty).to_string()))
+            } else {
+                None
+            }
         }).collect::<FxHashMap<String, String>>();
 
         let parser = Parser::new(&self.0);
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 680c03f02e1..4525bfc1baa 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -847,16 +847,6 @@ impl<'a, 'gcx, 'tcx> Generics {
         count
     }
 
-    pub fn types_depr(&self) -> impl DoubleEndedIterator<Item = &TypeParamDef> {
-        self.params.iter().filter_map(|p| {
-            if let GenericParamDef::Type(ty) = p {
-                Some(ty)
-            } else {
-                None
-            }
-        })
-    }
-
     pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
         if self.params.iter().any(|p| p.get_type().is_some()) {
             return true;
diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs
index e8edf58a9db..0817ededfaa 100644
--- a/src/librustc/util/ppaux.rs
+++ b/src/librustc/util/ppaux.rs
@@ -25,6 +25,7 @@ use util::nodemap::{FxHashSet, FxHashMap};
 use std::cell::Cell;
 use std::fmt;
 use std::usize;
+use std::iter;
 
 use rustc_data_structures::indexed_vec::Idx;
 use rustc_target::spec::abi::Abi;
@@ -335,17 +336,21 @@ impl PrintContext {
             }
 
             if !verbose {
-                if generics.types_depr().last().map_or(false, |def| def.has_default) {
-                    if let Some(substs) = tcx.lift(&substs) {
-                        let tps = substs.types().rev().skip(child_types);
-                        for (def, actual) in generics.types_depr().rev().zip(tps) {
-                            if !def.has_default {
-                                break;
-                            }
-                            if tcx.type_of(def.def_id).subst(tcx, substs) != actual {
-                                break;
+                let mut type_params =
+                    generics.params.iter().rev().filter_map(|param| param.get_type());
+                if let Some(last_ty) = type_params.next() {
+                    if last_ty.has_default {
+                        if let Some(substs) = tcx.lift(&substs) {
+                            let mut tps = substs.types().rev().skip(child_types);
+                            let zipped = iter::once((last_ty, tps.next().unwrap()))
+                                              .chain(type_params.zip(tps));
+                            for (ty, actual) in zipped {
+                                if !ty.has_default ||
+                                        tcx.type_of(ty.def_id).subst(tcx, substs) != actual {
+                                    break;
+                                }
+                                num_supplied_defaults += 1;
                             }
-                            num_supplied_defaults += 1;
                         }
                     }
                 }
diff --git a/src/librustc_trans/debuginfo/mod.rs b/src/librustc_trans/debuginfo/mod.rs
index d50c74da313..2463e571436 100644
--- a/src/librustc_trans/debuginfo/mod.rs
+++ b/src/librustc_trans/debuginfo/mod.rs
@@ -429,7 +429,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
         });
         names.extend(generics.params.iter().map(|param| {
             match param {
-                GenericParamDef::Lifetime(lt) => (Kind::Lifetime, lt.name.as_str()),
+                GenericParamDef::Lifetime(lt) => (Kind::Lifetime, lt.name),
                 GenericParamDef::Type(ty) => (Kind::Type, ty.name),
             }
         }));
diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs
index 59728542bcd..e02ba764057 100644
--- a/src/librustc_typeck/check/compare_method.rs
+++ b/src/librustc_typeck/check/compare_method.rs
@@ -728,7 +728,9 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     let mut error_found = false;
     let impl_m_generics = tcx.generics_of(impl_m.def_id);
     let trait_m_generics = tcx.generics_of(trait_m.def_id);
-    for (impl_ty, trait_ty) in impl_m_generics.types_depr().zip(trait_m_generics.types_depr()) {
+    let impl_m_type_params = impl_m_generics.params.iter().filter_map(|param| param.get_type());
+    let trait_m_type_params = trait_m_generics.params.iter().filter_map(|param| param.get_type());
+    for (impl_ty, trait_ty) in impl_m_type_params.zip(trait_m_type_params) {
         if impl_ty.synthetic != trait_ty.synthetic {
             let impl_node_id = tcx.hir.as_local_node_id(impl_ty.def_id).unwrap();
             let impl_span = tcx.hir.span(impl_node_id);
diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs
index 804fed10105..9eb53f2fdae 100644
--- a/src/librustc_typeck/check/wfcheck.rs
+++ b/src/librustc_typeck/check/wfcheck.rs
@@ -370,14 +370,22 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
     let mut substituted_predicates = Vec::new();
 
     let generics = tcx.generics_of(def_id);
-    let is_our_default = |def: &ty::TypeParamDef|
-                            def.has_default && def.index >= generics.parent_count as u32;
+    let is_our_default = |def: &ty::TypeParamDef| {
+        def.has_default && def.index >= generics.parent_count as u32
+    };
 
     // Check that concrete defaults are well-formed. See test `type-check-defaults.rs`.
     // For example this forbids the declaration:
     // struct Foo<T = Vec<[u32]>> { .. }
     // Here the default `Vec<[u32]>` is not WF because `[u32]: Sized` does not hold.
-    for d in generics.types_depr().cloned().filter(is_our_default).map(|p| p.def_id) {
+    for d in generics.params.iter().filter_map(|param| {
+        if let GenericParamDef::Type(ty) = *param {
+            if is_our_default(&ty) {
+                return Some(ty.def_id);
+            }
+        }
+        None
+    }) {
         let ty = fcx.tcx.type_of(d);
         // ignore dependent defaults -- that is, where the default of one type
         // parameter includes another (e.g., <T, U = T>). In those cases, we can't
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 6848b25097b..25766c553a5 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1800,12 +1800,16 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
         // Bounds in the type_params and lifetimes fields are repeated in the
         // predicates field (see rustc_typeck::collect::ty_generics), so remove
         // them.
-        let stripped_typarams = gens.types_depr().filter_map(|tp| {
-            if tp.name == keywords::SelfType.name().as_str() {
-                assert_eq!(tp.index, 0);
-                None
+        let stripped_typarams = gens.params.iter().filter_map(|param| {
+            if let ty::GenericParamDef::Type(ty) = param {
+                if ty.name == keywords::SelfType.name().as_str() {
+                    assert_eq!(ty.index, 0);
+                    None
+                } else {
+                    Some(ty.clean(cx))
+                }
             } else {
-                Some(tp.clean(cx))
+                None
             }
         }).collect::<Vec<_>>();