Rename param_counts to own_counts
This commit is contained in:
parent
365c8c3704
commit
fd8e284a20
11 changed files with 35 additions and 35 deletions
|
@ -1461,7 +1461,7 @@ impl<'a> LoweringContext<'a> {
|
|||
assert!(!def_id.is_local());
|
||||
let item_generics =
|
||||
self.cstore.item_generics_cloned_untracked(def_id, self.sess);
|
||||
let n = item_generics.param_counts().lifetimes;
|
||||
let n = item_generics.own_counts().lifetimes;
|
||||
self.type_def_lifetime_params.insert(def_id, n);
|
||||
n
|
||||
});
|
||||
|
|
|
@ -284,7 +284,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
// We can't monomorphize things like `fn foo<A>(...)`.
|
||||
if self.generics_of(method.def_id).param_counts().types != 0 {
|
||||
if self.generics_of(method.def_id).own_counts().types != 0 {
|
||||
return Some(MethodViolationCode::Generic);
|
||||
}
|
||||
|
||||
|
|
|
@ -794,23 +794,23 @@ impl<'a, 'gcx, 'tcx> Generics {
|
|||
self.parent_count + self.params.len()
|
||||
}
|
||||
|
||||
pub fn param_counts(&self) -> GenericParamCount {
|
||||
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 param_counts = GenericParamCount {
|
||||
let mut own_counts = GenericParamCount {
|
||||
lifetimes: 0,
|
||||
types: 0,
|
||||
};
|
||||
|
||||
for param in self.params.iter() {
|
||||
match param.kind {
|
||||
GenericParamDefKind::Lifetime => param_counts.lifetimes += 1,
|
||||
GenericParamDefKind::Type(_) => param_counts.types += 1,
|
||||
GenericParamDefKind::Lifetime => own_counts.lifetimes += 1,
|
||||
GenericParamDefKind::Type(_) => own_counts.types += 1,
|
||||
};
|
||||
}
|
||||
|
||||
param_counts
|
||||
own_counts
|
||||
}
|
||||
|
||||
pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
|
||||
|
|
|
@ -257,7 +257,7 @@ impl PrintContext {
|
|||
let verbose = self.is_verbose;
|
||||
let mut num_supplied_defaults = 0;
|
||||
let mut has_self = false;
|
||||
let mut param_counts = GenericParamCount {
|
||||
let mut own_counts = GenericParamCount {
|
||||
lifetimes: 0,
|
||||
types: 0,
|
||||
};
|
||||
|
@ -306,7 +306,7 @@ impl PrintContext {
|
|||
}
|
||||
}
|
||||
let mut generics = tcx.generics_of(item_def_id);
|
||||
let child_param_counts = generics.param_counts();
|
||||
let child_own_counts = generics.own_counts();
|
||||
let mut path_def_id = did;
|
||||
has_self = generics.has_self;
|
||||
|
||||
|
@ -314,9 +314,9 @@ impl PrintContext {
|
|||
if let Some(def_id) = generics.parent {
|
||||
// Methods.
|
||||
assert!(is_value_path);
|
||||
child_types = child_param_counts.types;
|
||||
child_types = child_own_counts.types;
|
||||
generics = tcx.generics_of(def_id);
|
||||
param_counts = generics.param_counts();
|
||||
own_counts = generics.own_counts();
|
||||
|
||||
if has_self {
|
||||
print!(f, self, write("<"), print_display(substs.type_at(0)), write(" as "))?;
|
||||
|
@ -331,7 +331,7 @@ impl PrintContext {
|
|||
assert_eq!(has_self, false);
|
||||
} else {
|
||||
// Types and traits.
|
||||
param_counts = child_param_counts;
|
||||
own_counts = child_own_counts;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,10 +415,10 @@ impl PrintContext {
|
|||
Ok(())
|
||||
};
|
||||
|
||||
print_regions(f, "<", 0, param_counts.lifetimes)?;
|
||||
print_regions(f, "<", 0, own_counts.lifetimes)?;
|
||||
|
||||
let tps = substs.types()
|
||||
.take(param_counts.types - num_supplied_defaults)
|
||||
.take(own_counts.types - num_supplied_defaults)
|
||||
.skip(has_self as usize);
|
||||
|
||||
for ty in tps {
|
||||
|
@ -450,10 +450,10 @@ impl PrintContext {
|
|||
write!(f, "::{}", item_name)?;
|
||||
}
|
||||
|
||||
print_regions(f, "::<", param_counts.lifetimes, usize::MAX)?;
|
||||
print_regions(f, "::<", own_counts.lifetimes, usize::MAX)?;
|
||||
|
||||
// FIXME: consider being smart with defaults here too
|
||||
for ty in substs.types().skip(param_counts.types) {
|
||||
for ty in substs.types().skip(own_counts.types) {
|
||||
start_or_continue(f, "::<", ", ")?;
|
||||
ty.print_display(f, self)?;
|
||||
}
|
||||
|
|
|
@ -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).param_counts().types != 0 {
|
||||
if tcx.generics_of(method.def_id).own_counts().types != 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -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).param_counts().types != 0 {
|
||||
let message = if tcx.generics_of(def_id).own_counts().types != 0 {
|
||||
format!("#[derive] can't be used on a #[repr(packed)] struct with \
|
||||
type parameters (error E0133)")
|
||||
} else {
|
||||
|
|
|
@ -208,9 +208,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
// 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 own_counts = decl_generics.own_counts();
|
||||
let num_types_provided = parameters.types.len();
|
||||
let expected_num_region_params = param_counts.lifetimes;
|
||||
let expected_num_region_params = own_counts.lifetimes;
|
||||
let supplied_num_region_params = parameters.lifetimes.len();
|
||||
if expected_num_region_params != supplied_num_region_params {
|
||||
report_lifetime_number_error(tcx, span,
|
||||
|
@ -223,7 +223,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
|
||||
// Check the number of type parameters supplied by the user.
|
||||
let own_self = self_ty.is_some() as usize;
|
||||
let ty_param_defs = param_counts.types - own_self;
|
||||
let ty_param_defs = own_counts.types - own_self;
|
||||
if !infer_types || num_types_provided > ty_param_defs {
|
||||
let type_params_without_defaults = {
|
||||
let mut count = 0;
|
||||
|
@ -279,7 +279,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
_ => unreachable!()
|
||||
};
|
||||
|
||||
let i = i - (param_counts.lifetimes + own_self);
|
||||
let i = i - (own_counts.lifetimes + own_self);
|
||||
if i < num_types_provided {
|
||||
// A provided type parameter.
|
||||
self.ast_ty_to_ty(¶meters.types[i])
|
||||
|
|
|
@ -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.param_counts().lifetimes;
|
||||
let impl_params = impl_generics.param_counts().lifetimes;
|
||||
let trait_params = trait_generics.own_counts().lifetimes;
|
||||
let impl_params = impl_generics.own_counts().lifetimes;
|
||||
|
||||
debug!("check_region_bounds_on_impl_method: \
|
||||
trait_generics={:?} \
|
||||
|
@ -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.param_counts().types;
|
||||
let num_trait_m_type_params = trait_m_generics.param_counts().types;
|
||||
let num_impl_m_type_params = impl_m_generics.own_counts().types;
|
||||
let num_trait_m_type_params = trait_m_generics.own_counts().types;
|
||||
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);
|
||||
|
|
|
@ -45,7 +45,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
}
|
||||
}
|
||||
|
||||
let i_n_tps = tcx.generics_of(def_id).param_counts().types;
|
||||
let i_n_tps = tcx.generics_of(def_id).own_counts().types;
|
||||
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).param_counts().types;
|
||||
let i_n_tps = tcx.generics_of(def_id).own_counts().types;
|
||||
let name = it.name.as_str();
|
||||
|
||||
let (n_tps, inputs, output) = match &*name {
|
||||
|
|
|
@ -316,7 +316,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
|
|||
// parameters from the type and those from the method.
|
||||
assert_eq!(method_generics.parent_count, parent_substs.len());
|
||||
let provided = &segment.parameters;
|
||||
let param_counts = method_generics.param_counts();
|
||||
let own_counts = method_generics.own_counts();
|
||||
Substs::for_item(self.tcx, pick.item.def_id, |def, _| {
|
||||
let i = def.index as usize;
|
||||
if i < parent_substs.len() {
|
||||
|
@ -334,7 +334,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
|
|||
} else if let Some(ast_ty)
|
||||
= provided.as_ref().and_then(|p| {
|
||||
let idx =
|
||||
i - parent_substs.len() - param_counts.lifetimes;
|
||||
i - parent_substs.len() - own_counts.lifetimes;
|
||||
p.types.get(idx)
|
||||
})
|
||||
{
|
||||
|
|
|
@ -1239,7 +1239,7 @@ pub fn check_item_type<'a,'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Item
|
|||
} else {
|
||||
for item in &m.items {
|
||||
let generics = tcx.generics_of(tcx.hir.local_def_id(item.id));
|
||||
if generics.params.len() - generics.param_counts().lifetimes != 0 {
|
||||
if generics.params.len() - generics.own_counts().lifetimes != 0 {
|
||||
let mut err = struct_span_err!(tcx.sess, item.span, E0044,
|
||||
"foreign items may not have type parameters");
|
||||
err.span_label(item.span, "can't have type parameters");
|
||||
|
@ -4799,7 +4799,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
|
||||
// Skip over the lifetimes in the same segment.
|
||||
if let Some((_, generics)) = segment {
|
||||
i -= generics.param_counts().lifetimes;
|
||||
i -= generics.own_counts().lifetimes;
|
||||
}
|
||||
|
||||
let has_default = match def.kind {
|
||||
|
@ -4925,10 +4925,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
// Check provided parameters.
|
||||
let (ty_req_len, accepted, lt_req_len) =
|
||||
segment.map_or((0, 0, 0), |(_, generics)| {
|
||||
let param_counts = generics.param_counts();
|
||||
let own_counts = generics.own_counts();
|
||||
|
||||
let own_self = (generics.parent.is_none() && generics.has_self) as usize;
|
||||
let type_params = param_counts.types - own_self;
|
||||
let type_params = own_counts.types - own_self;
|
||||
let type_params_without_defaults = {
|
||||
let mut count = 0;
|
||||
for param in generics.params.iter() {
|
||||
|
@ -4943,7 +4943,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
let type_params_barring_defaults =
|
||||
type_params_without_defaults - own_self;
|
||||
|
||||
(type_params_barring_defaults, type_params, param_counts.lifetimes)
|
||||
(type_params_barring_defaults, type_params, own_counts.lifetimes)
|
||||
});
|
||||
|
||||
if types.len() > accepted {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue