Skip to content

Rename {GenericArg,Term}::unpack() to kind() #141495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
@@ -606,8 +606,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
hir_args: &'hir hir::GenericArgs<'hir>,
search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>,
) -> Option<&'hir hir::Lifetime> {
for (kind, hir_arg) in iter::zip(args, hir_args.args) {
match (kind.unpack(), hir_arg) {
for (arg, hir_arg) in iter::zip(args, hir_args.args) {
match (arg.kind(), hir_arg) {
(GenericArgKind::Lifetime(r), hir::GenericArg::Lifetime(lt)) => {
if r.as_var() == needle_fr {
return Some(lt);
@@ -631,7 +631,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
) => {
self.dcx().span_delayed_bug(
hir_arg.span(),
format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"),
format!("unmatched arg and hir arg: found {arg:?} vs {hir_arg:?}"),
);
}
}
@@ -997,7 +997,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
) -> bool {
let tcx = self.infcx.tcx;
ty.walk().any(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
if let ty::GenericArgKind::Type(ty) = arg.kind()
&& let ty::Param(_) = ty.kind()
{
clauses.iter().any(|pred| {
Original file line number Diff line number Diff line change
@@ -148,7 +148,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {

let mut next_outlives_predicates = vec![];
for (ty::OutlivesPredicate(k1, r2), constraint_category) in outlives_predicates {
match k1.unpack() {
match k1.kind() {
GenericArgKind::Lifetime(r1) => {
let r1_vid = self.to_region_vid(r1);
let r2_vid = self.to_region_vid(r2);
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/opaque_types.rs
Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ fn register_member_constraints<'tcx>(
.iter()
.enumerate()
.filter(|(i, _)| variances[*i] == ty::Invariant)
.filter_map(|(_, arg)| match arg.unpack() {
.filter_map(|(_, arg)| match arg.kind() {
GenericArgKind::Lifetime(r) => Some(typeck.to_region_vid(r)),
GenericArgKind::Type(_) | GenericArgKind::Const(_) => None,
})
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/meth.rs
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ fn dyn_trait_in_self<'tcx>(
ty: Ty<'tcx>,
) -> Option<ty::ExistentialTraitRef<'tcx>> {
for arg in ty.peel_refs().walk() {
if let GenericArgKind::Type(ty) = arg.unpack()
if let GenericArgKind::Type(ty) = arg.kind()
&& let ty::Dynamic(data, _, _) = ty.kind()
{
// FIXME(arbitrary_self_types): This is likely broken for receivers which
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/check_consts/ops.rs
Original file line number Diff line number Diff line change
@@ -281,7 +281,7 @@ fn build_error_for_const_call<'tcx>(
let mut sugg = None;

if ccx.tcx.is_lang_item(trait_id, LangItem::PartialEq) {
match (args[0].unpack(), args[1].unpack()) {
match (args[0].kind(), args[1].kind()) {
(GenericArgKind::Type(self_ty), GenericArgKind::Type(rhs_ty))
if self_ty == rhs_ty
&& self_ty.is_ref()
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
) -> Result<(), PrintError> {
print_prefix(self)?;
let args =
args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
args.iter().cloned().filter(|arg| !matches!(arg.kind(), GenericArgKind::Lifetime(_)));
if args.clone().next().is_some() {
self.generic_delimiters(|cx| cx.comma_sep(args))
} else {
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
@@ -1575,7 +1575,7 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD

let mut params_used = DenseBitSet::new_empty(generics.own_params.len());
for leaf in ty.walk() {
if let GenericArgKind::Type(leaf_ty) = leaf.unpack()
if let GenericArgKind::Type(leaf_ty) = leaf.kind()
&& let ty::Param(param) = leaf_ty.kind()
{
debug!("found use of ty param {:?}", param);
@@ -1700,7 +1700,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG

let mut label_match = |ty: Ty<'_>, span| {
for arg in ty.walk() {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
if let ty::GenericArgKind::Type(ty) = arg.kind()
&& let ty::Alias(
ty::Opaque,
ty::AliasTy { def_id: captured_def_id, .. },
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
@@ -1231,7 +1231,7 @@ fn check_region_late_boundedness<'tcx>(
for (id_arg, arg) in
std::iter::zip(ty::GenericArgs::identity_for_item(tcx, impl_m.def_id), impl_m_args)
{
if let ty::GenericArgKind::Lifetime(r) = arg.unpack()
if let ty::GenericArgKind::Lifetime(r) = arg.kind()
&& let ty::ReVar(vid) = r.kind()
&& let r = infcx
.inner
@@ -1256,7 +1256,7 @@ fn check_region_late_boundedness<'tcx>(
for (id_arg, arg) in
std::iter::zip(ty::GenericArgs::identity_for_item(tcx, trait_m.def_id), trait_m_args)
{
if let ty::GenericArgKind::Lifetime(r) = arg.unpack()
if let ty::GenericArgKind::Lifetime(r) = arg.kind()
&& let ty::ReVar(vid) = r.kind()
&& let r = infcx
.inner
Original file line number Diff line number Diff line change
@@ -427,7 +427,7 @@ fn report_mismatched_rpitit_captures<'tcx>(
};

trait_captured_args
.sort_by_cached_key(|arg| !matches!(arg.unpack(), ty::GenericArgKind::Lifetime(_)));
.sort_by_cached_key(|arg| !matches!(arg.kind(), ty::GenericArgKind::Lifetime(_)));
let suggestion = format!("use<{}>", trait_captured_args.iter().join(", "));

tcx.emit_node_span_lint(
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
@@ -819,7 +819,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GATArgsCollector<'tcx> {
match t.kind() {
ty::Alias(ty::Projection, p) if p.def_id == self.gat => {
for (idx, arg) in p.args.iter().enumerate() {
match arg.unpack() {
match arg.kind() {
GenericArgKind::Lifetime(lt) if !lt.is_bound() => {
self.regions.insert((lt, idx));
}
@@ -1517,7 +1517,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
} else {
// If we've got a generic const parameter we still want to check its
// type is correct in case both it and the param type are fully concrete.
let GenericArgKind::Const(ct) = default.unpack() else {
let GenericArgKind::Const(ct) = default.kind() else {
continue;
};

2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/item_bounds.rs
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ fn remap_gat_vars_and_recurse_into_nested_projections<'tcx>(
let mut mapping = FxIndexMap::default();
let generics = tcx.generics_of(assoc_item_def_id);
for (param, var) in std::iter::zip(&generics.own_params, gat_vars) {
let existing = match var.unpack() {
let existing = match var.kind() {
ty::GenericArgKind::Lifetime(re) => {
if let ty::RegionKind::ReBound(ty::INNERMOST, bv) = re.kind() {
mapping.insert(bv.var, tcx.mk_param_from_def(param))
Original file line number Diff line number Diff line change
@@ -216,7 +216,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let pred = bound_predicate.rebind(pred);
// A `Self` within the original bound will be instantiated with a
// `trait_object_dummy_self`, so check for that.
let references_self = match pred.skip_binder().term.unpack() {
let references_self = match pred.skip_binder().term.kind() {
ty::TermKind::Ty(ty) => ty.walk().any(|arg| arg == dummy_self.into()),
// FIXME(associated_const_equality): We should walk the const instead of not doing anything
ty::TermKind::Const(_) => false,
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
@@ -607,7 +607,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
if !infer_args && has_default {
// No type parameter provided, but a default exists.
if let Some(prev) =
preceding_args.iter().find_map(|arg| match arg.unpack() {
preceding_args.iter().find_map(|arg| match arg.kind() {
GenericArgKind::Type(ty) => ty.error_reported().err(),
_ => None,
})
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
explicit_map: &mut ExplicitPredicatesMap<'tcx>,
) {
for arg in ty.walk() {
let leaf_ty = match arg.unpack() {
let leaf_ty = match arg.kind() {
GenericArgKind::Type(ty) => ty,

// No predicates from lifetimes or constants, except potentially
@@ -299,7 +299,7 @@ fn check_explicit_predicates<'tcx>(
// binding) and thus infer an outlives requirement that `X:
// 'b`.
if let Some(self_ty) = ignored_self_ty
&& let GenericArgKind::Type(ty) = outlives_predicate.0.unpack()
&& let GenericArgKind::Type(ty) = outlives_predicate.0.kind()
&& ty.walk().any(|arg| arg == self_ty.into())
{
debug!("skipping self ty = {ty:?}");
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/outlives/mod.rs
Original file line number Diff line number Diff line change
@@ -69,8 +69,8 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
.map(|(&def_id, set)| {
let predicates =
&*tcx.arena.alloc_from_iter(set.as_ref().skip_binder().iter().filter_map(
|(ty::OutlivesPredicate(kind1, region2), &span)| {
match kind1.unpack() {
|(ty::OutlivesPredicate(arg1, region2), &span)| {
match arg1.kind() {
GenericArgKind::Type(ty1) => Some((
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty1, *region2))
.upcast(tcx),
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/outlives/utils.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ pub(crate) type RequiredPredicates<'tcx> =
/// outlives_component and add it to `required_predicates`
pub(crate) fn insert_outlives_predicate<'tcx>(
tcx: TyCtxt<'tcx>,
kind: GenericArg<'tcx>,
arg: GenericArg<'tcx>,
outlived_region: Region<'tcx>,
span: Span,
required_predicates: &mut RequiredPredicates<'tcx>,
@@ -25,7 +25,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
return;
}

match kind.unpack() {
match arg.kind() {
GenericArgKind::Type(ty) => {
// `T: 'outlived_region` for some type `T`
// But T could be a lot of things:
@@ -135,7 +135,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
if !is_free_region(r) {
return;
}
required_predicates.entry(ty::OutlivesPredicate(kind, outlived_region)).or_insert(span);
required_predicates.entry(ty::OutlivesPredicate(arg, outlived_region)).or_insert(span);
}

GenericArgKind::Const(_) => {
10 changes: 5 additions & 5 deletions compiler/rustc_hir_analysis/src/variance/constraints.rs
Original file line number Diff line number Diff line change
@@ -200,8 +200,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
// Trait are always invariant so we can take advantage of that.
let variance_i = self.invariant(variance);

for k in args {
match k.unpack() {
for arg in args {
match arg.kind() {
GenericArgKind::Lifetime(lt) => {
self.add_constraints_from_region(current, lt, variance_i)
}
@@ -294,7 +294,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
}

for projection in data.projection_bounds() {
match projection.skip_binder().term.unpack() {
match projection.skip_binder().term.kind() {
ty::TermKind::Ty(ty) => {
self.add_constraints_from_ty(current, ty, self.invariant);
}
@@ -373,7 +373,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
(None, Some(self.tcx().variances_of(def_id)))
};

for (i, k) in args.iter().enumerate() {
for (i, arg) in args.iter().enumerate() {
let variance_decl = if let Some(InferredIndex(start)) = local {
// Parameter on an item defined within current crate:
// variance not yet inferred, so return a symbolic
@@ -389,7 +389,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
"add_constraints_from_args: variance_decl={:?} variance_i={:?}",
variance_decl, variance_i
);
match k.unpack() {
match arg.kind() {
GenericArgKind::Lifetime(lt) => {
self.add_constraints_from_region(current, lt, variance_i)
}
22 changes: 11 additions & 11 deletions compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs
Original file line number Diff line number Diff line change
@@ -80,12 +80,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let find_param_matching = |matches: &dyn Fn(ty::ParamTerm) -> bool| {
predicate_args.iter().find_map(|arg| {
arg.walk().find_map(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
if let ty::GenericArgKind::Type(ty) = arg.kind()
&& let ty::Param(param_ty) = *ty.kind()
&& matches(ty::ParamTerm::Ty(param_ty))
{
Some(arg)
} else if let ty::GenericArgKind::Const(ct) = arg.unpack()
} else if let ty::GenericArgKind::Const(ct) = arg.kind()
&& let ty::ConstKind::Param(param_ct) = ct.kind()
&& matches(ty::ParamTerm::Const(param_ct))
{
@@ -357,23 +357,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
error: &mut traits::FulfillmentError<'tcx>,
def_id: DefId,
param: ty::GenericArg<'tcx>,
arg: ty::GenericArg<'tcx>,
qpath: &hir::QPath<'tcx>,
) -> bool {
match qpath {
hir::QPath::Resolved(self_ty, path) => {
for segment in path.segments.iter().rev() {
if let Res::Def(kind, def_id) = segment.res
&& !matches!(kind, DefKind::Mod | DefKind::ForeignMod)
&& self.point_at_generic_if_possible(error, def_id, param, segment)
&& self.point_at_generic_if_possible(error, def_id, arg, segment)
{
return true;
}
}
// Handle `Self` param specifically, since it's separated in
// the path representation
if let Some(self_ty) = self_ty
&& let ty::GenericArgKind::Type(ty) = param.unpack()
&& let ty::GenericArgKind::Type(ty) = arg.kind()
&& ty == self.tcx.types.self_param
{
error.obligation.cause.span = self_ty
@@ -384,12 +384,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
hir::QPath::TypeRelative(self_ty, segment) => {
if self.point_at_generic_if_possible(error, def_id, param, segment) {
if self.point_at_generic_if_possible(error, def_id, arg, segment) {
return true;
}
// Handle `Self` param specifically, since it's separated in
// the path representation
if let ty::GenericArgKind::Type(ty) = param.unpack()
if let ty::GenericArgKind::Type(ty) = arg.kind()
&& ty == self.tcx.types.self_param
{
error.obligation.cause.span = self_ty
@@ -424,10 +424,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// the args list does not, then we should chop off all of the lifetimes,
// since they're all elided.
let segment_args = segment.args().args;
if matches!(own_args[0].unpack(), ty::GenericArgKind::Lifetime(_))
if matches!(own_args[0].kind(), ty::GenericArgKind::Lifetime(_))
&& segment_args.first().is_some_and(|arg| arg.is_ty_or_const())
&& let Some(offset) = own_args.iter().position(|arg| {
matches!(arg.unpack(), ty::GenericArgKind::Type(_) | ty::GenericArgKind::Const(_))
matches!(arg.kind(), ty::GenericArgKind::Type(_) | ty::GenericArgKind::Const(_))
})
&& let Some(new_index) = index.checked_sub(offset)
{
@@ -750,7 +750,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return Ok(expr);
}

let ty::GenericArgKind::Type(in_ty) = in_ty.unpack() else {
let ty::GenericArgKind::Type(in_ty) = in_ty.kind() else {
return Err(expr);
};

@@ -1045,7 +1045,7 @@ fn find_param_in_ty<'tcx>(
if arg == param_to_point_at {
return true;
}
if let ty::GenericArgKind::Type(ty) = arg.unpack()
if let ty::GenericArgKind::Type(ty) = arg.kind()
&& let ty::Alias(ty::Projection | ty::Inherent, ..) = ty.kind()
{
// This logic may seem a bit strange, but typically when
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
@@ -2226,7 +2226,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let infer_args = self.tcx.mk_args_from_iter(args.into_iter().map(|arg| {
if !arg.is_suggestable(self.tcx, true) {
has_unsuggestable_args = true;
match arg.unpack() {
match arg.kind() {
GenericArgKind::Lifetime(_) => self
.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
.into(),
@@ -2843,7 +2843,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let [first] = ***args else {
return;
};
let ty::GenericArgKind::Type(ty) = first.unpack() else {
let ty::GenericArgKind::Type(ty) = first.kind() else {
return;
};
let Ok(pick) = self.lookup_probe_for_diagnostic(
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
@@ -347,7 +347,7 @@ impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: match (a.unpack(), b.unpack()) {
values: match (a.kind(), b.kind()) {
(GenericArgKind::Lifetime(a), GenericArgKind::Lifetime(b)) => {
ValuePairs::Regions(ExpectedFound::new(a, b))
}
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/canonical/instantiate.rs
Original file line number Diff line number Diff line change
@@ -61,15 +61,15 @@ where
value
} else {
let delegate = FnMutDelegate {
regions: &mut |br: ty::BoundRegion| match var_values[br.var].unpack() {
regions: &mut |br: ty::BoundRegion| match var_values[br.var].kind() {
GenericArgKind::Lifetime(l) => l,
r => bug!("{:?} is a region but value is {:?}", br, r),
},
types: &mut |bound_ty: ty::BoundTy| match var_values[bound_ty.var].unpack() {
types: &mut |bound_ty: ty::BoundTy| match var_values[bound_ty.var].kind() {
GenericArgKind::Type(ty) => ty,
r => bug!("{:?} is a type but value is {:?}", bound_ty, r),
},
consts: &mut |bound_ct: ty::BoundVar| match var_values[bound_ct].unpack() {
consts: &mut |bound_ct: ty::BoundVar| match var_values[bound_ct].kind() {
GenericArgKind::Const(ct) => ct,
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
},
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.