From 1c19b6ad60d4993fb25c44ee8b6e625791084662 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 9 May 2024 20:56:44 -0400 Subject: [PATCH] Rename Generics::params to Generics::own_params --- .../src/diagnostics/explain_borrow.rs | 55 ++++++++++--------- .../src/debuginfo/metadata.rs | 2 +- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 2 +- .../rustc_hir_analysis/src/check/check.rs | 8 +-- .../src/check/compare_impl_item.rs | 24 ++++---- .../rustc_hir_analysis/src/check/wfcheck.rs | 6 +- .../src/coherence/orphan.rs | 2 +- .../src/coherence/unsafety.rs | 2 +- .../src/collect/generics_of.rs | 43 ++++++++------- .../src/collect/predicates_of.rs | 6 +- .../src/collect/resolve_bound_vars.rs | 7 ++- .../rustc_hir_analysis/src/collect/type_of.rs | 2 +- .../src/hir_ty_lowering/errors.rs | 2 +- .../src/hir_ty_lowering/generics.rs | 8 +-- .../src/hir_ty_lowering/mod.rs | 2 +- .../src/hir_ty_lowering/object_safety.rs | 2 +- .../rustc_hir_analysis/src/impl_wf_check.rs | 2 +- compiler/rustc_hir_analysis/src/lib.rs | 2 +- .../wrong_number_of_generic_args.rs | 6 +- .../rustc_hir_analysis/src/variance/mod.rs | 2 +- .../rustc_hir_analysis/src/variance/solve.rs | 2 +- .../src/fn_ctxt/adjust_fulfillment_errors.rs | 4 +- .../rustc_hir_typeck/src/method/confirm.rs | 2 +- .../src/method/prelude2021.rs | 36 ++++++------ compiler/rustc_hir_typeck/src/method/probe.rs | 2 +- .../src/infer/error_reporting/mod.rs | 2 +- .../infer/error_reporting/need_type_info.rs | 2 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 4 +- compiler/rustc_middle/src/ty/generic_args.rs | 4 +- compiler/rustc_middle/src/ty/generics.rs | 24 ++++---- compiler/rustc_middle/src/ty/predicate.rs | 4 +- compiler/rustc_middle/src/ty/print/mod.rs | 2 +- compiler/rustc_middle/src/values.rs | 2 +- .../rustc_monomorphize/src/polymorphize.rs | 6 +- compiler/rustc_privacy/src/lib.rs | 4 +- .../rustc_smir/src/rustc_smir/convert/ty.rs | 2 +- .../error_reporting/on_unimplemented.rs | 6 +- .../src/traits/error_reporting/suggestions.rs | 2 +- .../src/traits/object_safety.rs | 2 +- .../src/traits/select/confirmation.rs | 2 +- .../src/traits/select/mod.rs | 4 +- compiler/rustc_ty_utils/src/assoc.rs | 10 ++-- compiler/rustc_ty_utils/src/implied_bounds.rs | 3 +- .../rustc_ty_utils/src/representability.rs | 2 +- src/librustdoc/clean/auto_trait.rs | 4 +- src/librustdoc/clean/mod.rs | 4 +- .../clippy/clippy_lints/src/dereference.rs | 2 +- src/tools/clippy/clippy_lints/src/derive.rs | 2 +- .../src/implied_bounds_in_impls.rs | 2 +- .../src/iter_without_into_iter.rs | 2 +- .../src/mismatching_type_param_order.rs | 2 +- src/tools/clippy/clippy_utils/src/ty.rs | 6 +- .../clippy_utils/src/ty/type_certainty/mod.rs | 6 +- 54 files changed, 179 insertions(+), 171 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 5ebdb69050b24..e3ad92a5b2bf5 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -317,36 +317,39 @@ 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)| { - if let Some(ty::Dynamic(obj, _, ty::Dyn)) = arg.as_type().map(Ty::kind) { - let default = tcx.object_lifetime_default(param.def_id); - - let re_static = tcx.lifetimes.re_static; - - let implied_region = match default { - // This is not entirely precise. - ObjectLifetimeDefault::Empty => re_static, - ObjectLifetimeDefault::Ambiguous => { - failed = true; - re_static - } - ObjectLifetimeDefault::Param(param_def_id) => { - let index = generics.param_def_id_to_index[¶m_def_id] as usize; - args.get(index).and_then(|arg| arg.as_region()).unwrap_or_else(|| { + 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); + + let re_static = tcx.lifetimes.re_static; + + let implied_region = match default { + // This is not entirely precise. + ObjectLifetimeDefault::Empty => re_static, + ObjectLifetimeDefault::Ambiguous => { failed = true; re_static - }) - } - ObjectLifetimeDefault::Static => re_static, - }; + } + ObjectLifetimeDefault::Param(param_def_id) => { + let index = generics.param_def_id_to_index[¶m_def_id] as usize; + args.get(index).and_then(|arg| arg.as_region()).unwrap_or_else( + || { + failed = true; + re_static + }, + ) + } + ObjectLifetimeDefault::Static => re_static, + }; - has_dyn = true; + has_dyn = true; - Ty::new_dynamic(tcx, obj, implied_region, ty::Dyn).into() - } else { - arg - } - }); + Ty::new_dynamic(tcx, obj, implied_region, ty::Dyn).into() + } else { + arg + } + }); let elaborated_ty = Ty::new_adt(tcx, *def, tcx.mk_args_from_iter(elaborated_args)); if has_dyn && !failed { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index e5fecddec528d..f44738ba6421f 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -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 } } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 4fdaa59e0e559..6149c18696cf2 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -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 } diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 32e1b19eaaeb9..fb9d97ba08b01 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -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(¶m.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::>() }); - 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 { diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index d2759087cb471..8681061b912c9 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -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,14 +1494,16 @@ 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 { - 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 { - GenericParamDefKind::Type { synthetic, .. } => Some((param.def_id, synthetic)), - GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => None, - }); + 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.own_params.iter().filter_map(|param| match param.kind { + GenericParamDefKind::Type { synthetic, .. } => Some((param.def_id, synthetic)), + GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => None, + }); for ((impl_def_id, impl_synthetic), (trait_def_id, trait_synthetic)) in iter::zip(impl_m_type_params, trait_m_type_params) { @@ -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 { diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 5b127e0bf496a..ddfb88d72d805 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -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> { .. } // // 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() { diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 819e0925f68df..8e1b2e8e65c52 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -571,7 +571,7 @@ impl<'cx, 'tcx> TypeFolder> 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 { diff --git a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs index 13ce4f0759377..8a1dbc1f942fe 100644 --- a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs +++ b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs @@ -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) { diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index f83ddc51c76e2..6b41f79cf1e7f 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -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[¶m_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; 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(""), 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), diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 472657290ed1f..7e82571d172f1 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -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); } diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index a5f038d383d88..3ef132a3e8c97 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -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()); diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 5ccfd06f25822..24a5349858ade 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -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() { diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index 8e64a9425bb9f..bc6ecae05ee12 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -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 { diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs index e6a7dfa759c8e..749f78e79201e 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs @@ -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::>(); @@ -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, .. }) diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index f7213442ac2dd..591d554d335e1 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -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); } diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs index 97ba946b7e013..297cfe7027ec5 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs @@ -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()) { diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check.rs b/compiler/rustc_hir_analysis/src/impl_wf_check.rs index caa85092415b9..002be61196aa8 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check.rs @@ -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 { .. } => { diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 66b86c9eb02a3..e75740837f8d4 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -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(); diff --git a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs index dcab571eedf56..9ddba7a6e7a9b 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs @@ -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) diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index 42885b0c83282..27fdea01c2b27 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -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; diff --git a/compiler/rustc_hir_analysis/src/variance/solve.rs b/compiler/rustc_hir_analysis/src/variance/solve.rs index 54da327702675..e64c6721fe018 100644 --- a/compiler/rustc_hir_analysis/src/variance/solve.rs +++ b/compiler/rustc_hir_analysis/src/variance/solve.rs @@ -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; } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index a718760f4d895..2d98f312f8b10 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -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); } diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index d57015282de9e..128e599618aaf 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -450,7 +450,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // `foo.bar::(...)` -- 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, _| { diff --git a/compiler/rustc_hir_typeck/src/method/prelude2021.rs b/compiler/rustc_hir_typeck/src/method/prelude2021.rs index 22eef8e53dae0..2e528fec1b726 100644 --- a/compiler/rustc_hir_typeck/src/method/prelude2021.rs +++ b/compiler/rustc_hir_typeck/src/method/prelude2021.rs @@ -251,23 +251,23 @@ 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 - { - trait_path - } else { - let counts = trait_generics.own_counts(); - format!( - "{}<{}>", - trait_path, - std::iter::repeat("'_") - .take(counts.lifetimes) - .chain(std::iter::repeat("_").take( - counts.types + counts.consts - trait_generics.has_self as usize - )) - .collect::>() - .join(", ") - ) - }; + let trait_name = + if trait_generics.own_params.len() <= trait_generics.has_self as usize { + trait_path + } else { + let counts = trait_generics.own_counts(); + format!( + "{}<{}>", + trait_path, + std::iter::repeat("'_") + .take(counts.lifetimes) + .chain(std::iter::repeat("_").take( + counts.types + counts.consts - trait_generics.has_self as usize + )) + .collect::>() + .join(", ") + ) + }; let mut self_ty_name = self_ty_span .find_ancestor_inside(span) @@ -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!( "<{}>", diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 8a7ebd6478b13..5708630ca3c57 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -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, _| { diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 635bbca37ecc2..d976badff36d9 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -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::>(); diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index a2a38d1c507a1..35ab3ea18a24b 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -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, diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index c057f7e921e7f..7c96a6fa9a978 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -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); diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index d2eacdf762f1b..fa1cee8b16daf 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -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 (¶m.kind, arg.unpack()) { (ty::GenericParamDefKind::Type { .. }, ty::GenericArgKind::Type(_)) | (ty::GenericParamDefKind::Lifetime, ty::GenericArgKind::Lifetime(_)) diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index de2c01c304612..4a613083ef7dc 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -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); diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 6bf2051d67ccd..f380aeaae0edb 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -132,7 +132,7 @@ pub struct GenericParamCount { pub struct Generics { pub parent: Option, pub parent_count: usize, - pub params: Vec, + pub own_params: Vec, /// 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)) { diff --git a/compiler/rustc_middle/src/ty/predicate.rs b/compiler/rustc_middle/src/ty/predicate.rs index 56dd52567fde0..48d900ef0c93d 100644 --- a/compiler/rustc_middle/src/ty/predicate.rs +++ b/compiler/rustc_middle/src/ty/predicate.rs @@ -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` where `Pi` diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 9d0e1123e43ac..eecd7dc642229 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -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), diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index 5c17c0b3088fe..e3866b27ceef1 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -141,7 +141,7 @@ impl<'tcx> Value> 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!( diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index 6d237df073f81..6487169d17398 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -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); diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index a78f7e65981ab..e64d2eba06bb7 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -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, .. } => { diff --git a/compiler/rustc_smir/src/rustc_smir/convert/ty.rs b/compiler/rustc_smir/src/rustc_smir/convert/ty.rs index 4abf991fba25d..c442d33cf8660 100644 --- a/compiler/rustc_smir/src/rustc_smir/convert/ty.rs +++ b/compiler/rustc_smir/src/rustc_smir/convert/ty.rs @@ -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(); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index 4b49e014c0f1a..31f9ac1541bf0 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -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 { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 3d2574ac92b66..7c947f7469e21 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -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) { diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 0e15dd275371b..5cb61dff83141 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -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)] diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 4fa2455c42de1..8a8f17689cc35 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -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", diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 18cb3184fe114..dc005982695a1 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -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 diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index ba75424ec0c6d..d3fe8291e03c3 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -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, diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index e1534af4987df..862fb2e166394 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -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(..)) { diff --git a/compiler/rustc_ty_utils/src/representability.rs b/compiler/rustc_ty_utils/src/representability.rs index a5ffa553c2a8a..446f16b412546 100644 --- a/compiler/rustc_ty_utils/src/representability.rs +++ b/compiler/rustc_ty_utils/src/representability.rs @@ -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 { 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( diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index daf63998461ee..c464820413cf5 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -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), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1f84c9ded1154..90f2e3d09fe86 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -795,7 +795,7 @@ fn clean_ty_generics<'tcx>( let mut impl_trait = BTreeMap::>::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) => { diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index b936b28470b53..c6aef9ac2d606 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -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 diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index 42cd19fb8eca5..9662c8f4fe2fc 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -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::>(); diff --git a/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs b/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs index 3bf8d61895585..dc935ed3d7fe7 100644 --- a/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs +++ b/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs @@ -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()), } } diff --git a/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs b/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs index c749a71233033..a75dfaf286fdf 100644 --- a/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs +++ b/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs @@ -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()) diff --git a/src/tools/clippy/clippy_lints/src/mismatching_type_param_order.rs b/src/tools/clippy/clippy_lints/src/mismatching_type_param_order.rs index 0842a87282475..934b9f490addf 100644 --- a/src/tools/clippy/clippy_lints/src/mismatching_type_param_order.rs +++ b/src/tools/clippy/clippy_lints/src/mismatching_type_param_order.rs @@ -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 { diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index 23750ed4d1ba0..ad17c7cefff05 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -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!( diff --git a/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs index 2241494b484a8..c2ff19931d5c3 100644 --- a/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs @@ -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()