Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8cdb3cd

Browse files
committed
Auto merge of rust-lang#93095 - Aaron1011:remove-assoc-ident, r=cjgillot
Store a `Symbol` instead of an `Ident` in `AssocItem` This is the same idea as rust-lang#92533, but for `AssocItem` instead of `VariantDef`/`FieldDef`. With this change, we no longer have any uses of `#[stable_hasher(project(...))]`
2 parents 92ed874 + c8941d3 commit 8cdb3cd

File tree

28 files changed

+100
-92
lines changed

28 files changed

+100
-92
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
798798
.map(|assoc_items| {
799799
assoc_items
800800
.in_definition_order()
801-
.map(|assoc_item_def| assoc_item_def.ident)
801+
.map(|assoc_item_def| assoc_item_def.ident(self.infcx.tcx))
802802
.filter(|&ident| {
803803
let original_method_ident = path_segment.ident;
804804
original_method_ident != ident

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
26502650
infer::LateBoundRegion(_, br, infer::AssocTypeProjection(def_id)) => format!(
26512651
" for lifetime parameter {}in trait containing associated type `{}`",
26522652
br_string(br),
2653-
self.tcx.associated_item(def_id).ident
2653+
self.tcx.associated_item(def_id).name
26542654
),
26552655
infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{}`", name),
26562656
infer::UpvarRegion(ref upvar_id, _) => {

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
7070
.map(|s| format!("`{}`", s))
7171
.unwrap_or_else(|| "`fn` parameter".to_string()),
7272
lifetime,
73-
ctxt.assoc_item.ident,
73+
ctxt.assoc_item.name,
7474
);
7575
err.span_label(param.param_ty_span, &format!("this data with {}...", lifetime));
7676
err.span_label(
@@ -231,7 +231,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
231231
// Handle case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a
232232
// `'static` lifetime when called as a method on a binding: `bar.qux()`.
233233
if self.find_impl_on_dyn_trait(&mut err, param.param_ty, &ctxt) {
234-
override_error_code = Some(ctxt.assoc_item.ident);
234+
override_error_code = Some(ctxt.assoc_item.name);
235235
}
236236
}
237237
}
@@ -252,7 +252,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
252252
self.get_impl_ident_and_self_ty_from_trait(*item_def_id, &v.0)
253253
{
254254
if self.suggest_constrain_dyn_trait_in_impl(&mut err, &v.0, ident, self_ty) {
255-
override_error_code = Some(ident);
255+
override_error_code = Some(ident.name);
256256
}
257257
}
258258
}

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12791279
};
12801280

12811281
ty::AssocItem {
1282-
ident,
1282+
name: ident.name,
12831283
kind,
12841284
vis: self.get_visibility(id),
12851285
defaultness: container.defaultness(),

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12911291
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
12921292
}
12931293
}
1294-
self.encode_ident_span(def_id, impl_item.ident);
1294+
self.encode_ident_span(def_id, impl_item.ident(self.tcx));
12951295
self.encode_item_type(def_id);
12961296
if let Some(trait_item_def_id) = impl_item.trait_item_def_id {
12971297
record!(self.tables.trait_item_def_id[def_id] <- trait_item_def_id);

compiler/rustc_middle/src/ty/assoc.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ impl AssocItemContainer {
4444
#[derive(Copy, Clone, Debug, PartialEq, HashStable, Eq, Hash)]
4545
pub struct AssocItem {
4646
pub def_id: DefId,
47-
#[stable_hasher(project(name))]
48-
pub ident: Ident,
47+
pub name: Symbol,
4948
pub kind: AssocKind,
5049
pub vis: Visibility,
5150
pub defaultness: hir::Defaultness,
@@ -61,6 +60,10 @@ pub struct AssocItem {
6160
}
6261

6362
impl AssocItem {
63+
pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
64+
Ident::new(self.name, tcx.def_ident_span(self.def_id).unwrap())
65+
}
66+
6467
pub fn signature(&self, tcx: TyCtxt<'_>) -> String {
6568
match self.kind {
6669
ty::AssocKind::Fn => {
@@ -70,9 +73,9 @@ impl AssocItem {
7073
// regions just fine, showing `fn(&MyType)`.
7174
tcx.fn_sig(self.def_id).skip_binder().to_string()
7275
}
73-
ty::AssocKind::Type => format!("type {};", self.ident),
76+
ty::AssocKind::Type => format!("type {};", self.name),
7477
ty::AssocKind::Const => {
75-
format!("const {}: {:?};", self.ident, tcx.type_of(self.def_id))
78+
format!("const {}: {:?};", self.name, tcx.type_of(self.def_id))
7679
}
7780
}
7881
}
@@ -115,7 +118,7 @@ pub struct AssocItems<'tcx> {
115118
impl<'tcx> AssocItems<'tcx> {
116119
/// Constructs an `AssociatedItems` map from a series of `ty::AssocItem`s in definition order.
117120
pub fn new(items_in_def_order: impl IntoIterator<Item = &'tcx ty::AssocItem>) -> Self {
118-
let items = items_in_def_order.into_iter().map(|item| (item.ident.name, item)).collect();
121+
let items = items_in_def_order.into_iter().map(|item| (item.name, item)).collect();
119122
AssocItems { items }
120123
}
121124

@@ -149,7 +152,7 @@ impl<'tcx> AssocItems<'tcx> {
149152
) -> Option<&ty::AssocItem> {
150153
self.filter_by_name_unhygienic(ident.name)
151154
.filter(|item| item.kind == kind)
152-
.find(|item| tcx.hygienic_eq(ident, item.ident, parent_def_id))
155+
.find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
153156
}
154157

155158
/// Returns the associated item with the given name and any of `AssocKind`, if one exists.
@@ -162,7 +165,7 @@ impl<'tcx> AssocItems<'tcx> {
162165
) -> Option<&ty::AssocItem> {
163166
self.filter_by_name_unhygienic(ident.name)
164167
.filter(|item| kinds.contains(&item.kind))
165-
.find(|item| tcx.hygienic_eq(ident, item.ident, parent_def_id))
168+
.find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
166169
}
167170

168171
/// Returns the associated item with the given name in the given `Namespace`, if one exists.
@@ -175,6 +178,6 @@ impl<'tcx> AssocItems<'tcx> {
175178
) -> Option<&ty::AssocItem> {
176179
self.filter_by_name_unhygienic(ident.name)
177180
.filter(|item| item.kind.namespace() == ns)
178-
.find(|item| tcx.hygienic_eq(ident, item.ident, parent_def_id))
181+
.find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
179182
}
180183
}

compiler/rustc_middle/src/ty/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,10 @@ fn foo(&self) -> Self::T { String::new() }
972972
let (span, sugg) = if has_params {
973973
let pos = span.hi() - BytePos(1);
974974
let span = Span::new(pos, pos, span.ctxt(), span.parent());
975-
(span, format!(", {} = {}", assoc.ident, ty))
975+
(span, format!(", {} = {}", assoc.ident(self), ty))
976976
} else {
977977
let item_args = self.format_generic_args(assoc_substs);
978-
(span.shrink_to_hi(), format!("<{}{} = {}>", assoc.ident, item_args, ty))
978+
(span.shrink_to_hi(), format!("<{}{} = {}>", assoc.ident(self), item_args, ty))
979979
};
980980
db.span_suggestion_verbose(span, msg, sugg, MaybeIncorrect);
981981
return true;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ pub trait PrettyPrinter<'tcx>:
908908
if !first {
909909
p!(", ");
910910
}
911-
p!(write("{} = ", self.tcx().associated_item(assoc_item_def_id).ident));
911+
p!(write("{} = ", self.tcx().associated_item(assoc_item_def_id).name));
912912

913913
match term.skip_binder() {
914914
Term::Ty(ty) => {
@@ -2455,7 +2455,7 @@ define_print_and_forward_display! {
24552455
}
24562456

24572457
ty::ExistentialProjection<'tcx> {
2458-
let name = cx.tcx().associated_item(self.item_def_id).ident;
2458+
let name = cx.tcx().associated_item(self.item_def_id).name;
24592459
p!(write("{} = ", name), print(self.term))
24602460
}
24612461

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
556556
cx = cx.print_def_path(trait_ref.def_id, trait_ref.substs)?;
557557
}
558558
ty::ExistentialPredicate::Projection(projection) => {
559-
let name = cx.tcx.associated_item(projection.item_def_id).ident;
559+
let name = cx.tcx.associated_item(projection.item_def_id).name;
560560
cx.push("p");
561561
cx.push_ident(name.as_str());
562562
cx = match projection.term {

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,14 +1353,15 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
13531353
.map(|id| (trait_assoc_item, id))
13541354
})
13551355
.and_then(|(trait_assoc_item, id)| {
1356+
let trait_assoc_ident = trait_assoc_item.ident(self.tcx);
13561357
self.tcx.find_map_relevant_impl(
13571358
id,
13581359
proj.projection_ty.self_ty(),
13591360
|did| {
13601361
self.tcx
13611362
.associated_items(did)
13621363
.in_definition_order()
1363-
.filter(|assoc| assoc.ident == trait_assoc_item.ident)
1364+
.filter(|assoc| assoc.ident(self.tcx) == trait_assoc_ident)
13641365
.next()
13651366
},
13661367
)

0 commit comments

Comments
 (0)