]> git.lizzy.rs Git - rust.git/commitdiff
Generalise more cases of explicit iteration of specific kinds
authorvarkor <github@varkor.com>
Fri, 13 Apr 2018 22:12:14 +0000 (23:12 +0100)
committervarkor <github@varkor.com>
Tue, 15 May 2018 13:21:03 +0000 (14:21 +0100)
23 files changed:
src/librustc/hir/lowering.rs
src/librustc/infer/anon_types/mod.rs
src/librustc/lib.rs
src/librustc/middle/resolve_lifetime.rs
src/librustc/traits/error_reporting.rs
src/librustc/traits/object_safety.rs
src/librustc/traits/on_unimplemented.rs
src/librustc/ty/mod.rs
src/librustc/ty/subst.rs
src/librustc/util/ppaux.rs
src/librustc_mir/monomorphize/collector.rs
src/librustc_mir/transform/check_unsafety.rs
src/librustc_privacy/lib.rs
src/librustc_traits/dropck_outlives.rs
src/librustc_traits/lib.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/compare_method.rs
src/librustc_typeck/check/intrinsic.rs
src/librustc_typeck/check/method/confirm.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/wfcheck.rs
src/librustc_typeck/impl_wf_check.rs
src/librustdoc/clean/mod.rs

index 5b6b0284de5204deb88103ed8e617682da1fb588..c780d1b72f2a0319c0c2b67430232dc574b44ca8 100644 (file)
@@ -46,6 +46,7 @@
 use hir::map::{DefKey, DefPathData, Definitions};
 use hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX};
 use hir::def::{Def, PathResolution};
+use ty::Kind;
 use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES};
 use middle::cstore::CrateStore;
 use rustc_data_structures::indexed_vec::IndexVec;
@@ -1461,7 +1462,7 @@ fn lower_qpath(
                         assert!(!def_id.is_local());
                         let item_generics =
                             self.cstore.item_generics_cloned_untracked(def_id, self.sess);
-                        let n = item_generics.lifetimes().count();
+                        let n = item_generics.param_counts()[&Kind::Lifetime];
                         self.type_def_lifetime_params.insert(def_id, n);
                         n
                     });
index 1da6d9e17402438e6138098354a75969a8ef8a10..06af6d16c3006b9e9832bc3b888abb489f4794c7 100644 (file)
@@ -313,7 +313,7 @@ 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() {
+        for region_def in abstract_type_generics.lifetimes_depr() {
             // Find the index of this region in the list of substitutions.
             let index = region_def.index as usize;
 
index 2a288ae522aac16ddb25c0e0ac41154f93d718f4..26ac9d6ee9ea6798f8cd99d63c62250f018ec84a 100644 (file)
@@ -49,6 +49,7 @@
 #![cfg_attr(stage0, feature(dyn_trait))]
 #![feature(from_ref)]
 #![feature(fs_read_write)]
+#![feature(iterator_find_map)]
 #![cfg_attr(windows, feature(libc))]
 #![cfg_attr(stage0, feature(macro_lifetime_matcher))]
 #![feature(macro_vis_matcher)]
index a12506afb21f3e1017b60f13fba7759ee1e6929b..b450ef81c9178a408ca0cf0dd0095ef5315e53d4 100644 (file)
@@ -1659,7 +1659,7 @@ fn visit_segment_parameters(
                     .entry(def_id)
                     .or_insert_with(|| {
                         tcx.generics_of(def_id)
-                            .types()
+                            .types_depr()
                             .map(|def| def.object_lifetime_default)
                             .collect()
                     })
index 0dfb4572c35affca5ad0f22b2c375f2833b775b4..b7f0e6a32ea15a5b8c3247bd01740bb773cd17ce 100644 (file)
@@ -378,7 +378,7 @@ fn on_unimplemented_note(
             flags.push(("_Self".to_string(), Some(self.tcx.type_of(def.did).to_string())));
         }
 
-        for param in generics.types() {
+        for param in generics.types_depr() {
             let name = param.name.to_string();
             let ty = trait_ref.substs.type_for_def(param);
             let ty_str = ty.to_string();
index 3c82dbd7ad662c61cfbc6f9be7a2c83789bc1b73..cb8ff674188c48b8efeef24a35d40889d3bd9591 100644 (file)
@@ -21,7 +21,7 @@
 
 use hir::def_id::DefId;
 use traits;
-use ty::{self, Ty, TyCtxt, TypeFoldable};
+use ty::{self, Ty, TyCtxt, Kind, TypeFoldable};
 use ty::subst::Substs;
 use ty::util::ExplicitSelf;
 use std::borrow::Cow;
@@ -284,7 +284,7 @@ fn virtual_call_violation_for_method(self,
         }
 
         // We can't monomorphize things like `fn foo<A>(...)`.
-        if self.generics_of(method.def_id).types().count() != 0 {
+        if self.generics_of(method.def_id).param_counts()[&Kind::Type] != 0 {
             return Some(MethodViolationCode::Generic);
         }
 
index 3fc95e9518fb427e7baa5b461781d566832fc703..cee63e2ecc149a1cb6e4600ee0d2d6997b49df57 100644 (file)
@@ -291,7 +291,7 @@ pub fn format(&self,
         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().map(|param| {
+        let generic_map = generics.types_depr().map(|param| {
             (param.name.to_string(), trait_ref.substs.type_for_def(param).to_string())
         }).collect::<FxHashMap<String, String>>();
 
index f7d09b5070c1074f18d55e4df0d30dcce4366895..eabff9a9124137fd8d4e294911e6f5bcaccdf1bf 100644 (file)
@@ -782,6 +782,13 @@ pub fn index(&self) -> u32 {
             GenericParamDef::Type(ty)     => ty.index,
         }
     }
+
+    pub fn get_type(&self) -> Option<TypeParamDef> {
+        match *self {
+            GenericParamDef::Type(ty) => Some(ty),
+            _ => None,
+        }
+    }
 }
 
 /// Information about the formal type/lifetime parameters associated
@@ -828,7 +835,19 @@ pub fn param_counts(&self) -> FxHashMap<Kind, usize> {
         param_counts
     }
 
-    pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &RegionParamDef> {
+    pub fn type_params_without_defaults(&self) -> usize {
+        let mut count = 0;
+        for param in self.params.iter() {
+            if let GenericParamDef::Type(ty) = param {
+                if !ty.has_default {
+                    count += 1
+                }
+            }
+        }
+        count
+    }
+
+    pub fn lifetimes_depr(&self) -> impl DoubleEndedIterator<Item = &RegionParamDef> {
         self.params.iter().filter_map(|p| {
             if let GenericParamDef::Lifetime(lt) = p {
                 Some(lt)
@@ -838,7 +857,7 @@ pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &RegionParamDef> {
         })
     }
 
-    pub fn types(&self) -> impl DoubleEndedIterator<Item = &TypeParamDef> {
+    pub fn types_depr(&self) -> impl DoubleEndedIterator<Item = &TypeParamDef> {
         self.params.iter().filter_map(|p| {
             if let GenericParamDef::Type(ty) = p {
                 Some(ty)
@@ -849,9 +868,7 @@ pub fn types(&self) -> impl DoubleEndedIterator<Item = &TypeParamDef> {
     }
 
     pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
-        if self.params.iter().any(|p| {
-            if let GenericParamDef::Type(_) = p { true } else { false }
-        }) {
+        if self.params.iter().any(|p| p.get_type().is_some()) {
             return true;
         }
         if let Some(parent_def_id) = self.parent {
@@ -912,7 +929,7 @@ pub fn type_param(&'tcx self,
             // And it can be seen that in both cases, to move from a substs
             // offset to a generics offset you just have to offset by the
             // number of regions.
-            let type_param_offset = self.lifetimes().count();
+            let type_param_offset = self.param_counts()[&Kind::Lifetime];
 
             let has_self = self.has_self && self.parent.is_none();
             let is_separated_self = type_param_offset != 0 && idx == 0 && has_self;
index bec343afca82d8121173b27b334ac00495be2662..a9077eb193f38f4a6e31bc2cd613cc4a8e656d4d 100644 (file)
@@ -242,11 +242,10 @@ fn fill_single<FR, FT>(substs: &mut Vec<Kind<'tcx>>,
     where FR: FnMut(&ty::RegionParamDef, &[Kind<'tcx>]) -> ty::Region<'tcx>,
           FT: FnMut(&ty::TypeParamDef, &[Kind<'tcx>]) -> Ty<'tcx> {
         // Handle Self first, before all regions.
-        let mut types = defs.types();
         let mut skip_self = defs.parent.is_none() && defs.has_self;
         if skip_self {
-            let def = types.next().unwrap();
-            let ty = mk_type(def, substs);
+            let def = defs.params.iter().find_map(|p| p.get_type()).unwrap();
+            let ty = mk_type(&def, substs);
             assert_eq!(def.index as usize, substs.len());
             substs.push(ty.into());
         }
index c6a2dccac4952c64ad6c935066eb83ae9e9fa66b..e8edf58a9db394b37bb91ac6ec8e70bb2cd25c90 100644 (file)
@@ -335,10 +335,10 @@ fn parameterized<F: fmt::Write>(&mut self,
             }
 
             if !verbose {
-                if generics.types().last().map_or(false, |def| def.has_default) {
+                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().rev().zip(tps) {
+                        for (def, actual) in generics.types_depr().rev().zip(tps) {
                             if !def.has_default {
                                 break;
                             }
index 2bc4e651dd35797c25a020252e7801deb9228b21..99a7e0abe16796a3c196632f737cf36461414c84 100644 (file)
@@ -1108,7 +1108,7 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                         continue;
                     }
 
-                    if tcx.generics_of(method.def_id).types().count() != 0 {
+                    if tcx.generics_of(method.def_id).param_counts()[&ty::Kind::Type] != 0 {
                         continue;
                     }
 
index 68b8b256f290d4c86e774d76ae8ec0e65a2e7277..58e63fe6b048d468964a678ca76ce94542aab2cf 100644 (file)
@@ -13,7 +13,7 @@
 use rustc_data_structures::sync::Lrc;
 
 use rustc::ty::maps::Providers;
-use rustc::ty::{self, TyCtxt};
+use rustc::ty::{self, TyCtxt, Kind};
 use rustc::hir;
 use rustc::hir::def_id::DefId;
 use rustc::lint::builtin::{SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, UNUSED_UNSAFE};
@@ -357,7 +357,7 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D
 
     // FIXME: when we make this a hard error, this should have its
     // own error code.
-    let message = if tcx.generics_of(def_id).types().count() != 0 {
+    let message = if tcx.generics_of(def_id).param_counts()[&Kind::Type] != 0 {
         format!("#[derive] can't be used on a #[repr(packed)] struct with \
                  type parameters (error E0133)")
     } else {
index d590210925597ddd97351c0af3173f4f8e825623..56ffadc882a458be708e5fd3955c573d7d9af0f5 100644 (file)
@@ -27,7 +27,7 @@
 use rustc::hir::itemlikevisit::DeepVisitor;
 use rustc::lint;
 use rustc::middle::privacy::{AccessLevel, AccessLevels};
-use rustc::ty::{self, TyCtxt, Ty, TypeFoldable};
+use rustc::ty::{self, TyCtxt, Ty, TypeFoldable, GenericParamDef};
 use rustc::ty::fold::TypeVisitor;
 use rustc::ty::maps::Providers;
 use rustc::ty::subst::UnpackedKind;
@@ -399,9 +399,14 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
 
 impl<'b, 'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> {
     fn generics(&mut self) -> &mut Self {
-        for def in self.ev.tcx.generics_of(self.item_def_id).types() {
-            if def.has_default {
-                self.ev.tcx.type_of(def.def_id).visit_with(self);
+        for def in self.ev.tcx.generics_of(self.item_def_id).params.iter() {
+            match def {
+                GenericParamDef::Type(ty) => {
+                    if ty.has_default {
+                        self.ev.tcx.type_of(ty.def_id).visit_with(self);
+                    }
+                }
+                GenericParamDef::Lifetime(_) => {}
             }
         }
         self
@@ -1335,9 +1340,14 @@ struct SearchInterfaceForPrivateItemsVisitor<'a, 'tcx: 'a> {
 
 impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
     fn generics(&mut self) -> &mut Self {
-        for def in self.tcx.generics_of(self.item_def_id).types() {
-            if def.has_default {
-                self.tcx.type_of(def.def_id).visit_with(self);
+        for def in self.tcx.generics_of(self.item_def_id).params.iter() {
+            match def {
+                GenericParamDef::Type(ty) => {
+                    if ty.has_default {
+                        self.tcx.type_of(ty.def_id).visit_with(self);
+                    }
+                }
+                GenericParamDef::Lifetime(_) => {}
             }
         }
         self
index 39326713df2a13ed823dc5791959939d1aa0a275..c9c0902940e54069ae76056af4dfd406d56d0e56 100644 (file)
@@ -280,8 +280,12 @@ fn dtorck_constraint_for_ty<'a, 'gcx, 'tcx>(
     if def.is_phantom_data() {
         let result = DtorckConstraint {
             outlives: vec![],
-            dtorck_types: vec![tcx.mk_param_from_def(&tcx.generics_of(def_id).types().next()
-                .expect("should be at least one type parameter"))],
+            dtorck_types: vec![tcx.mk_param_from_def(
+                &tcx.generics_of(def_id)
+                    .params
+                    .iter()
+                    .find_map(|p| p.get_type())
+                    .expect("should be at least one type parameter"))],
             overflows: vec![],
         };
         debug!("dtorck_constraint: {:?} => {:?}", def, result);
index 7f18fac2db5a3a5b8996c722c6959492ac4302c1..f2627f65702411d3e53a0539551c273755c23c39 100644 (file)
@@ -12,6 +12,7 @@
 //! the guts are broken up into modules; see the comments in those modules.
 
 #![feature(crate_visibility_modifier)]
+#![feature(iterator_find_map)]
 
 #[macro_use]
 extern crate log;
index a6e24f155090d9fa68df5edb6a1d51bb7d6f845e..d77a090de682df96376a2b6f3f107729df097047 100644 (file)
@@ -208,8 +208,9 @@ fn create_substs_for_ast_path(&self,
         // region with the current anon region binding (in other words,
         // whatever & would get replaced with).
         let decl_generics = tcx.generics_of(def_id);
+        let param_counts = decl_generics.param_counts();
         let num_types_provided = parameters.types.len();
-        let expected_num_region_params = decl_generics.lifetimes().count();
+        let expected_num_region_params = param_counts[&ty::Kind::Lifetime];
         let supplied_num_region_params = parameters.lifetimes.len();
         if expected_num_region_params != supplied_num_region_params {
             report_lifetime_number_error(tcx, span,
@@ -221,10 +222,14 @@ fn create_substs_for_ast_path(&self,
         assert_eq!(decl_generics.has_self, self_ty.is_some());
 
         // Check the number of type parameters supplied by the user.
-        let ty_param_defs =
-            decl_generics.types().skip(self_ty.is_some() as usize).collect::<Vec<_>>();
-        if !infer_types || num_types_provided > ty_param_defs.len() {
-            check_type_argument_count(tcx, span, num_types_provided, &ty_param_defs);
+        let type_params_offset = self_ty.is_some() as usize;
+        let ty_param_defs = param_counts[&ty::Kind::Type] - type_params_offset;
+        if !infer_types || num_types_provided > ty_param_defs {
+            check_type_argument_count(tcx,
+                span,
+                num_types_provided,
+                ty_param_defs,
+                decl_generics.type_params_without_defaults() - type_params_offset);
         }
 
         let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF);
@@ -241,7 +246,7 @@ fn create_substs_for_ast_path(&self,
         };
 
         let substs = Substs::for_item(tcx, def_id, |def, _| {
-            let i = def.index as usize - self_ty.is_some() as usize;
+            let i = def.index as usize - type_params_offset;
             if let Some(lifetime) = parameters.lifetimes.get(i) {
                 self.ast_region_to_region(lifetime, Some(def))
             } else {
@@ -255,7 +260,7 @@ fn create_substs_for_ast_path(&self,
                 return ty;
             }
 
-            let i = i - self_ty.is_some() as usize - decl_generics.lifetimes().count();
+            let i = i - (param_counts[&ty::Kind::Lifetime] + type_params_offset);
             if i < num_types_provided {
                 // A provided type parameter.
                 self.ast_ty_to_ty(&parameters.types[i])
@@ -1300,10 +1305,14 @@ fn split_auto_traits<'a, 'b, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
     (auto_traits, trait_bounds)
 }
 
-fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
-                             ty_param_defs: &[&ty::TypeParamDef]) {
-    let accepted = ty_param_defs.len();
-    let required = ty_param_defs.iter().take_while(|x| !x.has_default).count();
+fn check_type_argument_count(tcx: TyCtxt,
+                             span: Span,
+                             supplied: usize,
+                             ty_param_defs: usize,
+                             ty_param_defs_without_default: usize)
+{
+    let accepted = ty_param_defs;
+    let required = ty_param_defs_without_default;
     if supplied < required {
         let expected = if required < accepted {
             "expected at least"
index 30620caf6927490431ec1985285aa11d7b6c33f2..59728542bcda043a4636064bf9cfb73272ca36be 100644 (file)
@@ -10,7 +10,7 @@
 
 use rustc::hir::{self, ImplItemKind, TraitItemKind};
 use rustc::infer::{self, InferOk};
-use rustc::ty::{self, TyCtxt};
+use rustc::ty::{self, TyCtxt, Kind};
 use rustc::ty::util::ExplicitSelf;
 use rustc::traits::{self, ObligationCause, ObligationCauseCode, Reveal};
 use rustc::ty::error::{ExpectedFound, TypeError};
@@ -357,8 +357,8 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                                 trait_to_skol_substs: &Substs<'tcx>)
                                                 -> Result<(), ErrorReported> {
     let span = tcx.sess.codemap().def_span(span);
-    let trait_params = trait_generics.lifetimes();
-    let impl_params = impl_generics.lifetimes();
+    let trait_params = trait_generics.param_counts()[&Kind::Lifetime];
+    let impl_params = impl_generics.param_counts()[&Kind::Lifetime];
 
     debug!("check_region_bounds_on_impl_method: \
             trait_generics={:?} \
@@ -377,7 +377,7 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     // but found 0" it's confusing, because it looks like there
     // are zero. Since I don't quite know how to phrase things at
     // the moment, give a kind of vague error message.
-    if trait_params.count() != impl_params.count() {
+    if trait_params != impl_params {
         let mut err = struct_span_err!(tcx.sess,
                                        span,
                                        E0195,
@@ -574,8 +574,8 @@ fn compare_number_of_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                         -> Result<(), ErrorReported> {
     let impl_m_generics = tcx.generics_of(impl_m.def_id);
     let trait_m_generics = tcx.generics_of(trait_m.def_id);
-    let num_impl_m_type_params = impl_m_generics.types().count();
-    let num_trait_m_type_params = trait_m_generics.types().count();
+    let num_impl_m_type_params = impl_m_generics.param_counts()[&Kind::Type];
+    let num_trait_m_type_params = trait_m_generics.param_counts()[&Kind::Type];
     if num_impl_m_type_params != num_trait_m_type_params {
         let impl_m_node_id = tcx.hir.as_local_node_id(impl_m.def_id).unwrap();
         let impl_m_item = tcx.hir.expect_impl_item(impl_m_node_id);
@@ -728,7 +728,7 @@ 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().zip(trait_m_generics.types()) {
+    for (impl_ty, trait_ty) in impl_m_generics.types_depr().zip(trait_m_generics.types_depr()) {
         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);
index e2deca38302cdc3db162a07de337b761d3b67cef..e3d7e16e15c9776b4db55f15b29619137f4a6b13 100644 (file)
@@ -13,7 +13,7 @@
 
 use intrinsics;
 use rustc::traits::{ObligationCause, ObligationCauseCode};
-use rustc::ty::{self, TyCtxt, Ty};
+use rustc::ty::{self, TyCtxt, Ty, Kind};
 use rustc::util::nodemap::FxHashMap;
 use require_same_types;
 
@@ -45,7 +45,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         }
     }
 
-    let i_n_tps = tcx.generics_of(def_id).types().count();
+    let i_n_tps = tcx.generics_of(def_id).param_counts()[&Kind::Type];
     if i_n_tps != n_tps {
         let span = match it.node {
             hir::ForeignItemFn(_, _, ref generics) => generics.span,
@@ -346,7 +346,7 @@ pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     };
 
     let def_id = tcx.hir.local_def_id(it.id);
-    let i_n_tps = tcx.generics_of(def_id).types().count();
+    let i_n_tps = tcx.generics_of(def_id).param_counts()[&Kind::Type];
     let name = it.name.as_str();
 
     let (n_tps, inputs, output) = match &*name {
index f075cd911ad9e61c6cfba2478838f70b2e65c6a6..038927bbac647cb352864a7a11d7c47e20066fe6 100644 (file)
@@ -15,7 +15,7 @@
 use hir::def_id::DefId;
 use rustc::ty::subst::Substs;
 use rustc::traits;
-use rustc::ty::{self, Ty};
+use rustc::ty::{self, Ty, Kind};
 use rustc::ty::subst::Subst;
 use rustc::ty::adjustment::{Adjustment, Adjust, OverloadedDeref};
 use rustc::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
@@ -332,7 +332,9 @@ fn instantiate_method_substs(&mut self,
                 parent_substs.type_at(i)
             } else if let Some(ast_ty)
                 = provided.as_ref().and_then(|p| {
-                    p.types.get(i - parent_substs.len() - method_generics.lifetimes().count())
+                    let idx =
+                        i - parent_substs.len() - method_generics.param_counts()[&Kind::Lifetime];
+                    p.types.get(idx)
                 })
             {
                 self.to_ty(ast_ty)
index 44b0ebf7f01167b4704f080b7ce0540c8e5d3ab6..6ed31a237ff5f38cbce95891b02331ee573bea42 100644 (file)
@@ -96,7 +96,7 @@
 use rustc::mir::interpret::{GlobalId};
 use rustc::ty::subst::{Kind, Subst, Substs};
 use rustc::traits::{self, ObligationCause, ObligationCauseCode, TraitEngine};
-use rustc::ty::{self, Ty, TyCtxt, Visibility, ToPredicate, GenericParamDef};
+use rustc::ty::{self, Ty, TyCtxt, Visibility, ToPredicate};
 use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
 use rustc::ty::fold::TypeFoldable;
 use rustc::ty::maps::Providers;
@@ -4923,16 +4923,11 @@ fn check_path_parameter_count(&self,
             segment.map_or((0, 0, 0), |(_, generics)| {
                 let params_count = generics.param_counts();
 
-                let offset_type_params = generics.parent.is_none() && generics.has_self;
-                let type_params = params_count[&ty::Kind::Type] - offset_type_params as usize;
+                let type_params_offset
+                    = (generics.parent.is_none() && generics.has_self) as usize;
+                let type_params = params_count[&ty::Kind::Type] - type_params_offset;
                 let type_params_barring_defaults =
-                    type_params - generics.params.iter().filter(|param| {
-                        if let GenericParamDef::Type(ty) = param {
-                            ty.has_default
-                        } else {
-                            false
-                        }
-                    }).count();
+                    generics.type_params_without_defaults() - type_params_offset;
 
                 (type_params_barring_defaults, type_params, params_count[&ty::Kind::Lifetime])
             });
index fa1ac49232ac02a9dee06ddeee28bdee0a351821..804fed10105469465f6093c1802dc37cc8fbc509 100644 (file)
@@ -377,7 +377,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
     // 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().cloned().filter(is_our_default).map(|p| p.def_id) {
+    for d in generics.types_depr().cloned().filter(is_our_default).map(|p| p.def_id) {
         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
index 60a998db3594fbda546fc752258f63fb74d96a52..e0786ea8b3c6fff62ea681bbefed16a5538b1adb 100644 (file)
@@ -105,7 +105,7 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         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().zip(impl_hir_generics.ty_params()) {
+    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());
@@ -122,13 +122,13 @@ 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_lifetime, lifetime) in impl_generics.lifetimes().zip(impl_hir_generics.lifetimes()) {
-        let param = ctp::Parameter::from(ty_lifetime.to_early_bound_region_data());
+    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, lifetime.lifetime.span,
-                                    "lifetime", &lifetime.lifetime.name.name().to_string());
+            report_unused_parameter(tcx, lt.lifetime.span,
+                                    "lifetime", &lt.lifetime.name.name().to_string());
         }
     }
 
index d1db5185f194a9996ef2cde86a0edaebbadfda61..7f6da5414c63757ad1417184f91ffaf14d0cd4ae 100644 (file)
@@ -1800,7 +1800,7 @@ fn clean(&self, cx: &DocContext) -> 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().filter_map(|tp| {
+        let stripped_typarams = gens.types_depr().filter_map(|tp| {
             if tp.name == keywords::SelfType.name().as_str() {
                 assert_eq!(tp.index, 0);
                 None
@@ -1849,7 +1849,7 @@ fn clean(&self, cx: &DocContext) -> Generics {
         // and instead see `where T: Foo + Bar + Sized + 'a`
 
         Generics {
-            params: gens.lifetimes()
+            params: gens.lifetimes_depr()
                         .into_iter()
                         .map(|lp| GenericParamDef::Lifetime(lp.clean(cx)))
                         .chain(