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
});
}
// 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);
}
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 {
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,
};
}
}
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;
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 "))?;
assert_eq!(has_self, false);
} else {
// Types and traits.
- param_counts = child_param_counts;
+ own_counts = child_own_counts;
}
}
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 {
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)?;
}
continue;
}
- if tcx.generics_of(method.def_id).param_counts().types != 0 {
+ if tcx.generics_of(method.def_id).own_counts().types != 0 {
continue;
}
// 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 {
// 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,
// 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;
_ => 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])
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={:?} \
-> 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);
}
}
- 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,
};
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 {
// 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() {
} 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)
})
{
} 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");
// 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 {
// 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() {
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 {