Skip to content

Commit b749895

Browse files
Same for types
1 parent 1c401b0 commit b749895

File tree

11 files changed

+29
-36
lines changed

11 files changed

+29
-36
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,7 @@ fn param_env_with_gat_bounds<'tcx>(
22592259
let normalize_impl_ty_args = ty::GenericArgs::identity_for_item(tcx, container_id)
22602260
.extend_to(tcx, impl_ty.def_id, |param, _| match param.kind {
22612261
GenericParamDefKind::Type { .. } => {
2262-
let kind = ty::BoundTyKind::Param(param.def_id, param.name);
2262+
let kind = ty::BoundTyKind::Param(param.def_id);
22632263
let bound_var = ty::BoundVariableKind::Ty(kind);
22642264
bound_vars.push(bound_var);
22652265
Ty::new_bound(

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,13 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou
272272
rbv
273273
}
274274

275-
fn late_arg_as_bound_arg<'tcx>(
276-
tcx: TyCtxt<'tcx>,
277-
param: &GenericParam<'tcx>,
278-
) -> ty::BoundVariableKind {
275+
fn late_arg_as_bound_arg<'tcx>(param: &GenericParam<'tcx>) -> ty::BoundVariableKind {
279276
let def_id = param.def_id.to_def_id();
280-
let name = tcx.item_name(def_id);
281277
match param.kind {
282278
GenericParamKind::Lifetime { .. } => {
283279
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id))
284280
}
285-
GenericParamKind::Type { .. } => {
286-
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id, name))
287-
}
281+
GenericParamKind::Type { .. } => ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id)),
288282
GenericParamKind::Const { .. } => ty::BoundVariableKind::Const,
289283
}
290284
}
@@ -298,7 +292,7 @@ fn generic_param_def_as_bound_arg(param: &ty::GenericParamDef) -> ty::BoundVaria
298292
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(param.def_id))
299293
}
300294
ty::GenericParamDefKind::Type { .. } => {
301-
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id, param.name))
295+
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id))
302296
}
303297
ty::GenericParamDefKind::Const { .. } => ty::BoundVariableKind::Const,
304298
}
@@ -379,7 +373,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
379373
trait_ref.bound_generic_params.iter().enumerate().map(|(late_bound_idx, param)| {
380374
let arg = ResolvedArg::late(initial_bound_vars + late_bound_idx as u32, param);
381375
bound_vars.insert(param.def_id, arg);
382-
late_arg_as_bound_arg(self.tcx, param)
376+
late_arg_as_bound_arg(param)
383377
});
384378
binders.extend(binders_iter);
385379

@@ -478,7 +472,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
478472
.map(|(late_bound_idx, param)| {
479473
(
480474
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
481-
late_arg_as_bound_arg(self.tcx, param),
475+
late_arg_as_bound_arg(param),
482476
)
483477
})
484478
.unzip();
@@ -710,7 +704,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
710704
.map(|(late_bound_idx, param)| {
711705
(
712706
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
713-
late_arg_as_bound_arg(self.tcx, param),
707+
late_arg_as_bound_arg(param),
714708
)
715709
})
716710
.unzip();
@@ -740,7 +734,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
740734
.map(|(late_bound_idx, param)| {
741735
(
742736
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
743-
late_arg_as_bound_arg(self.tcx, param),
737+
late_arg_as_bound_arg(param),
744738
)
745739
})
746740
.unzip();
@@ -949,7 +943,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
949943
.map(|(late_bound_idx, param)| {
950944
(
951945
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
952-
late_arg_as_bound_arg(self.tcx, param),
946+
late_arg_as_bound_arg(param),
953947
)
954948
})
955949
.unzip();
@@ -1163,7 +1157,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
11631157
matches!(param.kind, GenericParamKind::Lifetime { .. })
11641158
&& self.tcx.is_late_bound(param.hir_id)
11651159
})
1166-
.map(|param| late_arg_as_bound_arg(self.tcx, param))
1160+
.map(|param| late_arg_as_bound_arg(param))
11671161
.collect();
11681162
self.record_late_bound_vars(hir_id, binders);
11691163
let scope = Scope::Binder {

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 't
10131013
}
10141014
ty::Bound(db, bt) if *db >= self.depth => {
10151015
self.vars.insert(match bt.kind {
1016-
ty::BoundTyKind::Param(def_id, _) => def_id,
1016+
ty::BoundTyKind::Param(def_id) => def_id,
10171017
ty::BoundTyKind::Anon => {
10181018
let reported = self
10191019
.cx

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2231,10 +2231,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22312231
let tcx = self.tcx();
22322232
match tcx.named_bound_var(hir_id) {
22332233
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
2234-
let name = tcx.item_name(def_id.to_def_id());
22352234
let br = ty::BoundTy {
22362235
var: ty::BoundVar::from_u32(index),
2237-
kind: ty::BoundTyKind::Param(def_id.to_def_id(), name),
2236+
kind: ty::BoundTyKind::Param(def_id.to_def_id()),
22382237
};
22392238
Ty::new_bound(tcx, debruijn, br)
22402239
}

compiler/rustc_lint/src/impl_trait_overcaptures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ where
215215
let arg: ty::BoundVariableKind = arg;
216216
match arg {
217217
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id))
218-
| ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id, _)) => {
218+
| ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id)) => {
219219
added.push(def_id);
220220
let unique = self.in_scope_parameters.insert(def_id, ParamKind::Late);
221221
assert_eq!(unique, None);

compiler/rustc_middle/src/ty/print/pretty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
795795
ty::BoundTyKind::Anon => {
796796
rustc_type_ir::debug_bound_var(self, debruijn, bound_ty.var)?
797797
}
798-
ty::BoundTyKind::Param(_, s) => match self.should_print_verbose() {
798+
ty::BoundTyKind::Param(def_id) => match self.should_print_verbose() {
799799
true => p!(write("{:?}", ty.kind())),
800-
false => p!(write("{s}")),
800+
false => p!(write("{}", self.tcx().item_name(def_id))),
801801
},
802802
},
803803
ty::Adt(def, args) => {
@@ -825,9 +825,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
825825
}
826826
ty::Placeholder(placeholder) => match placeholder.bound.kind {
827827
ty::BoundTyKind::Anon => p!(write("{placeholder:?}")),
828-
ty::BoundTyKind::Param(_, name) => match self.should_print_verbose() {
828+
ty::BoundTyKind::Param(def_id) => match self.should_print_verbose() {
829829
true => p!(write("{:?}", ty.kind())),
830-
false => p!(write("{name}")),
830+
false => p!(write("{}", self.tcx().item_name(def_id))),
831831
},
832832
},
833833
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {

compiler/rustc_middle/src/ty/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl fmt::Debug for ty::BoundTy {
179179
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
180180
match self.kind {
181181
ty::BoundTyKind::Anon => write!(f, "{:?}", self.var),
182-
ty::BoundTyKind::Param(_, sym) => write!(f, "{sym:?}"),
182+
ty::BoundTyKind::Param(def_id) => write!(f, "{def_id:?}"),
183183
}
184184
}
185185
}

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundTy {
385385
#[derive(HashStable)]
386386
pub enum BoundTyKind {
387387
Anon,
388-
Param(DefId, Symbol),
388+
Param(DefId),
389389
}
390390

391391
impl From<BoundVar> for BoundTy {

compiler/rustc_smir/src/rustc_internal/internal.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// Prefer importing stable_mir over internal rustc constructs to make this file more readable.
77

88
use rustc_middle::ty::{self as rustc_ty, Const as InternalConst, Ty as InternalTy, TyCtxt};
9-
use rustc_span::Symbol;
109
use stable_mir::abi::Layout;
1110
use stable_mir::mir::alloc::AllocId;
1211
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
@@ -345,10 +344,9 @@ impl RustcInternal for BoundVariableKind {
345344
match self {
346345
BoundVariableKind::Ty(kind) => rustc_ty::BoundVariableKind::Ty(match kind {
347346
BoundTyKind::Anon => rustc_ty::BoundTyKind::Anon,
348-
BoundTyKind::Param(def, symbol) => rustc_ty::BoundTyKind::Param(
349-
def.0.internal(tables, tcx),
350-
Symbol::intern(symbol),
351-
),
347+
BoundTyKind::Param(def, _symbol) => {
348+
rustc_ty::BoundTyKind::Param(def.0.internal(tables, tcx))
349+
}
352350
}),
353351
BoundVariableKind::Region(kind) => rustc_ty::BoundVariableKind::Region(match kind {
354352
BoundRegionKind::BrAnon => rustc_ty::BoundRegionKind::Anon,

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,10 @@ impl<'tcx> Stable<'tcx> for ty::BoundTyKind {
230230

231231
match self {
232232
ty::BoundTyKind::Anon => BoundTyKind::Anon,
233-
ty::BoundTyKind::Param(def_id, symbol) => {
234-
BoundTyKind::Param(tables.param_def(*def_id), symbol.to_string())
235-
}
233+
ty::BoundTyKind::Param(def_id) => BoundTyKind::Param(
234+
tables.param_def(*def_id),
235+
tables.tcx.item_name(*def_id).to_string(),
236+
),
236237
}
237238
}
238239
}

src/librustdoc/clean/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
22642264
}
22652265

22662266
ty::Bound(_, ref ty) => match ty.kind {
2267-
ty::BoundTyKind::Param(_, name) => Generic(name),
2267+
ty::BoundTyKind::Param(def_id) => Generic(cx.tcx.item_name(def_id)),
22682268
ty::BoundTyKind::Anon => panic!("unexpected anonymous bound type variable"),
22692269
},
22702270

@@ -3198,7 +3198,8 @@ fn clean_bound_vars<'tcx>(
31983198
None
31993199
}
32003200
}
3201-
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id, name)) => {
3201+
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id)) => {
3202+
let name = cx.tcx.item_name(def_id);
32023203
Some(GenericParamDef {
32033204
name,
32043205
def_id,

0 commit comments

Comments
 (0)