Rename Generics::params to Generics::own_params

This commit is contained in:
Michael Goulet 2024-05-09 20:56:44 -04:00
parent 8c7c151a7a
commit 1c19b6ad60
54 changed files with 177 additions and 169 deletions

View File

@ -317,7 +317,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
let mut has_dyn = false;
let mut failed = false;
let elaborated_args = std::iter::zip(*args, &generics.params).map(|(arg, param)| {
let elaborated_args =
std::iter::zip(*args, &generics.own_params).map(|(arg, param)| {
if let Some(ty::Dynamic(obj, _, ty::Dyn)) = arg.as_type().map(Ty::kind) {
let default = tcx.object_lifetime_default(param.def_id);
@ -332,10 +333,12 @@ impl<'tcx> BorrowExplanation<'tcx> {
}
ObjectLifetimeDefault::Param(param_def_id) => {
let index = generics.param_def_id_to_index[&param_def_id] as usize;
args.get(index).and_then(|arg| arg.as_region()).unwrap_or_else(|| {
args.get(index).and_then(|arg| arg.as_region()).unwrap_or_else(
|| {
failed = true;
re_static
})
},
)
}
ObjectLifetimeDefault::Static => re_static,
};

View File

@ -1281,7 +1281,7 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
let mut names = generics
.parent
.map_or_else(Vec::new, |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
names.extend(generics.params.iter().map(|param| param.name));
names.extend(generics.own_params.iter().map(|param| param.name));
names
}
}

View File

@ -512,7 +512,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let mut names = generics.parent.map_or_else(Vec::new, |def_id| {
get_parameter_names(cx, cx.tcx.generics_of(def_id))
});
names.extend(generics.params.iter().map(|param| param.name));
names.extend(generics.own_params.iter().map(|param| param.name));
names
}

View File

@ -561,7 +561,7 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
let generics = tcx.generics_of(generics);
def_id = generics.parent;
for param in &generics.params {
for param in &generics.own_params {
if expected_captures.contains(&param.def_id) {
assert_eq!(
variances[param.index as usize],
@ -778,7 +778,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let def_id = item.id.owner_id.def_id;
let generics = tcx.generics_of(def_id);
let own_counts = generics.own_counts();
if generics.params.len() - own_counts.lifetimes != 0 {
if generics.own_params.len() - own_counts.lifetimes != 0 {
let (kinds, kinds_pl, egs) = match (own_counts.types, own_counts.consts)
{
(_, 0) => ("type", "types", Some("u32")),
@ -1544,7 +1544,7 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD
.collect::<FxIndexMap<_, _>>()
});
let mut params_used = BitSet::new_empty(generics.params.len());
let mut params_used = BitSet::new_empty(generics.own_params.len());
for leaf in ty.walk() {
if let GenericArgKind::Type(leaf_ty) = leaf.unpack()
&& let ty::Param(param) = leaf_ty.kind()
@ -1554,7 +1554,7 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD
}
}
for param in &generics.params {
for param in &generics.own_params {
if !params_used.contains(param.index)
&& let ty::GenericParamDefKind::Type { .. } = param.kind
{

View File

@ -716,7 +716,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
// since we previously enforce that the trait method and impl method have the
// same generics.
let num_trait_args = trait_to_impl_args.len();
let num_impl_args = tcx.generics_of(impl_m.container_id(tcx)).params.len();
let num_impl_args = tcx.generics_of(impl_m.container_id(tcx)).own_params.len();
let ty = match ty.try_fold_with(&mut RemapHiddenTyRegions {
tcx,
map,
@ -1494,11 +1494,13 @@ fn compare_synthetic_generics<'tcx>(
let mut error_found = None;
let impl_m_generics = tcx.generics_of(impl_m.def_id);
let trait_m_generics = tcx.generics_of(trait_m.def_id);
let impl_m_type_params = impl_m_generics.params.iter().filter_map(|param| match param.kind {
let impl_m_type_params =
impl_m_generics.own_params.iter().filter_map(|param| match param.kind {
GenericParamDefKind::Type { synthetic, .. } => Some((param.def_id, synthetic)),
GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => None,
});
let trait_m_type_params = trait_m_generics.params.iter().filter_map(|param| match param.kind {
let trait_m_type_params =
trait_m_generics.own_params.iter().filter_map(|param| match param.kind {
GenericParamDefKind::Type { synthetic, .. } => Some((param.def_id, synthetic)),
GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => None,
});
@ -1639,7 +1641,7 @@ fn compare_generic_param_kinds<'tcx>(
assert_eq!(impl_item.kind, trait_item.kind);
let ty_const_params_of = |def_id| {
tcx.generics_of(def_id).params.iter().filter(|param| {
tcx.generics_of(def_id).own_params.iter().filter(|param| {
matches!(
param.kind,
GenericParamDefKind::Const { .. } | GenericParamDefKind::Type { .. }
@ -2140,7 +2142,7 @@ fn param_env_with_gat_bounds<'tcx>(
};
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> =
smallvec::SmallVec::with_capacity(tcx.generics_of(impl_ty.def_id).params.len());
smallvec::SmallVec::with_capacity(tcx.generics_of(impl_ty.def_id).own_params.len());
// Extend the impl's identity args with late-bound GAT vars
let normalize_impl_ty_args = ty::GenericArgs::identity_for_item(tcx, container_id)
.extend_to(tcx, impl_ty.def_id, |param, _| match param.kind {

View File

@ -431,7 +431,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
}
let gat_generics = tcx.generics_of(gat_def_id);
// FIXME(jackh726): we can also warn in the more general case
if gat_generics.params.is_empty() {
if gat_generics.own_params.is_empty() {
continue;
}
@ -1400,7 +1400,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
// struct Foo<T = Vec<[u32]>> { .. }
//
// Here, the default `Vec<[u32]>` is not WF because `[u32]: Sized` does not hold.
for param in &generics.params {
for param in &generics.own_params {
match param.kind {
GenericParamDefKind::Type { .. } => {
if is_our_default(param) {
@ -1879,7 +1879,7 @@ fn check_variances_for_type_defn<'tcx>(
continue;
}
let ty_param = &ty_generics.params[index];
let ty_param = &ty_generics.own_params[index];
let hir_param = &hir_generics.params[index];
if ty_param.def_id != hir_param.def_id.into() {

View File

@ -571,7 +571,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for TyVarReplacer<'cx, 'tcx> {
if let Some(def_id) = origin.param_def_id {
// The generics of an `impl` don't have a parent, we can index directly.
let index = self.generics.param_def_id_to_index[&def_id];
let name = self.generics.params[index as usize].name;
let name = self.generics.own_params[index as usize].name;
Ty::new_param(self.infcx.tcx, index, name)
} else {

View File

@ -14,7 +14,7 @@ pub(super) fn check_item(
trait_def: &TraitDef,
) -> Result<(), ErrorGuaranteed> {
let unsafe_attr =
tcx.generics_of(def_id).params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");
tcx.generics_of(def_id).own_params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");
let trait_ref = trait_header.trait_ref.instantiate_identity();
match (trait_def.unsafety, unsafe_attr, trait_header.unsafety, trait_header.polarity) {

View File

@ -22,28 +22,28 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
let trait_def_id = tcx.parent(fn_def_id);
let opaque_ty_generics = tcx.generics_of(opaque_def_id);
let opaque_ty_parent_count = opaque_ty_generics.parent_count;
let mut params = opaque_ty_generics.params.clone();
let mut own_params = opaque_ty_generics.own_params.clone();
let parent_generics = tcx.generics_of(trait_def_id);
let parent_count = parent_generics.parent_count + parent_generics.params.len();
let parent_count = parent_generics.parent_count + parent_generics.own_params.len();
let mut trait_fn_params = tcx.generics_of(fn_def_id).params.clone();
let mut trait_fn_params = tcx.generics_of(fn_def_id).own_params.clone();
for param in &mut params {
for param in &mut own_params {
param.index = param.index + parent_count as u32 + trait_fn_params.len() as u32
- opaque_ty_parent_count as u32;
}
trait_fn_params.extend(params);
params = trait_fn_params;
trait_fn_params.extend(own_params);
own_params = trait_fn_params;
let param_def_id_to_index =
params.iter().map(|param| (param.def_id, param.index)).collect();
own_params.iter().map(|param| (param.def_id, param.index)).collect();
return ty::Generics {
parent: Some(trait_def_id),
parent_count,
params,
own_params,
param_def_id_to_index,
has_self: opaque_ty_generics.has_self,
has_late_bound_regions: opaque_ty_generics.has_late_bound_regions,
@ -124,9 +124,9 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
let generics = tcx.generics_of(parent_def_id.to_def_id());
let param_def_idx = generics.param_def_id_to_index[&param_id.to_def_id()];
// In the above example this would be .params[..N#0]
let params = generics.params_to(param_def_idx as usize, tcx).to_owned();
let own_params = generics.params_to(param_def_idx as usize, tcx).to_owned();
let param_def_id_to_index =
params.iter().map(|param| (param.def_id, param.index)).collect();
own_params.iter().map(|param| (param.def_id, param.index)).collect();
return ty::Generics {
// we set the parent of these generics to be our parent's parent so that we
@ -134,7 +134,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
// struct Foo<const N: usize, const M: usize = { ... }>;
parent: generics.parent,
parent_count: generics.parent_count,
params,
own_params,
param_def_id_to_index,
has_self: generics.has_self,
has_late_bound_regions: generics.has_late_bound_regions,
@ -274,17 +274,17 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
parent_has_self = generics.has_self;
host_effect_index = generics.host_effect_index;
own_start = generics.count() as u32;
generics.parent_count + generics.params.len()
generics.parent_count + generics.own_params.len()
});
let mut params: Vec<_> = Vec::with_capacity(hir_generics.params.len() + has_self as usize);
let mut own_params: Vec<_> = Vec::with_capacity(hir_generics.params.len() + has_self as usize);
if let Some(opt_self) = opt_self {
params.push(opt_self);
own_params.push(opt_self);
}
let early_lifetimes = super::early_bound_lifetimes_from_generics(tcx, hir_generics);
params.extend(early_lifetimes.enumerate().map(|(i, param)| ty::GenericParamDef {
own_params.extend(early_lifetimes.enumerate().map(|(i, param)| ty::GenericParamDef {
name: param.name.ident().name,
index: own_start + i as u32,
def_id: param.def_id.to_def_id(),
@ -293,7 +293,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
}));
// Now create the real type and const parameters.
let type_start = own_start - has_self as u32 + params.len() as u32;
let type_start = own_start - has_self as u32 + own_params.len() as u32;
let mut i: u32 = 0;
let mut next_index = || {
let prev = i;
@ -304,7 +304,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
const TYPE_DEFAULT_NOT_ALLOWED: &'static str = "defaults for type parameters are only allowed in \
`struct`, `enum`, `type`, or `trait` definitions";
params.extend(hir_generics.params.iter().filter_map(|param| match param.kind {
own_params.extend(hir_generics.params.iter().filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => None,
GenericParamKind::Type { default, synthetic, .. } => {
if default.is_some() {
@ -404,7 +404,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
][..],
};
params.extend(dummy_args.iter().map(|&arg| ty::GenericParamDef {
own_params.extend(dummy_args.iter().map(|&arg| ty::GenericParamDef {
index: next_index(),
name: Symbol::intern(arg),
def_id: def_id.to_def_id(),
@ -415,7 +415,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
// provide junk type parameter defs for const blocks.
if let Node::ConstBlock(_) = node {
params.push(ty::GenericParamDef {
own_params.push(ty::GenericParamDef {
index: next_index(),
name: Symbol::intern("<const_ty>"),
def_id: def_id.to_def_id(),
@ -424,12 +424,13 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
});
}
let param_def_id_to_index = params.iter().map(|param| (param.def_id, param.index)).collect();
let param_def_id_to_index =
own_params.iter().map(|param| (param.def_id, param.index)).collect();
ty::Generics {
parent: parent_def_id,
parent_count,
params,
own_params,
param_def_id_to_index,
has_self: has_self || parent_has_self,
has_late_bound_regions: has_late_bound_regions(tcx, node),

View File

@ -73,8 +73,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
// opaque lifetimes, which explains the slicing below.
compute_bidirectional_outlives_predicates(
tcx,
&tcx.generics_of(def_id.to_def_id()).params
[tcx.generics_of(fn_def_id).params.len()..],
&tcx.generics_of(def_id.to_def_id()).own_params
[tcx.generics_of(fn_def_id).own_params.len()..],
&mut predicates,
);
@ -300,7 +300,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
};
debug!(?lifetimes);
compute_bidirectional_outlives_predicates(tcx, &generics.params, &mut predicates);
compute_bidirectional_outlives_predicates(tcx, &generics.own_params, &mut predicates);
debug!(?predicates);
}

View File

@ -1562,7 +1562,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
ObjectLifetimeDefault::Ambiguous => None,
};
generics
.params
.own_params
.iter()
.filter_map(|param| {
match self.tcx.def_kind(param.def_id) {
@ -1668,7 +1668,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
binding.ident,
ty::AssocKind::Fn,
) {
bound_vars.extend(self.tcx.generics_of(assoc_fn.def_id).params.iter().map(
bound_vars.extend(self.tcx.generics_of(assoc_fn.def_id).own_params.iter().map(
|param| match param.kind {
ty::GenericParamDefKind::Lifetime => ty::BoundVariableKind::Region(
ty::BoundRegionKind::BrNamed(param.def_id, param.name),
@ -2003,7 +2003,8 @@ fn is_late_bound_map(
// just consider args to be unconstrained.
let generics = self.tcx.generics_of(alias_def);
let mut walker = ConstrainedCollectorPostHirTyLowering {
arg_is_constrained: vec![false; generics.params.len()].into_boxed_slice(),
arg_is_constrained: vec![false; generics.own_params.len()]
.into_boxed_slice(),
};
walker.visit_ty(self.tcx.type_of(alias_def).instantiate_identity());

View File

@ -255,7 +255,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
debug!(?parent_node);
debug!(?generics, ?arg_idx);
if let Some(param_def_id) = generics
.params
.own_params
.iter()
.filter(|param| param.kind.is_ty_or_const())
.nth(match generics.has_self && generics.parent.is_none() {

View File

@ -1299,7 +1299,7 @@ pub fn prohibit_assoc_item_binding(
// same name as the assoc type name in type binding
let generics = tcx.generics_of(def_id);
let matching_param =
generics.params.iter().find(|p| p.name.as_str() == binding.ident.as_str());
generics.own_params.iter().find(|p| p.name.as_str() == binding.ident.as_str());
// Now emit the appropriate suggestion
if let Some(matching_param) = matching_param {

View File

@ -196,7 +196,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
let mut args: SmallVec<[ty::GenericArg<'tcx>; 8]> = SmallVec::with_capacity(count);
// Iterate over each segment of the path.
while let Some((def_id, defs)) = stack.pop() {
let mut params = defs.params.iter().peekable();
let mut params = defs.own_params.iter().peekable();
// If we have already computed the generic arguments for parents,
// we can use those directly.
@ -312,7 +312,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
// We're going to iterate over the parameters to sort them out, and
// show that order to the user as a possible order for the parameters
let mut param_types_present = defs
.params
.own_params
.iter()
.map(|param| (param.kind.to_ord(), param.clone()))
.collect::<Vec<(ParamKindOrd, GenericParamDef)>>();
@ -435,13 +435,13 @@ pub(crate) fn check_generic_arg_count(
// Subtracting from param count to ensure type params synthesized from `impl Trait`
// cannot be explicitly specified.
let synth_type_param_count = gen_params
.params
.own_params
.iter()
.filter(|param| matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. }))
.count();
let named_type_param_count = param_counts.types - has_self as usize - synth_type_param_count;
let synth_const_param_count = gen_params
.params
.own_params
.iter()
.filter(|param| {
matches!(param.kind, ty::GenericParamDefKind::Const { is_host_effect: true, .. })

View File

@ -411,7 +411,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// Traits always have `Self` as a generic parameter, which means they will not return early
// here and so associated type bindings will be handled regardless of whether there are any
// non-`Self` generic parameters.
if generics.params.is_empty() {
if generics.own_params.is_empty() {
return (tcx.mk_args(parent_args), arg_count);
}

View File

@ -227,7 +227,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
.skip(1) // Remove `Self` for `ExistentialPredicate`.
.map(|(index, arg)| {
if arg == dummy_self.into() {
let param = &generics.params[index];
let param = &generics.own_params[index];
missing_type_params.push(param.name);
Ty::new_misc_error(tcx).into()
} else if arg.walk().any(|arg| arg == dummy_self.into()) {

View File

@ -114,7 +114,7 @@ fn enforce_impl_params_are_constrained(
.collect();
let mut res = Ok(());
for param in &impl_generics.params {
for param in &impl_generics.own_params {
match param.kind {
// Disallow ANY unconstrained type parameters.
ty::GenericParamDefKind::Type { .. } => {

View File

@ -184,7 +184,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
let def_kind = tcx.def_kind(item_def_id);
match def_kind {
DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id),
DefKind::Const if tcx.generics_of(item_def_id).params.is_empty() => {
DefKind::Const if tcx.generics_of(item_def_id).own_params.is_empty() => {
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
let cid = GlobalId { instance, promoted: None };
let param_env = ty::ParamEnv::reveal_all();

View File

@ -421,7 +421,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
// We could not gather enough lifetime parameters in the scope.
// We use the parameter names from the target type's definition instead.
self.gen_params
.params
.own_params
.iter()
.skip(self.params_offset + self.num_provided_lifetime_args())
.take(num_params_to_take)
@ -464,7 +464,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
})
};
self.gen_params
.params
.own_params
.iter()
.skip(self.params_offset + self.num_provided_type_or_const_args())
.take(num_params_to_take)
@ -1076,7 +1076,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
} else {
let params = self
.gen_params
.params
.own_params
.iter()
.skip(self.params_offset)
.take(bound)

View File

@ -133,7 +133,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
let mut generics = generics;
while let Some(def_id) = generics.parent {
generics = tcx.generics_of(def_id);
for param in &generics.params {
for param in &generics.own_params {
match param.kind {
ty::GenericParamDefKind::Lifetime => {
variances[param.index as usize] = ty::Bivariant;

View File

@ -76,7 +76,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> {
let tcx = self.terms_cx.tcx;
// Make all const parameters invariant.
for param in generics.params.iter() {
for param in generics.own_params.iter() {
if let ty::GenericParamDefKind::Const { .. } = param.kind {
variances[param.index as usize] = ty::Invariant;
}

View File

@ -729,7 +729,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
let struct_generic_parameters: &ty::Generics = self.tcx.generics_of(in_ty_adt.did());
if drill_generic_index >= struct_generic_parameters.params.len() {
if drill_generic_index >= struct_generic_parameters.own_params.len() {
return Err(expr);
}
@ -852,7 +852,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
let struct_generic_parameters: &ty::Generics = self.tcx.generics_of(in_ty_adt.did());
if drill_generic_index >= struct_generic_parameters.params.len() {
if drill_generic_index >= struct_generic_parameters.own_params.len() {
return Err(expr);
}

View File

@ -450,7 +450,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// `foo.bar::<u32>(...)` -- the `Self` type here will be the
// type of `foo` (possibly adjusted), but we don't want to
// include that. We want just the `[_, u32]` part.
if !args.is_empty() && !generics.params.is_empty() {
if !args.is_empty() && !generics.own_params.is_empty() {
let user_type_annotation = self.probe(|_| {
let user_args = UserArgs {
args: GenericArgs::for_item(self.tcx, pick.item.def_id, |param, _| {

View File

@ -251,8 +251,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let trait_path = self.trait_path_or_bare_name(span, expr_id, container_id);
let trait_generics = self.tcx.generics_of(container_id);
let trait_name = if trait_generics.params.len() <= trait_generics.has_self as usize
{
let trait_name =
if trait_generics.own_params.len() <= trait_generics.has_self as usize {
trait_path
} else {
let counts = trait_generics.own_counts();
@ -280,7 +280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if !self_ty_name.contains('<') {
if let ty::Adt(def, _) = self_ty.kind() {
let generics = self.tcx.generics_of(def.did());
if !generics.params.is_empty() {
if !generics.own_params.is_empty() {
let counts = generics.own_counts();
self_ty_name += &format!(
"<{}>",

View File

@ -1735,7 +1735,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let generics = self.tcx.generics_of(method);
assert_eq!(args.len(), generics.parent_count);
let xform_fn_sig = if generics.params.is_empty() {
let xform_fn_sig = if generics.own_params.is_empty() {
fn_sig.instantiate(self.tcx, args)
} else {
let args = GenericArgs::for_item(self.tcx, method, |param, _| {

View File

@ -2507,7 +2507,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let generics = self.tcx.generics_of(lifetime_scope);
let mut used_names =
iter::successors(Some(generics), |g| g.parent.map(|p| self.tcx.generics_of(p)))
.flat_map(|g| &g.params)
.flat_map(|g| &g.own_params)
.filter(|p| matches!(p.kind, ty::GenericParamDefKind::Lifetime))
.map(|p| p.name)
.collect::<Vec<_>>();

View File

@ -522,7 +522,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
infer_subdiags.push(SourceKindSubdiag::GenericLabel {
span,
is_type,
param_name: generics.params[argument_index].name.to_string(),
param_name: generics.own_params[argument_index].name.to_string(),
parent_exists,
parent_prefix,
parent_name,

View File

@ -1402,7 +1402,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let inferred_outlives = self.tcx.inferred_outlives_of(def_id);
record_defaulted_array!(self.tables.inferred_outlives_of[def_id] <- inferred_outlives);
for param in &g.params {
for param in &g.own_params {
if let ty::GenericParamDefKind::Const { has_default: true, .. } = param.kind {
let default = self.tcx.const_param_default(param.def_id);
record!(self.tables.const_param_default[param.def_id] <- default);

View File

@ -2060,7 +2060,7 @@ impl<'tcx> TyCtxt<'tcx> {
&& let DefKind::AssocTy = self.def_kind(def_id)
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id))
{
if generics.params.len() + 1 != args.len() {
if generics.own_params.len() + 1 != args.len() {
return false;
}
@ -2085,7 +2085,7 @@ impl<'tcx> TyCtxt<'tcx> {
own_args
};
for (param, arg) in std::iter::zip(&generics.params, own_args) {
for (param, arg) in std::iter::zip(&generics.own_params, own_args) {
match (&param.kind, arg.unpack()) {
(ty::GenericParamDefKind::Type { .. }, ty::GenericArgKind::Type(_))
| (ty::GenericParamDefKind::Lifetime, ty::GenericArgKind::Lifetime(_))

View File

@ -359,8 +359,8 @@ impl<'tcx> GenericArgs<'tcx> {
) where
F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
{
args.reserve(defs.params.len());
for param in &defs.params {
args.reserve(defs.own_params.len());
for param in &defs.own_params {
let kind = mk_kind(param, args);
assert_eq!(param.index as usize, args.len(), "{args:#?}, {defs:#?}");
args.push(kind);

View File

@ -132,7 +132,7 @@ pub struct GenericParamCount {
pub struct Generics {
pub parent: Option<DefId>,
pub parent_count: usize,
pub params: Vec<GenericParamDef>,
pub own_params: Vec<GenericParamDef>,
/// Reverse map to the `index` field of each `GenericParamDef`.
#[stable_hasher(ignore)]
@ -163,7 +163,7 @@ impl<'tcx> Generics {
#[inline]
pub fn count(&self) -> usize {
self.parent_count + self.params.len()
self.parent_count + self.own_params.len()
}
pub fn own_counts(&self) -> GenericParamCount {
@ -172,7 +172,7 @@ impl<'tcx> Generics {
// presence of this method will be a constant reminder.
let mut own_counts = GenericParamCount::default();
for param in &self.params {
for param in &self.own_params {
match param.kind {
GenericParamDefKind::Lifetime => own_counts.lifetimes += 1,
GenericParamDefKind::Type { .. } => own_counts.types += 1,
@ -186,7 +186,7 @@ impl<'tcx> Generics {
pub fn own_defaults(&self) -> GenericParamCount {
let mut own_defaults = GenericParamCount::default();
for param in &self.params {
for param in &self.own_params {
match param.kind {
GenericParamDefKind::Lifetime => (),
GenericParamDefKind::Type { has_default, .. } => {
@ -215,7 +215,7 @@ impl<'tcx> Generics {
}
pub fn own_requires_monomorphization(&self) -> bool {
for param in &self.params {
for param in &self.own_params {
match param.kind {
GenericParamDefKind::Type { .. }
| GenericParamDefKind::Const { is_host_effect: false, .. } => {
@ -231,7 +231,7 @@ impl<'tcx> Generics {
/// Returns the `GenericParamDef` with the given index.
pub fn param_at(&'tcx self, param_index: usize, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
if let Some(index) = param_index.checked_sub(self.parent_count) {
&self.params[index]
&self.own_params[index]
} else {
tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
.param_at(param_index, tcx)
@ -245,7 +245,7 @@ impl<'tcx> Generics {
tcx: TyCtxt<'tcx>,
) -> Option<&'tcx GenericParamDef> {
if let Some(index) = param_index.checked_sub(self.parent_count) {
self.params.get(index)
self.own_params.get(index)
} else {
tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
.opt_param_at(param_index, tcx)
@ -254,7 +254,7 @@ impl<'tcx> Generics {
pub fn params_to(&'tcx self, param_index: usize, tcx: TyCtxt<'tcx>) -> &'tcx [GenericParamDef] {
if let Some(index) = param_index.checked_sub(self.parent_count) {
&self.params[..index]
&self.own_params[..index]
} else {
tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
.params_to(param_index, tcx)
@ -308,7 +308,7 @@ impl<'tcx> Generics {
/// Returns `true` if `params` has `impl Trait`.
pub fn has_impl_trait(&'tcx self) -> bool {
self.params.iter().any(|param| {
self.own_params.iter().any(|param| {
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
})
}
@ -336,7 +336,7 @@ impl<'tcx> Generics {
// good enough for now as this should only be used
// for diagnostics anyways.
own_params.end -= self
.params
.own_params
.iter()
.rev()
.take_while(|param| {
@ -358,7 +358,7 @@ impl<'tcx> Generics {
&'tcx self,
args: &'tcx [ty::GenericArg<'tcx>],
) -> &'tcx [ty::GenericArg<'tcx>] {
let own = &args[self.parent_count..][..self.params.len()];
let own = &args[self.parent_count..][..self.own_params.len()];
if self.has_self && self.parent.is_none() { &own[1..] } else { own }
}
@ -372,7 +372,7 @@ impl<'tcx> Generics {
args: &'tcx [ty::GenericArg<'tcx>],
) -> bool {
let mut default_param_seen = false;
for param in self.params.iter() {
for param in self.own_params.iter() {
if let Some(inst) =
param.default_value(tcx).map(|default| default.instantiate(tcx, args))
{

View File

@ -250,7 +250,7 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
}
ExistentialPredicate::AutoTrait(did) => {
let generics = tcx.generics_of(did);
let trait_ref = if generics.params.len() == 1 {
let trait_ref = if generics.own_params.len() == 1 {
ty::TraitRef::new(tcx, did, [self_ty])
} else {
// If this is an ill-formed auto trait, then synthesize
@ -373,7 +373,7 @@ impl<'tcx> TraitRef<'tcx> {
args: GenericArgsRef<'tcx>,
) -> ty::TraitRef<'tcx> {
let defs = tcx.generics_of(trait_id);
ty::TraitRef::new(tcx, trait_id, tcx.mk_args(&args[..defs.params.len()]))
ty::TraitRef::new(tcx, trait_id, tcx.mk_args(&args[..defs.own_params.len()]))
}
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`

View File

@ -157,7 +157,7 @@ pub trait Printer<'tcx>: Sized {
// If we have any generic arguments to print, we do that
// on top of the same path, but without its own generics.
_ => {
if !generics.params.is_empty() && args.len() >= generics.count() {
if !generics.own_params.is_empty() && args.len() >= generics.count() {
let args = generics.own_args_no_defaults(self.tcx(), args);
return self.path_generic_args(
|cx| cx.print_def_path(def_id, parent_args),

View File

@ -141,7 +141,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for &[ty::Variance] {
&& frame.query.dep_kind == dep_kinds::variances_of
&& let Some(def_id) = frame.query.def_id
{
let n = tcx.generics_of(def_id).params.len();
let n = tcx.generics_of(def_id).own_params.len();
vec![ty::Variance::Bivariant; n].leak()
} else {
span_bug!(

View File

@ -131,7 +131,7 @@ fn mark_used_by_default_parameters<'tcx>(
) {
match tcx.def_kind(def_id) {
DefKind::Closure => {
for param in &generics.params {
for param in &generics.own_params {
debug!(?param, "(closure/gen)");
unused_parameters.mark_used(param.index);
}
@ -165,7 +165,7 @@ fn mark_used_by_default_parameters<'tcx>(
| DefKind::LifetimeParam
| DefKind::GlobalAsm
| DefKind::Impl { .. } => {
for param in &generics.params {
for param in &generics.own_params {
debug!(?param, "(other)");
if let ty::GenericParamDefKind::Lifetime = param.kind {
unused_parameters.mark_used(param.index);
@ -202,7 +202,7 @@ fn emit_unused_generic_params_error<'tcx>(
let mut param_names = Vec::new();
let mut next_generics = Some(generics);
while let Some(generics) = next_generics {
for param in &generics.params {
for param in &generics.own_params {
if unused_parameters.is_unused(param.index) {
debug!(?param);
let def_span = tcx.def_span(param.def_id);

View File

@ -787,7 +787,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
fn generics(&mut self) -> &mut Self {
for param in &self.ev.tcx.generics_of(self.item_def_id).params {
for param in &self.ev.tcx.generics_of(self.item_def_id).own_params {
match param.kind {
GenericParamDefKind::Lifetime => {}
GenericParamDefKind::Type { has_default, .. } => {
@ -1259,7 +1259,7 @@ struct SearchInterfaceForPrivateItemsVisitor<'tcx> {
impl SearchInterfaceForPrivateItemsVisitor<'_> {
fn generics(&mut self) -> &mut Self {
self.in_primary_interface = true;
for param in &self.tcx.generics_of(self.item_def_id).params {
for param in &self.tcx.generics_of(self.item_def_id).own_params {
match param.kind {
GenericParamDefKind::Lifetime => {}
GenericParamDefKind::Type { has_default, .. } => {

View File

@ -523,7 +523,7 @@ impl<'tcx> Stable<'tcx> for ty::Generics {
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
use stable_mir::ty::Generics;
let params: Vec<_> = self.params.iter().map(|param| param.stable(tables)).collect();
let params: Vec<_> = self.own_params.iter().map(|param| param.stable(tables)).collect();
let param_def_id_to_index =
params.iter().map(|param| (param.def_id, param.index)).collect();

View File

@ -165,7 +165,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
));
}
for param in generics.params.iter() {
for param in generics.own_params.iter() {
let value = match param.kind {
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
args[param.index as usize].to_string()
@ -821,7 +821,7 @@ impl<'tcx> OnUnimplementedFormatString {
()
}
// So is `{A}` if A is a type parameter
s if generics.params.iter().any(|param| param.name == s) => (),
s if generics.own_params.iter().any(|param| param.name == s) => (),
s => {
if self.is_diagnostic_namespace_variant {
if let Some(item_def_id) = item_def_id.as_local() {
@ -915,7 +915,7 @@ impl<'tcx> OnUnimplementedFormatString {
let trait_str = tcx.def_path_str(trait_ref.def_id);
let generics = tcx.generics_of(trait_ref.def_id);
let generic_map = generics
.params
.own_params
.iter()
.filter_map(|param| {
let value = match param.kind {

View File

@ -2799,7 +2799,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// Check if this is an implicit bound, even in foreign crates.
if tcx
.generics_of(item_def_id)
.params
.own_params
.iter()
.any(|param| tcx.def_span(param.def_id) == span)
{

View File

@ -397,7 +397,7 @@ pub fn object_safety_violations_for_assoc_item(
// Associated types can only be object safe if they have `Self: Sized` bounds.
ty::AssocKind::Type => {
if !tcx.features().generic_associated_types_extended
&& !tcx.generics_of(item.def_id).params.is_empty()
&& !tcx.generics_of(item.def_id).own_params.is_empty()
&& !item.is_impl_trait_in_trait()
{
vec![ObjectSafetyViolation::GAT(item.name, item.ident(tcx).span)]

View File

@ -606,7 +606,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
for assoc_type in assoc_types {
let defs: &ty::Generics = tcx.generics_of(assoc_type);
if !defs.params.is_empty() && !tcx.features().generic_associated_types_extended {
if !defs.own_params.is_empty() && !tcx.features().generic_associated_types_extended {
tcx.dcx().span_delayed_bug(
obligation.cause.span,
"GATs in trait object shouldn't have been considered",

View File

@ -1777,7 +1777,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// If this type is a GAT, and of the GAT args resolve to something new,
// that means that we must have newly inferred something about the GAT.
// We should give up in that case.
if !generics.params.is_empty()
if !generics.own_params.is_empty()
&& obligation.predicate.args[generics.parent_count..].iter().any(|&p| {
p.has_non_region_infer() && self.infcx.resolve_vars_if_possible(p) != p
})
@ -2441,7 +2441,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
});
let tcx = self.tcx();
let trait_ref = if tcx.generics_of(trait_def_id).params.len() == 1 {
let trait_ref = if tcx.generics_of(trait_def_id).own_params.len() == 1 {
ty::TraitRef::new(tcx, trait_def_id, [normalized_ty])
} else {
// If this is an ill-formed auto/built-in trait, then synthesize

View File

@ -340,22 +340,22 @@ fn associated_type_for_impl_trait_in_impl(
impl_assoc_ty.generics_of({
let trait_assoc_generics = tcx.generics_of(trait_assoc_def_id);
let trait_assoc_parent_count = trait_assoc_generics.parent_count;
let mut params = trait_assoc_generics.params.clone();
let mut own_params = trait_assoc_generics.own_params.clone();
let parent_generics = tcx.generics_of(impl_local_def_id.to_def_id());
let parent_count = parent_generics.parent_count + parent_generics.params.len();
let parent_count = parent_generics.parent_count + parent_generics.own_params.len();
for param in &mut params {
for param in &mut own_params {
param.index = param.index + parent_count as u32 - trait_assoc_parent_count as u32;
}
let param_def_id_to_index =
params.iter().map(|param| (param.def_id, param.index)).collect();
own_params.iter().map(|param| (param.def_id, param.index)).collect();
ty::Generics {
parent: Some(impl_local_def_id.to_def_id()),
parent_count,
params,
own_params,
param_def_id_to_index,
has_self: false,
has_late_bound_regions: trait_assoc_generics.has_late_bound_regions,

View File

@ -69,7 +69,8 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
// case, since it has been liberated), map it back to the early-bound lifetime of
// the GAT. Since RPITITs also have all of the fn's generics, we slice only
// the end of the list corresponding to the opaque's generics.
for param in &generics.params[tcx.generics_of(fn_def_id).params.len()..] {
for param in &generics.own_params[tcx.generics_of(fn_def_id).own_params.len()..]
{
let orig_lt =
tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local());
if matches!(*orig_lt, ty::ReLateParam(..)) {

View File

@ -85,7 +85,7 @@ fn representability_adt_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Representab
fn params_in_repr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> BitSet<u32> {
let adt_def = tcx.adt_def(def_id);
let generics = tcx.generics_of(def_id);
let mut params_in_repr = BitSet::new_empty(generics.params.len());
let mut params_in_repr = BitSet::new_empty(generics.own_params.len());
for variant in adt_def.variants() {
for field in variant.fields.iter() {
params_in_repr_ty(

View File

@ -150,7 +150,7 @@ fn clean_param_env<'tcx>(
let generics = tcx.generics_of(item_def_id);
let params: ThinVec<_> = generics
.params
.own_params
.iter()
.inspect(|param| {
if cfg!(debug_assertions) {
@ -326,7 +326,7 @@ fn clean_region_outlives_constraints<'tcx>(
}
let region_params: FxIndexSet<_> = generics
.params
.own_params
.iter()
.filter_map(|param| match param.kind {
ty::GenericParamDefKind::Lifetime => Some(param.name),

View File

@ -795,7 +795,7 @@ fn clean_ty_generics<'tcx>(
let mut impl_trait = BTreeMap::<u32, Vec<GenericBound>>::default();
let params: ThinVec<_> = gens
.params
.own_params
.iter()
.filter(|param| match param.kind {
ty::GenericParamDefKind::Lifetime => !param.is_anonymous_lifetime(),
@ -1988,7 +1988,7 @@ impl<'tcx> ContainerTy<'_, 'tcx> {
let generics = tcx.generics_of(container);
debug_assert_eq!(generics.parent_count, 0);
let param = generics.params[index].def_id;
let param = generics.own_params[index].def_id;
let default = tcx.object_lifetime_default(param);
match default {
rbv::ObjectLifetimeDefault::Param(lifetime) => {

View File

@ -382,7 +382,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
cx,
impl_ty,
trait_id,
&args[..cx.tcx.generics_of(trait_id).params.len() - 1],
&args[..cx.tcx.generics_of(trait_id).own_params.len() - 1],
)
{
false

View File

@ -480,7 +480,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
// Vec<(param_def, needs_eq)>
let mut params = tcx
.generics_of(did)
.params
.own_params
.iter()
.map(|p| (p, matches!(p.kind, GenericParamDefKind::Type { .. })))
.collect::<Vec<_>>();

View File

@ -148,7 +148,7 @@ fn try_resolve_type<'tcx>(
match args.get(index - 1) {
Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)),
Some(_) => None,
None => Some(tcx.type_of(generics.params[index].def_id).skip_binder()),
None => Some(tcx.type_of(generics.own_params[index].def_id).skip_binder()),
}
}

View File

@ -225,7 +225,7 @@ impl {self_ty_without_ref} {{
&& let ImplItemKind::Fn(sig, _) = item.kind
&& let FnRetTy::Return(ret) = sig.decl.output
&& is_nameable_in_impl_trait(ret)
&& cx.tcx.generics_of(item_did).params.is_empty()
&& cx.tcx.generics_of(item_did).own_params.is_empty()
&& sig.decl.implicit_self == expected_implicit_self
&& sig.decl.inputs.len() == 1
&& let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id())

View File

@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeParamMismatch {
};
// get the names of the generic parameters in the type
let type_params = &cx.tcx.generics_of(defid).params;
let type_params = &cx.tcx.generics_of(defid).own_params;
let type_param_names: Vec<_> = type_params
.iter()
.filter_map(|p| match p.kind {

View File

@ -1070,11 +1070,11 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 {
fn assert_generic_args_match<'tcx>(tcx: TyCtxt<'tcx>, did: DefId, args: &[GenericArg<'tcx>]) {
let g = tcx.generics_of(did);
let parent = g.parent.map(|did| tcx.generics_of(did));
let count = g.parent_count + g.params.len();
let count = g.parent_count + g.own_params.len();
let params = parent
.map_or([].as_slice(), |p| p.params.as_slice())
.map_or([].as_slice(), |p| p.own_params.as_slice())
.iter()
.chain(&g.params)
.chain(&g.own_params)
.map(|x| &x.kind);
assert!(

View File

@ -176,7 +176,7 @@ fn qpath_certainty(cx: &LateContext<'_>, qpath: &QPath<'_>, resolves_to_type: bo
.get(*lang_item)
.map_or(Certainty::Uncertain, |def_id| {
let generics = cx.tcx.generics_of(def_id);
if generics.parent_count == 0 && generics.params.is_empty() {
if generics.parent_count == 0 && generics.own_params.is_empty() {
Certainty::Certain(if resolves_to_type { Some(def_id) } else { None })
} else {
Certainty::Uncertain
@ -206,7 +206,7 @@ fn path_segment_certainty(
// Checking `res_generics_def_id(..)` before calling `generics_of` avoids an ICE.
if cx.tcx.res_generics_def_id(path_segment.res).is_some() {
let generics = cx.tcx.generics_of(def_id);
let count = generics.params.len() - usize::from(generics.host_effect_index.is_some());
let count = generics.own_params.len() - usize::from(generics.host_effect_index.is_some());
let lhs = if (parent_certainty.is_certain() || generics.parent_count == 0) && count == 0 {
Certainty::Certain(None)
} else {
@ -299,7 +299,7 @@ fn type_is_inferable_from_arguments(cx: &LateContext<'_>, expr: &Expr<'_>) -> bo
let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder();
// Check that all type parameters appear in the functions input types.
(0..(generics.parent_count + generics.params.len()) as u32).all(|index| {
(0..(generics.parent_count + generics.own_params.len()) as u32).all(|index| {
Some(index as usize) == generics.host_effect_index
|| fn_sig
.inputs()