summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2022-01-02 22:37:05 -0500
committerAaron Hill <aa1ronham@gmail.com>2022-01-11 10:16:22 -0500
commit450ef8613ce80278b98e1b1a73448ea810322567 (patch)
treee08cf73fb202a792894812d4e8c435940196b496
parente4b1d5841494d6eb7f4944c91a057e16b0f0a9ea (diff)
downloadrust-450ef8613ce80278b98e1b1a73448ea810322567.tar.gz
Store a `Symbol` instead of an `Ident` in `VariantDef`/`FieldDef`
The field is also renamed from `ident` to `name. In most cases, we don't actually need the `Span`. A new `ident` method is added to `VariantDef` and `FieldDef`, which constructs the full `Ident` using `tcx.def_ident_span()`. This method is used in the cases where we actually need an `Ident`. This makes incremental compilation properly track changes to the `Span`, without all of the invalidations caused by storing a `Span` directly via an `Ident`.
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mod.rs2
-rw-r--r--compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs2
-rw-r--r--compiler/rustc_codegen_gcc/src/type_of.rs2
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs12
-rw-r--r--compiler/rustc_codegen_llvm/src/type_of.rs2
-rw-r--r--compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs4
-rw-r--r--compiler/rustc_const_eval/src/interpret/validity.rs6
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/mod.rs2
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder.rs4
-rw-r--r--compiler/rustc_metadata/src/rmeta/encoder.rs4
-rw-r--r--compiler/rustc_middle/src/mir/mod.rs4
-rw-r--r--compiler/rustc_middle/src/thir.rs4
-rw-r--r--compiler/rustc_middle/src/ty/closure.rs4
-rw-r--r--compiler/rustc_middle/src/ty/context.rs2
-rw-r--r--compiler/rustc_middle/src/ty/layout.rs15
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs29
-rw-r--r--compiler/rustc_middle/src/ty/print/pretty.rs2
-rw-r--r--compiler/rustc_mir_build/src/build/expr/as_place.rs5
-rw-r--r--compiler/rustc_mir_build/src/build/matches/test.rs6
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/check_match.rs4
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs2
-rw-r--r--compiler/rustc_mir_dataflow/src/elaborate_drops.rs2
-rw-r--r--compiler/rustc_privacy/src/lib.rs4
-rw-r--r--compiler/rustc_typeck/src/astconv/mod.rs4
-rw-r--r--compiler/rustc_typeck/src/check/check.rs2
-rw-r--r--compiler/rustc_typeck/src/check/expr.rs55
-rw-r--r--compiler/rustc_typeck/src/check/method/mod.rs2
-rw-r--r--compiler/rustc_typeck/src/check/method/suggest.rs2
-rw-r--r--compiler/rustc_typeck/src/check/pat.rs9
-rw-r--r--compiler/rustc_typeck/src/coherence/builtin.rs6
-rw-r--r--compiler/rustc_typeck/src/collect.rs4
-rw-r--r--src/librustdoc/clean/mod.rs4
-rw-r--r--src/librustdoc/html/render/print_item.rs4
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/default.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/matches.rs2
38 files changed, 120 insertions, 107 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs
index e2eb125981f..84acfbf941d 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mod.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs
@@ -372,7 +372,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} else {
def.non_enum_variant()
};
- variant.fields[field.index()].ident.to_string()
+ variant.fields[field.index()].name.to_string()
}
ty::Tuple(_) => field.index().to_string(),
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {
diff --git a/compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs b/compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs
index 638b025be22..8e203b8cfa0 100644
--- a/compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs
+++ b/compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs
@@ -174,7 +174,7 @@ impl<'tcx> DebugContext<'tcx> {
field_entry.set(
gimli::DW_AT_name,
- AttributeValue::String(field_def.ident.as_str().to_string().into_bytes()),
+ AttributeValue::String(field_def.name.as_str().to_string().into_bytes()),
);
field_entry.set(
gimli::DW_AT_data_member_location,
diff --git a/compiler/rustc_codegen_gcc/src/type_of.rs b/compiler/rustc_codegen_gcc/src/type_of.rs
index 9c39c8f91a1..281e49fa8a3 100644
--- a/compiler/rustc_codegen_gcc/src/type_of.rs
+++ b/compiler/rustc_codegen_gcc/src/type_of.rs
@@ -57,7 +57,7 @@ pub fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLa
(layout.ty.kind(), &layout.variants)
{
if def.is_enum() && !def.variants.is_empty() {
- write!(&mut name, "::{}", def.variants[index].ident).unwrap();
+ write!(&mut name, "::{}", def.variants[index].name).unwrap();
}
}
if let (&ty::Generator(_, _, _), &Variants::Single { index }) =
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
index 60ff18af0a9..5c02e3d0fa7 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
@@ -1300,7 +1300,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> {
let name = if self.variant.ctor_kind == CtorKind::Fn {
format!("__{}", i)
} else {
- f.ident.to_string()
+ f.name.to_string()
};
let field = layout.field(cx, i);
MemberDescription {
@@ -1480,7 +1480,7 @@ impl<'tcx> UnionMemberDescriptionFactory<'tcx> {
.map(|(i, f)| {
let field = self.layout.field(cx, i);
MemberDescription {
- name: f.ident.to_string(),
+ name: f.name.to_string(),
type_metadata: type_metadata(cx, field.ty, self.span),
offset: Size::ZERO,
size: field.size,
@@ -1950,7 +1950,7 @@ enum VariantInfo<'a, 'tcx> {
impl<'tcx> VariantInfo<'_, 'tcx> {
fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
match self {
- VariantInfo::Adt(variant) => f(variant.ident.as_str()),
+ VariantInfo::Adt(variant) => f(variant.name.as_str()),
VariantInfo::Generator { variant_index, .. } => {
f(&GeneratorSubsts::variant_name(*variant_index))
}
@@ -1959,7 +1959,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
fn variant_name(&self) -> String {
match self {
- VariantInfo::Adt(variant) => variant.ident.to_string(),
+ VariantInfo::Adt(variant) => variant.name.to_string(),
VariantInfo::Generator { variant_index, .. } => {
// Since GDB currently prints out the raw discriminant along
// with every variant, make each variant name be just the value
@@ -1973,7 +1973,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
fn field_name(&self, i: usize) -> String {
let field_name = match *self {
VariantInfo::Adt(variant) if variant.ctor_kind != CtorKind::Fn => {
- Some(variant.fields[i].ident.name)
+ Some(variant.fields[i].name)
}
VariantInfo::Generator {
generator_layout,
@@ -2063,7 +2063,7 @@ fn prepare_enum_metadata<'ll, 'tcx>(
let enumerators_metadata: Vec<_> = match enum_type.kind() {
ty::Adt(def, _) => iter::zip(def.discriminants(tcx), &def.variants)
.map(|((_, discr), v)| {
- let name = v.ident.as_str();
+ let name = v.name.as_str();
let is_unsigned = match discr.ty.kind() {
ty::Int(_) => false,
ty::Uint(_) => true,
diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs
index f8c919ec2aa..81d0603bc52 100644
--- a/compiler/rustc_codegen_llvm/src/type_of.rs
+++ b/compiler/rustc_codegen_llvm/src/type_of.rs
@@ -49,7 +49,7 @@ fn uncached_llvm_type<'a, 'tcx>(
(layout.ty.kind(), &layout.variants)
{
if def.is_enum() && !def.variants.is_empty() {
- write!(&mut name, "::{}", def.variants[index].ident).unwrap();
+ write!(&mut name, "::{}", def.variants[index].name).unwrap();
}
}
if let (&ty::Generator(_, _, _), &Variants::Single { index }) =
diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
index 93bb1aee25f..9ecab82dd2e 100644
--- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
+++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
@@ -409,14 +409,14 @@ fn push_debuginfo_type_name<'tcx>(
let max = dataful_discriminant_range.end;
let max = tag.value.size(&tcx).truncate(max);
- let dataful_variant_name = def.variants[*dataful_variant].ident.as_str();
+ let dataful_variant_name = def.variants[*dataful_variant].name.as_str();
output.push_str(&format!(", {}, {}, {}", min, max, dataful_variant_name));
} else if let Variants::Single { index: variant_idx } = &layout.variants {
// Uninhabited enums can't be constructed and should never need to be visualized so
// skip this step for them.
if def.variants.len() != 0 {
- let variant = def.variants[*variant_idx].ident.as_str();
+ let variant = def.variants[*variant_idx].name.as_str();
output.push_str(&format!(", {}", variant));
}
diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs
index 5a398c2f45a..9dc7930fc51 100644
--- a/compiler/rustc_const_eval/src/interpret/validity.rs
+++ b/compiler/rustc_const_eval/src/interpret/validity.rs
@@ -267,14 +267,14 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
match layout.variants {
Variants::Single { index } => {
// Inside a variant
- PathElem::Field(def.variants[index].fields[field].ident.name)
+ PathElem::Field(def.variants[index].fields[field].name)
}
Variants::Multiple { .. } => bug!("we handled variants above"),
}
}
// other ADTs
- ty::Adt(def, _) => PathElem::Field(def.non_enum_variant().fields[field].ident.name),
+ ty::Adt(def, _) => PathElem::Field(def.non_enum_variant().fields[field].name),
// arrays/slices
ty::Array(..) | ty::Slice(..) => PathElem::ArrayElem(field),
@@ -726,7 +726,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
new_op: &OpTy<'tcx, M::PointerTag>,
) -> InterpResult<'tcx> {
let name = match old_op.layout.ty.kind() {
- ty::Adt(adt, _) => PathElem::Variant(adt.variants[variant_id].ident.name),
+ ty::Adt(adt, _) => PathElem::Variant(adt.variants[variant_id].name),
// Generators also have variants
ty::Generator(..) => PathElem::GeneratorState(variant_id),
_ => bug!("Unexpected type with variant: {:?}", old_op.layout.ty),
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
index f0c73d0c2f3..fc3bfd8fc2b 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
@@ -1924,7 +1924,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
.fields
.iter()
.filter(|field| field.vis.is_accessible_from(field.did, self.tcx))
- .map(|field| (field.ident.name, field.ty(self.tcx, expected_substs)))
+ .map(|field| (field.name, field.ty(self.tcx, expected_substs)))
.find(|(_, ty)| same_type_modulo_infer(ty, exp_found.found))
{
if let ObligationCauseCode::Pattern { span: Some(span), .. } = *cause.code() {
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs
index e39ea46c0c0..3ec384193c3 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -862,7 +862,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
let ctor_did = data.ctor.map(|index| self.local_def_id(index));
ty::VariantDef::new(
- self.item_ident(index, sess),
+ self.item_ident(index, sess).name,
variant_did,
ctor_did,
data.discr,
@@ -874,7 +874,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode(self)
.map(|index| ty::FieldDef {
did: self.local_def_id(index),
- ident: self.item_ident(index, sess),
+ name: self.item_ident(index, sess).name,
vis: self.get_visibility(index),
})
.collect(),
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs
index 2e556275fb5..fa1752aaec3 100644
--- a/compiler/rustc_metadata/src/rmeta/encoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/encoder.rs
@@ -1052,7 +1052,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
assert!(f.did.is_local());
f.did.index
}));
- self.encode_ident_span(def_id, variant.ident);
+ self.encode_ident_span(def_id, variant.ident(tcx));
self.encode_item_type(def_id);
if variant.ctor_kind == CtorKind::Fn {
// FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
@@ -1138,7 +1138,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_field({:?})", def_id);
record!(self.tables.kind[def_id] <- EntryKind::Field);
- self.encode_ident_span(def_id, field.ident);
+ self.encode_ident_span(def_id, field.ident(self.tcx));
self.encode_item_type(def_id);
}
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs
index 52ef380001c..6d1d9dd9720 100644
--- a/compiler/rustc_middle/src/mir/mod.rs
+++ b/compiler/rustc_middle/src/mir/mod.rs
@@ -2439,7 +2439,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
CtorKind::Fictive => {
let mut struct_fmt = fmt.debug_struct(&name);
for (field, place) in iter::zip(&variant_def.fields, places) {
- struct_fmt.field(field.ident.as_str(), place);
+ struct_fmt.field(field.name.as_str(), place);
}
struct_fmt.finish()
}
@@ -2785,7 +2785,7 @@ impl UserTypeProjection {
field: Field,
) -> Self {
self.projs.push(ProjectionElem::Downcast(
- Some(adt_def.variants[variant_index].ident.name),
+ Some(adt_def.variants[variant_index].name),
variant_index,
));
self.projs.push(ProjectionElem::Field(field, ()));
diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs
index 8d6fd1e729d..d2e3ce97d12 100644
--- a/compiler/rustc_middle/src/thir.rs
+++ b/compiler/rustc_middle/src/thir.rs
@@ -726,7 +726,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
};
if let Some(variant) = variant {
- write!(f, "{}", variant.ident)?;
+ write!(f, "{}", variant.name)?;
// Only for Adt we can have `S {...}`,
// which we handle separately here.
@@ -738,7 +738,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
if let PatKind::Wild = *p.pattern.kind {
continue;
}
- let name = variant.fields[p.field.index()].ident;
+ let name = variant.fields[p.field.index()].name;
write!(f, "{}{}: {}", start_or_comma(), name, p.pattern)?;
printed += 1;
}
diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs
index 771acc29649..c463d9a02f7 100644
--- a/compiler/rustc_middle/src/ty/closure.rs
+++ b/compiler/rustc_middle/src/ty/closure.rs
@@ -178,7 +178,7 @@ impl<'tcx> CapturedPlace<'tcx> {
write!(
&mut symbol,
"__{}",
- def.variants[variant].fields[idx as usize].ident.name.as_str(),
+ def.variants[variant].fields[idx as usize].name.as_str(),
)
.unwrap();
}
@@ -344,7 +344,7 @@ pub fn place_to_string_for_capture<'tcx>(tcx: TyCtxt<'tcx>, place: &HirPlace<'tc
curr_string = format!(
"{}.{}",
curr_string,
- def.variants[variant].fields[idx as usize].ident.name.as_str()
+ def.variants[variant].fields[idx as usize].name.as_str()
);
}
ty::Tuple(_) => {
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 86ad573b5d7..0c4e3becabe 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -2452,7 +2452,7 @@ impl<'tcx> TyCtxt<'tcx> {
) -> Place<'tcx> {
self.mk_place_elem(
place,
- PlaceElem::Downcast(Some(adt_def.variants[variant_index].ident.name), variant_index),
+ PlaceElem::Downcast(Some(adt_def.variants[variant_index].name), variant_index),
)
}
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs
index 196fe7ce1b6..4e6b2acb67f 100644
--- a/compiler/rustc_middle/src/ty/layout.rs
+++ b/compiler/rustc_middle/src/ty/layout.rs
@@ -10,7 +10,7 @@ use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::BitSet;
use rustc_index::vec::{Idx, IndexVec};
use rustc_session::{config::OptLevel, DataTypeKind, FieldInfo, SizeKind, VariantInfo};
-use rustc_span::symbol::{Ident, Symbol};
+use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::call::{
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode, Reg, RegKind,
@@ -1810,7 +1810,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
let adt_kind = adt_def.adt_kind();
let adt_packed = adt_def.repr.pack.is_some();
- let build_variant_info = |n: Option<Ident>, flds: &[Symbol], layout: TyAndLayout<'tcx>| {
+ let build_variant_info = |n: Option<Symbol>, flds: &[Symbol], layout: TyAndLayout<'tcx>| {
let mut min_size = Size::ZERO;
let field_info: Vec<_> = flds
.iter()
@@ -1845,15 +1845,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
if !adt_def.variants.is_empty() && layout.fields != FieldsShape::Primitive {
debug!(
"print-type-size `{:#?}` variant {}",
- layout, adt_def.variants[index].ident
+ layout, adt_def.variants[index].name
);
let variant_def = &adt_def.variants[index];
- let fields: Vec<_> = variant_def.fields.iter().map(|f| f.ident.name).collect();
+ let fields: Vec<_> = variant_def.fields.iter().map(|f| f.name).collect();
record(
adt_kind.into(),
adt_packed,
None,
- vec![build_variant_info(Some(variant_def.ident), &fields, layout)],
+ vec![build_variant_info(Some(variant_def.name), &fields, layout)],
);
} else {
// (This case arises for *empty* enums; so give it
@@ -1872,10 +1872,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
.variants
.iter_enumerated()
.map(|(i, variant_def)| {
- let fields: Vec<_> =
- variant_def.fields.iter().map(|f| f.ident.name).collect();
+ let fields: Vec<_> = variant_def.fields.iter().map(|f| f.name).collect();
build_variant_info(
- Some(variant_def.ident),
+ Some(variant_def.name),
&fields,
layout.for_variant(self, i),
)
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index 16adf93b69a..2b079696be2 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -1504,8 +1504,7 @@ pub struct VariantDef {
/// If this variant is a struct variant, then this is `None`.
pub ctor_def_id: Option<DefId>,
/// Variant or struct name.
- #[stable_hasher(project(name))]
- pub ident: Ident,
+ pub name: Symbol,
/// Discriminant of this variant.
pub discr: VariantDiscr,
/// Fields of this variant.
@@ -1534,7 +1533,7 @@ impl VariantDef {
/// If someone speeds up attribute loading to not be a performance concern, they can
/// remove this hack and use the constructor `DefId` everywhere.
pub fn new(
- ident: Ident,
+ name: Symbol,
variant_did: Option<DefId>,
ctor_def_id: Option<DefId>,
discr: VariantDiscr,
@@ -1546,9 +1545,9 @@ impl VariantDef {
is_field_list_non_exhaustive: bool,
) -> Self {
debug!(
- "VariantDef::new(ident = {:?}, variant_did = {:?}, ctor_def_id = {:?}, discr = {:?},
+ "VariantDef::new(name = {:?}, variant_did = {:?}, ctor_def_id = {:?}, discr = {:?},
fields = {:?}, ctor_kind = {:?}, adt_kind = {:?}, parent_did = {:?})",
- ident, variant_did, ctor_def_id, discr, fields, ctor_kind, adt_kind, parent_did,
+ name, variant_did, ctor_def_id, discr, fields, ctor_kind, adt_kind, parent_did,
);
let mut flags = VariantFlags::NO_VARIANT_FLAGS;
@@ -1563,7 +1562,7 @@ impl VariantDef {
VariantDef {
def_id: variant_did.unwrap_or(parent_did),
ctor_def_id,
- ident,
+ name,
discr,
fields,
ctor_kind,
@@ -1582,6 +1581,11 @@ impl VariantDef {
pub fn is_recovered(&self) -> bool {
self.flags.intersects(VariantFlags::IS_RECOVERED)
}
+
+ /// Computes the `Ident` of this variant by looking up the `Span`
+ pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
+ Ident::new(self.name, tcx.def_ident_span(self.def_id).unwrap())
+ }
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
@@ -1600,8 +1604,7 @@ pub enum VariantDiscr {
#[derive(Debug, HashStable, TyEncodable, TyDecodable)]
pub struct FieldDef {
pub did: DefId,
- #[stable_hasher(project(name))]
- pub ident: Ident,
+ pub name: Symbol,
pub vis: Visibility,
}
@@ -1776,6 +1779,11 @@ impl<'tcx> FieldDef {
pub fn ty(&self, tcx: TyCtxt<'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> {
tcx.type_of(self.did).subst(tcx, subst)
}
+
+ /// Computes the `Ident` of this variant by looking up the `Span`
+ pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
+ Ident::new(self.name, tcx.def_ident_span(self.did).unwrap())
+ }
}
pub type Attributes<'tcx> = &'tcx [ast::Attribute];
@@ -1892,7 +1900,10 @@ impl<'tcx> TyCtxt<'tcx> {
}
pub fn find_field_index(self, ident: Ident, variant: &VariantDef) -> Option<usize> {
- variant.fields.iter().position(|field| self.hygienic_eq(ident, field.ident, variant.def_id))
+ variant
+ .fields
+ .iter()
+ .position(|field| self.hygienic_eq(ident, field.ident(self), variant.def_id))
}
/// Returns `true` if the impls are the same polarity and the trait either
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs
index c6454f3e0d0..350386f8d93 100644
--- a/compiler/rustc_middle/src/ty/print/pretty.rs
+++ b/compiler/rustc_middle/src/ty/print/pretty.rs
@@ -1475,7 +1475,7 @@ pub trait PrettyPrinter<'tcx>:
if !first {
p!(", ");
}
- p!(write("{}: ", field_def.ident), print(field));
+ p!(write("{}: ", field_def.name), print(field));
first = false;
}
p!(" }}");
diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs
index c6a34ece245..b3126b72bb8 100644
--- a/compiler/rustc_mir_build/src/build/expr/as_place.rs
+++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs
@@ -336,10 +336,7 @@ impl<'tcx> PlaceBuilder<'tcx> {
}
crate fn downcast(self, adt_def: &'tcx AdtDef, variant_index: VariantIdx) -> Self {
- self.project(PlaceElem::Downcast(
- Some(adt_def.variants[variant_index].ident.name),
- variant_index,
- ))
+ self.project(PlaceElem::Downcast(Some(adt_def.variants[variant_index].name), variant_index))
}
fn index(self, index: Local) -> Self {
diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs
index a01df2372a0..7ed5d1d67ab 100644
--- a/compiler/rustc_mir_build/src/build/matches/test.rs
+++ b/compiler/rustc_mir_build/src/build/matches/test.rs
@@ -754,10 +754,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// So, if we have a match-pattern like `x @ Enum::Variant(P1, P2)`,
// we want to create a set of derived match-patterns like
// `(x as Variant).0 @ P1` and `(x as Variant).1 @ P1`.
- let elem = ProjectionElem::Downcast(
- Some(adt_def.variants[variant_index].ident.name),
- variant_index,
- );
+ let elem =
+ ProjectionElem::Downcast(Some(adt_def.variants[variant_index].name), variant_index);
let downcast_place = match_pair.place.project(elem); // `(x as Variant)`
let consequent_match_pairs = subpatterns.iter().map(|subpattern| {
// e.g., `(x as Variant).0`
diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs
index 7a4fd6ffc4a..0980c669f33 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs
@@ -327,7 +327,7 @@ fn check_for_bindings_named_same_as_variants(
if let ty::Adt(edef, _) = pat_ty.kind() {
if edef.is_enum()
&& edef.variants.iter().any(|variant| {
- variant.ident == ident && variant.ctor_kind == CtorKind::Const
+ variant.ident(cx.tcx) == ident && variant.ctor_kind == CtorKind::Const
})
{
let variant_count = edef.variants.len();
@@ -627,7 +627,7 @@ fn maybe_point_at_variant<'a, 'p: 'a, 'tcx: 'a>(
continue;
}
}
- let sp = def.variants[*variant_index].ident.span;
+ let sp = def.variants[*variant_index].ident(cx.tcx).span;
if covered.contains(&sp) {
// Don't point at variants that have already been covered due to other patterns to avoid
// visual clutter.
diff --git a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
index 368e3957dd0..801c8778bff 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
@@ -1648,7 +1648,7 @@ impl<'p, 'tcx> fmt::Debug for DeconstructedPat<'p, 'tcx> {
};
if let Some(variant) = variant {
- write!(f, "{}", variant.ident)?;
+ write!(f, "{}", variant.name)?;
}
// Without `cx`, we can't know which field corresponds to which, so we can't
diff --git a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs
index 11856f6e047..501bc96401a 100644
--- a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs
+++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs
@@ -491,7 +491,7 @@ where
if let Some(variant_path) = subpath {
let base_place = tcx.mk_place_elem(
self.place,
- ProjectionElem::Downcast(Some(variant.ident.name), variant_index),
+ ProjectionElem::Downcast(Some(variant.name), variant_index),
);
let fields = self.move_paths_for_fields(base_place, variant_path, &variant, substs);
values.push(discr.val);
diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs
index e93cd813db5..45da5f81224 100644
--- a/compiler/rustc_privacy/src/lib.rs
+++ b/compiler/rustc_privacy/src/lib.rs
@@ -903,7 +903,7 @@ impl<'tcx> NamePrivacyVisitor<'tcx> {
let def_id = self.tcx.adjust_ident_and_get_scope(ident, def.did, hir_id).1;
if !field.vis.is_accessible_from(def_id, self.tcx) {
let label = if in_update_syntax {
- format!("field `{}` is private", field.ident)
+ format!("field `{}` is private", field.name)
} else {
"private field".to_string()
};
@@ -913,7 +913,7 @@ impl<'tcx> NamePrivacyVisitor<'tcx> {
span,
E0451,
"field `{}` of {} `{}` is private",
- field.ident,
+ field.name,
def.variant_descr(),
self.tcx.def_path_str(def.did)
)
diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs
index 8226ffbccc4..17cf3667611 100644
--- a/compiler/rustc_typeck/src/astconv/mod.rs
+++ b/compiler/rustc_typeck/src/astconv/mod.rs
@@ -1727,7 +1727,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let variant_def = adt_def
.variants
.iter()
- .find(|vd| tcx.hygienic_eq(assoc_ident, vd.ident, adt_def.did));
+ .find(|vd| tcx.hygienic_eq(assoc_ident, vd.ident(tcx), adt_def.did));
if let Some(variant_def) = variant_def {
if permit_variants {
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None);
@@ -1786,7 +1786,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&adt_def
.variants
.iter()
- .map(|variant| variant.ident.name)
+ .map(|variant| variant.name)
.collect::<Vec<Symbol>>(),
assoc_ident.name,
None,
diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs
index dcf42e1aefe..ae3d33fcdb7 100644
--- a/compiler/rustc_typeck/src/check/check.rs
+++ b/compiler/rustc_typeck/src/check/check.rs
@@ -1173,7 +1173,7 @@ pub(super) fn check_packed_inner(
if let ty::Adt(def, _) = field.ty(tcx, substs).kind() {
if !stack.contains(&def.did) {
if let Some(mut defs) = check_packed_inner(tcx, def.did, stack) {
- defs.push((def.did, field.ident.span));
+ defs.push((def.did, field.ident(tcx).span));
return Some(defs);
}
}
diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs
index 621938c9b78..14180526d84 100644
--- a/compiler/rustc_typeck/src/check/expr.rs
+++ b/compiler/rustc_typeck/src/check/expr.rs
@@ -1376,7 +1376,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.fields
.iter()
.enumerate()
- .map(|(i, field)| (field.ident.normalize_to_macros_2_0(), (i, field)))
+ .map(|(i, field)| (field.ident(tcx).normalize_to_macros_2_0(), (i, field)))
.collect::<FxHashMap<_, _>>();
let mut seen_fields = FxHashMap::default();
@@ -1457,7 +1457,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr_span,
self.field_ty(base_expr.span, f, base_subs),
);
- let ident = self.tcx.adjust_ident(f.ident, variant.def_id);
+ let ident = self
+ .tcx
+ .adjust_ident(f.ident(self.tcx), variant.def_id);
if let Some(_) = remaining_fields.remove(&ident) {
let target_ty =
self.field_ty(base_expr.span, f, substs);
@@ -1475,10 +1477,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&cause,
target_ty,
fru_ty,
- FieldMisMatch(
- variant.ident.name,
- ident.name,
- ),
+ FieldMisMatch(variant.name, ident.name),
)
.emit(),
}
@@ -1665,7 +1664,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"{} `{}::{}` has no field named `{}`",
kind_name,
actual,
- variant.ident,
+ variant.name,
field.ident
),
_ => struct_span_err!(
@@ -1680,15 +1679,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
},
ty,
);
+
+ let variant_ident_span = self.tcx.def_ident_span(variant.def_id).unwrap();
match variant.ctor_kind {
CtorKind::Fn => match ty.kind() {
ty::Adt(adt, ..) if adt.is_enum() => {
err.span_label(
- variant.ident.span,
+ variant_ident_span,
format!(
"`{adt}::{variant}` defined here",
adt = ty,
- variant = variant.ident,
+ variant = variant.name,
),
);
err.span_label(field.ident.span, "field does not exist");
@@ -1697,18 +1698,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&format!(
"`{adt}::{variant}` is a tuple {kind_name}, use the appropriate syntax",
adt = ty,
- variant = variant.ident,
+ variant = variant.name,
),
format!(
"{adt}::{variant}(/* fields */)",
adt = ty,
- variant = variant.ident,
+ variant = variant.name,
),
Applicability::HasPlaceholders,
);
}
_ => {
- err.span_label(variant.ident.span, format!("`{adt}` defined here", adt = ty));
+ err.span_label(variant_ident_span, format!("`{adt}` defined here", adt = ty));
err.span_label(field.ident.span, "field does not exist");
err.span_suggestion_verbose(
expr_span,
@@ -1740,7 +1741,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if adt.is_enum() {
err.span_label(
field.ident.span,
- format!("`{}::{}` does not have this field", ty, variant.ident),
+ format!("`{}::{}` does not have this field", ty, variant.name),
);
} else {
err.span_label(
@@ -1775,12 +1776,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.iter()
.filter_map(|field| {
// ignore already set fields and private fields from non-local crates
- if skip.iter().any(|&x| x == field.ident.name)
+ if skip.iter().any(|&x| x == field.name)
|| (!variant.def_id.is_local() && !field.vis.is_public())
{
None
} else {
- Some(field.ident.name)
+ Some(field.name)
}
})
.collect::<Vec<Symbol>>();
@@ -1795,11 +1796,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.filter(|field| {
let def_scope = self
.tcx
- .adjust_ident_and_get_scope(field.ident, variant.def_id, self.body_id)
+ .adjust_ident_and_get_scope(field.ident(self.tcx), variant.def_id, self.body_id)
.1;
field.vis.is_accessible_from(def_scope, self.tcx)
})
- .map(|field| field.ident.name)
+ .map(|field| field.name)
.collect()
}
@@ -1834,8 +1835,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (ident, def_scope) =
self.tcx.adjust_ident_and_get_scope(field, base_def.did, self.body_id);
let fields = &base_def.non_enum_variant().fields;
- if let Some(index) =
- fields.iter().position(|f| f.ident.normalize_to_macros_2_0() == ident)
+ if let Some(index) = fields
+ .iter()
+ .position(|f| f.ident(self.tcx).normalize_to_macros_2_0() == ident)
{
let field = &fields[index];
let field_ty = self.field_ty(expr.span, field, substs);
@@ -1916,7 +1918,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let ty::Adt(def, _) = output_ty.kind() {
// no field access on enum type
if !def.is_enum() {
- if def.non_enum_variant().fields.iter().any(|field| field.ident == field_ident) {
+ if def
+ .non_enum_variant()
+ .fields
+ .iter()
+ .any(|field| field.ident(self.tcx) == field_ident)
+ {
add_label = false;
err.span_label(
field_ident.span,
@@ -2075,7 +2082,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.unwrap()
.fields
.iter()
- .any(|f| f.ident == field)
+ .any(|f| f.ident(self.tcx) == field)
{
if let Some(dot_loc) = expr_snippet.rfind('.') {
found = true;
@@ -2262,7 +2269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span, candidate_field, field_path
);
- if candidate_field.ident == target_field {
+ if candidate_field.ident(self.tcx) == target_field {
Some(field_path)
} else if field_path.len() > 3 {
// For compile-time reasons and to avoid infinite recursion we only check for fields
@@ -2271,11 +2278,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
// recursively search fields of `candidate_field` if it's a ty::Adt
- field_path.push(candidate_field.ident.normalize_to_macros_2_0());
+ field_path.push(candidate_field.ident(self.tcx).normalize_to_macros_2_0());
let field_ty = candidate_field.ty(self.tcx, subst);
if let Some((nested_fields, subst)) = self.get_field_candidates(span, &field_ty) {
for field in nested_fields.iter() {
- let ident = field.ident.normalize_to_macros_2_0();
+ let ident = field.ident(self.tcx).normalize_to_macros_2_0();
if ident == target_field {
return Some(field_path);
} else {
diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs
index f7f4c52c2a1..ac3e09318e5 100644
--- a/compiler/rustc_typeck/src/check/method/mod.rs
+++ b/compiler/rustc_typeck/src/check/method/mod.rs
@@ -482,7 +482,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let variant_def = adt_def
.variants
.iter()
- .find(|vd| tcx.hygienic_eq(method_name, vd.ident, adt_def.did));
+ .find(|vd| tcx.hygienic_eq(method_name, vd.ident(tcx), adt_def.did));
if let Some(variant_def) = variant_def {
// Braced variants generate unusable names in value namespace (reserved for
// possible future use), so variants resolved as associated items may refer to
diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs
index 1a6fcbc57bf..7cda27041a2 100644
--- a/compiler/rustc_typeck/src/check/method/suggest.rs
+++ b/compiler/rustc_typeck/src/check/method/suggest.rs
@@ -997,7 +997,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if unsatisfied_predicates.is_empty() && actual.is_enum() {
let adt_def = actual.ty_adt_def().expect("enum is not an ADT");
if let Some(suggestion) = lev_distance::find_best_match_for_name(
- &adt_def.variants.iter().map(|s| s.ident.name).collect::<Vec<_>>(),
+ &adt_def.variants.iter().map(|s| s.name).collect::<Vec<_>>(),
item_name.name,
None,
) {
diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs
index ec06e0b1126..17b97d4cad1 100644
--- a/compiler/rustc_typeck/src/check/pat.rs
+++ b/compiler/rustc_typeck/src/check/pat.rs
@@ -1029,7 +1029,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let field_def_spans = if fields.is_empty() {
vec![res_span]
} else {
- fields.iter().map(|f| f.ident.span).collect()
+ fields.iter().map(|f| f.ident(self.tcx).span).collect()
};
let last_field_def_span = *field_def_spans.last().unwrap();
@@ -1231,7 +1231,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.fields
.iter()
.enumerate()
- .map(|(i, field)| (field.ident.normalize_to_macros_2_0(), (i, field)))
+ .map(|(i, field)| (field.ident(self.tcx).normalize_to_macros_2_0(), (i, field)))
.collect::<FxHashMap<_, _>>();
// Keep track of which fields have already appeared in the pattern.
@@ -1272,7 +1272,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut unmentioned_fields = variant
.fields
.iter()
- .map(|field| (field, field.ident.normalize_to_macros_2_0()))
+ .map(|field| (field, field.ident(self.tcx).normalize_to_macros_2_0()))
.filter(|(_, ident)| !used_fields.contains_key(ident))
.collect::<Vec<_>>();
@@ -1579,7 +1579,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fields: &[hir::PatField<'_>],
variant: &VariantDef,
) -> String {
- let variant_field_idents = variant.fields.iter().map(|f| f.ident).collect::<Vec<Ident>>();
+ let variant_field_idents =
+ variant.fields.iter().map(|f| f.ident(self.tcx)).collect::<Vec<Ident>>();
fields
.iter()
.map(|field| {
diff --git a/compiler/rustc_typeck/src/coherence/builtin.rs b/compiler/rustc_typeck/src/coherence/builtin.rs
index d5494c5a685..dff6b7b58a0 100644
--- a/compiler/rustc_typeck/src/coherence/builtin.rs
+++ b/compiler/rustc_typeck/src/coherence/builtin.rs
@@ -199,7 +199,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did:
)
.note(&format!(
"extra field `{}` of type `{}` is not allowed",
- field.ident, ty_a,
+ field.name, ty_a,
))
.emit();
@@ -235,7 +235,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did:
.map(|field| {
format!(
"`{}` (`{}` to `{}`)",
- field.ident,
+ field.name,
field.ty(tcx, substs_a),
field.ty(tcx, substs_b),
)
@@ -479,7 +479,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
diff_fields
.iter()
.map(|&(i, a, b)| {
- format!("`{}` (`{}` to `{}`)", fields[i].ident, a, b)
+ format!("`{}` (`{}` to `{}`)", fields[i].name, a, b)
})
.collect::<Vec<_>>()
.join(", ")
diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs
index ccf8d1d9cea..3cccdb27448 100644
--- a/compiler/rustc_typeck/src/collect.rs
+++ b/compiler/rustc_typeck/src/collect.rs
@@ -994,7 +994,7 @@ fn convert_variant(
seen_fields.insert(f.ident.normalize_to_macros_2_0(), f.span);
}
- ty::FieldDef { did: fid.to_def_id(), ident: f.ident, vis: tcx.visibility(fid) }
+ ty::FieldDef { did: fid.to_def_id(), name: f.ident.name, vis: tcx.visibility(fid) }
})
.collect();
let recovered = match def {
@@ -1002,7 +1002,7 @@ fn convert_variant(
_ => false,
};
ty::VariantDef::new(
- ident,
+ ident.name,
variant_did.map(LocalDefId::to_def_id),
ctor_did.map(LocalDefId::to_def_id),
discr,
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index d80e79d164a..5d1e9d6754e 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1618,7 +1618,7 @@ impl Clean<Item> for hir::FieldDef<'_> {
impl Clean<Item> for ty::FieldDef {
fn clean(&self, cx: &mut DocContext<'_>) -> Item {
- clean_field(self.did, self.ident.name, cx.tcx.type_of(self.did).clean(cx), cx)
+ clean_field(self.did, self.name, cx.tcx.type_of(self.did).clean(cx), cx)
}
}
@@ -1689,7 +1689,7 @@ impl Clean<Item> for ty::VariantDef {
}),
};
let what_rustc_thinks =
- Item::from_def_id_and_parts(self.def_id, Some(self.ident.name), VariantItem(kind), cx);
+ Item::from_def_id_and_parts(self.def_id, Some(self.name), VariantItem(kind), cx);
// don't show `pub` for variants, which always inherit visibility
Item { visibility: Inherited, ..what_rustc_thinks }
}
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index 9f2830ba542..c8ae5bf1f02 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -1776,8 +1776,8 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
};
for (index, layout) in variants.iter_enumerated() {
- let ident = adt.variants[index].ident;
- write!(w, "<li><code>{name}</code>: ", name = ident);
+ let name = adt.variants[index].name;
+ write!(w, "<li><code>{name}</code>: ", name = name);
write_size_of_layout(w, layout, tag_size);
writeln!(w, "</li>");
}
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 9d1a8b3f80f..af62232e792 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -399,7 +399,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
match tcx.type_of(did).kind() {
ty::Adt(def, _) if def.is_enum() => {
if let Some(field) =
- def.all_fields().find(|f| f.ident.name == variant_field_name)
+ def.all_fields().find(|f| f.ident(tcx).name == variant_field_name)
{
Ok((ty_res, Some(ItemFragment(FragmentKind::VariantField, field.did))))
} else {
@@ -774,7 +774,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
.non_enum_variant()
.fields
.iter()
- .find(|item| item.ident.name == item_name)?;
+ .find(|item| item.ident(tcx).name == item_name)?;
Some((root_res, ItemFragment(FragmentKind::StructField, field.did)))
}
Res::Def(DefKind::Trait, did) => tcx
diff --git a/src/tools/clippy/clippy_lints/src/default.rs b/src/tools/clippy/clippy_lints/src/default.rs
index a0b137efe22..6422f5aabe5 100644
--- a/src/tools/clippy/clippy_lints/src/default.rs
+++ b/src/tools/clippy/clippy_lints/src/default.rs
@@ -198,7 +198,7 @@ impl LateLintPass<'_> for Default {
let ext_with_default = !variant
.fields
.iter()
- .all(|field| assigned_fields.iter().any(|(a, _)| a == &field.ident.name));
+ .all(|field| assigned_fields.iter().any(|(a, _)| a == &field.name));
let field_list = assigned_fields
.into_iter()
diff --git a/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs b/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs
index 3573ea5f026..15215ac15cd 100644
--- a/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs
+++ b/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs
@@ -161,7 +161,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
fields_def
.iter()
.find_map(|f_def| {
- if f_def.ident == field.ident
+ if f_def.ident(self.cx.tcx) == field.ident
{ Some(self.cx.tcx.type_of(f_def.did)) }
else { None }
});
diff --git a/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs b/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs
index 1debdef9d86..388bb3727f9 100644
--- a/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs
+++ b/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs
@@ -76,7 +76,7 @@ impl LateLintPass<'_> for InconsistentStructConstructor {
then {
let mut def_order_map = FxHashMap::default();
for (idx, field) in variant.fields.iter().enumerate() {
- def_order_map.insert(field.ident.name, idx);
+ def_order_map.insert(field.name, idx);
}
if is_consistent_order(fields, &def_order_map) {
diff --git a/src/tools/clippy/clippy_lints/src/matches.rs b/src/tools/clippy/clippy_lints/src/matches.rs
index 22970507f96..5fa8f249e70 100644
--- a/src/tools/clippy/clippy_lints/src/matches.rs
+++ b/src/tools/clippy/clippy_lints/src/matches.rs
@@ -1136,7 +1136,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
s.push_str("::");
s
},
- variant.ident.name,
+ variant.name,
match variant.ctor_kind {
CtorKind::Fn if variant.fields.len() == 1 => "(_)",
CtorKind::Fn => "(..)",