1
Fork 0

Add Default for GenericParamCount

This commit is contained in:
varkor 2018-08-07 17:44:30 +01:00
parent 7c9f7c2fa3
commit a14bc713e7
4 changed files with 22 additions and 16 deletions

View file

@ -445,6 +445,22 @@ impl GenericArgs {
} }
bug!("GenericArgs::inputs: not a `Fn(T) -> U`"); 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 /// A modifier on a bound, currently this is only used for `?Sized`, where the
@ -503,6 +519,7 @@ pub struct GenericParam {
pub kind: GenericParamKind, pub kind: GenericParamKind,
} }
#[derive(Default)]
pub struct GenericParamCount { pub struct GenericParamCount {
pub lifetimes: usize, pub lifetimes: usize,
pub types: usize, pub types: usize,
@ -533,10 +550,7 @@ impl Generics {
// We could cache this as a property of `GenericParamCount`, but // We could cache this as a property of `GenericParamCount`, but
// the aim is to refactor this away entirely eventually and the // the aim is to refactor this away entirely eventually and the
// presence of this method will be a constant reminder. // presence of this method will be a constant reminder.
let mut own_counts = GenericParamCount { let mut own_counts: GenericParamCount = Default::default();
lifetimes: 0,
types: 0,
};
for param in &self.params { for param in &self.params {
match param.kind { match param.kind {

View file

@ -881,6 +881,7 @@ impl GenericParamDef {
} }
} }
#[derive(Default)]
pub struct GenericParamCount { pub struct GenericParamCount {
pub lifetimes: usize, pub lifetimes: usize,
pub types: usize, pub types: usize,
@ -913,10 +914,7 @@ impl<'a, 'gcx, 'tcx> Generics {
// We could cache this as a property of `GenericParamCount`, but // We could cache this as a property of `GenericParamCount`, but
// the aim is to refactor this away entirely eventually and the // the aim is to refactor this away entirely eventually and the
// presence of this method will be a constant reminder. // presence of this method will be a constant reminder.
let mut own_counts = GenericParamCount { let mut own_counts: GenericParamCount = Default::default();
lifetimes: 0,
types: 0,
};
for param in &self.params { for param in &self.params {
match param.kind { match param.kind {

View file

@ -262,10 +262,7 @@ impl PrintContext {
let verbose = self.is_verbose; let verbose = self.is_verbose;
let mut num_supplied_defaults = 0; let mut num_supplied_defaults = 0;
let mut has_self = false; let mut has_self = false;
let mut own_counts = GenericParamCount { let mut own_counts: GenericParamCount = Default::default();
lifetimes: 0,
types: 0,
};
let mut is_value_path = false; let mut is_value_path = false;
let fn_trait_kind = ty::tls::with(|tcx| { let fn_trait_kind = ty::tls::with(|tcx| {
// Unfortunately, some kinds of items (e.g., closures) don't have // Unfortunately, some kinds of items (e.g., closures) don't have

View file

@ -2432,10 +2432,7 @@ impl Clean<Type> for hir::Ty {
let mut ty_substs = FxHashMap(); let mut ty_substs = FxHashMap();
let mut lt_substs = FxHashMap(); let mut lt_substs = FxHashMap();
provided_params.with_generic_args(|generic_args| { provided_params.with_generic_args(|generic_args| {
let mut indices = ty::GenericParamCount { let mut indices: GenericParamCount = Default::default();
lifetimes: 0,
types: 0
};
for param in generics.params.iter() { for param in generics.params.iter() {
match param.kind { match param.kind {
hir::GenericParamKind::Lifetime { .. } => { hir::GenericParamKind::Lifetime { .. } => {