diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 589f3c9d87c..991b80ad3e9 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -445,6 +445,22 @@ impl GenericArgs { } bug!("GenericArgs::inputs: not a `Fn(T) -> U`"); } + + pub fn own_counts(&self) -> GenericParamCount { + // We could cache this as a property of `GenericParamCount`, but + // the aim is to refactor this away entirely eventually and the + // presence of this method will be a constant reminder. + let mut own_counts: GenericParamCount = Default::default(); + + for arg in &self.args { + match arg { + GenericArg::Lifetime(_) => own_counts.lifetimes += 1, + GenericArg::Type(_) => own_counts.types += 1, + }; + } + + own_counts + } } /// A modifier on a bound, currently this is only used for `?Sized`, where the @@ -503,6 +519,7 @@ pub struct GenericParam { pub kind: GenericParamKind, } +#[derive(Default)] pub struct GenericParamCount { pub lifetimes: usize, pub types: usize, @@ -533,10 +550,7 @@ impl Generics { // We could cache this as a property of `GenericParamCount`, but // the aim is to refactor this away entirely eventually and the // presence of this method will be a constant reminder. - let mut own_counts = GenericParamCount { - lifetimes: 0, - types: 0, - }; + let mut own_counts: GenericParamCount = Default::default(); for param in &self.params { match param.kind { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 4479c7239df..3e4527cacd4 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -881,6 +881,7 @@ impl GenericParamDef { } } +#[derive(Default)] pub struct GenericParamCount { pub lifetimes: usize, pub types: usize, @@ -913,10 +914,7 @@ impl<'a, 'gcx, 'tcx> Generics { // We could cache this as a property of `GenericParamCount`, but // the aim is to refactor this away entirely eventually and the // presence of this method will be a constant reminder. - let mut own_counts = GenericParamCount { - lifetimes: 0, - types: 0, - }; + let mut own_counts: GenericParamCount = Default::default(); for param in &self.params { match param.kind { diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index bb54e183604..9513086667b 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -262,10 +262,7 @@ impl PrintContext { let verbose = self.is_verbose; let mut num_supplied_defaults = 0; let mut has_self = false; - let mut own_counts = GenericParamCount { - lifetimes: 0, - types: 0, - }; + let mut own_counts: GenericParamCount = Default::default(); let mut is_value_path = false; let fn_trait_kind = ty::tls::with(|tcx| { // Unfortunately, some kinds of items (e.g., closures) don't have diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index ad774f98602..687a606cecb 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2432,10 +2432,7 @@ impl Clean for hir::Ty { let mut ty_substs = FxHashMap(); let mut lt_substs = FxHashMap(); provided_params.with_generic_args(|generic_args| { - let mut indices = ty::GenericParamCount { - lifetimes: 0, - types: 0 - }; + let mut indices: GenericParamCount = Default::default(); for param in generics.params.iter() { match param.kind { hir::GenericParamKind::Lifetime { .. } => {