Skip to content

Commit a14bc71

Browse files
committed
Add Default for GenericParamCount
1 parent 7c9f7c2 commit a14bc71

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

src/librustc/hir/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,22 @@ impl GenericArgs {
445445
}
446446
bug!("GenericArgs::inputs: not a `Fn(T) -> U`");
447447
}
448+
449+
pub fn own_counts(&self) -> GenericParamCount {
450+
// We could cache this as a property of `GenericParamCount`, but
451+
// the aim is to refactor this away entirely eventually and the
452+
// presence of this method will be a constant reminder.
453+
let mut own_counts: GenericParamCount = Default::default();
454+
455+
for arg in &self.args {
456+
match arg {
457+
GenericArg::Lifetime(_) => own_counts.lifetimes += 1,
458+
GenericArg::Type(_) => own_counts.types += 1,
459+
};
460+
}
461+
462+
own_counts
463+
}
448464
}
449465

450466
/// A modifier on a bound, currently this is only used for `?Sized`, where the
@@ -503,6 +519,7 @@ pub struct GenericParam {
503519
pub kind: GenericParamKind,
504520
}
505521

522+
#[derive(Default)]
506523
pub struct GenericParamCount {
507524
pub lifetimes: usize,
508525
pub types: usize,
@@ -533,10 +550,7 @@ impl Generics {
533550
// We could cache this as a property of `GenericParamCount`, but
534551
// the aim is to refactor this away entirely eventually and the
535552
// presence of this method will be a constant reminder.
536-
let mut own_counts = GenericParamCount {
537-
lifetimes: 0,
538-
types: 0,
539-
};
553+
let mut own_counts: GenericParamCount = Default::default();
540554

541555
for param in &self.params {
542556
match param.kind {

src/librustc/ty/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ impl GenericParamDef {
881881
}
882882
}
883883

884+
#[derive(Default)]
884885
pub struct GenericParamCount {
885886
pub lifetimes: usize,
886887
pub types: usize,
@@ -913,10 +914,7 @@ impl<'a, 'gcx, 'tcx> Generics {
913914
// We could cache this as a property of `GenericParamCount`, but
914915
// the aim is to refactor this away entirely eventually and the
915916
// presence of this method will be a constant reminder.
916-
let mut own_counts = GenericParamCount {
917-
lifetimes: 0,
918-
types: 0,
919-
};
917+
let mut own_counts: GenericParamCount = Default::default();
920918

921919
for param in &self.params {
922920
match param.kind {

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,7 @@ impl PrintContext {
262262
let verbose = self.is_verbose;
263263
let mut num_supplied_defaults = 0;
264264
let mut has_self = false;
265-
let mut own_counts = GenericParamCount {
266-
lifetimes: 0,
267-
types: 0,
268-
};
265+
let mut own_counts: GenericParamCount = Default::default();
269266
let mut is_value_path = false;
270267
let fn_trait_kind = ty::tls::with(|tcx| {
271268
// Unfortunately, some kinds of items (e.g., closures) don't have

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,10 +2432,7 @@ impl Clean<Type> for hir::Ty {
24322432
let mut ty_substs = FxHashMap();
24332433
let mut lt_substs = FxHashMap();
24342434
provided_params.with_generic_args(|generic_args| {
2435-
let mut indices = ty::GenericParamCount {
2436-
lifetimes: 0,
2437-
types: 0
2438-
};
2435+
let mut indices: GenericParamCount = Default::default();
24392436
for param in generics.params.iter() {
24402437
match param.kind {
24412438
hir::GenericParamKind::Lifetime { .. } => {

0 commit comments

Comments
 (0)