Skip to content

Commit 7fd1345

Browse files
Same for types
1 parent fe1c8b3 commit 7fd1345

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2468,7 +2468,7 @@ fn param_env_with_gat_bounds<'tcx>(
24682468
let normalize_impl_ty_args = ty::GenericArgs::identity_for_item(tcx, container_id)
24692469
.extend_to(tcx, impl_ty.def_id, |param, _| match param.kind {
24702470
GenericParamDefKind::Type { .. } => {
2471-
let kind = ty::BoundTyKind::Param(param.def_id, param.name);
2471+
let kind = ty::BoundTyKind::Param(param.def_id);
24722472
let bound_var = ty::BoundVariableKind::Ty(kind);
24732473
bound_vars.push(bound_var);
24742474
Ty::new_bound(

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,13 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou
278278
rbv
279279
}
280280

281-
fn late_arg_as_bound_arg<'tcx>(
282-
tcx: TyCtxt<'tcx>,
283-
param: &GenericParam<'tcx>,
284-
) -> ty::BoundVariableKind {
281+
fn late_arg_as_bound_arg<'tcx>(param: &GenericParam<'tcx>) -> ty::BoundVariableKind {
285282
let def_id = param.def_id.to_def_id();
286-
let name = tcx.item_name(def_id);
287283
match param.kind {
288284
GenericParamKind::Lifetime { .. } => {
289285
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id))
290286
}
291-
GenericParamKind::Type { .. } => {
292-
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id, name))
293-
}
287+
GenericParamKind::Type { .. } => ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id)),
294288
GenericParamKind::Const { .. } => ty::BoundVariableKind::Const,
295289
}
296290
}
@@ -304,7 +298,7 @@ fn generic_param_def_as_bound_arg(param: &ty::GenericParamDef) -> ty::BoundVaria
304298
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(param.def_id))
305299
}
306300
ty::GenericParamDefKind::Type { .. } => {
307-
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id, param.name))
301+
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id))
308302
}
309303
ty::GenericParamDefKind::Const { .. } => ty::BoundVariableKind::Const,
310304
}
@@ -385,7 +379,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
385379
trait_ref.bound_generic_params.iter().enumerate().map(|(late_bound_idx, param)| {
386380
let arg = ResolvedArg::late(initial_bound_vars + late_bound_idx as u32, param);
387381
bound_vars.insert(param.def_id, arg);
388-
late_arg_as_bound_arg(self.tcx, param)
382+
late_arg_as_bound_arg(param)
389383
});
390384
binders.extend(binders_iter);
391385

@@ -484,7 +478,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
484478
.map(|(late_bound_idx, param)| {
485479
(
486480
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
487-
late_arg_as_bound_arg(self.tcx, param),
481+
late_arg_as_bound_arg(param),
488482
)
489483
})
490484
.unzip();
@@ -717,7 +711,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
717711
.map(|(late_bound_idx, param)| {
718712
(
719713
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
720-
late_arg_as_bound_arg(self.tcx, param),
714+
late_arg_as_bound_arg(param),
721715
)
722716
})
723717
.unzip();
@@ -747,7 +741,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
747741
.map(|(late_bound_idx, param)| {
748742
(
749743
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
750-
late_arg_as_bound_arg(self.tcx, param),
744+
late_arg_as_bound_arg(param),
751745
)
752746
})
753747
.unzip();
@@ -956,7 +950,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
956950
.map(|(late_bound_idx, param)| {
957951
(
958952
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
959-
late_arg_as_bound_arg(self.tcx, param),
953+
late_arg_as_bound_arg(param),
960954
)
961955
})
962956
.unzip();
@@ -1170,7 +1164,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
11701164
matches!(param.kind, GenericParamKind::Lifetime { .. })
11711165
&& self.tcx.is_late_bound(param.hir_id)
11721166
})
1173-
.map(|param| late_arg_as_bound_arg(self.tcx, param))
1167+
.map(|param| late_arg_as_bound_arg(param))
11741168
.collect();
11751169
self.record_late_bound_vars(hir_id, binders);
11761170
let scope = Scope::Binder {

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 't
10481048
}
10491049
ty::Bound(db, bt) if *db >= self.depth => {
10501050
self.vars.insert(match bt.kind {
1051-
ty::BoundTyKind::Param(def_id, _) => def_id,
1051+
ty::BoundTyKind::Param(def_id) => def_id,
10521052
ty::BoundTyKind::Anon => {
10531053
let reported = self
10541054
.cx

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,10 +2067,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20672067
let tcx = self.tcx();
20682068
match tcx.named_bound_var(hir_id) {
20692069
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
2070-
let name = tcx.item_name(def_id.to_def_id());
20712070
let br = ty::BoundTy {
20722071
var: ty::BoundVar::from_u32(index),
2073-
kind: ty::BoundTyKind::Param(def_id.to_def_id(), name),
2072+
kind: ty::BoundTyKind::Param(def_id.to_def_id()),
20742073
};
20752074
Ty::new_bound(tcx, debruijn, br)
20762075
}

compiler/rustc_lint/src/impl_trait_overcaptures.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl fmt::Debug for ty::BoundTy {
183183
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
184184
match self.kind {
185185
ty::BoundTyKind::Anon => write!(f, "{:?}", self.var),
186-
ty::BoundTyKind::Param(_, sym) => write!(f, "{sym:?}"),
186+
ty::BoundTyKind::Param(def_id) => write!(f, "{def_id:?}"),
187187
}
188188
}
189189
}

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundTy {
400400
#[derive(HashStable)]
401401
pub enum BoundTyKind {
402402
Anon,
403-
Param(DefId, Symbol),
403+
Param(DefId),
404404
}
405405

406406
impl From<BoundVar> for BoundTy {

compiler/rustc_smir/src/rustc_internal/internal.rs

Lines changed: 3 additions & 5 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
22212221
}
22222222

22232223
ty::Bound(_, ref ty) => match ty.kind {
2224-
ty::BoundTyKind::Param(_, name) => Generic(name),
2224+
ty::BoundTyKind::Param(def_id) => Generic(cx.tcx.item_name(def_id)),
22252225
ty::BoundTyKind::Anon => panic!("unexpected anonymous bound type variable"),
22262226
},
22272227

@@ -3188,7 +3188,8 @@ fn clean_bound_vars<'tcx>(
31883188
None
31893189
}
31903190
}
3191-
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id, name)) => {
3191+
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id)) => {
3192+
let name = cx.tcx.item_name(def_id);
31923193
Some(GenericParamDef {
31933194
name,
31943195
def_id,

0 commit comments

Comments
 (0)