about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-08-07 17:44:30 +0100
committervarkor <github@varkor.com>2018-08-19 20:02:34 +0100
commita14bc713e77cfdf2c91e2e24f428f9dd13da786a (patch)
tree49f64fad929430b16d95db31a661e2f0310f80c1
parent7c9f7c2fa3b48f8bfefa148dc425db68684cf953 (diff)
downloadrust-a14bc713e77cfdf2c91e2e24f428f9dd13da786a.tar.gz
rust-a14bc713e77cfdf2c91e2e24f428f9dd13da786a.zip
Add Default for GenericParamCount
-rw-r--r--src/librustc/hir/mod.rs22
-rw-r--r--src/librustc/ty/mod.rs6
-rw-r--r--src/librustc/util/ppaux.rs5
-rw-r--r--src/librustdoc/clean/mod.rs5
4 files changed, 22 insertions, 16 deletions
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<Type> 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 { .. } => {