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:
parent
e4b1d58414
commit
450ef8613c
38 changed files with 120 additions and 107 deletions
|
@ -372,7 +372,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
def.non_enum_variant()
|
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::Tuple(_) => field.index().to_string(),
|
||||||
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {
|
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {
|
||||||
|
|
|
@ -174,7 +174,7 @@ impl<'tcx> DebugContext<'tcx> {
|
||||||
|
|
||||||
field_entry.set(
|
field_entry.set(
|
||||||
gimli::DW_AT_name,
|
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(
|
field_entry.set(
|
||||||
gimli::DW_AT_data_member_location,
|
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)
|
(layout.ty.kind(), &layout.variants)
|
||||||
{
|
{
|
||||||
if def.is_enum() && !def.variants.is_empty() {
|
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 }) =
|
if let (&ty::Generator(_, _, _), &Variants::Single { index }) =
|
||||||
|
|
|
@ -1300,7 +1300,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> {
|
||||||
let name = if self.variant.ctor_kind == CtorKind::Fn {
|
let name = if self.variant.ctor_kind == CtorKind::Fn {
|
||||||
format!("__{}", i)
|
format!("__{}", i)
|
||||||
} else {
|
} else {
|
||||||
f.ident.to_string()
|
f.name.to_string()
|
||||||
};
|
};
|
||||||
let field = layout.field(cx, i);
|
let field = layout.field(cx, i);
|
||||||
MemberDescription {
|
MemberDescription {
|
||||||
|
@ -1480,7 +1480,7 @@ impl<'tcx> UnionMemberDescriptionFactory<'tcx> {
|
||||||
.map(|(i, f)| {
|
.map(|(i, f)| {
|
||||||
let field = self.layout.field(cx, i);
|
let field = self.layout.field(cx, i);
|
||||||
MemberDescription {
|
MemberDescription {
|
||||||
name: f.ident.to_string(),
|
name: f.name.to_string(),
|
||||||
type_metadata: type_metadata(cx, field.ty, self.span),
|
type_metadata: type_metadata(cx, field.ty, self.span),
|
||||||
offset: Size::ZERO,
|
offset: Size::ZERO,
|
||||||
size: field.size,
|
size: field.size,
|
||||||
|
@ -1950,7 +1950,7 @@ enum VariantInfo<'a, 'tcx> {
|
||||||
impl<'tcx> VariantInfo<'_, 'tcx> {
|
impl<'tcx> VariantInfo<'_, 'tcx> {
|
||||||
fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
|
fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
|
||||||
match self {
|
match self {
|
||||||
VariantInfo::Adt(variant) => f(variant.ident.as_str()),
|
VariantInfo::Adt(variant) => f(variant.name.as_str()),
|
||||||
VariantInfo::Generator { variant_index, .. } => {
|
VariantInfo::Generator { variant_index, .. } => {
|
||||||
f(&GeneratorSubsts::variant_name(*variant_index))
|
f(&GeneratorSubsts::variant_name(*variant_index))
|
||||||
}
|
}
|
||||||
|
@ -1959,7 +1959,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
|
||||||
|
|
||||||
fn variant_name(&self) -> String {
|
fn variant_name(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
VariantInfo::Adt(variant) => variant.ident.to_string(),
|
VariantInfo::Adt(variant) => variant.name.to_string(),
|
||||||
VariantInfo::Generator { variant_index, .. } => {
|
VariantInfo::Generator { variant_index, .. } => {
|
||||||
// Since GDB currently prints out the raw discriminant along
|
// Since GDB currently prints out the raw discriminant along
|
||||||
// with every variant, make each variant name be just the value
|
// 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 {
|
fn field_name(&self, i: usize) -> String {
|
||||||
let field_name = match *self {
|
let field_name = match *self {
|
||||||
VariantInfo::Adt(variant) if variant.ctor_kind != CtorKind::Fn => {
|
VariantInfo::Adt(variant) if variant.ctor_kind != CtorKind::Fn => {
|
||||||
Some(variant.fields[i].ident.name)
|
Some(variant.fields[i].name)
|
||||||
}
|
}
|
||||||
VariantInfo::Generator {
|
VariantInfo::Generator {
|
||||||
generator_layout,
|
generator_layout,
|
||||||
|
@ -2063,7 +2063,7 @@ fn prepare_enum_metadata<'ll, 'tcx>(
|
||||||
let enumerators_metadata: Vec<_> = match enum_type.kind() {
|
let enumerators_metadata: Vec<_> = match enum_type.kind() {
|
||||||
ty::Adt(def, _) => iter::zip(def.discriminants(tcx), &def.variants)
|
ty::Adt(def, _) => iter::zip(def.discriminants(tcx), &def.variants)
|
||||||
.map(|((_, discr), v)| {
|
.map(|((_, discr), v)| {
|
||||||
let name = v.ident.as_str();
|
let name = v.name.as_str();
|
||||||
let is_unsigned = match discr.ty.kind() {
|
let is_unsigned = match discr.ty.kind() {
|
||||||
ty::Int(_) => false,
|
ty::Int(_) => false,
|
||||||
ty::Uint(_) => true,
|
ty::Uint(_) => true,
|
||||||
|
|
|
@ -49,7 +49,7 @@ fn uncached_llvm_type<'a, 'tcx>(
|
||||||
(layout.ty.kind(), &layout.variants)
|
(layout.ty.kind(), &layout.variants)
|
||||||
{
|
{
|
||||||
if def.is_enum() && !def.variants.is_empty() {
|
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 }) =
|
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 = dataful_discriminant_range.end;
|
||||||
let max = tag.value.size(&tcx).truncate(max);
|
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));
|
output.push_str(&format!(", {}, {}, {}", min, max, dataful_variant_name));
|
||||||
} else if let Variants::Single { index: variant_idx } = &layout.variants {
|
} else if let Variants::Single { index: variant_idx } = &layout.variants {
|
||||||
// Uninhabited enums can't be constructed and should never need to be visualized so
|
// Uninhabited enums can't be constructed and should never need to be visualized so
|
||||||
// skip this step for them.
|
// skip this step for them.
|
||||||
if def.variants.len() != 0 {
|
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));
|
output.push_str(&format!(", {}", variant));
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,14 +267,14 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||||
match layout.variants {
|
match layout.variants {
|
||||||
Variants::Single { index } => {
|
Variants::Single { index } => {
|
||||||
// Inside a variant
|
// 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"),
|
Variants::Multiple { .. } => bug!("we handled variants above"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// other ADTs
|
// 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
|
// arrays/slices
|
||||||
ty::Array(..) | ty::Slice(..) => PathElem::ArrayElem(field),
|
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>,
|
new_op: &OpTy<'tcx, M::PointerTag>,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
let name = match old_op.layout.ty.kind() {
|
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
|
// Generators also have variants
|
||||||
ty::Generator(..) => PathElem::GeneratorState(variant_id),
|
ty::Generator(..) => PathElem::GeneratorState(variant_id),
|
||||||
_ => bug!("Unexpected type with variant: {:?}", old_op.layout.ty),
|
_ => bug!("Unexpected type with variant: {:?}", old_op.layout.ty),
|
||||||
|
|
|
@ -1924,7 +1924,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|field| field.vis.is_accessible_from(field.did, self.tcx))
|
.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))
|
.find(|(_, ty)| same_type_modulo_infer(ty, exp_found.found))
|
||||||
{
|
{
|
||||||
if let ObligationCauseCode::Pattern { span: Some(span), .. } = *cause.code() {
|
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));
|
let ctor_did = data.ctor.map(|index| self.local_def_id(index));
|
||||||
|
|
||||||
ty::VariantDef::new(
|
ty::VariantDef::new(
|
||||||
self.item_ident(index, sess),
|
self.item_ident(index, sess).name,
|
||||||
variant_did,
|
variant_did,
|
||||||
ctor_did,
|
ctor_did,
|
||||||
data.discr,
|
data.discr,
|
||||||
|
@ -874,7 +874,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
.decode(self)
|
.decode(self)
|
||||||
.map(|index| ty::FieldDef {
|
.map(|index| ty::FieldDef {
|
||||||
did: self.local_def_id(index),
|
did: self.local_def_id(index),
|
||||||
ident: self.item_ident(index, sess),
|
name: self.item_ident(index, sess).name,
|
||||||
vis: self.get_visibility(index),
|
vis: self.get_visibility(index),
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|
|
@ -1052,7 +1052,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
assert!(f.did.is_local());
|
assert!(f.did.is_local());
|
||||||
f.did.index
|
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);
|
self.encode_item_type(def_id);
|
||||||
if variant.ctor_kind == CtorKind::Fn {
|
if variant.ctor_kind == CtorKind::Fn {
|
||||||
// FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
|
// 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);
|
debug!("EncodeContext::encode_field({:?})", def_id);
|
||||||
|
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::Field);
|
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);
|
self.encode_item_type(def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2439,7 +2439,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
||||||
CtorKind::Fictive => {
|
CtorKind::Fictive => {
|
||||||
let mut struct_fmt = fmt.debug_struct(&name);
|
let mut struct_fmt = fmt.debug_struct(&name);
|
||||||
for (field, place) in iter::zip(&variant_def.fields, places) {
|
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()
|
struct_fmt.finish()
|
||||||
}
|
}
|
||||||
|
@ -2785,7 +2785,7 @@ impl UserTypeProjection {
|
||||||
field: Field,
|
field: Field,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.projs.push(ProjectionElem::Downcast(
|
self.projs.push(ProjectionElem::Downcast(
|
||||||
Some(adt_def.variants[variant_index].ident.name),
|
Some(adt_def.variants[variant_index].name),
|
||||||
variant_index,
|
variant_index,
|
||||||
));
|
));
|
||||||
self.projs.push(ProjectionElem::Field(field, ()));
|
self.projs.push(ProjectionElem::Field(field, ()));
|
||||||
|
|
|
@ -726,7 +726,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(variant) = variant {
|
if let Some(variant) = variant {
|
||||||
write!(f, "{}", variant.ident)?;
|
write!(f, "{}", variant.name)?;
|
||||||
|
|
||||||
// Only for Adt we can have `S {...}`,
|
// Only for Adt we can have `S {...}`,
|
||||||
// which we handle separately here.
|
// which we handle separately here.
|
||||||
|
@ -738,7 +738,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
|
||||||
if let PatKind::Wild = *p.pattern.kind {
|
if let PatKind::Wild = *p.pattern.kind {
|
||||||
continue;
|
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)?;
|
write!(f, "{}{}: {}", start_or_comma(), name, p.pattern)?;
|
||||||
printed += 1;
|
printed += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ impl<'tcx> CapturedPlace<'tcx> {
|
||||||
write!(
|
write!(
|
||||||
&mut symbol,
|
&mut symbol,
|
||||||
"__{}",
|
"__{}",
|
||||||
def.variants[variant].fields[idx as usize].ident.name.as_str(),
|
def.variants[variant].fields[idx as usize].name.as_str(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -344,7 +344,7 @@ pub fn place_to_string_for_capture<'tcx>(tcx: TyCtxt<'tcx>, place: &HirPlace<'tc
|
||||||
curr_string = format!(
|
curr_string = format!(
|
||||||
"{}.{}",
|
"{}.{}",
|
||||||
curr_string,
|
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(_) => {
|
ty::Tuple(_) => {
|
||||||
|
|
|
@ -2452,7 +2452,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
) -> Place<'tcx> {
|
) -> Place<'tcx> {
|
||||||
self.mk_place_elem(
|
self.mk_place_elem(
|
||||||
place,
|
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::bit_set::BitSet;
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
use rustc_session::{config::OptLevel, DataTypeKind, FieldInfo, SizeKind, VariantInfo};
|
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_span::{Span, DUMMY_SP};
|
||||||
use rustc_target::abi::call::{
|
use rustc_target::abi::call::{
|
||||||
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode, Reg, RegKind,
|
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_kind = adt_def.adt_kind();
|
||||||
let adt_packed = adt_def.repr.pack.is_some();
|
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 mut min_size = Size::ZERO;
|
||||||
let field_info: Vec<_> = flds
|
let field_info: Vec<_> = flds
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1845,15 +1845,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
if !adt_def.variants.is_empty() && layout.fields != FieldsShape::Primitive {
|
if !adt_def.variants.is_empty() && layout.fields != FieldsShape::Primitive {
|
||||||
debug!(
|
debug!(
|
||||||
"print-type-size `{:#?}` variant {}",
|
"print-type-size `{:#?}` variant {}",
|
||||||
layout, adt_def.variants[index].ident
|
layout, adt_def.variants[index].name
|
||||||
);
|
);
|
||||||
let variant_def = &adt_def.variants[index];
|
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(
|
record(
|
||||||
adt_kind.into(),
|
adt_kind.into(),
|
||||||
adt_packed,
|
adt_packed,
|
||||||
None,
|
None,
|
||||||
vec![build_variant_info(Some(variant_def.ident), &fields, layout)],
|
vec![build_variant_info(Some(variant_def.name), &fields, layout)],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// (This case arises for *empty* enums; so give it
|
// (This case arises for *empty* enums; so give it
|
||||||
|
@ -1872,10 +1872,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
.variants
|
.variants
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
.map(|(i, variant_def)| {
|
.map(|(i, variant_def)| {
|
||||||
let fields: Vec<_> =
|
let fields: Vec<_> = variant_def.fields.iter().map(|f| f.name).collect();
|
||||||
variant_def.fields.iter().map(|f| f.ident.name).collect();
|
|
||||||
build_variant_info(
|
build_variant_info(
|
||||||
Some(variant_def.ident),
|
Some(variant_def.name),
|
||||||
&fields,
|
&fields,
|
||||||
layout.for_variant(self, i),
|
layout.for_variant(self, i),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1504,8 +1504,7 @@ pub struct VariantDef {
|
||||||
/// If this variant is a struct variant, then this is `None`.
|
/// If this variant is a struct variant, then this is `None`.
|
||||||
pub ctor_def_id: Option<DefId>,
|
pub ctor_def_id: Option<DefId>,
|
||||||
/// Variant or struct name.
|
/// Variant or struct name.
|
||||||
#[stable_hasher(project(name))]
|
pub name: Symbol,
|
||||||
pub ident: Ident,
|
|
||||||
/// Discriminant of this variant.
|
/// Discriminant of this variant.
|
||||||
pub discr: VariantDiscr,
|
pub discr: VariantDiscr,
|
||||||
/// Fields of this variant.
|
/// Fields of this variant.
|
||||||
|
@ -1534,7 +1533,7 @@ impl VariantDef {
|
||||||
/// If someone speeds up attribute loading to not be a performance concern, they can
|
/// If someone speeds up attribute loading to not be a performance concern, they can
|
||||||
/// remove this hack and use the constructor `DefId` everywhere.
|
/// remove this hack and use the constructor `DefId` everywhere.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
ident: Ident,
|
name: Symbol,
|
||||||
variant_did: Option<DefId>,
|
variant_did: Option<DefId>,
|
||||||
ctor_def_id: Option<DefId>,
|
ctor_def_id: Option<DefId>,
|
||||||
discr: VariantDiscr,
|
discr: VariantDiscr,
|
||||||
|
@ -1546,9 +1545,9 @@ impl VariantDef {
|
||||||
is_field_list_non_exhaustive: bool,
|
is_field_list_non_exhaustive: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
debug!(
|
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 = {:?})",
|
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;
|
let mut flags = VariantFlags::NO_VARIANT_FLAGS;
|
||||||
|
@ -1563,7 +1562,7 @@ impl VariantDef {
|
||||||
VariantDef {
|
VariantDef {
|
||||||
def_id: variant_did.unwrap_or(parent_did),
|
def_id: variant_did.unwrap_or(parent_did),
|
||||||
ctor_def_id,
|
ctor_def_id,
|
||||||
ident,
|
name,
|
||||||
discr,
|
discr,
|
||||||
fields,
|
fields,
|
||||||
ctor_kind,
|
ctor_kind,
|
||||||
|
@ -1582,6 +1581,11 @@ impl VariantDef {
|
||||||
pub fn is_recovered(&self) -> bool {
|
pub fn is_recovered(&self) -> bool {
|
||||||
self.flags.intersects(VariantFlags::IS_RECOVERED)
|
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)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
|
||||||
|
@ -1600,8 +1604,7 @@ pub enum VariantDiscr {
|
||||||
#[derive(Debug, HashStable, TyEncodable, TyDecodable)]
|
#[derive(Debug, HashStable, TyEncodable, TyDecodable)]
|
||||||
pub struct FieldDef {
|
pub struct FieldDef {
|
||||||
pub did: DefId,
|
pub did: DefId,
|
||||||
#[stable_hasher(project(name))]
|
pub name: Symbol,
|
||||||
pub ident: Ident,
|
|
||||||
pub vis: Visibility,
|
pub vis: Visibility,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1776,6 +1779,11 @@ impl<'tcx> FieldDef {
|
||||||
pub fn ty(&self, tcx: TyCtxt<'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> {
|
pub fn ty(&self, tcx: TyCtxt<'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> {
|
||||||
tcx.type_of(self.did).subst(tcx, subst)
|
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];
|
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> {
|
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
|
/// Returns `true` if the impls are the same polarity and the trait either
|
||||||
|
|
|
@ -1475,7 +1475,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
if !first {
|
if !first {
|
||||||
p!(", ");
|
p!(", ");
|
||||||
}
|
}
|
||||||
p!(write("{}: ", field_def.ident), print(field));
|
p!(write("{}: ", field_def.name), print(field));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
p!(" }}");
|
p!(" }}");
|
||||||
|
|
|
@ -336,10 +336,7 @@ impl<'tcx> PlaceBuilder<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn downcast(self, adt_def: &'tcx AdtDef, variant_index: VariantIdx) -> Self {
|
crate fn downcast(self, adt_def: &'tcx AdtDef, variant_index: VariantIdx) -> Self {
|
||||||
self.project(PlaceElem::Downcast(
|
self.project(PlaceElem::Downcast(Some(adt_def.variants[variant_index].name), variant_index))
|
||||||
Some(adt_def.variants[variant_index].ident.name),
|
|
||||||
variant_index,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index(self, index: Local) -> Self {
|
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)`,
|
// So, if we have a match-pattern like `x @ Enum::Variant(P1, P2)`,
|
||||||
// we want to create a set of derived match-patterns like
|
// we want to create a set of derived match-patterns like
|
||||||
// `(x as Variant).0 @ P1` and `(x as Variant).1 @ P1`.
|
// `(x as Variant).0 @ P1` and `(x as Variant).1 @ P1`.
|
||||||
let elem = ProjectionElem::Downcast(
|
let elem =
|
||||||
Some(adt_def.variants[variant_index].ident.name),
|
ProjectionElem::Downcast(Some(adt_def.variants[variant_index].name), variant_index);
|
||||||
variant_index,
|
|
||||||
);
|
|
||||||
let downcast_place = match_pair.place.project(elem); // `(x as Variant)`
|
let downcast_place = match_pair.place.project(elem); // `(x as Variant)`
|
||||||
let consequent_match_pairs = subpatterns.iter().map(|subpattern| {
|
let consequent_match_pairs = subpatterns.iter().map(|subpattern| {
|
||||||
// e.g., `(x as Variant).0`
|
// 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 let ty::Adt(edef, _) = pat_ty.kind() {
|
||||||
if edef.is_enum()
|
if edef.is_enum()
|
||||||
&& edef.variants.iter().any(|variant| {
|
&& 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();
|
let variant_count = edef.variants.len();
|
||||||
|
@ -627,7 +627,7 @@ fn maybe_point_at_variant<'a, 'p: 'a, 'tcx: 'a>(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let sp = def.variants[*variant_index].ident.span;
|
let sp = def.variants[*variant_index].ident(cx.tcx).span;
|
||||||
if covered.contains(&sp) {
|
if covered.contains(&sp) {
|
||||||
// Don't point at variants that have already been covered due to other patterns to avoid
|
// Don't point at variants that have already been covered due to other patterns to avoid
|
||||||
// visual clutter.
|
// visual clutter.
|
||||||
|
|
|
@ -1648,7 +1648,7 @@ impl<'p, 'tcx> fmt::Debug for DeconstructedPat<'p, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(variant) = variant {
|
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
|
// 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 {
|
if let Some(variant_path) = subpath {
|
||||||
let base_place = tcx.mk_place_elem(
|
let base_place = tcx.mk_place_elem(
|
||||||
self.place,
|
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);
|
let fields = self.move_paths_for_fields(base_place, variant_path, &variant, substs);
|
||||||
values.push(discr.val);
|
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;
|
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) {
|
if !field.vis.is_accessible_from(def_id, self.tcx) {
|
||||||
let label = if in_update_syntax {
|
let label = if in_update_syntax {
|
||||||
format!("field `{}` is private", field.ident)
|
format!("field `{}` is private", field.name)
|
||||||
} else {
|
} else {
|
||||||
"private field".to_string()
|
"private field".to_string()
|
||||||
};
|
};
|
||||||
|
@ -913,7 +913,7 @@ impl<'tcx> NamePrivacyVisitor<'tcx> {
|
||||||
span,
|
span,
|
||||||
E0451,
|
E0451,
|
||||||
"field `{}` of {} `{}` is private",
|
"field `{}` of {} `{}` is private",
|
||||||
field.ident,
|
field.name,
|
||||||
def.variant_descr(),
|
def.variant_descr(),
|
||||||
self.tcx.def_path_str(def.did)
|
self.tcx.def_path_str(def.did)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1727,7 +1727,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
let variant_def = adt_def
|
let variant_def = adt_def
|
||||||
.variants
|
.variants
|
||||||
.iter()
|
.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 let Some(variant_def) = variant_def {
|
||||||
if permit_variants {
|
if permit_variants {
|
||||||
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None);
|
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
|
&adt_def
|
||||||
.variants
|
.variants
|
||||||
.iter()
|
.iter()
|
||||||
.map(|variant| variant.ident.name)
|
.map(|variant| variant.name)
|
||||||
.collect::<Vec<Symbol>>(),
|
.collect::<Vec<Symbol>>(),
|
||||||
assoc_ident.name,
|
assoc_ident.name,
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -1173,7 +1173,7 @@ pub(super) fn check_packed_inner(
|
||||||
if let ty::Adt(def, _) = field.ty(tcx, substs).kind() {
|
if let ty::Adt(def, _) = field.ty(tcx, substs).kind() {
|
||||||
if !stack.contains(&def.did) {
|
if !stack.contains(&def.did) {
|
||||||
if let Some(mut defs) = check_packed_inner(tcx, def.did, stack) {
|
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);
|
return Some(defs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1376,7 +1376,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.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<_, _>>();
|
.collect::<FxHashMap<_, _>>();
|
||||||
|
|
||||||
let mut seen_fields = FxHashMap::default();
|
let mut seen_fields = FxHashMap::default();
|
||||||
|
@ -1457,7 +1457,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
expr_span,
|
expr_span,
|
||||||
self.field_ty(base_expr.span, f, base_subs),
|
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) {
|
if let Some(_) = remaining_fields.remove(&ident) {
|
||||||
let target_ty =
|
let target_ty =
|
||||||
self.field_ty(base_expr.span, f, substs);
|
self.field_ty(base_expr.span, f, substs);
|
||||||
|
@ -1475,10 +1477,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&cause,
|
&cause,
|
||||||
target_ty,
|
target_ty,
|
||||||
fru_ty,
|
fru_ty,
|
||||||
FieldMisMatch(
|
FieldMisMatch(variant.name, ident.name),
|
||||||
variant.ident.name,
|
|
||||||
ident.name,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.emit(),
|
.emit(),
|
||||||
}
|
}
|
||||||
|
@ -1665,7 +1664,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
"{} `{}::{}` has no field named `{}`",
|
"{} `{}::{}` has no field named `{}`",
|
||||||
kind_name,
|
kind_name,
|
||||||
actual,
|
actual,
|
||||||
variant.ident,
|
variant.name,
|
||||||
field.ident
|
field.ident
|
||||||
),
|
),
|
||||||
_ => struct_span_err!(
|
_ => struct_span_err!(
|
||||||
|
@ -1680,15 +1679,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
},
|
},
|
||||||
ty,
|
ty,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let variant_ident_span = self.tcx.def_ident_span(variant.def_id).unwrap();
|
||||||
match variant.ctor_kind {
|
match variant.ctor_kind {
|
||||||
CtorKind::Fn => match ty.kind() {
|
CtorKind::Fn => match ty.kind() {
|
||||||
ty::Adt(adt, ..) if adt.is_enum() => {
|
ty::Adt(adt, ..) if adt.is_enum() => {
|
||||||
err.span_label(
|
err.span_label(
|
||||||
variant.ident.span,
|
variant_ident_span,
|
||||||
format!(
|
format!(
|
||||||
"`{adt}::{variant}` defined here",
|
"`{adt}::{variant}` defined here",
|
||||||
adt = ty,
|
adt = ty,
|
||||||
variant = variant.ident,
|
variant = variant.name,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
err.span_label(field.ident.span, "field does not exist");
|
err.span_label(field.ident.span, "field does not exist");
|
||||||
|
@ -1697,18 +1698,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&format!(
|
&format!(
|
||||||
"`{adt}::{variant}` is a tuple {kind_name}, use the appropriate syntax",
|
"`{adt}::{variant}` is a tuple {kind_name}, use the appropriate syntax",
|
||||||
adt = ty,
|
adt = ty,
|
||||||
variant = variant.ident,
|
variant = variant.name,
|
||||||
),
|
),
|
||||||
format!(
|
format!(
|
||||||
"{adt}::{variant}(/* fields */)",
|
"{adt}::{variant}(/* fields */)",
|
||||||
adt = ty,
|
adt = ty,
|
||||||
variant = variant.ident,
|
variant = variant.name,
|
||||||
),
|
),
|
||||||
Applicability::HasPlaceholders,
|
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_label(field.ident.span, "field does not exist");
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
expr_span,
|
expr_span,
|
||||||
|
@ -1740,7 +1741,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
if adt.is_enum() {
|
if adt.is_enum() {
|
||||||
err.span_label(
|
err.span_label(
|
||||||
field.ident.span,
|
field.ident.span,
|
||||||
format!("`{}::{}` does not have this field", ty, variant.ident),
|
format!("`{}::{}` does not have this field", ty, variant.name),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
err.span_label(
|
err.span_label(
|
||||||
|
@ -1775,12 +1776,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|field| {
|
.filter_map(|field| {
|
||||||
// ignore already set fields and private fields from non-local crates
|
// 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())
|
|| (!variant.def_id.is_local() && !field.vis.is_public())
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(field.ident.name)
|
Some(field.name)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<Symbol>>();
|
.collect::<Vec<Symbol>>();
|
||||||
|
@ -1795,11 +1796,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
.filter(|field| {
|
.filter(|field| {
|
||||||
let def_scope = self
|
let def_scope = self
|
||||||
.tcx
|
.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;
|
.1;
|
||||||
field.vis.is_accessible_from(def_scope, self.tcx)
|
field.vis.is_accessible_from(def_scope, self.tcx)
|
||||||
})
|
})
|
||||||
.map(|field| field.ident.name)
|
.map(|field| field.name)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1834,8 +1835,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let (ident, def_scope) =
|
let (ident, def_scope) =
|
||||||
self.tcx.adjust_ident_and_get_scope(field, base_def.did, self.body_id);
|
self.tcx.adjust_ident_and_get_scope(field, base_def.did, self.body_id);
|
||||||
let fields = &base_def.non_enum_variant().fields;
|
let fields = &base_def.non_enum_variant().fields;
|
||||||
if let Some(index) =
|
if let Some(index) = fields
|
||||||
fields.iter().position(|f| f.ident.normalize_to_macros_2_0() == ident)
|
.iter()
|
||||||
|
.position(|f| f.ident(self.tcx).normalize_to_macros_2_0() == ident)
|
||||||
{
|
{
|
||||||
let field = &fields[index];
|
let field = &fields[index];
|
||||||
let field_ty = self.field_ty(expr.span, field, substs);
|
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() {
|
if let ty::Adt(def, _) = output_ty.kind() {
|
||||||
// no field access on enum type
|
// no field access on enum type
|
||||||
if !def.is_enum() {
|
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;
|
add_label = false;
|
||||||
err.span_label(
|
err.span_label(
|
||||||
field_ident.span,
|
field_ident.span,
|
||||||
|
@ -2075,7 +2082,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.any(|f| f.ident == field)
|
.any(|f| f.ident(self.tcx) == field)
|
||||||
{
|
{
|
||||||
if let Some(dot_loc) = expr_snippet.rfind('.') {
|
if let Some(dot_loc) = expr_snippet.rfind('.') {
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -2262,7 +2269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
span, candidate_field, field_path
|
span, candidate_field, field_path
|
||||||
);
|
);
|
||||||
|
|
||||||
if candidate_field.ident == target_field {
|
if candidate_field.ident(self.tcx) == target_field {
|
||||||
Some(field_path)
|
Some(field_path)
|
||||||
} else if field_path.len() > 3 {
|
} else if field_path.len() > 3 {
|
||||||
// For compile-time reasons and to avoid infinite recursion we only check for fields
|
// 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 {
|
} else {
|
||||||
// recursively search fields of `candidate_field` if it's a ty::Adt
|
// 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);
|
let field_ty = candidate_field.ty(self.tcx, subst);
|
||||||
if let Some((nested_fields, subst)) = self.get_field_candidates(span, &field_ty) {
|
if let Some((nested_fields, subst)) = self.get_field_candidates(span, &field_ty) {
|
||||||
for field in nested_fields.iter() {
|
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 {
|
if ident == target_field {
|
||||||
return Some(field_path);
|
return Some(field_path);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -482,7 +482,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let variant_def = adt_def
|
let variant_def = adt_def
|
||||||
.variants
|
.variants
|
||||||
.iter()
|
.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 {
|
if let Some(variant_def) = variant_def {
|
||||||
// Braced variants generate unusable names in value namespace (reserved for
|
// Braced variants generate unusable names in value namespace (reserved for
|
||||||
// possible future use), so variants resolved as associated items may refer to
|
// 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() {
|
if unsatisfied_predicates.is_empty() && actual.is_enum() {
|
||||||
let adt_def = actual.ty_adt_def().expect("enum is not an ADT");
|
let adt_def = actual.ty_adt_def().expect("enum is not an ADT");
|
||||||
if let Some(suggestion) = lev_distance::find_best_match_for_name(
|
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,
|
item_name.name,
|
||||||
None,
|
None,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -1029,7 +1029,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let field_def_spans = if fields.is_empty() {
|
let field_def_spans = if fields.is_empty() {
|
||||||
vec![res_span]
|
vec![res_span]
|
||||||
} else {
|
} 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();
|
let last_field_def_span = *field_def_spans.last().unwrap();
|
||||||
|
|
||||||
|
@ -1231,7 +1231,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.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<_, _>>();
|
.collect::<FxHashMap<_, _>>();
|
||||||
|
|
||||||
// Keep track of which fields have already appeared in the pattern.
|
// 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
|
let mut unmentioned_fields = variant
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.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))
|
.filter(|(_, ident)| !used_fields.contains_key(ident))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
@ -1579,7 +1579,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
fields: &[hir::PatField<'_>],
|
fields: &[hir::PatField<'_>],
|
||||||
variant: &VariantDef,
|
variant: &VariantDef,
|
||||||
) -> String {
|
) -> 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
|
fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|field| {
|
.map(|field| {
|
||||||
|
|
|
@ -199,7 +199,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did:
|
||||||
)
|
)
|
||||||
.note(&format!(
|
.note(&format!(
|
||||||
"extra field `{}` of type `{}` is not allowed",
|
"extra field `{}` of type `{}` is not allowed",
|
||||||
field.ident, ty_a,
|
field.name, ty_a,
|
||||||
))
|
))
|
||||||
.emit();
|
.emit();
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did:
|
||||||
.map(|field| {
|
.map(|field| {
|
||||||
format!(
|
format!(
|
||||||
"`{}` (`{}` to `{}`)",
|
"`{}` (`{}` to `{}`)",
|
||||||
field.ident,
|
field.name,
|
||||||
field.ty(tcx, substs_a),
|
field.ty(tcx, substs_a),
|
||||||
field.ty(tcx, substs_b),
|
field.ty(tcx, substs_b),
|
||||||
)
|
)
|
||||||
|
@ -479,7 +479,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
|
||||||
diff_fields
|
diff_fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(i, a, b)| {
|
.map(|&(i, a, b)| {
|
||||||
format!("`{}` (`{}` to `{}`)", fields[i].ident, a, b)
|
format!("`{}` (`{}` to `{}`)", fields[i].name, a, b)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", ")
|
.join(", ")
|
||||||
|
|
|
@ -994,7 +994,7 @@ fn convert_variant(
|
||||||
seen_fields.insert(f.ident.normalize_to_macros_2_0(), f.span);
|
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();
|
.collect();
|
||||||
let recovered = match def {
|
let recovered = match def {
|
||||||
|
@ -1002,7 +1002,7 @@ fn convert_variant(
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
ty::VariantDef::new(
|
ty::VariantDef::new(
|
||||||
ident,
|
ident.name,
|
||||||
variant_did.map(LocalDefId::to_def_id),
|
variant_did.map(LocalDefId::to_def_id),
|
||||||
ctor_did.map(LocalDefId::to_def_id),
|
ctor_did.map(LocalDefId::to_def_id),
|
||||||
discr,
|
discr,
|
||||||
|
|
|
@ -1618,7 +1618,7 @@ impl Clean<Item> for hir::FieldDef<'_> {
|
||||||
|
|
||||||
impl Clean<Item> for ty::FieldDef {
|
impl Clean<Item> for ty::FieldDef {
|
||||||
fn clean(&self, cx: &mut DocContext<'_>) -> Item {
|
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 =
|
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
|
// don't show `pub` for variants, which always inherit visibility
|
||||||
Item { visibility: Inherited, ..what_rustc_thinks }
|
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() {
|
for (index, layout) in variants.iter_enumerated() {
|
||||||
let ident = adt.variants[index].ident;
|
let name = adt.variants[index].name;
|
||||||
write!(w, "<li><code>{name}</code>: ", name = ident);
|
write!(w, "<li><code>{name}</code>: ", name = name);
|
||||||
write_size_of_layout(w, layout, tag_size);
|
write_size_of_layout(w, layout, tag_size);
|
||||||
writeln!(w, "</li>");
|
writeln!(w, "</li>");
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,7 +399,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
|
||||||
match tcx.type_of(did).kind() {
|
match tcx.type_of(did).kind() {
|
||||||
ty::Adt(def, _) if def.is_enum() => {
|
ty::Adt(def, _) if def.is_enum() => {
|
||||||
if let Some(field) =
|
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))))
|
Ok((ty_res, Some(ItemFragment(FragmentKind::VariantField, field.did))))
|
||||||
} else {
|
} else {
|
||||||
|
@ -774,7 +774,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
|
||||||
.non_enum_variant()
|
.non_enum_variant()
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.find(|item| item.ident.name == item_name)?;
|
.find(|item| item.ident(tcx).name == item_name)?;
|
||||||
Some((root_res, ItemFragment(FragmentKind::StructField, field.did)))
|
Some((root_res, ItemFragment(FragmentKind::StructField, field.did)))
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::Trait, did) => tcx
|
Res::Def(DefKind::Trait, did) => tcx
|
||||||
|
|
|
@ -198,7 +198,7 @@ impl LateLintPass<'_> for Default {
|
||||||
let ext_with_default = !variant
|
let ext_with_default = !variant
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.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
|
let field_list = assigned_fields
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -161,7 +161,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
|
||||||
fields_def
|
fields_def
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|f_def| {
|
.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)) }
|
{ Some(self.cx.tcx.type_of(f_def.did)) }
|
||||||
else { None }
|
else { None }
|
||||||
});
|
});
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl LateLintPass<'_> for InconsistentStructConstructor {
|
||||||
then {
|
then {
|
||||||
let mut def_order_map = FxHashMap::default();
|
let mut def_order_map = FxHashMap::default();
|
||||||
for (idx, field) in variant.fields.iter().enumerate() {
|
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) {
|
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.push_str("::");
|
||||||
s
|
s
|
||||||
},
|
},
|
||||||
variant.ident.name,
|
variant.name,
|
||||||
match variant.ctor_kind {
|
match variant.ctor_kind {
|
||||||
CtorKind::Fn if variant.fields.len() == 1 => "(_)",
|
CtorKind::Fn if variant.fields.len() == 1 => "(_)",
|
||||||
CtorKind::Fn => "(..)",
|
CtorKind::Fn => "(..)",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue