mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Auto merge of #92533 - Aaron1011:variant-symbol, r=petrochenkov
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`.
This commit is contained in:
commit
72e74d7b9c
@ -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, .. }) => {
|
||||
|
@ -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,
|
||||
|
@ -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 }) =
|
||||
|
@ -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,
|
||||
|
@ -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 }) =
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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),
|
||||
|
@ -1921,7 +1921,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() {
|
||||
|
@ -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(),
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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, ()));
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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(_) => {
|
||||
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
)
|
||||
|
@ -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
|
||||
|
@ -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!(" }}");
|
||||
|
@ -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 {
|
||||
|
@ -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`
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
)
|
||||
|
@ -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,
|
||||
|
@ -1177,7 +1177,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);
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
) {
|
||||
|
@ -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| {
|
||||
|
@ -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(", ")
|
||||
|
@ -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,
|
||||
|
@ -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 }
|
||||
}
|
||||
|
@ -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>");
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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 }
|
||||
});
|
||||
|
@ -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) {
|
||||
|
@ -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 => "(..)",
|
||||
|
Loading…
Reference in New Issue
Block a user