1
Fork 0

Auto merge of #93095 - Aaron1011:remove-assoc-ident, r=cjgillot

Store a `Symbol` instead of an `Ident` in `AssocItem`

This is the same idea as #92533, but for `AssocItem` instead
of `VariantDef`/`FieldDef`.

With this change, we no longer have any uses of
`#[stable_hasher(project(...))]`
This commit is contained in:
bors 2022-01-25 18:53:45 +00:00
commit 8cdb3cd94e
28 changed files with 100 additions and 92 deletions

View file

@ -798,7 +798,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
.map(|assoc_items| { .map(|assoc_items| {
assoc_items assoc_items
.in_definition_order() .in_definition_order()
.map(|assoc_item_def| assoc_item_def.ident) .map(|assoc_item_def| assoc_item_def.ident(self.infcx.tcx))
.filter(|&ident| { .filter(|&ident| {
let original_method_ident = path_segment.ident; let original_method_ident = path_segment.ident;
original_method_ident != ident original_method_ident != ident

View file

@ -2650,7 +2650,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
infer::LateBoundRegion(_, br, infer::AssocTypeProjection(def_id)) => format!( infer::LateBoundRegion(_, br, infer::AssocTypeProjection(def_id)) => format!(
" for lifetime parameter {}in trait containing associated type `{}`", " for lifetime parameter {}in trait containing associated type `{}`",
br_string(br), br_string(br),
self.tcx.associated_item(def_id).ident self.tcx.associated_item(def_id).name
), ),
infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{}`", name), infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{}`", name),
infer::UpvarRegion(ref upvar_id, _) => { infer::UpvarRegion(ref upvar_id, _) => {

View file

@ -70,7 +70,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
.map(|s| format!("`{}`", s)) .map(|s| format!("`{}`", s))
.unwrap_or_else(|| "`fn` parameter".to_string()), .unwrap_or_else(|| "`fn` parameter".to_string()),
lifetime, lifetime,
ctxt.assoc_item.ident, ctxt.assoc_item.name,
); );
err.span_label(param.param_ty_span, &format!("this data with {}...", lifetime)); err.span_label(param.param_ty_span, &format!("this data with {}...", lifetime));
err.span_label( err.span_label(
@ -231,7 +231,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// Handle case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a // Handle case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a
// `'static` lifetime when called as a method on a binding: `bar.qux()`. // `'static` lifetime when called as a method on a binding: `bar.qux()`.
if self.find_impl_on_dyn_trait(&mut err, param.param_ty, &ctxt) { if self.find_impl_on_dyn_trait(&mut err, param.param_ty, &ctxt) {
override_error_code = Some(ctxt.assoc_item.ident); override_error_code = Some(ctxt.assoc_item.name);
} }
} }
} }
@ -252,7 +252,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
self.get_impl_ident_and_self_ty_from_trait(*item_def_id, &v.0) self.get_impl_ident_and_self_ty_from_trait(*item_def_id, &v.0)
{ {
if self.suggest_constrain_dyn_trait_in_impl(&mut err, &v.0, ident, self_ty) { if self.suggest_constrain_dyn_trait_in_impl(&mut err, &v.0, ident, self_ty) {
override_error_code = Some(ident); override_error_code = Some(ident.name);
} }
} }
} }

View file

@ -1279,7 +1279,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}; };
ty::AssocItem { ty::AssocItem {
ident, name: ident.name,
kind, kind,
vis: self.get_visibility(id), vis: self.get_visibility(id),
defaultness: container.defaultness(), defaultness: container.defaultness(),

View file

@ -1291,7 +1291,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container)); record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
} }
} }
self.encode_ident_span(def_id, impl_item.ident); self.encode_ident_span(def_id, impl_item.ident(self.tcx));
self.encode_item_type(def_id); self.encode_item_type(def_id);
if let Some(trait_item_def_id) = impl_item.trait_item_def_id { if let Some(trait_item_def_id) = impl_item.trait_item_def_id {
record!(self.tables.trait_item_def_id[def_id] <- trait_item_def_id); record!(self.tables.trait_item_def_id[def_id] <- trait_item_def_id);

View file

@ -44,8 +44,7 @@ impl AssocItemContainer {
#[derive(Copy, Clone, Debug, PartialEq, HashStable, Eq, Hash)] #[derive(Copy, Clone, Debug, PartialEq, HashStable, Eq, Hash)]
pub struct AssocItem { pub struct AssocItem {
pub def_id: DefId, pub def_id: DefId,
#[stable_hasher(project(name))] pub name: Symbol,
pub ident: Ident,
pub kind: AssocKind, pub kind: AssocKind,
pub vis: Visibility, pub vis: Visibility,
pub defaultness: hir::Defaultness, pub defaultness: hir::Defaultness,
@ -61,6 +60,10 @@ pub struct AssocItem {
} }
impl AssocItem { impl AssocItem {
pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
Ident::new(self.name, tcx.def_ident_span(self.def_id).unwrap())
}
pub fn signature(&self, tcx: TyCtxt<'_>) -> String { pub fn signature(&self, tcx: TyCtxt<'_>) -> String {
match self.kind { match self.kind {
ty::AssocKind::Fn => { ty::AssocKind::Fn => {
@ -70,9 +73,9 @@ impl AssocItem {
// regions just fine, showing `fn(&MyType)`. // regions just fine, showing `fn(&MyType)`.
tcx.fn_sig(self.def_id).skip_binder().to_string() tcx.fn_sig(self.def_id).skip_binder().to_string()
} }
ty::AssocKind::Type => format!("type {};", self.ident), ty::AssocKind::Type => format!("type {};", self.name),
ty::AssocKind::Const => { ty::AssocKind::Const => {
format!("const {}: {:?};", self.ident, tcx.type_of(self.def_id)) format!("const {}: {:?};", self.name, tcx.type_of(self.def_id))
} }
} }
} }
@ -115,7 +118,7 @@ pub struct AssocItems<'tcx> {
impl<'tcx> AssocItems<'tcx> { impl<'tcx> AssocItems<'tcx> {
/// Constructs an `AssociatedItems` map from a series of `ty::AssocItem`s in definition order. /// Constructs an `AssociatedItems` map from a series of `ty::AssocItem`s in definition order.
pub fn new(items_in_def_order: impl IntoIterator<Item = &'tcx ty::AssocItem>) -> Self { pub fn new(items_in_def_order: impl IntoIterator<Item = &'tcx ty::AssocItem>) -> Self {
let items = items_in_def_order.into_iter().map(|item| (item.ident.name, item)).collect(); let items = items_in_def_order.into_iter().map(|item| (item.name, item)).collect();
AssocItems { items } AssocItems { items }
} }
@ -149,7 +152,7 @@ impl<'tcx> AssocItems<'tcx> {
) -> Option<&ty::AssocItem> { ) -> Option<&ty::AssocItem> {
self.filter_by_name_unhygienic(ident.name) self.filter_by_name_unhygienic(ident.name)
.filter(|item| item.kind == kind) .filter(|item| item.kind == kind)
.find(|item| tcx.hygienic_eq(ident, item.ident, parent_def_id)) .find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
} }
/// Returns the associated item with the given name and any of `AssocKind`, if one exists. /// Returns the associated item with the given name and any of `AssocKind`, if one exists.
@ -162,7 +165,7 @@ impl<'tcx> AssocItems<'tcx> {
) -> Option<&ty::AssocItem> { ) -> Option<&ty::AssocItem> {
self.filter_by_name_unhygienic(ident.name) self.filter_by_name_unhygienic(ident.name)
.filter(|item| kinds.contains(&item.kind)) .filter(|item| kinds.contains(&item.kind))
.find(|item| tcx.hygienic_eq(ident, item.ident, parent_def_id)) .find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
} }
/// Returns the associated item with the given name in the given `Namespace`, if one exists. /// Returns the associated item with the given name in the given `Namespace`, if one exists.
@ -175,6 +178,6 @@ impl<'tcx> AssocItems<'tcx> {
) -> Option<&ty::AssocItem> { ) -> Option<&ty::AssocItem> {
self.filter_by_name_unhygienic(ident.name) self.filter_by_name_unhygienic(ident.name)
.filter(|item| item.kind.namespace() == ns) .filter(|item| item.kind.namespace() == ns)
.find(|item| tcx.hygienic_eq(ident, item.ident, parent_def_id)) .find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
} }
} }

View file

@ -972,10 +972,10 @@ fn foo(&self) -> Self::T { String::new() }
let (span, sugg) = if has_params { let (span, sugg) = if has_params {
let pos = span.hi() - BytePos(1); let pos = span.hi() - BytePos(1);
let span = Span::new(pos, pos, span.ctxt(), span.parent()); let span = Span::new(pos, pos, span.ctxt(), span.parent());
(span, format!(", {} = {}", assoc.ident, ty)) (span, format!(", {} = {}", assoc.ident(self), ty))
} else { } else {
let item_args = self.format_generic_args(assoc_substs); let item_args = self.format_generic_args(assoc_substs);
(span.shrink_to_hi(), format!("<{}{} = {}>", assoc.ident, item_args, ty)) (span.shrink_to_hi(), format!("<{}{} = {}>", assoc.ident(self), item_args, ty))
}; };
db.span_suggestion_verbose(span, msg, sugg, MaybeIncorrect); db.span_suggestion_verbose(span, msg, sugg, MaybeIncorrect);
return true; return true;

View file

@ -908,7 +908,7 @@ pub trait PrettyPrinter<'tcx>:
if !first { if !first {
p!(", "); p!(", ");
} }
p!(write("{} = ", self.tcx().associated_item(assoc_item_def_id).ident)); p!(write("{} = ", self.tcx().associated_item(assoc_item_def_id).name));
match term.skip_binder() { match term.skip_binder() {
Term::Ty(ty) => { Term::Ty(ty) => {
@ -2455,7 +2455,7 @@ define_print_and_forward_display! {
} }
ty::ExistentialProjection<'tcx> { ty::ExistentialProjection<'tcx> {
let name = cx.tcx().associated_item(self.item_def_id).ident; let name = cx.tcx().associated_item(self.item_def_id).name;
p!(write("{} = ", name), print(self.term)) p!(write("{} = ", name), print(self.term))
} }

View file

@ -556,7 +556,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
cx = cx.print_def_path(trait_ref.def_id, trait_ref.substs)?; cx = cx.print_def_path(trait_ref.def_id, trait_ref.substs)?;
} }
ty::ExistentialPredicate::Projection(projection) => { ty::ExistentialPredicate::Projection(projection) => {
let name = cx.tcx.associated_item(projection.item_def_id).ident; let name = cx.tcx.associated_item(projection.item_def_id).name;
cx.push("p"); cx.push("p");
cx.push_ident(name.as_str()); cx.push_ident(name.as_str());
cx = match projection.term { cx = match projection.term {

View file

@ -1353,6 +1353,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
.map(|id| (trait_assoc_item, id)) .map(|id| (trait_assoc_item, id))
}) })
.and_then(|(trait_assoc_item, id)| { .and_then(|(trait_assoc_item, id)| {
let trait_assoc_ident = trait_assoc_item.ident(self.tcx);
self.tcx.find_map_relevant_impl( self.tcx.find_map_relevant_impl(
id, id,
proj.projection_ty.self_ty(), proj.projection_ty.self_ty(),
@ -1360,7 +1361,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
self.tcx self.tcx
.associated_items(did) .associated_items(did)
.in_definition_order() .in_definition_order()
.filter(|assoc| assoc.ident == trait_assoc_item.ident) .filter(|assoc| assoc.ident(self.tcx) == trait_assoc_ident)
.next() .next()
}, },
) )

View file

@ -1367,7 +1367,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
err.span_suggestion( err.span_suggestion(
span, span,
"use the fully qualified path to an implementation", "use the fully qualified path to an implementation",
format!("<Type as {}>::{}", self.tcx.def_path_str(trait_ref), assoc_item.ident), format!("<Type as {}>::{}", self.tcx.def_path_str(trait_ref), assoc_item.name),
Applicability::HasPlaceholders, Applicability::HasPlaceholders,
); );
} }

View file

@ -89,7 +89,7 @@ fn object_safety_violations_for_trait(
.filter(|item| item.kind == ty::AssocKind::Fn) .filter(|item| item.kind == ty::AssocKind::Fn)
.filter_map(|item| { .filter_map(|item| {
object_safety_violation_for_method(tcx, trait_def_id, &item) object_safety_violation_for_method(tcx, trait_def_id, &item)
.map(|(code, span)| ObjectSafetyViolation::Method(item.ident.name, code, span)) .map(|(code, span)| ObjectSafetyViolation::Method(item.name, code, span))
}) })
.filter(|violation| { .filter(|violation| {
if let ObjectSafetyViolation::Method( if let ObjectSafetyViolation::Method(
@ -125,7 +125,10 @@ fn object_safety_violations_for_trait(
tcx.associated_items(trait_def_id) tcx.associated_items(trait_def_id)
.in_definition_order() .in_definition_order()
.filter(|item| item.kind == ty::AssocKind::Const) .filter(|item| item.kind == ty::AssocKind::Const)
.map(|item| ObjectSafetyViolation::AssocConst(item.ident.name, item.ident.span)), .map(|item| {
let ident = item.ident(tcx);
ObjectSafetyViolation::AssocConst(ident.name, ident.span)
}),
); );
violations.extend( violations.extend(
@ -133,7 +136,10 @@ fn object_safety_violations_for_trait(
.in_definition_order() .in_definition_order()
.filter(|item| item.kind == ty::AssocKind::Type) .filter(|item| item.kind == ty::AssocKind::Type)
.filter(|item| !tcx.generics_of(item.def_id).params.is_empty()) .filter(|item| !tcx.generics_of(item.def_id).params.is_empty())
.map(|item| ObjectSafetyViolation::GAT(item.ident.name, item.ident.span)), .map(|item| {
let ident = item.ident(tcx);
ObjectSafetyViolation::GAT(ident.name, ident.span)
}),
); );
debug!( debug!(
@ -367,15 +373,15 @@ fn object_safety_violation_for_method(
(MethodViolationCode::ReferencesSelfInput(arg), Some(node)) => node (MethodViolationCode::ReferencesSelfInput(arg), Some(node)) => node
.fn_decl() .fn_decl()
.and_then(|decl| decl.inputs.get(arg + 1)) .and_then(|decl| decl.inputs.get(arg + 1))
.map_or(method.ident.span, |arg| arg.span), .map_or(method.ident(tcx).span, |arg| arg.span),
(MethodViolationCode::UndispatchableReceiver, Some(node)) => node (MethodViolationCode::UndispatchableReceiver, Some(node)) => node
.fn_decl() .fn_decl()
.and_then(|decl| decl.inputs.get(0)) .and_then(|decl| decl.inputs.get(0))
.map_or(method.ident.span, |arg| arg.span), .map_or(method.ident(tcx).span, |arg| arg.span),
(MethodViolationCode::ReferencesSelfOutput, Some(node)) => { (MethodViolationCode::ReferencesSelfOutput, Some(node)) => {
node.fn_decl().map_or(method.ident.span, |decl| decl.output.span()) node.fn_decl().map_or(method.ident(tcx).span, |decl| decl.output.span())
} }
_ => method.ident.span, _ => method.ident(tcx).span,
}; };
(v, span) (v, span)
}) })
@ -404,10 +410,10 @@ fn virtual_call_violation_for_method<'tcx>(
); );
// Get the span pointing at where the `self` receiver should be. // Get the span pointing at where the `self` receiver should be.
let sm = tcx.sess.source_map(); let sm = tcx.sess.source_map();
let self_span = method.ident.span.to(tcx let self_span = method.ident(tcx).span.to(tcx
.hir() .hir()
.span_if_local(method.def_id) .span_if_local(method.def_id)
.unwrap_or_else(|| sm.next_point(method.ident.span)) .unwrap_or_else(|| sm.next_point(method.ident(tcx).span))
.shrink_to_hi()); .shrink_to_hi());
let self_span = sm.span_through_char(self_span, '(').shrink_to_hi(); let self_span = sm.span_through_char(self_span, '(').shrink_to_hi();
return Some(MethodViolationCode::StaticMethod( return Some(MethodViolationCode::StaticMethod(

View file

@ -1600,7 +1600,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
gen_sig, gen_sig,
) )
.map_bound(|(trait_ref, yield_ty, return_ty)| { .map_bound(|(trait_ref, yield_ty, return_ty)| {
let name = tcx.associated_item(obligation.predicate.item_def_id).ident.name; let name = tcx.associated_item(obligation.predicate.item_def_id).name;
let ty = if name == sym::Return { let ty = if name == sym::Return {
return_ty return_ty
} else if name == sym::Yield { } else if name == sym::Yield {
@ -1842,7 +1842,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
// just return Error. // just return Error.
debug!( debug!(
"confirm_impl_candidate: no associated type {:?} for {:?}", "confirm_impl_candidate: no associated type {:?} for {:?}",
assoc_ty.item.ident, obligation.predicate assoc_ty.item.name, obligation.predicate
); );
return Progress { ty: tcx.ty_error(), obligations: nested }; return Progress { ty: tcx.ty_error(), obligations: nested };
} }

View file

@ -100,7 +100,7 @@ fn associated_item_from_trait_item_ref(
}; };
ty::AssocItem { ty::AssocItem {
ident: trait_item_ref.ident, name: trait_item_ref.ident.name,
kind, kind,
vis: tcx.visibility(def_id), vis: tcx.visibility(def_id),
defaultness: trait_item_ref.defaultness, defaultness: trait_item_ref.defaultness,
@ -124,7 +124,7 @@ fn associated_item_from_impl_item_ref(
}; };
ty::AssocItem { ty::AssocItem {
ident: impl_item_ref.ident, name: impl_item_ref.ident.name,
kind, kind,
vis: tcx.visibility(def_id), vis: tcx.visibility(def_id),
defaultness: impl_item_ref.defaultness, defaultness: impl_item_ref.defaultness,

View file

@ -214,7 +214,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.map(|r| self.tcx().associated_items(r.def_id()).in_definition_order()) .map(|r| self.tcx().associated_items(r.def_id()).in_definition_order())
.flatten() .flatten()
.filter_map( .filter_map(
|item| if item.kind == ty::AssocKind::Type { Some(item.ident.name) } else { None }, |item| if item.kind == ty::AssocKind::Type { Some(item.name) } else { None },
) )
.collect(); .collect();
@ -270,7 +270,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let trait_def_id = assoc_item.container.id(); let trait_def_id = assoc_item.container.id();
names.push(format!( names.push(format!(
"`{}` (from trait `{}`)", "`{}` (from trait `{}`)",
assoc_item.ident, assoc_item.name,
tcx.def_path_str(trait_def_id), tcx.def_path_str(trait_def_id),
)); ));
} }
@ -327,11 +327,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let mut names: FxHashMap<_, usize> = FxHashMap::default(); let mut names: FxHashMap<_, usize> = FxHashMap::default();
for item in assoc_items { for item in assoc_items {
types_count += 1; types_count += 1;
*names.entry(item.ident.name).or_insert(0) += 1; *names.entry(item.name).or_insert(0) += 1;
} }
let mut dupes = false; let mut dupes = false;
for item in assoc_items { for item in assoc_items {
let prefix = if names[&item.ident.name] > 1 { let prefix = if names[&item.name] > 1 {
let trait_def_id = item.container.id(); let trait_def_id = item.container.id();
dupes = true; dupes = true;
format!("{}::", tcx.def_path_str(trait_def_id)) format!("{}::", tcx.def_path_str(trait_def_id))
@ -339,7 +339,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
String::new() String::new()
}; };
if let Some(sp) = tcx.hir().span_if_local(item.def_id) { if let Some(sp) = tcx.hir().span_if_local(item.def_id) {
err.span_label(sp, format!("`{}{}` defined here", prefix, item.ident)); err.span_label(sp, format!("`{}{}` defined here", prefix, item.name));
} }
} }
if potential_assoc_types.len() == assoc_items.len() { if potential_assoc_types.len() == assoc_items.len() {
@ -350,14 +350,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// `Iterator<Item = isize>`. // `Iterator<Item = isize>`.
for (potential, item) in iter::zip(&potential_assoc_types, assoc_items) { for (potential, item) in iter::zip(&potential_assoc_types, assoc_items) {
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(*potential) { if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(*potential) {
suggestions.push((*potential, format!("{} = {}", item.ident, snippet))); suggestions.push((*potential, format!("{} = {}", item.name, snippet)));
} }
} }
} else if let (Ok(snippet), false) = } else if let (Ok(snippet), false) =
(tcx.sess.source_map().span_to_snippet(*span), dupes) (tcx.sess.source_map().span_to_snippet(*span), dupes)
{ {
let types: Vec<_> = let types: Vec<_> =
assoc_items.iter().map(|item| format!("{} = Type", item.ident)).collect(); assoc_items.iter().map(|item| format!("{} = Type", item.name)).collect();
let code = if snippet.ends_with('>') { let code = if snippet.ends_with('>') {
// The user wrote `Trait<'a>` or similar and we don't have a type we can // The user wrote `Trait<'a>` or similar and we don't have a type we can
// suggest, but at least we can clue them to the correct syntax // suggest, but at least we can clue them to the correct syntax
@ -388,17 +388,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let mut names: FxHashMap<_, usize> = FxHashMap::default(); let mut names: FxHashMap<_, usize> = FxHashMap::default();
for item in assoc_items { for item in assoc_items {
types_count += 1; types_count += 1;
*names.entry(item.ident.name).or_insert(0) += 1; *names.entry(item.name).or_insert(0) += 1;
} }
let mut label = vec![]; let mut label = vec![];
for item in assoc_items { for item in assoc_items {
let postfix = if names[&item.ident.name] > 1 { let postfix = if names[&item.name] > 1 {
let trait_def_id = item.container.id(); let trait_def_id = item.container.id();
format!(" (from trait `{}`)", tcx.def_path_str(trait_def_id)) format!(" (from trait `{}`)", tcx.def_path_str(trait_def_id))
} else { } else {
String::new() String::new()
}; };
label.push(format!("`{}`{}", item.ident, postfix)); label.push(format!("`{}`{}", item.name, postfix));
} }
if !label.is_empty() { if !label.is_empty() {
err.span_label( err.span_label(

View file

@ -1137,7 +1137,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.filter_by_name_unhygienic(assoc_ident.name) .filter_by_name_unhygienic(assoc_ident.name)
.find(|i| { .find(|i| {
(i.kind == ty::AssocKind::Type || i.kind == ty::AssocKind::Const) (i.kind == ty::AssocKind::Type || i.kind == ty::AssocKind::Const)
&& i.ident.normalize_to_macros_2_0() == assoc_ident && i.ident(tcx).normalize_to_macros_2_0() == assoc_ident
}) })
.expect("missing associated type"); .expect("missing associated type");
// FIXME(associated_const_equality): need to handle assoc_consts here as well. // FIXME(associated_const_equality): need to handle assoc_consts here as well.
@ -1176,7 +1176,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// Include substitutions for generic parameters of associated types // Include substitutions for generic parameters of associated types
let projection_ty = candidate.map_bound(|trait_ref| { let projection_ty = candidate.map_bound(|trait_ref| {
let ident = Ident::new(assoc_ty.ident.name, binding.item_name.span); let ident = Ident::new(assoc_ty.name, binding.item_name.span);
let item_segment = hir::PathSegment { let item_segment = hir::PathSegment {
ident, ident,
hir_id: Some(binding.hir_id), hir_id: Some(binding.hir_id),
@ -1868,7 +1868,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.in_definition_order() .in_definition_order()
.find(|i| { .find(|i| {
i.kind.namespace() == Namespace::TypeNS i.kind.namespace() == Namespace::TypeNS
&& i.ident.normalize_to_macros_2_0() == assoc_ident && i.ident(tcx).normalize_to_macros_2_0() == assoc_ident
}) })
.expect("missing associated type"); .expect("missing associated type");

View file

@ -999,7 +999,7 @@ fn check_impl_items_against_trait<'tcx>(
if is_implemented_here { if is_implemented_here {
let trait_item = tcx.associated_item(trait_item_id); let trait_item = tcx.associated_item(trait_item_id);
if required_items.contains(&trait_item.ident) { if required_items.contains(&trait_item.ident(tcx)) {
must_implement_one_of = None; must_implement_one_of = None;
} }
} }

View file

@ -300,7 +300,7 @@ fn compare_predicate_entailment<'tcx>(
cause.span(tcx), cause.span(tcx),
E0053, E0053,
"method `{}` has an incompatible type for trait", "method `{}` has an incompatible type for trait",
trait_m.ident trait_m.name
); );
match &terr { match &terr {
TypeError::ArgumentMutability(0) | TypeError::ArgumentSorts(_, 0) TypeError::ArgumentMutability(0) | TypeError::ArgumentSorts(_, 0)
@ -452,7 +452,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait { tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait {
span, span,
item_kind, item_kind,
ident: impl_m.ident, ident: impl_m.ident(tcx),
generics_span, generics_span,
}); });
return Err(ErrorReported); return Err(ErrorReported);
@ -540,14 +540,14 @@ fn compare_self_type<'tcx>(
impl_m_span, impl_m_span,
E0185, E0185,
"method `{}` has a `{}` declaration in the impl, but not in the trait", "method `{}` has a `{}` declaration in the impl, but not in the trait",
trait_m.ident, trait_m.name,
self_descr self_descr
); );
err.span_label(impl_m_span, format!("`{}` used in impl", self_descr)); err.span_label(impl_m_span, format!("`{}` used in impl", self_descr));
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) { if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
err.span_label(span, format!("trait method declared without `{}`", self_descr)); err.span_label(span, format!("trait method declared without `{}`", self_descr));
} else { } else {
err.note_trait_signature(trait_m.ident.to_string(), trait_m.signature(tcx)); err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
} }
err.emit(); err.emit();
return Err(ErrorReported); return Err(ErrorReported);
@ -560,14 +560,14 @@ fn compare_self_type<'tcx>(
impl_m_span, impl_m_span,
E0186, E0186,
"method `{}` has a `{}` declaration in the trait, but not in the impl", "method `{}` has a `{}` declaration in the trait, but not in the impl",
trait_m.ident, trait_m.name,
self_descr self_descr
); );
err.span_label(impl_m_span, format!("expected `{}` in impl", self_descr)); err.span_label(impl_m_span, format!("expected `{}` in impl", self_descr));
if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) { if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
err.span_label(span, format!("`{}` used in trait", self_descr)); err.span_label(span, format!("`{}` used in trait", self_descr));
} else { } else {
err.note_trait_signature(trait_m.ident.to_string(), trait_m.signature(tcx)); err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
} }
err.emit(); err.emit();
return Err(ErrorReported); return Err(ErrorReported);
@ -640,7 +640,7 @@ fn compare_number_of_generics<'tcx>(
"{} `{}` has {} {kind} parameter{} but its trait \ "{} `{}` has {} {kind} parameter{} but its trait \
declaration has {} {kind} parameter{}", declaration has {} {kind} parameter{}",
item_kind, item_kind,
trait_.ident, trait_.name,
impl_count, impl_count,
pluralize!(impl_count), pluralize!(impl_count),
trait_count, trait_count,
@ -747,7 +747,7 @@ fn compare_number_of_method_arguments<'tcx>(
impl_span, impl_span,
E0050, E0050,
"method `{}` has {} but the declaration in trait `{}` has {}", "method `{}` has {} but the declaration in trait `{}` has {}",
trait_m.ident, trait_m.name,
potentially_plural_count(impl_number_args, "parameter"), potentially_plural_count(impl_number_args, "parameter"),
tcx.def_path_str(trait_m.def_id), tcx.def_path_str(trait_m.def_id),
trait_number_args trait_number_args
@ -761,7 +761,7 @@ fn compare_number_of_method_arguments<'tcx>(
), ),
); );
} else { } else {
err.note_trait_signature(trait_m.ident.to_string(), trait_m.signature(tcx)); err.note_trait_signature(trait_m.name.to_string(), trait_m.signature(tcx));
} }
err.span_label( err.span_label(
impl_span, impl_span,
@ -811,7 +811,7 @@ fn compare_synthetic_generics<'tcx>(
impl_span, impl_span,
E0643, E0643,
"method `{}` has incompatible signature for trait", "method `{}` has incompatible signature for trait",
trait_m.ident trait_m.name
); );
err.span_label(trait_span, "declaration in trait here"); err.span_label(trait_span, "declaration in trait here");
match (impl_synthetic, trait_synthetic) { match (impl_synthetic, trait_synthetic) {
@ -965,7 +965,7 @@ fn compare_const_param_types<'tcx>(
*impl_span, *impl_span,
E0053, E0053,
"method `{}` has an incompatible const parameter type for trait", "method `{}` has an incompatible const parameter type for trait",
trait_m.ident trait_m.name
); );
err.span_note( err.span_note(
trait_span.map_or_else(|| trait_item_span.unwrap_or(*impl_span), |span| *span), trait_span.map_or_else(|| trait_item_span.unwrap_or(*impl_span), |span| *span),
@ -1053,7 +1053,7 @@ crate fn compare_const_impl<'tcx>(
cause.span, cause.span,
E0326, E0326,
"implemented const `{}` has an incompatible type for trait", "implemented const `{}` has an incompatible type for trait",
trait_c.ident trait_c.name
); );
let trait_c_span = trait_c.def_id.as_local().map(|trait_c_def_id| { let trait_c_span = trait_c.def_id.as_local().map(|trait_c_def_id| {

View file

@ -237,7 +237,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) { if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
let mut suggestions = iter::zip(iter::repeat(&expr_text), &methods) let mut suggestions = iter::zip(iter::repeat(&expr_text), &methods)
.filter_map(|(receiver, method)| { .filter_map(|(receiver, method)| {
let method_call = format!(".{}()", method.ident); let method_call = format!(".{}()", method.name);
if receiver.ends_with(&method_call) { if receiver.ends_with(&method_call) {
None // do not suggest code that is already there (#53348) None // do not suggest code that is already there (#53348)
} else { } else {

View file

@ -1033,7 +1033,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
true true
} }
}) })
.map(|candidate| candidate.item.ident) .map(|candidate| candidate.item.ident(self.tcx))
.filter(|&name| set.insert(name)) .filter(|&name| set.insert(name))
.collect(); .collect();
@ -1438,7 +1438,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
"<{} as {}>::{}", "<{} as {}>::{}",
stable_pick.self_ty, stable_pick.self_ty,
self.tcx.def_path_str(def_id), self.tcx.def_path_str(def_id),
stable_pick.item.ident stable_pick.item.name
), ),
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
@ -1748,14 +1748,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let best_name = { let best_name = {
let names = applicable_close_candidates let names = applicable_close_candidates
.iter() .iter()
.map(|cand| cand.ident.name) .map(|cand| cand.name)
.collect::<Vec<Symbol>>(); .collect::<Vec<Symbol>>();
find_best_match_for_name(&names, self.method_name.unwrap().name, None) find_best_match_for_name(&names, self.method_name.unwrap().name, None)
} }
.unwrap(); .unwrap();
Ok(applicable_close_candidates Ok(applicable_close_candidates.into_iter().find(|method| method.name == best_name))
.into_iter()
.find(|method| method.ident.name == best_name))
} }
}) })
} }
@ -1906,7 +1904,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
.associated_items(def_id) .associated_items(def_id)
.in_definition_order() .in_definition_order()
.filter(|x| { .filter(|x| {
let dist = lev_distance(name.as_str(), x.ident.as_str()); let dist = lev_distance(name.as_str(), x.name.as_str());
x.kind.namespace() == Namespace::ValueNS && dist > 0 && dist <= max_dist x.kind.namespace() == Namespace::ValueNS && dist > 0 && dist <= max_dist
}) })
.copied() .copied()

View file

@ -1025,7 +1025,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
def_kind.article(), def_kind.article(),
def_kind.descr(lev_candidate.def_id), def_kind.descr(lev_candidate.def_id),
), ),
lev_candidate.ident.to_string(), lev_candidate.name.to_string(),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
); );
} }
@ -1480,7 +1480,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let skip = skippable.contains(&did); let skip = skippable.contains(&did);
if pick.autoderefs == 0 && !skip { if pick.autoderefs == 0 && !skip {
err.span_label( err.span_label(
pick.item.ident.span, pick.item.ident(self.tcx).span,
&format!("the method is available for `{}` here", rcvr_ty), &format!("the method is available for `{}` here", rcvr_ty),
); );
} }
@ -1514,7 +1514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// an autoderef to `&self` // an autoderef to `&self`
if pick.autoderefs == 0 && !skip { if pick.autoderefs == 0 && !skip {
err.span_label( err.span_label(
pick.item.ident.span, pick.item.ident(self.tcx).span,
&format!("the method is available for `{}` here", new_rcvr_t), &format!("the method is available for `{}` here", new_rcvr_t),
); );
err.multipart_suggestion( err.multipart_suggestion(

View file

@ -599,7 +599,7 @@ fn missing_items_err(
) { ) {
let missing_items_msg = missing_items let missing_items_msg = missing_items
.iter() .iter()
.map(|trait_item| trait_item.ident.to_string()) .map(|trait_item| trait_item.name.to_string())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("`, `"); .join("`, `");
@ -628,7 +628,7 @@ fn missing_items_err(
let msg = format!("implement the missing item: `{}`", snippet); let msg = format!("implement the missing item: `{}`", snippet);
let appl = Applicability::HasPlaceholders; let appl = Applicability::HasPlaceholders;
if let Some(span) = tcx.hir().span_if_local(trait_item.def_id) { if let Some(span) = tcx.hir().span_if_local(trait_item.def_id) {
err.span_label(span, format!("`{}` from trait", trait_item.ident)); err.span_label(span, format!("`{}` from trait", trait_item.name));
err.tool_only_span_suggestion(sugg_sp, &msg, code, appl); err.tool_only_span_suggestion(sugg_sp, &msg, code, appl);
} else { } else {
err.span_suggestion_hidden(sugg_sp, &msg, code, appl); err.span_suggestion_hidden(sugg_sp, &msg, code, appl);
@ -805,16 +805,16 @@ fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
fn_sig_suggestion( fn_sig_suggestion(
tcx, tcx,
tcx.fn_sig(assoc.def_id).skip_binder(), tcx.fn_sig(assoc.def_id).skip_binder(),
assoc.ident, assoc.ident(tcx),
tcx.predicates_of(assoc.def_id), tcx.predicates_of(assoc.def_id),
assoc, assoc,
) )
} }
ty::AssocKind::Type => format!("type {} = Type;", assoc.ident), ty::AssocKind::Type => format!("type {} = Type;", assoc.name),
ty::AssocKind::Const => { ty::AssocKind::Const => {
let ty = tcx.type_of(assoc.def_id); let ty = tcx.type_of(assoc.def_id);
let val = expr::ty_kind_suggestion(ty).unwrap_or("value"); let val = expr::ty_kind_suggestion(ty).unwrap_or("value");
format!("const {}: {} = {};", assoc.ident, ty, val) format!("const {}: {} = {};", assoc.name, ty, val)
} }
} }
} }

View file

@ -864,7 +864,7 @@ fn check_associated_item(
let hir_sig = sig_if_method.expect("bad signature for method"); let hir_sig = sig_if_method.expect("bad signature for method");
check_fn_or_method( check_fn_or_method(
fcx, fcx,
item.ident.span, item.ident(fcx.tcx).span,
sig, sig,
hir_sig.decl, hir_sig.decl,
item.def_id, item.def_id,

View file

@ -36,7 +36,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
for item1 in impl_items1.in_definition_order() { for item1 in impl_items1.in_definition_order() {
let collision = impl_items2 let collision = impl_items2
.filter_by_name_unhygienic(item1.ident.name) .filter_by_name_unhygienic(item1.name)
.any(|item2| self.compare_hygienically(item1, item2)); .any(|item2| self.compare_hygienically(item1, item2));
if collision { if collision {
@ -50,7 +50,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
fn compare_hygienically(&self, item1: &ty::AssocItem, item2: &ty::AssocItem) -> bool { fn compare_hygienically(&self, item1: &ty::AssocItem, item2: &ty::AssocItem) -> bool {
// Symbols and namespace match, compare hygienically. // Symbols and namespace match, compare hygienically.
item1.kind.namespace() == item2.kind.namespace() item1.kind.namespace() == item2.kind.namespace()
&& item1.ident.normalize_to_macros_2_0() == item2.ident.normalize_to_macros_2_0() && item1.ident(self.tcx).normalize_to_macros_2_0()
== item2.ident(self.tcx).normalize_to_macros_2_0()
} }
fn check_for_common_items_in_impls( fn check_for_common_items_in_impls(
@ -64,11 +65,11 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
for item1 in impl_items1.in_definition_order() { for item1 in impl_items1.in_definition_order() {
let collision = impl_items2 let collision = impl_items2
.filter_by_name_unhygienic(item1.ident.name) .filter_by_name_unhygienic(item1.name)
.find(|item2| self.compare_hygienically(item1, item2)); .find(|item2| self.compare_hygienically(item1, item2));
if let Some(item2) = collision { if let Some(item2) = collision {
let name = item1.ident.normalize_to_macros_2_0(); let name = item1.ident(self.tcx).normalize_to_macros_2_0();
let mut err = struct_span_err!( let mut err = struct_span_err!(
self.tcx.sess, self.tcx.sess,
self.tcx.span_of_impl(item1.def_id).unwrap(), self.tcx.span_of_impl(item1.def_id).unwrap(),
@ -181,11 +182,11 @@ impl<'tcx> ItemLikeVisitor<'_> for InherentOverlapChecker<'tcx> {
let mut ids = impl_items let mut ids = impl_items
.in_definition_order() .in_definition_order()
.filter_map(|item| { .filter_map(|item| {
let entry = connected_region_ids.entry(item.ident.name); let entry = connected_region_ids.entry(item.name);
if let Entry::Occupied(e) = &entry { if let Entry::Occupied(e) = &entry {
Some(*e.get()) Some(*e.get())
} else { } else {
idents_to_add.push(item.ident.name); idents_to_add.push(item.name);
None None
} }
}) })

View file

@ -387,7 +387,7 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
let trait_ = lifted.trait_ref(cx.tcx).clean(cx); let trait_ = lifted.trait_ref(cx.tcx).clean(cx);
let self_type = self.self_ty().clean(cx); let self_type = self.self_ty().clean(cx);
Type::QPath { Type::QPath {
name: cx.tcx.associated_item(self.item_def_id).ident.name, name: cx.tcx.associated_item(self.item_def_id).name,
self_def_id: self_type.def_id(&cx.cache), self_def_id: self_type.def_id(&cx.cache),
self_type: box self_type, self_type: box self_type,
trait_, trait_,
@ -1131,7 +1131,7 @@ impl Clean<Item> for ty::AssocItem {
} }
} }
ty::AssocKind::Type => { ty::AssocKind::Type => {
let my_name = self.ident.name; let my_name = self.name;
if let ty::TraitContainer(_) = self.container { if let ty::TraitContainer(_) = self.container {
let bounds = tcx.explicit_item_bounds(self.def_id); let bounds = tcx.explicit_item_bounds(self.def_id);
@ -1197,7 +1197,7 @@ impl Clean<Item> for ty::AssocItem {
} }
}; };
Item::from_def_id_and_parts(self.def_id, Some(self.ident.name), kind, cx) Item::from_def_id_and_parts(self.def_id, Some(self.name), kind, cx)
} }
} }
@ -1521,7 +1521,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
let mut bindings = vec![]; let mut bindings = vec![];
for pb in obj.projection_bounds() { for pb in obj.projection_bounds() {
bindings.push(TypeBinding { bindings.push(TypeBinding {
name: cx.tcx.associated_item(pb.item_def_id()).ident.name, name: cx.tcx.associated_item(pb.item_def_id()).name,
kind: TypeBindingKind::Equality { kind: TypeBindingKind::Equality {
term: pb.skip_binder().term.clean(cx).into(), term: pb.skip_binder().term.clean(cx).into(),
}, },
@ -1592,7 +1592,6 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
name: cx name: cx
.tcx .tcx
.associated_item(proj.projection_ty.item_def_id) .associated_item(proj.projection_ty.item_def_id)
.ident
.name, .name,
kind: TypeBindingKind::Equality { kind: TypeBindingKind::Equality {
term: proj.term.clean(cx), term: proj.term.clean(cx),

View file

@ -2194,7 +2194,7 @@ impl Impl {
self.trait_ self.trait_
.as_ref() .as_ref()
.map(|t| t.def_id()) .map(|t| t.def_id())
.map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.name).collect()) .map(|did| tcx.provided_trait_methods(did).map(|meth| meth.name).collect())
.unwrap_or_default() .unwrap_or_default()
} }
} }

View file

@ -427,7 +427,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
.inherent_impls(did) .inherent_impls(did)
.iter() .iter()
.flat_map(|imp| tcx.associated_items(*imp).in_definition_order()) .flat_map(|imp| tcx.associated_items(*imp).in_definition_order())
.any(|item| item.ident.name == variant_name) .any(|item| item.name == variant_name)
{ {
// This is just to let `fold_item` know that this shouldn't be considered; // This is just to let `fold_item` know that this shouldn't be considered;
// it's a bug for the error to make it to the user // it's a bug for the error to make it to the user

View file

@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
.filter(|assoc_item| { .filter(|assoc_item| {
matches!(assoc_item.kind, AssocKind::Fn) matches!(assoc_item.kind, AssocKind::Fn)
}) })
.map(|assoc_item| assoc_item.ident.name) .map(|assoc_item| assoc_item.name)
.collect() .collect()
}else{ }else{
BTreeSet::new() BTreeSet::new()