mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Auto merge of #83188 - petrochenkov:field, r=lcnr
ast/hir: Rename field-related structures I always forget what `ast::Field` and `ast::StructField` mean despite working with AST for long time, so this PR changes the naming to less confusing and more consistent. - `StructField` -> `FieldDef` ("field definition") - `Field` -> `ExprField` ("expression field", not "field expression") - `FieldPat` -> `PatField` ("pattern field", not "field pattern") Various visiting and other methods working with the fields are renamed correspondingly too. The second commit reduces the size of `ExprKind` by boxing fields of `ExprKind::Struct` in preparation for https://github.com/rust-lang/rust/pull/80080.
This commit is contained in:
commit
b4adc21c4f
@ -655,7 +655,7 @@ impl Pat {
|
||||
/// are treated the same as `x: x, y: ref y, z: ref mut z`,
|
||||
/// except when `is_shorthand` is true.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct FieldPat {
|
||||
pub struct PatField {
|
||||
/// The identifier for the field.
|
||||
pub ident: Ident,
|
||||
/// The pattern the field is destructured to.
|
||||
@ -700,7 +700,7 @@ pub enum PatKind {
|
||||
|
||||
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
|
||||
/// The `bool` is `true` in the presence of a `..`.
|
||||
Struct(Path, Vec<FieldPat>, /* recovered */ bool),
|
||||
Struct(Path, Vec<PatField>, /* recovered */ bool),
|
||||
|
||||
/// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
|
||||
TupleStruct(Path, Vec<P<Pat>>),
|
||||
@ -1035,9 +1035,9 @@ pub struct Arm {
|
||||
pub is_placeholder: bool,
|
||||
}
|
||||
|
||||
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field.
|
||||
/// A single field in a struct expression, e.g. `x: value` and `y` in `Foo { x: value, y }`.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct Field {
|
||||
pub struct ExprField {
|
||||
pub attrs: AttrVec,
|
||||
pub id: NodeId,
|
||||
pub span: Span,
|
||||
@ -1082,7 +1082,7 @@ pub struct Expr {
|
||||
|
||||
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
rustc_data_structures::static_assert_size!(Expr, 120);
|
||||
rustc_data_structures::static_assert_size!(Expr, 104);
|
||||
|
||||
impl Expr {
|
||||
/// Returns `true` if this expression would be valid somewhere that expects a value;
|
||||
@ -1252,6 +1252,13 @@ pub enum StructRest {
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct StructExpr {
|
||||
pub path: Path,
|
||||
pub fields: Vec<ExprField>,
|
||||
pub rest: StructRest,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum ExprKind {
|
||||
/// A `box x` expression.
|
||||
@ -1377,7 +1384,7 @@ pub enum ExprKind {
|
||||
/// A struct literal expression.
|
||||
///
|
||||
/// E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. rest}`.
|
||||
Struct(Path, Vec<Field>, StructRest),
|
||||
Struct(P<StructExpr>),
|
||||
|
||||
/// An array literal constructed from one repeated element.
|
||||
///
|
||||
@ -2527,11 +2534,11 @@ impl VisibilityKind {
|
||||
}
|
||||
}
|
||||
|
||||
/// Field of a struct.
|
||||
/// Field definition in a struct, variant or union.
|
||||
///
|
||||
/// E.g., `bar: usize` as in `struct Foo { bar: usize }`.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct StructField {
|
||||
pub struct FieldDef {
|
||||
pub attrs: Vec<Attribute>,
|
||||
pub id: NodeId,
|
||||
pub span: Span,
|
||||
@ -2548,11 +2555,11 @@ pub enum VariantData {
|
||||
/// Struct variant.
|
||||
///
|
||||
/// E.g., `Bar { .. }` as in `enum Foo { Bar { .. } }`.
|
||||
Struct(Vec<StructField>, bool),
|
||||
Struct(Vec<FieldDef>, bool),
|
||||
/// Tuple variant.
|
||||
///
|
||||
/// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`.
|
||||
Tuple(Vec<StructField>, NodeId),
|
||||
Tuple(Vec<FieldDef>, NodeId),
|
||||
/// Unit variant.
|
||||
///
|
||||
/// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`.
|
||||
@ -2561,7 +2568,7 @@ pub enum VariantData {
|
||||
|
||||
impl VariantData {
|
||||
/// Return the fields of this variant.
|
||||
pub fn fields(&self) -> &[StructField] {
|
||||
pub fn fields(&self) -> &[FieldDef] {
|
||||
match *self {
|
||||
VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, _) => fields,
|
||||
_ => &[],
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::ptr::P;
|
||||
use super::tokenstream::LazyTokenStream;
|
||||
use super::{Arm, Field, FieldPat, GenericParam, Param, StructField, Variant};
|
||||
use super::{Arm, ExprField, FieldDef, GenericParam, Param, PatField, Variant};
|
||||
use super::{AssocItem, Expr, ForeignItem, Item, Local};
|
||||
use super::{AttrItem, AttrKind, Block, Pat, Path, Ty, Visibility};
|
||||
use super::{AttrVec, Attribute, Stmt, StmtKind};
|
||||
@ -187,8 +187,7 @@ derive_has_tokens_and_attrs! {
|
||||
// These ast nodes only support inert attributes, so they don't
|
||||
// store tokens (since nothing can observe them)
|
||||
derive_has_attrs_no_tokens! {
|
||||
StructField, Arm,
|
||||
Field, FieldPat, Variant, Param, GenericParam
|
||||
FieldDef, Arm, ExprField, PatField, Variant, Param, GenericParam
|
||||
}
|
||||
|
||||
// These AST nodes don't support attributes, but can
|
||||
|
@ -102,8 +102,8 @@ pub trait MutVisitor: Sized {
|
||||
noop_visit_fn_header(header, self);
|
||||
}
|
||||
|
||||
fn flat_map_struct_field(&mut self, sf: StructField) -> SmallVec<[StructField; 1]> {
|
||||
noop_flat_map_struct_field(sf, self)
|
||||
fn flat_map_field_def(&mut self, fd: FieldDef) -> SmallVec<[FieldDef; 1]> {
|
||||
noop_flat_map_field_def(fd, self)
|
||||
}
|
||||
|
||||
fn visit_item_kind(&mut self, i: &mut ItemKind) {
|
||||
@ -254,8 +254,8 @@ pub trait MutVisitor: Sized {
|
||||
noop_visit_mt(mt, self);
|
||||
}
|
||||
|
||||
fn flat_map_field(&mut self, f: Field) -> SmallVec<[Field; 1]> {
|
||||
noop_flat_map_field(f, self)
|
||||
fn flat_map_expr_field(&mut self, f: ExprField) -> SmallVec<[ExprField; 1]> {
|
||||
noop_flat_map_expr_field(f, self)
|
||||
}
|
||||
|
||||
fn visit_where_clause(&mut self, where_clause: &mut WhereClause) {
|
||||
@ -278,8 +278,8 @@ pub trait MutVisitor: Sized {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
fn flat_map_field_pattern(&mut self, fp: FieldPat) -> SmallVec<[FieldPat; 1]> {
|
||||
noop_flat_map_field_pattern(fp, self)
|
||||
fn flat_map_pat_field(&mut self, fp: PatField) -> SmallVec<[PatField; 1]> {
|
||||
noop_flat_map_pat_field(fp, self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -385,11 +385,11 @@ pub fn visit_delim_span<T: MutVisitor>(dspan: &mut DelimSpan, vis: &mut T) {
|
||||
vis.visit_span(&mut dspan.close);
|
||||
}
|
||||
|
||||
pub fn noop_flat_map_field_pattern<T: MutVisitor>(
|
||||
mut fp: FieldPat,
|
||||
pub fn noop_flat_map_pat_field<T: MutVisitor>(
|
||||
mut fp: PatField,
|
||||
vis: &mut T,
|
||||
) -> SmallVec<[FieldPat; 1]> {
|
||||
let FieldPat { attrs, id, ident, is_placeholder: _, is_shorthand: _, pat, span } = &mut fp;
|
||||
) -> SmallVec<[PatField; 1]> {
|
||||
let PatField { attrs, id, ident, is_placeholder: _, is_shorthand: _, pat, span } = &mut fp;
|
||||
vis.visit_id(id);
|
||||
vis.visit_ident(ident);
|
||||
vis.visit_pat(pat);
|
||||
@ -842,10 +842,10 @@ pub fn noop_visit_where_predicate<T: MutVisitor>(pred: &mut WherePredicate, vis:
|
||||
pub fn noop_visit_variant_data<T: MutVisitor>(vdata: &mut VariantData, vis: &mut T) {
|
||||
match vdata {
|
||||
VariantData::Struct(fields, ..) => {
|
||||
fields.flat_map_in_place(|field| vis.flat_map_struct_field(field));
|
||||
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
|
||||
}
|
||||
VariantData::Tuple(fields, id) => {
|
||||
fields.flat_map_in_place(|field| vis.flat_map_struct_field(field));
|
||||
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
|
||||
vis.visit_id(id);
|
||||
}
|
||||
VariantData::Unit(id) => vis.visit_id(id),
|
||||
@ -864,22 +864,25 @@ pub fn noop_visit_poly_trait_ref<T: MutVisitor>(p: &mut PolyTraitRef, vis: &mut
|
||||
vis.visit_span(span);
|
||||
}
|
||||
|
||||
pub fn noop_flat_map_struct_field<T: MutVisitor>(
|
||||
mut sf: StructField,
|
||||
pub fn noop_flat_map_field_def<T: MutVisitor>(
|
||||
mut fd: FieldDef,
|
||||
visitor: &mut T,
|
||||
) -> SmallVec<[StructField; 1]> {
|
||||
let StructField { span, ident, vis, id, ty, attrs, is_placeholder: _ } = &mut sf;
|
||||
) -> SmallVec<[FieldDef; 1]> {
|
||||
let FieldDef { span, ident, vis, id, ty, attrs, is_placeholder: _ } = &mut fd;
|
||||
visitor.visit_span(span);
|
||||
visit_opt(ident, |ident| visitor.visit_ident(ident));
|
||||
visitor.visit_vis(vis);
|
||||
visitor.visit_id(id);
|
||||
visitor.visit_ty(ty);
|
||||
visit_attrs(attrs, visitor);
|
||||
smallvec![sf]
|
||||
smallvec![fd]
|
||||
}
|
||||
|
||||
pub fn noop_flat_map_field<T: MutVisitor>(mut f: Field, vis: &mut T) -> SmallVec<[Field; 1]> {
|
||||
let Field { ident, expr, span, is_shorthand: _, attrs, id, is_placeholder: _ } = &mut f;
|
||||
pub fn noop_flat_map_expr_field<T: MutVisitor>(
|
||||
mut f: ExprField,
|
||||
vis: &mut T,
|
||||
) -> SmallVec<[ExprField; 1]> {
|
||||
let ExprField { ident, expr, span, is_shorthand: _, attrs, id, is_placeholder: _ } = &mut f;
|
||||
vis.visit_ident(ident);
|
||||
vis.visit_expr(expr);
|
||||
vis.visit_id(id);
|
||||
@ -1102,7 +1105,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
|
||||
}
|
||||
PatKind::Struct(path, fields, _etc) => {
|
||||
vis.visit_path(path);
|
||||
fields.flat_map_in_place(|field| vis.flat_map_field_pattern(field));
|
||||
fields.flat_map_in_place(|field| vis.flat_map_pat_field(field));
|
||||
}
|
||||
PatKind::Box(inner) => vis.visit_pat(inner),
|
||||
PatKind::Ref(inner, _mutbl) => vis.visit_pat(inner),
|
||||
@ -1283,10 +1286,11 @@ pub fn noop_visit_expr<T: MutVisitor>(
|
||||
visit_vec(inputs, |(_c, expr)| vis.visit_expr(expr));
|
||||
}
|
||||
ExprKind::MacCall(mac) => vis.visit_mac_call(mac),
|
||||
ExprKind::Struct(path, fields, expr) => {
|
||||
ExprKind::Struct(se) => {
|
||||
let StructExpr { path, fields, rest } = se.deref_mut();
|
||||
vis.visit_path(path);
|
||||
fields.flat_map_in_place(|field| vis.flat_map_field(field));
|
||||
match expr {
|
||||
fields.flat_map_in_place(|field| vis.flat_map_expr_field(field));
|
||||
match rest {
|
||||
StructRest::Base(expr) => vis.visit_expr(expr),
|
||||
StructRest::Rest(_span) => {}
|
||||
StructRest::None => {}
|
||||
|
@ -151,8 +151,8 @@ pub trait Visitor<'ast>: Sized {
|
||||
fn visit_variant_data(&mut self, s: &'ast VariantData) {
|
||||
walk_struct_def(self, s)
|
||||
}
|
||||
fn visit_struct_field(&mut self, s: &'ast StructField) {
|
||||
walk_struct_field(self, s)
|
||||
fn visit_field_def(&mut self, s: &'ast FieldDef) {
|
||||
walk_field_def(self, s)
|
||||
}
|
||||
fn visit_enum_def(
|
||||
&mut self,
|
||||
@ -208,11 +208,11 @@ pub trait Visitor<'ast>: Sized {
|
||||
fn visit_fn_header(&mut self, _header: &'ast FnHeader) {
|
||||
// Nothing to do
|
||||
}
|
||||
fn visit_field(&mut self, f: &'ast Field) {
|
||||
walk_field(self, f)
|
||||
fn visit_expr_field(&mut self, f: &'ast ExprField) {
|
||||
walk_expr_field(self, f)
|
||||
}
|
||||
fn visit_field_pattern(&mut self, fp: &'ast FieldPat) {
|
||||
walk_field_pattern(self, fp)
|
||||
fn visit_pat_field(&mut self, fp: &'ast PatField) {
|
||||
walk_pat_field(self, fp)
|
||||
}
|
||||
}
|
||||
|
||||
@ -364,13 +364,13 @@ where
|
||||
walk_list!(visitor, visit_attribute, &variant.attrs);
|
||||
}
|
||||
|
||||
pub fn walk_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a Field) {
|
||||
pub fn walk_expr_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a ExprField) {
|
||||
visitor.visit_expr(&f.expr);
|
||||
visitor.visit_ident(f.ident);
|
||||
walk_list!(visitor, visit_attribute, f.attrs.iter());
|
||||
}
|
||||
|
||||
pub fn walk_field_pattern<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a FieldPat) {
|
||||
pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) {
|
||||
visitor.visit_ident(fp.ident);
|
||||
visitor.visit_pat(&fp.pat);
|
||||
walk_list!(visitor, visit_attribute, fp.attrs.iter());
|
||||
@ -509,7 +509,7 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
|
||||
}
|
||||
PatKind::Struct(ref path, ref fields, _) => {
|
||||
visitor.visit_path(path, pattern.id);
|
||||
walk_list!(visitor, visit_field_pattern, fields);
|
||||
walk_list!(visitor, visit_pat_field, fields);
|
||||
}
|
||||
PatKind::Box(ref subpattern)
|
||||
| PatKind::Ref(ref subpattern, _)
|
||||
@ -668,16 +668,16 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem,
|
||||
}
|
||||
|
||||
pub fn walk_struct_def<'a, V: Visitor<'a>>(visitor: &mut V, struct_definition: &'a VariantData) {
|
||||
walk_list!(visitor, visit_struct_field, struct_definition.fields());
|
||||
walk_list!(visitor, visit_field_def, struct_definition.fields());
|
||||
}
|
||||
|
||||
pub fn walk_struct_field<'a, V: Visitor<'a>>(visitor: &mut V, struct_field: &'a StructField) {
|
||||
visitor.visit_vis(&struct_field.vis);
|
||||
if let Some(ident) = struct_field.ident {
|
||||
pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef) {
|
||||
visitor.visit_vis(&field.vis);
|
||||
if let Some(ident) = field.ident {
|
||||
visitor.visit_ident(ident);
|
||||
}
|
||||
visitor.visit_ty(&struct_field.ty);
|
||||
walk_list!(visitor, visit_attribute, &struct_field.attrs);
|
||||
visitor.visit_ty(&field.ty);
|
||||
walk_list!(visitor, visit_attribute, &field.attrs);
|
||||
}
|
||||
|
||||
pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) {
|
||||
@ -721,10 +721,10 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
|
||||
visitor.visit_expr(element);
|
||||
visitor.visit_anon_const(count)
|
||||
}
|
||||
ExprKind::Struct(ref path, ref fields, ref optional_base) => {
|
||||
visitor.visit_path(path, expression.id);
|
||||
walk_list!(visitor, visit_field, fields);
|
||||
match optional_base {
|
||||
ExprKind::Struct(ref se) => {
|
||||
visitor.visit_path(&se.path, expression.id);
|
||||
walk_list!(visitor, visit_expr_field, &se.fields);
|
||||
match &se.rest {
|
||||
StructRest::Base(expr) => visitor.visit_expr(expr),
|
||||
StructRest::Rest(_span) => {}
|
||||
StructRest::None => {}
|
||||
|
@ -224,8 +224,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
}
|
||||
ExprKind::InlineAsm(ref asm) => self.lower_expr_asm(e.span, asm),
|
||||
ExprKind::LlvmInlineAsm(ref asm) => self.lower_expr_llvm_asm(asm),
|
||||
ExprKind::Struct(ref path, ref fields, ref rest) => {
|
||||
let rest = match rest {
|
||||
ExprKind::Struct(ref se) => {
|
||||
let rest = match &se.rest {
|
||||
StructRest::Base(e) => Some(self.lower_expr(e)),
|
||||
StructRest::Rest(sp) => {
|
||||
self.sess
|
||||
@ -240,11 +240,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
self.arena.alloc(self.lower_qpath(
|
||||
e.id,
|
||||
&None,
|
||||
path,
|
||||
&se.path,
|
||||
ParamMode::Optional,
|
||||
ImplTraitContext::disallowed(),
|
||||
)),
|
||||
self.arena.alloc_from_iter(fields.iter().map(|x| self.lower_field(x))),
|
||||
self.arena
|
||||
.alloc_from_iter(se.fields.iter().map(|x| self.lower_expr_field(x))),
|
||||
rest,
|
||||
)
|
||||
}
|
||||
@ -1110,10 +1111,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
}
|
||||
}
|
||||
// Structs.
|
||||
ExprKind::Struct(path, fields, rest) => {
|
||||
let field_pats = self.arena.alloc_from_iter(fields.iter().map(|f| {
|
||||
ExprKind::Struct(se) => {
|
||||
let field_pats = self.arena.alloc_from_iter(se.fields.iter().map(|f| {
|
||||
let pat = self.destructure_assign(&f.expr, eq_sign_span, assignments);
|
||||
hir::FieldPat {
|
||||
hir::PatField {
|
||||
hir_id: self.next_id(),
|
||||
ident: f.ident,
|
||||
pat,
|
||||
@ -1124,11 +1125,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
let qpath = self.lower_qpath(
|
||||
lhs.id,
|
||||
&None,
|
||||
path,
|
||||
&se.path,
|
||||
ParamMode::Optional,
|
||||
ImplTraitContext::disallowed(),
|
||||
);
|
||||
let fields_omitted = match rest {
|
||||
let fields_omitted = match &se.rest {
|
||||
StructRest::Base(e) => {
|
||||
self.sess
|
||||
.struct_span_err(
|
||||
@ -1244,7 +1245,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
e1.iter().map(|e| ("start", e)).chain(e2.iter().map(|e| ("end", e))).map(|(s, e)| {
|
||||
let expr = self.lower_expr(&e);
|
||||
let ident = Ident::new(Symbol::intern(s), e.span);
|
||||
self.field(ident, expr, e.span)
|
||||
self.expr_field(ident, expr, e.span)
|
||||
}),
|
||||
);
|
||||
|
||||
@ -1657,8 +1658,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
hir::ExprKind::LlvmInlineAsm(self.arena.alloc(hir_asm))
|
||||
}
|
||||
|
||||
fn lower_field(&mut self, f: &Field) -> hir::Field<'hir> {
|
||||
hir::Field {
|
||||
fn lower_expr_field(&mut self, f: &ExprField) -> hir::ExprField<'hir> {
|
||||
hir::ExprField {
|
||||
hir_id: self.next_id(),
|
||||
ident: f.ident,
|
||||
expr: self.lower_expr(&f.expr),
|
||||
@ -2155,8 +2156,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
hir::Expr { hir_id, kind, span }
|
||||
}
|
||||
|
||||
fn field(&mut self, ident: Ident, expr: &'hir hir::Expr<'hir>, span: Span) -> hir::Field<'hir> {
|
||||
hir::Field { hir_id: self.next_id(), ident, span, expr, is_shorthand: false }
|
||||
fn expr_field(
|
||||
&mut self,
|
||||
ident: Ident,
|
||||
expr: &'hir hir::Expr<'hir>,
|
||||
span: Span,
|
||||
) -> hir::ExprField<'hir> {
|
||||
hir::ExprField { hir_id: self.next_id(), ident, span, expr, is_shorthand: false }
|
||||
}
|
||||
|
||||
fn arm(&mut self, pat: &'hir hir::Pat<'hir>, expr: &'hir hir::Expr<'hir>) -> hir::Arm<'hir> {
|
||||
|
@ -769,7 +769,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
match *vdata {
|
||||
VariantData::Struct(ref fields, recovered) => hir::VariantData::Struct(
|
||||
self.arena
|
||||
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_struct_field(f))),
|
||||
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f))),
|
||||
recovered,
|
||||
),
|
||||
VariantData::Tuple(ref fields, id) => {
|
||||
@ -777,7 +777,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
self.alias_attrs(ctor_id, parent_id);
|
||||
hir::VariantData::Tuple(
|
||||
self.arena.alloc_from_iter(
|
||||
fields.iter().enumerate().map(|f| self.lower_struct_field(f)),
|
||||
fields.iter().enumerate().map(|f| self.lower_field_def(f)),
|
||||
),
|
||||
ctor_id,
|
||||
)
|
||||
@ -790,7 +790,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::StructField<'hir> {
|
||||
fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> hir::FieldDef<'hir> {
|
||||
let ty = if let TyKind::Path(ref qself, ref path) = f.ty.kind {
|
||||
let t = self.lower_path_ty(
|
||||
&f.ty,
|
||||
@ -805,7 +805,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
};
|
||||
let hir_id = self.lower_node_id(f.id);
|
||||
self.lower_attrs(hir_id, &f.attrs);
|
||||
hir::StructField {
|
||||
hir::FieldDef {
|
||||
span: f.span,
|
||||
hir_id,
|
||||
ident: match f.ident {
|
||||
|
@ -2559,8 +2559,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
&mut self,
|
||||
span: Span,
|
||||
pat: &'hir hir::Pat<'hir>,
|
||||
) -> &'hir [hir::FieldPat<'hir>] {
|
||||
let field = hir::FieldPat {
|
||||
) -> &'hir [hir::PatField<'hir>] {
|
||||
let field = hir::PatField {
|
||||
hir_id: self.next_id(),
|
||||
ident: Ident::new(sym::integer(0), span),
|
||||
is_shorthand: false,
|
||||
@ -2574,7 +2574,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
&mut self,
|
||||
span: Span,
|
||||
lang_item: hir::LangItem,
|
||||
fields: &'hir [hir::FieldPat<'hir>],
|
||||
fields: &'hir [hir::PatField<'hir>],
|
||||
) -> &'hir hir::Pat<'hir> {
|
||||
let qpath = hir::QPath::LangItem(lang_item, span);
|
||||
self.pat(span, hir::PatKind::Struct(qpath, fields, false))
|
||||
|
@ -56,7 +56,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
ImplTraitContext::disallowed(),
|
||||
);
|
||||
|
||||
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::FieldPat {
|
||||
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::PatField {
|
||||
hir_id: self.next_id(),
|
||||
ident: f.ident,
|
||||
pat: self.lower_pat(&f.pat),
|
||||
|
@ -88,9 +88,9 @@ impl<'ast> Visitor<'ast> for NodeCounter {
|
||||
self.count += 1;
|
||||
walk_struct_def(self, s)
|
||||
}
|
||||
fn visit_struct_field(&mut self, s: &StructField) {
|
||||
fn visit_field_def(&mut self, s: &FieldDef) {
|
||||
self.count += 1;
|
||||
walk_struct_field(self, s)
|
||||
walk_field_def(self, s)
|
||||
}
|
||||
fn visit_enum_def(
|
||||
&mut self,
|
||||
|
@ -1711,7 +1711,7 @@ impl<'a> State<'a> {
|
||||
fn print_expr_struct(
|
||||
&mut self,
|
||||
path: &ast::Path,
|
||||
fields: &[ast::Field],
|
||||
fields: &[ast::ExprField],
|
||||
rest: &ast::StructRest,
|
||||
attrs: &[ast::Attribute],
|
||||
) {
|
||||
@ -1873,8 +1873,8 @@ impl<'a> State<'a> {
|
||||
ast::ExprKind::Repeat(ref element, ref count) => {
|
||||
self.print_expr_repeat(element, count, attrs);
|
||||
}
|
||||
ast::ExprKind::Struct(ref path, ref fields, ref rest) => {
|
||||
self.print_expr_struct(path, &fields[..], rest, attrs);
|
||||
ast::ExprKind::Struct(ref se) => {
|
||||
self.print_expr_struct(&se.path, &se.fields, &se.rest, attrs);
|
||||
}
|
||||
ast::ExprKind::Tup(ref exprs) => {
|
||||
self.print_expr_tup(&exprs[..], attrs);
|
||||
|
@ -67,11 +67,11 @@ impl CfgEval<'_> {
|
||||
expr
|
||||
}),
|
||||
Annotatable::Arm(arm) => Annotatable::Arm(self.flat_map_arm(arm).pop().unwrap()),
|
||||
Annotatable::Field(field) => {
|
||||
Annotatable::Field(self.flat_map_field(field).pop().unwrap())
|
||||
Annotatable::ExprField(field) => {
|
||||
Annotatable::ExprField(self.flat_map_expr_field(field).pop().unwrap())
|
||||
}
|
||||
Annotatable::FieldPat(fp) => {
|
||||
Annotatable::FieldPat(self.flat_map_field_pattern(fp).pop().unwrap())
|
||||
Annotatable::PatField(fp) => {
|
||||
Annotatable::PatField(self.flat_map_pat_field(fp).pop().unwrap())
|
||||
}
|
||||
Annotatable::GenericParam(param) => {
|
||||
Annotatable::GenericParam(self.flat_map_generic_param(param).pop().unwrap())
|
||||
@ -79,8 +79,8 @@ impl CfgEval<'_> {
|
||||
Annotatable::Param(param) => {
|
||||
Annotatable::Param(self.flat_map_param(param).pop().unwrap())
|
||||
}
|
||||
Annotatable::StructField(sf) => {
|
||||
Annotatable::StructField(self.flat_map_struct_field(sf).pop().unwrap())
|
||||
Annotatable::FieldDef(sf) => {
|
||||
Annotatable::FieldDef(self.flat_map_field_def(sf).pop().unwrap())
|
||||
}
|
||||
Annotatable::Variant(v) => {
|
||||
Annotatable::Variant(self.flat_map_variant(v).pop().unwrap())
|
||||
@ -135,20 +135,20 @@ impl MutVisitor for CfgEval<'_> {
|
||||
mut_visit::noop_flat_map_arm(configure!(self, arm), self)
|
||||
}
|
||||
|
||||
fn flat_map_field(&mut self, field: ast::Field) -> SmallVec<[ast::Field; 1]> {
|
||||
mut_visit::noop_flat_map_field(configure!(self, field), self)
|
||||
fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> {
|
||||
mut_visit::noop_flat_map_expr_field(configure!(self, field), self)
|
||||
}
|
||||
|
||||
fn flat_map_field_pattern(&mut self, fp: ast::FieldPat) -> SmallVec<[ast::FieldPat; 1]> {
|
||||
mut_visit::noop_flat_map_field_pattern(configure!(self, fp), self)
|
||||
fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> {
|
||||
mut_visit::noop_flat_map_pat_field(configure!(self, fp), self)
|
||||
}
|
||||
|
||||
fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> {
|
||||
mut_visit::noop_flat_map_param(configure!(self, p), self)
|
||||
}
|
||||
|
||||
fn flat_map_struct_field(&mut self, sf: ast::StructField) -> SmallVec<[ast::StructField; 1]> {
|
||||
mut_visit::noop_flat_map_struct_field(configure!(self, sf), self)
|
||||
fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> {
|
||||
mut_visit::noop_flat_map_field_def(configure!(self, sf), self)
|
||||
}
|
||||
|
||||
fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> {
|
||||
|
@ -1578,7 +1578,7 @@ impl<'a> TraitDef<'a> {
|
||||
if ident.is_none() {
|
||||
cx.span_bug(sp, "a braced struct with unnamed fields in `derive`");
|
||||
}
|
||||
ast::FieldPat {
|
||||
ast::PatField {
|
||||
ident: ident.unwrap(),
|
||||
is_shorthand: false,
|
||||
attrs: ast::AttrVec::new(),
|
||||
|
@ -36,11 +36,11 @@ pub enum Annotatable {
|
||||
Stmt(P<ast::Stmt>),
|
||||
Expr(P<ast::Expr>),
|
||||
Arm(ast::Arm),
|
||||
Field(ast::Field),
|
||||
FieldPat(ast::FieldPat),
|
||||
ExprField(ast::ExprField),
|
||||
PatField(ast::PatField),
|
||||
GenericParam(ast::GenericParam),
|
||||
Param(ast::Param),
|
||||
StructField(ast::StructField),
|
||||
FieldDef(ast::FieldDef),
|
||||
Variant(ast::Variant),
|
||||
}
|
||||
|
||||
@ -54,11 +54,11 @@ impl AstLike for Annotatable {
|
||||
Annotatable::Stmt(ref stmt) => stmt.attrs(),
|
||||
Annotatable::Expr(ref expr) => &expr.attrs,
|
||||
Annotatable::Arm(ref arm) => &arm.attrs,
|
||||
Annotatable::Field(ref field) => &field.attrs,
|
||||
Annotatable::FieldPat(ref fp) => &fp.attrs,
|
||||
Annotatable::ExprField(ref field) => &field.attrs,
|
||||
Annotatable::PatField(ref fp) => &fp.attrs,
|
||||
Annotatable::GenericParam(ref gp) => &gp.attrs,
|
||||
Annotatable::Param(ref p) => &p.attrs,
|
||||
Annotatable::StructField(ref sf) => &sf.attrs,
|
||||
Annotatable::FieldDef(ref sf) => &sf.attrs,
|
||||
Annotatable::Variant(ref v) => &v.attrs(),
|
||||
}
|
||||
}
|
||||
@ -72,11 +72,11 @@ impl AstLike for Annotatable {
|
||||
Annotatable::Stmt(stmt) => stmt.visit_attrs(f),
|
||||
Annotatable::Expr(expr) => expr.visit_attrs(f),
|
||||
Annotatable::Arm(arm) => arm.visit_attrs(f),
|
||||
Annotatable::Field(field) => field.visit_attrs(f),
|
||||
Annotatable::FieldPat(fp) => fp.visit_attrs(f),
|
||||
Annotatable::ExprField(field) => field.visit_attrs(f),
|
||||
Annotatable::PatField(fp) => fp.visit_attrs(f),
|
||||
Annotatable::GenericParam(gp) => gp.visit_attrs(f),
|
||||
Annotatable::Param(p) => p.visit_attrs(f),
|
||||
Annotatable::StructField(sf) => sf.visit_attrs(f),
|
||||
Annotatable::FieldDef(sf) => sf.visit_attrs(f),
|
||||
Annotatable::Variant(v) => v.visit_attrs(f),
|
||||
}
|
||||
}
|
||||
@ -90,11 +90,11 @@ impl AstLike for Annotatable {
|
||||
Annotatable::Stmt(stmt) => stmt.tokens_mut(),
|
||||
Annotatable::Expr(expr) => expr.tokens_mut(),
|
||||
Annotatable::Arm(arm) => arm.tokens_mut(),
|
||||
Annotatable::Field(field) => field.tokens_mut(),
|
||||
Annotatable::FieldPat(fp) => fp.tokens_mut(),
|
||||
Annotatable::ExprField(field) => field.tokens_mut(),
|
||||
Annotatable::PatField(fp) => fp.tokens_mut(),
|
||||
Annotatable::GenericParam(gp) => gp.tokens_mut(),
|
||||
Annotatable::Param(p) => p.tokens_mut(),
|
||||
Annotatable::StructField(sf) => sf.tokens_mut(),
|
||||
Annotatable::FieldDef(sf) => sf.tokens_mut(),
|
||||
Annotatable::Variant(v) => v.tokens_mut(),
|
||||
}
|
||||
}
|
||||
@ -110,11 +110,11 @@ impl Annotatable {
|
||||
Annotatable::Stmt(ref stmt) => stmt.span,
|
||||
Annotatable::Expr(ref expr) => expr.span,
|
||||
Annotatable::Arm(ref arm) => arm.span,
|
||||
Annotatable::Field(ref field) => field.span,
|
||||
Annotatable::FieldPat(ref fp) => fp.pat.span,
|
||||
Annotatable::ExprField(ref field) => field.span,
|
||||
Annotatable::PatField(ref fp) => fp.pat.span,
|
||||
Annotatable::GenericParam(ref gp) => gp.ident.span,
|
||||
Annotatable::Param(ref p) => p.span,
|
||||
Annotatable::StructField(ref sf) => sf.span,
|
||||
Annotatable::FieldDef(ref sf) => sf.span,
|
||||
Annotatable::Variant(ref v) => v.span,
|
||||
}
|
||||
}
|
||||
@ -128,11 +128,11 @@ impl Annotatable {
|
||||
Annotatable::Stmt(stmt) => visitor.visit_stmt(stmt),
|
||||
Annotatable::Expr(expr) => visitor.visit_expr(expr),
|
||||
Annotatable::Arm(arm) => visitor.visit_arm(arm),
|
||||
Annotatable::Field(field) => visitor.visit_field(field),
|
||||
Annotatable::FieldPat(fp) => visitor.visit_field_pattern(fp),
|
||||
Annotatable::ExprField(field) => visitor.visit_expr_field(field),
|
||||
Annotatable::PatField(fp) => visitor.visit_pat_field(fp),
|
||||
Annotatable::GenericParam(gp) => visitor.visit_generic_param(gp),
|
||||
Annotatable::Param(p) => visitor.visit_param(p),
|
||||
Annotatable::StructField(sf) => visitor.visit_struct_field(sf),
|
||||
Annotatable::FieldDef(sf) => visitor.visit_field_def(sf),
|
||||
Annotatable::Variant(v) => visitor.visit_variant(v),
|
||||
}
|
||||
}
|
||||
@ -149,11 +149,11 @@ impl Annotatable {
|
||||
Annotatable::Stmt(stmt) => token::NtStmt(stmt.into_inner()),
|
||||
Annotatable::Expr(expr) => token::NtExpr(expr),
|
||||
Annotatable::Arm(..)
|
||||
| Annotatable::Field(..)
|
||||
| Annotatable::FieldPat(..)
|
||||
| Annotatable::ExprField(..)
|
||||
| Annotatable::PatField(..)
|
||||
| Annotatable::GenericParam(..)
|
||||
| Annotatable::Param(..)
|
||||
| Annotatable::StructField(..)
|
||||
| Annotatable::FieldDef(..)
|
||||
| Annotatable::Variant(..) => panic!("unexpected annotatable"),
|
||||
}
|
||||
}
|
||||
@ -214,16 +214,16 @@ impl Annotatable {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_field(self) -> ast::Field {
|
||||
pub fn expect_expr_field(self) -> ast::ExprField {
|
||||
match self {
|
||||
Annotatable::Field(field) => field,
|
||||
Annotatable::ExprField(field) => field,
|
||||
_ => panic!("expected field"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_field_pattern(self) -> ast::FieldPat {
|
||||
pub fn expect_pat_field(self) -> ast::PatField {
|
||||
match self {
|
||||
Annotatable::FieldPat(fp) => fp,
|
||||
Annotatable::PatField(fp) => fp,
|
||||
_ => panic!("expected field pattern"),
|
||||
}
|
||||
}
|
||||
@ -242,9 +242,9 @@ impl Annotatable {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_struct_field(self) -> ast::StructField {
|
||||
pub fn expect_field_def(self) -> ast::FieldDef {
|
||||
match self {
|
||||
Annotatable::StructField(sf) => sf,
|
||||
Annotatable::FieldDef(sf) => sf,
|
||||
_ => panic!("expected struct field"),
|
||||
}
|
||||
}
|
||||
@ -430,11 +430,11 @@ pub trait MacResult {
|
||||
None
|
||||
}
|
||||
|
||||
fn make_fields(self: Box<Self>) -> Option<SmallVec<[ast::Field; 1]>> {
|
||||
fn make_expr_fields(self: Box<Self>) -> Option<SmallVec<[ast::ExprField; 1]>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn make_field_patterns(self: Box<Self>) -> Option<SmallVec<[ast::FieldPat; 1]>> {
|
||||
fn make_pat_fields(self: Box<Self>) -> Option<SmallVec<[ast::PatField; 1]>> {
|
||||
None
|
||||
}
|
||||
|
||||
@ -446,7 +446,7 @@ pub trait MacResult {
|
||||
None
|
||||
}
|
||||
|
||||
fn make_struct_fields(self: Box<Self>) -> Option<SmallVec<[ast::StructField; 1]>> {
|
||||
fn make_field_defs(self: Box<Self>) -> Option<SmallVec<[ast::FieldDef; 1]>> {
|
||||
None
|
||||
}
|
||||
|
||||
@ -630,11 +630,11 @@ impl MacResult for DummyResult {
|
||||
Some(SmallVec::new())
|
||||
}
|
||||
|
||||
fn make_fields(self: Box<DummyResult>) -> Option<SmallVec<[ast::Field; 1]>> {
|
||||
fn make_expr_fields(self: Box<DummyResult>) -> Option<SmallVec<[ast::ExprField; 1]>> {
|
||||
Some(SmallVec::new())
|
||||
}
|
||||
|
||||
fn make_field_patterns(self: Box<DummyResult>) -> Option<SmallVec<[ast::FieldPat; 1]>> {
|
||||
fn make_pat_fields(self: Box<DummyResult>) -> Option<SmallVec<[ast::PatField; 1]>> {
|
||||
Some(SmallVec::new())
|
||||
}
|
||||
|
||||
@ -646,7 +646,7 @@ impl MacResult for DummyResult {
|
||||
Some(SmallVec::new())
|
||||
}
|
||||
|
||||
fn make_struct_fields(self: Box<DummyResult>) -> Option<SmallVec<[ast::StructField; 1]>> {
|
||||
fn make_field_defs(self: Box<DummyResult>) -> Option<SmallVec<[ast::FieldDef; 1]>> {
|
||||
Some(SmallVec::new())
|
||||
}
|
||||
|
||||
|
@ -267,8 +267,8 @@ impl<'a> ExtCtxt<'a> {
|
||||
pub fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr> {
|
||||
self.expr(b.span, ast::ExprKind::Block(b, None))
|
||||
}
|
||||
pub fn field_imm(&self, span: Span, ident: Ident, e: P<ast::Expr>) -> ast::Field {
|
||||
ast::Field {
|
||||
pub fn field_imm(&self, span: Span, ident: Ident, e: P<ast::Expr>) -> ast::ExprField {
|
||||
ast::ExprField {
|
||||
ident: ident.with_span_pos(span),
|
||||
expr: e,
|
||||
span,
|
||||
@ -282,15 +282,18 @@ impl<'a> ExtCtxt<'a> {
|
||||
&self,
|
||||
span: Span,
|
||||
path: ast::Path,
|
||||
fields: Vec<ast::Field>,
|
||||
fields: Vec<ast::ExprField>,
|
||||
) -> P<ast::Expr> {
|
||||
self.expr(span, ast::ExprKind::Struct(path, fields, ast::StructRest::None))
|
||||
self.expr(
|
||||
span,
|
||||
ast::ExprKind::Struct(P(ast::StructExpr { path, fields, rest: ast::StructRest::None })),
|
||||
)
|
||||
}
|
||||
pub fn expr_struct_ident(
|
||||
&self,
|
||||
span: Span,
|
||||
id: Ident,
|
||||
fields: Vec<ast::Field>,
|
||||
fields: Vec<ast::ExprField>,
|
||||
) -> P<ast::Expr> {
|
||||
self.expr_struct(span, self.path_ident(span, id), fields)
|
||||
}
|
||||
@ -419,7 +422,7 @@ impl<'a> ExtCtxt<'a> {
|
||||
&self,
|
||||
span: Span,
|
||||
path: ast::Path,
|
||||
field_pats: Vec<ast::FieldPat>,
|
||||
field_pats: Vec<ast::PatField>,
|
||||
) -> P<ast::Pat> {
|
||||
self.pat(span, PatKind::Struct(path, field_pats, false))
|
||||
}
|
||||
|
@ -177,14 +177,14 @@ ast_fragments! {
|
||||
Arms(SmallVec<[ast::Arm; 1]>) {
|
||||
"match arm"; many fn flat_map_arm; fn visit_arm(); fn make_arms;
|
||||
}
|
||||
Fields(SmallVec<[ast::Field; 1]>) {
|
||||
"field expression"; many fn flat_map_field; fn visit_field(); fn make_fields;
|
||||
Fields(SmallVec<[ast::ExprField; 1]>) {
|
||||
"field expression"; many fn flat_map_expr_field; fn visit_expr_field(); fn make_expr_fields;
|
||||
}
|
||||
FieldPats(SmallVec<[ast::FieldPat; 1]>) {
|
||||
FieldPats(SmallVec<[ast::PatField; 1]>) {
|
||||
"field pattern";
|
||||
many fn flat_map_field_pattern;
|
||||
fn visit_field_pattern();
|
||||
fn make_field_patterns;
|
||||
many fn flat_map_pat_field;
|
||||
fn visit_pat_field();
|
||||
fn make_pat_fields;
|
||||
}
|
||||
GenericParams(SmallVec<[ast::GenericParam; 1]>) {
|
||||
"generic parameter";
|
||||
@ -195,11 +195,11 @@ ast_fragments! {
|
||||
Params(SmallVec<[ast::Param; 1]>) {
|
||||
"function parameter"; many fn flat_map_param; fn visit_param(); fn make_params;
|
||||
}
|
||||
StructFields(SmallVec<[ast::StructField; 1]>) {
|
||||
StructFields(SmallVec<[ast::FieldDef; 1]>) {
|
||||
"field";
|
||||
many fn flat_map_struct_field;
|
||||
fn visit_struct_field();
|
||||
fn make_struct_fields;
|
||||
many fn flat_map_field_def;
|
||||
fn visit_field_def();
|
||||
fn make_field_defs;
|
||||
}
|
||||
Variants(SmallVec<[ast::Variant; 1]>) {
|
||||
"variant"; many fn flat_map_variant; fn visit_variant(); fn make_variants;
|
||||
@ -243,10 +243,10 @@ impl AstFragmentKind {
|
||||
AstFragment::Arms(items.map(Annotatable::expect_arm).collect())
|
||||
}
|
||||
AstFragmentKind::Fields => {
|
||||
AstFragment::Fields(items.map(Annotatable::expect_field).collect())
|
||||
AstFragment::Fields(items.map(Annotatable::expect_expr_field).collect())
|
||||
}
|
||||
AstFragmentKind::FieldPats => {
|
||||
AstFragment::FieldPats(items.map(Annotatable::expect_field_pattern).collect())
|
||||
AstFragment::FieldPats(items.map(Annotatable::expect_pat_field).collect())
|
||||
}
|
||||
AstFragmentKind::GenericParams => {
|
||||
AstFragment::GenericParams(items.map(Annotatable::expect_generic_param).collect())
|
||||
@ -255,7 +255,7 @@ impl AstFragmentKind {
|
||||
AstFragment::Params(items.map(Annotatable::expect_param).collect())
|
||||
}
|
||||
AstFragmentKind::StructFields => {
|
||||
AstFragment::StructFields(items.map(Annotatable::expect_struct_field).collect())
|
||||
AstFragment::StructFields(items.map(Annotatable::expect_field_def).collect())
|
||||
}
|
||||
AstFragmentKind::Variants => {
|
||||
AstFragment::Variants(items.map(Annotatable::expect_variant).collect())
|
||||
@ -321,8 +321,8 @@ impl InvocationKind {
|
||||
// The assumption is that the attribute expansion cannot change field visibilities,
|
||||
// and it holds because only inert attributes are supported in this position.
|
||||
match self {
|
||||
InvocationKind::Attr { item: Annotatable::StructField(field), .. }
|
||||
| InvocationKind::Derive { item: Annotatable::StructField(field), .. }
|
||||
InvocationKind::Attr { item: Annotatable::FieldDef(field), .. }
|
||||
| InvocationKind::Derive { item: Annotatable::FieldDef(field), .. }
|
||||
if field.ident.is_none() =>
|
||||
{
|
||||
Some(field.vis.clone())
|
||||
@ -787,11 +787,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||
}
|
||||
Annotatable::Expr(_) => "expressions",
|
||||
Annotatable::Arm(..)
|
||||
| Annotatable::Field(..)
|
||||
| Annotatable::FieldPat(..)
|
||||
| Annotatable::ExprField(..)
|
||||
| Annotatable::PatField(..)
|
||||
| Annotatable::GenericParam(..)
|
||||
| Annotatable::Param(..)
|
||||
| Annotatable::StructField(..)
|
||||
| Annotatable::FieldDef(..)
|
||||
| Annotatable::Variant(..) => panic!("unexpected annotatable"),
|
||||
};
|
||||
if self.cx.ecfg.proc_macro_hygiene() {
|
||||
@ -1108,28 +1108,28 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||
noop_flat_map_arm(arm, self)
|
||||
}
|
||||
|
||||
fn flat_map_field(&mut self, field: ast::Field) -> SmallVec<[ast::Field; 1]> {
|
||||
fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> {
|
||||
let mut field = configure!(self, field);
|
||||
|
||||
if let Some(attr) = self.take_first_attr(&mut field) {
|
||||
return self
|
||||
.collect_attr(attr, Annotatable::Field(field), AstFragmentKind::Fields)
|
||||
.make_fields();
|
||||
.collect_attr(attr, Annotatable::ExprField(field), AstFragmentKind::Fields)
|
||||
.make_expr_fields();
|
||||
}
|
||||
|
||||
noop_flat_map_field(field, self)
|
||||
noop_flat_map_expr_field(field, self)
|
||||
}
|
||||
|
||||
fn flat_map_field_pattern(&mut self, fp: ast::FieldPat) -> SmallVec<[ast::FieldPat; 1]> {
|
||||
fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> {
|
||||
let mut fp = configure!(self, fp);
|
||||
|
||||
if let Some(attr) = self.take_first_attr(&mut fp) {
|
||||
return self
|
||||
.collect_attr(attr, Annotatable::FieldPat(fp), AstFragmentKind::FieldPats)
|
||||
.make_field_patterns();
|
||||
.collect_attr(attr, Annotatable::PatField(fp), AstFragmentKind::FieldPats)
|
||||
.make_pat_fields();
|
||||
}
|
||||
|
||||
noop_flat_map_field_pattern(fp, self)
|
||||
noop_flat_map_pat_field(fp, self)
|
||||
}
|
||||
|
||||
fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> {
|
||||
@ -1144,16 +1144,16 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||
noop_flat_map_param(p, self)
|
||||
}
|
||||
|
||||
fn flat_map_struct_field(&mut self, sf: ast::StructField) -> SmallVec<[ast::StructField; 1]> {
|
||||
fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> {
|
||||
let mut sf = configure!(self, sf);
|
||||
|
||||
if let Some(attr) = self.take_first_attr(&mut sf) {
|
||||
return self
|
||||
.collect_attr(attr, Annotatable::StructField(sf), AstFragmentKind::StructFields)
|
||||
.make_struct_fields();
|
||||
.collect_attr(attr, Annotatable::FieldDef(sf), AstFragmentKind::StructFields)
|
||||
.make_field_defs();
|
||||
}
|
||||
|
||||
noop_flat_map_struct_field(sf, self)
|
||||
noop_flat_map_field_def(sf, self)
|
||||
}
|
||||
|
||||
fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> {
|
||||
|
@ -117,7 +117,7 @@ pub fn placeholder(
|
||||
span,
|
||||
is_placeholder: true,
|
||||
}]),
|
||||
AstFragmentKind::Fields => AstFragment::Fields(smallvec![ast::Field {
|
||||
AstFragmentKind::Fields => AstFragment::Fields(smallvec![ast::ExprField {
|
||||
attrs: Default::default(),
|
||||
expr: expr_placeholder(),
|
||||
id,
|
||||
@ -126,7 +126,7 @@ pub fn placeholder(
|
||||
span,
|
||||
is_placeholder: true,
|
||||
}]),
|
||||
AstFragmentKind::FieldPats => AstFragment::FieldPats(smallvec![ast::FieldPat {
|
||||
AstFragmentKind::FieldPats => AstFragment::FieldPats(smallvec![ast::PatField {
|
||||
attrs: Default::default(),
|
||||
id,
|
||||
ident,
|
||||
@ -153,7 +153,7 @@ pub fn placeholder(
|
||||
ty: ty(),
|
||||
is_placeholder: true,
|
||||
}]),
|
||||
AstFragmentKind::StructFields => AstFragment::StructFields(smallvec![ast::StructField {
|
||||
AstFragmentKind::StructFields => AstFragment::StructFields(smallvec![ast::FieldDef {
|
||||
attrs: Default::default(),
|
||||
id,
|
||||
ident: None,
|
||||
@ -205,19 +205,19 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
fn flat_map_field(&mut self, field: ast::Field) -> SmallVec<[ast::Field; 1]> {
|
||||
fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> {
|
||||
if field.is_placeholder {
|
||||
self.remove(field.id).make_fields()
|
||||
self.remove(field.id).make_expr_fields()
|
||||
} else {
|
||||
noop_flat_map_field(field, self)
|
||||
noop_flat_map_expr_field(field, self)
|
||||
}
|
||||
}
|
||||
|
||||
fn flat_map_field_pattern(&mut self, fp: ast::FieldPat) -> SmallVec<[ast::FieldPat; 1]> {
|
||||
fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> {
|
||||
if fp.is_placeholder {
|
||||
self.remove(fp.id).make_field_patterns()
|
||||
self.remove(fp.id).make_pat_fields()
|
||||
} else {
|
||||
noop_flat_map_field_pattern(fp, self)
|
||||
noop_flat_map_pat_field(fp, self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,11 +240,11 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
fn flat_map_struct_field(&mut self, sf: ast::StructField) -> SmallVec<[ast::StructField; 1]> {
|
||||
fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> {
|
||||
if sf.is_placeholder {
|
||||
self.remove(sf.id).make_struct_fields()
|
||||
self.remove(sf.id).make_field_defs()
|
||||
} else {
|
||||
noop_flat_map_struct_field(sf, self)
|
||||
noop_flat_map_field_def(sf, self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ macro_rules! arena_types {
|
||||
[] generic_bound: rustc_hir::GenericBound<$tcx>,
|
||||
[] generic_param: rustc_hir::GenericParam<$tcx>,
|
||||
[] expr: rustc_hir::Expr<$tcx>,
|
||||
[] field: rustc_hir::Field<$tcx>,
|
||||
[] field_pat: rustc_hir::FieldPat<$tcx>,
|
||||
[] expr_field: rustc_hir::ExprField<$tcx>,
|
||||
[] pat_field: rustc_hir::PatField<$tcx>,
|
||||
[] fn_decl: rustc_hir::FnDecl<$tcx>,
|
||||
[] foreign_item: rustc_hir::ForeignItem<$tcx>,
|
||||
[few] foreign_item_ref: rustc_hir::ForeignItemRef<$tcx>,
|
||||
@ -42,7 +42,7 @@ macro_rules! arena_types {
|
||||
[] poly_trait_ref: rustc_hir::PolyTraitRef<$tcx>,
|
||||
[] qpath: rustc_hir::QPath<$tcx>,
|
||||
[] stmt: rustc_hir::Stmt<$tcx>,
|
||||
[] struct_field: rustc_hir::StructField<$tcx>,
|
||||
[] field_def: rustc_hir::FieldDef<$tcx>,
|
||||
[] trait_item_ref: rustc_hir::TraitItemRef,
|
||||
[] ty: rustc_hir::Ty<$tcx>,
|
||||
[] type_binding: rustc_hir::TypeBinding<$tcx>,
|
||||
|
@ -882,7 +882,7 @@ impl<'hir> Pat<'hir> {
|
||||
/// are treated the same as` x: x, y: ref y, z: ref mut z`,
|
||||
/// except `is_shorthand` is true.
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct FieldPat<'hir> {
|
||||
pub struct PatField<'hir> {
|
||||
#[stable_hasher(ignore)]
|
||||
pub hir_id: HirId,
|
||||
/// The identifier for the field.
|
||||
@ -946,7 +946,7 @@ pub enum PatKind<'hir> {
|
||||
|
||||
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
|
||||
/// The `bool` is `true` in the presence of a `..`.
|
||||
Struct(QPath<'hir>, &'hir [FieldPat<'hir>], bool),
|
||||
Struct(QPath<'hir>, &'hir [PatField<'hir>], bool),
|
||||
|
||||
/// A tuple struct/variant pattern `Variant(x, y, .., z)`.
|
||||
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
|
||||
@ -1203,7 +1203,7 @@ pub enum Guard<'hir> {
|
||||
}
|
||||
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct Field<'hir> {
|
||||
pub struct ExprField<'hir> {
|
||||
#[stable_hasher(ignore)]
|
||||
pub hir_id: HirId,
|
||||
pub ident: Ident,
|
||||
@ -1762,7 +1762,7 @@ pub enum ExprKind<'hir> {
|
||||
///
|
||||
/// E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. base}`,
|
||||
/// where `base` is the `Option<Expr>`.
|
||||
Struct(&'hir QPath<'hir>, &'hir [Field<'hir>], Option<&'hir Expr<'hir>>),
|
||||
Struct(&'hir QPath<'hir>, &'hir [ExprField<'hir>], Option<&'hir Expr<'hir>>),
|
||||
|
||||
/// An array literal constructed from one repeated element.
|
||||
///
|
||||
@ -2623,7 +2623,7 @@ impl VisibilityKind<'_> {
|
||||
}
|
||||
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct StructField<'hir> {
|
||||
pub struct FieldDef<'hir> {
|
||||
pub span: Span,
|
||||
#[stable_hasher(project(name))]
|
||||
pub ident: Ident,
|
||||
@ -2632,7 +2632,7 @@ pub struct StructField<'hir> {
|
||||
pub ty: &'hir Ty<'hir>,
|
||||
}
|
||||
|
||||
impl StructField<'_> {
|
||||
impl FieldDef<'_> {
|
||||
// Still necessary in couple of places
|
||||
pub fn is_positional(&self) -> bool {
|
||||
let first = self.ident.as_str().as_bytes()[0];
|
||||
@ -2646,11 +2646,11 @@ pub enum VariantData<'hir> {
|
||||
/// A struct variant.
|
||||
///
|
||||
/// E.g., `Bar { .. }` as in `enum Foo { Bar { .. } }`.
|
||||
Struct(&'hir [StructField<'hir>], /* recovered */ bool),
|
||||
Struct(&'hir [FieldDef<'hir>], /* recovered */ bool),
|
||||
/// A tuple variant.
|
||||
///
|
||||
/// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`.
|
||||
Tuple(&'hir [StructField<'hir>], HirId),
|
||||
Tuple(&'hir [FieldDef<'hir>], HirId),
|
||||
/// A unit variant.
|
||||
///
|
||||
/// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`.
|
||||
@ -2659,7 +2659,7 @@ pub enum VariantData<'hir> {
|
||||
|
||||
impl VariantData<'hir> {
|
||||
/// Return the fields of this variant.
|
||||
pub fn fields(&self) -> &'hir [StructField<'hir>] {
|
||||
pub fn fields(&self) -> &'hir [FieldDef<'hir>] {
|
||||
match *self {
|
||||
VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, ..) => fields,
|
||||
_ => &[],
|
||||
@ -2967,7 +2967,7 @@ pub enum Node<'hir> {
|
||||
TraitItem(&'hir TraitItem<'hir>),
|
||||
ImplItem(&'hir ImplItem<'hir>),
|
||||
Variant(&'hir Variant<'hir>),
|
||||
Field(&'hir StructField<'hir>),
|
||||
Field(&'hir FieldDef<'hir>),
|
||||
AnonConst(&'hir AnonConst),
|
||||
Expr(&'hir Expr<'hir>),
|
||||
Stmt(&'hir Stmt<'hir>),
|
||||
@ -2998,7 +2998,7 @@ impl<'hir> Node<'hir> {
|
||||
Node::TraitItem(TraitItem { ident, .. })
|
||||
| Node::ImplItem(ImplItem { ident, .. })
|
||||
| Node::ForeignItem(ForeignItem { ident, .. })
|
||||
| Node::Field(StructField { ident, .. })
|
||||
| Node::Field(FieldDef { ident, .. })
|
||||
| Node::Variant(Variant { ident, .. })
|
||||
| Node::MacroDef(MacroDef { ident, .. })
|
||||
| Node::Item(Item { ident, .. }) => Some(*ident),
|
||||
@ -3046,7 +3046,7 @@ impl<'hir> Node<'hir> {
|
||||
| Node::ImplItem(ImplItem { def_id, .. })
|
||||
| Node::ForeignItem(ForeignItem { def_id, .. })
|
||||
| Node::MacroDef(MacroDef { def_id, .. }) => Some(HirId::make_owner(*def_id)),
|
||||
Node::Field(StructField { hir_id, .. })
|
||||
Node::Field(FieldDef { hir_id, .. })
|
||||
| Node::AnonConst(AnonConst { hir_id, .. })
|
||||
| Node::Expr(Expr { hir_id, .. })
|
||||
| Node::Stmt(Stmt { hir_id, .. })
|
||||
|
@ -415,8 +415,8 @@ pub trait Visitor<'v>: Sized {
|
||||
) {
|
||||
walk_struct_def(self, s)
|
||||
}
|
||||
fn visit_struct_field(&mut self, s: &'v StructField<'v>) {
|
||||
walk_struct_field(self, s)
|
||||
fn visit_field_def(&mut self, s: &'v FieldDef<'v>) {
|
||||
walk_field_def(self, s)
|
||||
}
|
||||
fn visit_enum_def(
|
||||
&mut self,
|
||||
@ -1045,14 +1045,14 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(
|
||||
struct_definition: &'v VariantData<'v>,
|
||||
) {
|
||||
walk_list!(visitor, visit_id, struct_definition.ctor_hir_id());
|
||||
walk_list!(visitor, visit_struct_field, struct_definition.fields());
|
||||
walk_list!(visitor, visit_field_def, struct_definition.fields());
|
||||
}
|
||||
|
||||
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField<'v>) {
|
||||
visitor.visit_id(struct_field.hir_id);
|
||||
visitor.visit_vis(&struct_field.vis);
|
||||
visitor.visit_ident(struct_field.ident);
|
||||
visitor.visit_ty(&struct_field.ty);
|
||||
pub fn walk_field_def<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v FieldDef<'v>) {
|
||||
visitor.visit_id(field.hir_id);
|
||||
visitor.visit_vis(&field.vis);
|
||||
visitor.visit_ident(field.ident);
|
||||
visitor.visit_ty(&field.ty);
|
||||
}
|
||||
|
||||
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) {
|
||||
|
@ -114,7 +114,7 @@ impl<'a> State<'a> {
|
||||
Node::Lifetime(a) => self.print_lifetime(&a),
|
||||
Node::Visibility(a) => self.print_visibility(&a),
|
||||
Node::GenericParam(_) => panic!("cannot print Node::GenericParam"),
|
||||
Node::Field(_) => panic!("cannot print StructField"),
|
||||
Node::Field(_) => panic!("cannot print Node::Field"),
|
||||
// These cases do not carry enough information in the
|
||||
// `hir_map` to reconstruct their full structure for pretty
|
||||
// printing.
|
||||
@ -1207,7 +1207,7 @@ impl<'a> State<'a> {
|
||||
fn print_expr_struct(
|
||||
&mut self,
|
||||
qpath: &hir::QPath<'_>,
|
||||
fields: &[hir::Field<'_>],
|
||||
fields: &[hir::ExprField<'_>],
|
||||
wth: &Option<&hir::Expr<'_>>,
|
||||
) {
|
||||
self.print_qpath(qpath, true);
|
||||
|
@ -182,9 +182,9 @@ impl Visitor<'tcx> for IfThisChanged<'tcx> {
|
||||
intravisit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) {
|
||||
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
|
||||
self.process_attrs(s.hir_id);
|
||||
intravisit::walk_struct_field(self, s);
|
||||
intravisit::walk_field_def(self, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -651,7 +651,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
self.check_missing_docs_attrs(cx, foreign_item.hir_id(), foreign_item.span, article, desc);
|
||||
}
|
||||
|
||||
fn check_struct_field(&mut self, cx: &LateContext<'_>, sf: &hir::StructField<'_>) {
|
||||
fn check_field_def(&mut self, cx: &LateContext<'_>, sf: &hir::FieldDef<'_>) {
|
||||
if !sf.is_positional() {
|
||||
self.check_missing_docs_attrs(cx, sf.hir_id, sf.span, "a", "struct field")
|
||||
}
|
||||
@ -1345,7 +1345,7 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
|
||||
);
|
||||
}
|
||||
|
||||
fn check_struct_field(&mut self, cx: &LateContext<'_>, field: &hir::StructField<'_>) {
|
||||
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
|
||||
self.perform_lint(cx, "field", field.hir_id, &field.vis, field.span, false);
|
||||
}
|
||||
|
||||
|
@ -163,10 +163,10 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
||||
run_early_pass!(self, check_struct_def_post, s);
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'a ast::StructField) {
|
||||
fn visit_field_def(&mut self, s: &'a ast::FieldDef) {
|
||||
self.with_lint_attrs(s.id, &s.attrs, |cx| {
|
||||
run_early_pass!(cx, check_struct_field, s);
|
||||
ast_visit::walk_struct_field(cx, s);
|
||||
run_early_pass!(cx, check_field_def, s);
|
||||
ast_visit::walk_field_def(cx, s);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -219,10 +219,10 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
||||
lint_callback!(self, check_struct_def_post, s);
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) {
|
||||
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
|
||||
self.with_lint_attrs(s.hir_id, |cx| {
|
||||
lint_callback!(cx, check_struct_field, s);
|
||||
hir_visit::walk_struct_field(cx, s);
|
||||
lint_callback!(cx, check_field_def, s);
|
||||
hir_visit::walk_field_def(cx, s);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -619,9 +619,9 @@ impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) {
|
||||
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
|
||||
self.with_lint_attrs(s.hir_id, |builder| {
|
||||
intravisit::walk_struct_field(builder, s);
|
||||
intravisit::walk_field_def(builder, s);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ macro_rules! late_lint_methods {
|
||||
fn check_impl_item_post(a: &$hir hir::ImplItem<$hir>);
|
||||
fn check_struct_def(a: &$hir hir::VariantData<$hir>);
|
||||
fn check_struct_def_post(a: &$hir hir::VariantData<$hir>);
|
||||
fn check_struct_field(a: &$hir hir::StructField<$hir>);
|
||||
fn check_field_def(a: &$hir hir::FieldDef<$hir>);
|
||||
fn check_variant(a: &$hir hir::Variant<$hir>);
|
||||
fn check_variant_post(a: &$hir hir::Variant<$hir>);
|
||||
fn check_lifetime(a: &$hir hir::Lifetime);
|
||||
@ -193,7 +193,7 @@ macro_rules! early_lint_methods {
|
||||
fn check_impl_item_post(a: &ast::AssocItem);
|
||||
fn check_struct_def(a: &ast::VariantData);
|
||||
fn check_struct_def_post(a: &ast::VariantData);
|
||||
fn check_struct_field(a: &ast::StructField);
|
||||
fn check_field_def(a: &ast::FieldDef);
|
||||
fn check_variant(a: &ast::Variant);
|
||||
fn check_variant_post(a: &ast::Variant);
|
||||
fn check_lifetime(a: &ast::Lifetime);
|
||||
|
@ -553,10 +553,10 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, field: &'hir StructField<'hir>) {
|
||||
fn visit_field_def(&mut self, field: &'hir FieldDef<'hir>) {
|
||||
self.insert(field.span, field.hir_id, Node::Field(field));
|
||||
self.with_parent(field.hir_id, |this| {
|
||||
intravisit::walk_struct_field(this, field);
|
||||
intravisit::walk_field_def(this, field);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1111,7 +1111,10 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
|
||||
}
|
||||
|
||||
/// Converts a list of named fields (i.e., for struct-like struct/enum ADTs) into FieldExpr.
|
||||
fn field_refs(&mut self, fields: &'tcx [hir::Field<'tcx>]) -> &'thir [FieldExpr<'thir, 'tcx>] {
|
||||
fn field_refs(
|
||||
&mut self,
|
||||
fields: &'tcx [hir::ExprField<'tcx>],
|
||||
) -> &'thir [FieldExpr<'thir, 'tcx>] {
|
||||
self.arena.alloc_from_iter(fields.iter().map(|field| FieldExpr {
|
||||
name: Field::new(self.tcx.field_index(field.hir_id, self.typeck_results)),
|
||||
expr: self.mirror_expr(field.expr),
|
||||
|
@ -10,7 +10,7 @@ use rustc_ast::tokenstream::Spacing;
|
||||
use rustc_ast::util::classify;
|
||||
use rustc_ast::util::literal::LitError;
|
||||
use rustc_ast::util::parser::{prec_let_scrutinee_needs_par, AssocOp, Fixity};
|
||||
use rustc_ast::{self as ast, AttrStyle, AttrVec, CaptureBy, Field, Lit, UnOp, DUMMY_NODE_ID};
|
||||
use rustc_ast::{self as ast, AttrStyle, AttrVec, CaptureBy, ExprField, Lit, UnOp, DUMMY_NODE_ID};
|
||||
use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty, TyKind};
|
||||
use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
|
||||
use rustc_ast_pretty::pprust;
|
||||
@ -2316,7 +2316,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
let recovery_field = self.find_struct_error_after_field_looking_code();
|
||||
let parsed_field = match self.parse_field() {
|
||||
let parsed_field = match self.parse_expr_field() {
|
||||
Ok(f) => Some(f),
|
||||
Err(mut e) => {
|
||||
if pth == kw::Async {
|
||||
@ -2373,18 +2373,22 @@ impl<'a> Parser<'a> {
|
||||
|
||||
let span = pth.span.to(self.token.span);
|
||||
self.expect(&token::CloseDelim(token::Brace))?;
|
||||
let expr = if recover_async { ExprKind::Err } else { ExprKind::Struct(pth, fields, base) };
|
||||
let expr = if recover_async {
|
||||
ExprKind::Err
|
||||
} else {
|
||||
ExprKind::Struct(P(ast::StructExpr { path: pth, fields, rest: base }))
|
||||
};
|
||||
Ok(self.mk_expr(span, expr, attrs))
|
||||
}
|
||||
|
||||
/// Use in case of error after field-looking code: `S { foo: () with a }`.
|
||||
fn find_struct_error_after_field_looking_code(&self) -> Option<Field> {
|
||||
fn find_struct_error_after_field_looking_code(&self) -> Option<ExprField> {
|
||||
match self.token.ident() {
|
||||
Some((ident, is_raw))
|
||||
if (is_raw || !ident.is_reserved())
|
||||
&& self.look_ahead(1, |t| *t == token::Colon) =>
|
||||
{
|
||||
Some(ast::Field {
|
||||
Some(ast::ExprField {
|
||||
ident,
|
||||
span: self.token.span,
|
||||
expr: self.mk_expr_err(self.token.span),
|
||||
@ -2418,7 +2422,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
/// Parses `ident (COLON expr)?`.
|
||||
fn parse_field(&mut self) -> PResult<'a, Field> {
|
||||
fn parse_expr_field(&mut self) -> PResult<'a, ExprField> {
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
|
||||
let lo = this.token.span;
|
||||
@ -2438,7 +2442,7 @@ impl<'a> Parser<'a> {
|
||||
};
|
||||
|
||||
Ok((
|
||||
ast::Field {
|
||||
ast::ExprField {
|
||||
ident,
|
||||
span: lo.to(expr.span),
|
||||
expr,
|
||||
|
@ -9,7 +9,7 @@ use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree};
|
||||
use rustc_ast::{self as ast, AttrVec, Attribute, DUMMY_NODE_ID};
|
||||
use rustc_ast::{Async, Const, Defaultness, IsAuto, Mutability, Unsafe, UseTree, UseTreeKind};
|
||||
use rustc_ast::{BindingMode, Block, FnDecl, FnSig, Param, SelfKind};
|
||||
use rustc_ast::{EnumDef, Generics, StructField, TraitRef, Ty, TyKind, Variant, VariantData};
|
||||
use rustc_ast::{EnumDef, FieldDef, Generics, TraitRef, Ty, TyKind, Variant, VariantData};
|
||||
use rustc_ast::{FnHeader, ForeignItem, Path, PathSegment, Visibility, VisibilityKind};
|
||||
use rustc_ast::{MacArgs, MacCall, MacDelimiter};
|
||||
use rustc_ast_pretty::pprust;
|
||||
@ -1231,14 +1231,12 @@ impl<'a> Parser<'a> {
|
||||
Ok((class_name, ItemKind::Union(vdata, generics)))
|
||||
}
|
||||
|
||||
fn parse_record_struct_body(
|
||||
&mut self,
|
||||
) -> PResult<'a, (Vec<StructField>, /* recovered */ bool)> {
|
||||
fn parse_record_struct_body(&mut self) -> PResult<'a, (Vec<FieldDef>, /* recovered */ bool)> {
|
||||
let mut fields = Vec::new();
|
||||
let mut recovered = false;
|
||||
if self.eat(&token::OpenDelim(token::Brace)) {
|
||||
while self.token != token::CloseDelim(token::Brace) {
|
||||
let field = self.parse_struct_decl_field().map_err(|e| {
|
||||
let field = self.parse_field_def().map_err(|e| {
|
||||
self.consume_block(token::Brace, ConsumeClosingDelim::No);
|
||||
recovered = true;
|
||||
e
|
||||
@ -1263,7 +1261,7 @@ impl<'a> Parser<'a> {
|
||||
Ok((fields, recovered))
|
||||
}
|
||||
|
||||
fn parse_tuple_struct_body(&mut self) -> PResult<'a, Vec<StructField>> {
|
||||
fn parse_tuple_struct_body(&mut self) -> PResult<'a, Vec<FieldDef>> {
|
||||
// This is the case where we find `struct Foo<T>(T) where T: Copy;`
|
||||
// Unit like structs are handled in parse_item_struct function
|
||||
self.parse_paren_comma_seq(|p| {
|
||||
@ -1274,7 +1272,7 @@ impl<'a> Parser<'a> {
|
||||
let ty = p.parse_ty()?;
|
||||
|
||||
Ok((
|
||||
StructField {
|
||||
FieldDef {
|
||||
span: lo.to(ty.span),
|
||||
vis,
|
||||
ident: None,
|
||||
@ -1291,7 +1289,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
/// Parses an element of a struct declaration.
|
||||
fn parse_struct_decl_field(&mut self) -> PResult<'a, StructField> {
|
||||
fn parse_field_def(&mut self) -> PResult<'a, FieldDef> {
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
|
||||
let lo = this.token.span;
|
||||
@ -1306,7 +1304,7 @@ impl<'a> Parser<'a> {
|
||||
lo: Span,
|
||||
vis: Visibility,
|
||||
attrs: Vec<Attribute>,
|
||||
) -> PResult<'a, StructField> {
|
||||
) -> PResult<'a, FieldDef> {
|
||||
let mut seen_comma: bool = false;
|
||||
let a_var = self.parse_name_and_ty(lo, vis, attrs)?;
|
||||
if self.token == token::Comma {
|
||||
@ -1398,11 +1396,11 @@ impl<'a> Parser<'a> {
|
||||
lo: Span,
|
||||
vis: Visibility,
|
||||
attrs: Vec<Attribute>,
|
||||
) -> PResult<'a, StructField> {
|
||||
) -> PResult<'a, FieldDef> {
|
||||
let name = self.parse_ident_common(false)?;
|
||||
self.expect(&token::Colon)?;
|
||||
let ty = self.parse_ty()?;
|
||||
Ok(StructField {
|
||||
Ok(FieldDef {
|
||||
span: lo.to(self.prev_token.span),
|
||||
ident: Some(name),
|
||||
vis,
|
||||
|
@ -3,7 +3,7 @@ use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
|
||||
use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token;
|
||||
use rustc_ast::{self as ast, AttrVec, Attribute, FieldPat, MacCall, Pat, PatKind, RangeEnd};
|
||||
use rustc_ast::{self as ast, AttrVec, Attribute, MacCall, Pat, PatField, PatKind, RangeEnd};
|
||||
use rustc_ast::{BindingMode, Expr, ExprKind, Mutability, Path, QSelf, RangeSyntax};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, PResult};
|
||||
@ -928,7 +928,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
/// Parses the fields of a struct-like pattern.
|
||||
fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<FieldPat>, bool)> {
|
||||
fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<PatField>, bool)> {
|
||||
let mut fields = Vec::new();
|
||||
let mut etc = false;
|
||||
let mut ate_comma = true;
|
||||
@ -1072,7 +1072,7 @@ impl<'a> Parser<'a> {
|
||||
.emit();
|
||||
}
|
||||
|
||||
fn parse_pat_field(&mut self, lo: Span, attrs: Vec<Attribute>) -> PResult<'a, FieldPat> {
|
||||
fn parse_pat_field(&mut self, lo: Span, attrs: Vec<Attribute>) -> PResult<'a, PatField> {
|
||||
// Check if a colon exists one ahead. This means we're parsing a fieldname.
|
||||
let hi;
|
||||
let (subpat, fieldname, is_shorthand) = if self.look_ahead(1, |t| t == &token::Colon) {
|
||||
@ -1104,7 +1104,7 @@ impl<'a> Parser<'a> {
|
||||
(subpat, fieldname, true)
|
||||
};
|
||||
|
||||
Ok(FieldPat {
|
||||
Ok(PatField {
|
||||
ident: fieldname,
|
||||
pat: subpat,
|
||||
is_shorthand,
|
||||
|
@ -1282,9 +1282,9 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
||||
intravisit::walk_trait_item(self, trait_item)
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, struct_field: &'tcx hir::StructField<'tcx>) {
|
||||
fn visit_field_def(&mut self, struct_field: &'tcx hir::FieldDef<'tcx>) {
|
||||
self.check_attributes(struct_field.hir_id, &struct_field.span, Target::Field, None);
|
||||
intravisit::walk_struct_field(self, struct_field);
|
||||
intravisit::walk_field_def(self, struct_field);
|
||||
}
|
||||
|
||||
fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
|
||||
|
@ -153,7 +153,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
||||
&mut self,
|
||||
lhs: &hir::Pat<'_>,
|
||||
res: Res,
|
||||
pats: &[hir::FieldPat<'_>],
|
||||
pats: &[hir::PatField<'_>],
|
||||
) {
|
||||
let variant = match self.typeck_results().node_type(lhs.hir_id).kind() {
|
||||
ty::Adt(adt, _) => adt.variant_of_res(res),
|
||||
@ -224,7 +224,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
||||
self.inherited_pub_visibility = had_inherited_pub_visibility;
|
||||
}
|
||||
|
||||
fn mark_as_used_if_union(&mut self, adt: &ty::AdtDef, fields: &[hir::Field<'_>]) {
|
||||
fn mark_as_used_if_union(&mut self, adt: &ty::AdtDef, fields: &[hir::ExprField<'_>]) {
|
||||
if adt.is_union() && adt.non_enum_variant().fields.len() > 1 && adt.did.is_local() {
|
||||
for field in fields {
|
||||
let index = self.tcx.field_index(field.hir_id, self.typeck_results());
|
||||
@ -525,7 +525,7 @@ impl DeadVisitor<'tcx> {
|
||||
should_warn && !self.symbol_is_live(item.hir_id())
|
||||
}
|
||||
|
||||
fn should_warn_about_field(&mut self, field: &hir::StructField<'_>) -> bool {
|
||||
fn should_warn_about_field(&mut self, field: &hir::FieldDef<'_>) -> bool {
|
||||
let field_type = self.tcx.type_of(self.tcx.hir().local_def_id(field.hir_id));
|
||||
!field.is_positional()
|
||||
&& !self.symbol_is_live(field.hir_id)
|
||||
@ -650,11 +650,11 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
|
||||
intravisit::walk_foreign_item(self, fi);
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, field: &'tcx hir::StructField<'tcx>) {
|
||||
fn visit_field_def(&mut self, field: &'tcx hir::FieldDef<'tcx>) {
|
||||
if self.should_warn_about_field(&field) {
|
||||
self.warn_dead_code(field.hir_id, field.span, field.ident.name, "read");
|
||||
}
|
||||
intravisit::walk_struct_field(self, field);
|
||||
intravisit::walk_field_def(self, field);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
|
@ -201,9 +201,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
||||
hir_visit::walk_param_bound(self, bounds)
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'v hir::StructField<'v>) {
|
||||
self.record("StructField", Id::Node(s.hir_id), s);
|
||||
hir_visit::walk_struct_field(self, s)
|
||||
fn visit_field_def(&mut self, s: &'v hir::FieldDef<'v>) {
|
||||
self.record("FieldDef", Id::Node(s.hir_id), s);
|
||||
hir_visit::walk_field_def(self, s)
|
||||
}
|
||||
|
||||
fn visit_variant(
|
||||
@ -316,9 +316,9 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
|
||||
ast_visit::walk_param_bound(self, bounds)
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'v ast::StructField) {
|
||||
self.record("StructField", Id::None, s);
|
||||
ast_visit::walk_struct_field(self, s)
|
||||
fn visit_field_def(&mut self, s: &'v ast::FieldDef) {
|
||||
self.record("FieldDef", Id::None, s);
|
||||
ast_visit::walk_field_def(self, s)
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'v ast::Variant) {
|
||||
|
@ -9,7 +9,7 @@ use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::{Generics, HirId, Item, StructField, TraitRef, Ty, TyKind, Variant};
|
||||
use rustc_hir::{FieldDef, Generics, HirId, Item, TraitRef, Ty, TyKind, Variant};
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::middle::privacy::AccessLevels;
|
||||
use rustc_middle::middle::stability::{DeprecationEntry, Index};
|
||||
@ -465,7 +465,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
||||
)
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) {
|
||||
fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) {
|
||||
self.annotate(
|
||||
s.hir_id,
|
||||
s.span,
|
||||
@ -474,7 +474,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
||||
InheritConstStability::No,
|
||||
InheritStability::Yes,
|
||||
|v| {
|
||||
intravisit::walk_struct_field(v, s);
|
||||
intravisit::walk_field_def(v, s);
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -610,9 +610,9 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
|
||||
intravisit::walk_variant(self, var, g, item_id);
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) {
|
||||
fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) {
|
||||
self.check_missing_stability(s.hir_id, s.span);
|
||||
intravisit::walk_struct_field(self, s);
|
||||
intravisit::walk_field_def(self, s);
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) {
|
||||
|
@ -1698,9 +1698,9 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) {
|
||||
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
|
||||
if s.vis.node.is_pub() || self.in_variant {
|
||||
intravisit::walk_struct_field(self, s);
|
||||
intravisit::walk_field_def(self, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1426,19 +1426,19 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_field(&mut self, f: &'b ast::Field) {
|
||||
fn visit_expr_field(&mut self, f: &'b ast::ExprField) {
|
||||
if f.is_placeholder {
|
||||
self.visit_invoc(f.id);
|
||||
} else {
|
||||
visit::walk_field(self, f);
|
||||
visit::walk_expr_field(self, f);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_field_pattern(&mut self, fp: &'b ast::FieldPat) {
|
||||
fn visit_pat_field(&mut self, fp: &'b ast::PatField) {
|
||||
if fp.is_placeholder {
|
||||
self.visit_invoc(fp.id);
|
||||
} else {
|
||||
visit::walk_field_pattern(self, fp);
|
||||
visit::walk_pat_field(self, fp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1458,13 +1458,13 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, sf: &'b ast::StructField) {
|
||||
fn visit_field_def(&mut self, sf: &'b ast::FieldDef) {
|
||||
if sf.is_placeholder {
|
||||
self.visit_invoc(sf.id);
|
||||
} else {
|
||||
let vis = self.resolve_visibility(&sf.vis);
|
||||
self.r.visibilities.insert(self.r.local_def_id(sf.id), vis);
|
||||
visit::walk_struct_field(self, sf);
|
||||
visit::walk_field_def(self, sf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ impl<'a, 'b> DefCollector<'a, 'b> {
|
||||
self.impl_trait_context = orig_itc;
|
||||
}
|
||||
|
||||
fn collect_field(&mut self, field: &'a StructField, index: Option<usize>) {
|
||||
fn collect_field(&mut self, field: &'a FieldDef, index: Option<usize>) {
|
||||
let index = |this: &Self| {
|
||||
index.unwrap_or_else(|| {
|
||||
let node_id = NodeId::placeholder_from_expn_id(this.expansion);
|
||||
@ -66,7 +66,7 @@ impl<'a, 'b> DefCollector<'a, 'b> {
|
||||
} else {
|
||||
let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
|
||||
let def = self.create_def(field.id, DefPathData::ValueNs(name), field.span);
|
||||
self.with_parent(def, |this| visit::walk_struct_field(this, field));
|
||||
self.with_parent(def, |this| visit::walk_field_def(this, field));
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,15 +309,19 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
|
||||
if arm.is_placeholder { self.visit_macro_invoc(arm.id) } else { visit::walk_arm(self, arm) }
|
||||
}
|
||||
|
||||
fn visit_field(&mut self, f: &'a Field) {
|
||||
if f.is_placeholder { self.visit_macro_invoc(f.id) } else { visit::walk_field(self, f) }
|
||||
fn visit_expr_field(&mut self, f: &'a ExprField) {
|
||||
if f.is_placeholder {
|
||||
self.visit_macro_invoc(f.id)
|
||||
} else {
|
||||
visit::walk_expr_field(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_field_pattern(&mut self, fp: &'a FieldPat) {
|
||||
fn visit_pat_field(&mut self, fp: &'a PatField) {
|
||||
if fp.is_placeholder {
|
||||
self.visit_macro_invoc(fp.id)
|
||||
} else {
|
||||
visit::walk_field_pattern(self, fp)
|
||||
visit::walk_pat_field(self, fp)
|
||||
}
|
||||
}
|
||||
|
||||
@ -333,7 +337,7 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
|
||||
|
||||
// This method is called only when we are visiting an individual field
|
||||
// after expanding an attribute on it.
|
||||
fn visit_struct_field(&mut self, field: &'a StructField) {
|
||||
fn visit_field_def(&mut self, field: &'a FieldDef) {
|
||||
self.collect_field(field, None);
|
||||
}
|
||||
}
|
||||
|
@ -2251,8 +2251,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
visit::walk_expr(self, expr);
|
||||
}
|
||||
|
||||
ExprKind::Struct(ref path, ..) => {
|
||||
self.smart_resolve_path(expr.id, None, path, PathSource::Struct);
|
||||
ExprKind::Struct(ref se) => {
|
||||
self.smart_resolve_path(expr.id, None, &se.path, PathSource::Struct);
|
||||
visit::walk_expr(self, expr);
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
|
||||
fn process_struct_field_def(
|
||||
&mut self,
|
||||
field: &'tcx hir::StructField<'tcx>,
|
||||
field: &'tcx hir::FieldDef<'tcx>,
|
||||
parent_id: hir::HirId,
|
||||
) {
|
||||
let field_data = self.save_ctxt.get_field_data(field, parent_id);
|
||||
@ -793,7 +793,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
&mut self,
|
||||
ex: &'tcx hir::Expr<'tcx>,
|
||||
path: &'tcx hir::QPath<'tcx>,
|
||||
fields: &'tcx [hir::Field<'tcx>],
|
||||
fields: &'tcx [hir::ExprField<'tcx>],
|
||||
variant: &'tcx ty::VariantDef,
|
||||
rest: Option<&'tcx hir::Expr<'tcx>>,
|
||||
) {
|
||||
|
@ -379,7 +379,7 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_field_data(&self, field: &hir::StructField<'_>, scope: hir::HirId) -> Option<Def> {
|
||||
pub fn get_field_data(&self, field: &hir::FieldDef<'_>, scope: hir::HirId) -> Option<Def> {
|
||||
let name = field.ident.to_string();
|
||||
let scope_def_id = self.tcx.hir().local_def_id(scope).to_def_id();
|
||||
let qualname = format!("::{}::{}", self.tcx.def_path_str(scope_def_id), field.ident);
|
||||
@ -769,7 +769,7 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
|
||||
pub fn get_field_ref_data(
|
||||
&self,
|
||||
field_ref: &hir::Field<'_>,
|
||||
field_ref: &hir::ExprField<'_>,
|
||||
variant: &ty::VariantDef,
|
||||
) -> Option<Ref> {
|
||||
filter!(self.span_utils, field_ref.ident.span);
|
||||
|
@ -55,7 +55,7 @@ pub fn foreign_item_signature(
|
||||
|
||||
/// Signature for a struct or tuple field declaration.
|
||||
/// Does not include a trailing comma.
|
||||
pub fn field_signature(field: &hir::StructField<'_>, scx: &SaveContext<'_>) -> Option<Signature> {
|
||||
pub fn field_signature(field: &hir::FieldDef<'_>, scx: &SaveContext<'_>) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
@ -655,7 +655,7 @@ impl<'hir> Sig for hir::Generics<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Sig for hir::StructField<'hir> {
|
||||
impl<'hir> Sig for hir::FieldDef<'hir> {
|
||||
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
||||
let mut text = String::new();
|
||||
|
||||
|
@ -1158,7 +1158,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
expr: &hir::Expr<'_>,
|
||||
expected: Expectation<'tcx>,
|
||||
qpath: &QPath<'_>,
|
||||
fields: &'tcx [hir::Field<'tcx>],
|
||||
fields: &'tcx [hir::ExprField<'tcx>],
|
||||
base_expr: &'tcx Option<&'tcx hir::Expr<'tcx>>,
|
||||
) -> Ty<'tcx> {
|
||||
// Find the relevant variant
|
||||
@ -1231,7 +1231,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
expr_id: hir::HirId,
|
||||
span: Span,
|
||||
variant: &'tcx ty::VariantDef,
|
||||
ast_fields: &'tcx [hir::Field<'tcx>],
|
||||
ast_fields: &'tcx [hir::ExprField<'tcx>],
|
||||
check_completeness: bool,
|
||||
) -> bool {
|
||||
let tcx = self.tcx;
|
||||
@ -1320,7 +1320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn check_struct_fields_on_error(
|
||||
&self,
|
||||
fields: &'tcx [hir::Field<'tcx>],
|
||||
fields: &'tcx [hir::ExprField<'tcx>],
|
||||
base_expr: &'tcx Option<&'tcx hir::Expr<'tcx>>,
|
||||
) {
|
||||
for field in fields {
|
||||
@ -1411,8 +1411,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
variant: &'tcx ty::VariantDef,
|
||||
field: &hir::Field<'_>,
|
||||
skip_fields: &[hir::Field<'_>],
|
||||
field: &hir::ExprField<'_>,
|
||||
skip_fields: &[hir::ExprField<'_>],
|
||||
kind_name: &str,
|
||||
ty_span: Span,
|
||||
) {
|
||||
|
@ -680,7 +680,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
pat: &'tcx Pat<'tcx>,
|
||||
qpath: &hir::QPath<'_>,
|
||||
fields: &'tcx [hir::FieldPat<'tcx>],
|
||||
fields: &'tcx [hir::PatField<'tcx>],
|
||||
etc: bool,
|
||||
expected: Ty<'tcx>,
|
||||
def_bm: BindingMode,
|
||||
@ -1151,7 +1151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
adt_ty: Ty<'tcx>,
|
||||
pat: &'tcx Pat<'tcx>,
|
||||
variant: &'tcx ty::VariantDef,
|
||||
fields: &'tcx [hir::FieldPat<'tcx>],
|
||||
fields: &'tcx [hir::PatField<'tcx>],
|
||||
etc: bool,
|
||||
def_bm: BindingMode,
|
||||
ti: TopInfo<'tcx>,
|
||||
@ -1291,7 +1291,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
variant: &VariantDef,
|
||||
pat: &'_ Pat<'_>,
|
||||
fields: &[hir::FieldPat<'_>],
|
||||
fields: &[hir::PatField<'_>],
|
||||
) -> Option<DiagnosticBuilder<'_>> {
|
||||
// if this is a tuple struct, then all field names will be numbers
|
||||
// so if any fields in a struct pattern use shorthand syntax, they will
|
||||
@ -1446,7 +1446,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
fn error_tuple_variant_as_struct_pat(
|
||||
&self,
|
||||
pat: &Pat<'_>,
|
||||
fields: &'tcx [hir::FieldPat<'tcx>],
|
||||
fields: &'tcx [hir::PatField<'tcx>],
|
||||
variant: &ty::VariantDef,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
if let (CtorKind::Fn, PatKind::Struct(qpath, ..)) = (variant.ctor_kind, &pat.kind) {
|
||||
@ -1484,7 +1484,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn get_suggested_tuple_struct_pattern(
|
||||
&self,
|
||||
fields: &[hir::FieldPat<'_>],
|
||||
fields: &[hir::PatField<'_>],
|
||||
variant: &VariantDef,
|
||||
) -> String {
|
||||
let variant_field_idents = variant.fields.iter().map(|f| f.ident).collect::<Vec<Ident>>();
|
||||
@ -1528,7 +1528,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
fn error_no_accessible_fields(
|
||||
&self,
|
||||
pat: &Pat<'_>,
|
||||
fields: &'tcx [hir::FieldPat<'tcx>],
|
||||
fields: &'tcx [hir::PatField<'tcx>],
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let mut err = self
|
||||
.tcx
|
||||
@ -1574,7 +1574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
pat: &Pat<'_>,
|
||||
unmentioned_fields: &[(&ty::FieldDef, Ident)],
|
||||
fields: &'tcx [hir::FieldPat<'tcx>],
|
||||
fields: &'tcx [hir::PatField<'tcx>],
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let field_names = if unmentioned_fields.len() == 1 {
|
||||
format!("field `{}`", unmentioned_fields[0].1)
|
||||
|
@ -456,7 +456,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
||||
|
||||
fn walk_struct_expr(
|
||||
&mut self,
|
||||
fields: &[hir::Field<'_>],
|
||||
fields: &[hir::ExprField<'_>],
|
||||
opt_with: &Option<&'hir hir::Expr<'_>>,
|
||||
) {
|
||||
// Consume the expressions supplying values for each field.
|
||||
|
@ -1754,7 +1754,7 @@ impl<'tcx> Clean<Constant> for ty::Const<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clean<Item> for hir::StructField<'_> {
|
||||
impl Clean<Item> for hir::FieldDef<'_> {
|
||||
fn clean(&self, cx: &mut DocContext<'_>) -> Item {
|
||||
let what_rustc_thinks = Item::from_hir_id_and_parts(
|
||||
self.hir_id,
|
||||
|
@ -1089,9 +1089,9 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, f: &'hir hir::StructField<'_>) {
|
||||
fn visit_field_def(&mut self, f: &'hir hir::FieldDef<'_>) {
|
||||
self.visit_testable(f.ident.to_string(), f.hir_id, f.span, |this| {
|
||||
intravisit::walk_struct_field(this, f);
|
||||
intravisit::walk_field_def(this, f);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,9 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
|
||||
},
|
||||
17 => {
|
||||
let path = Path::from_ident(Ident::from_str("S"));
|
||||
g(ExprKind::Struct(path, vec![], StructRest::Base(make_x())));
|
||||
g(ExprKind::Struct(P(StructExpr {
|
||||
path, fields: vec![], rest: StructRest::Base(make_x())
|
||||
})));
|
||||
},
|
||||
18 => {
|
||||
iter_exprs(depth - 1, &mut |e| g(ExprKind::Try(e)));
|
||||
|
@ -119,7 +119,7 @@ impl LateLintPass<'_> for InconsistentStructConstructor {
|
||||
|
||||
// Check whether the order of the fields in the constructor is consistent with the order in the
|
||||
// definition.
|
||||
fn is_consistent_order<'tcx>(fields: &'tcx [hir::Field<'tcx>], def_order_map: &FxHashMap<Symbol, usize>) -> bool {
|
||||
fn is_consistent_order<'tcx>(fields: &'tcx [hir::ExprField<'tcx>], def_order_map: &FxHashMap<Symbol, usize>) -> bool {
|
||||
let mut cur_idx = usize::MIN;
|
||||
for f in fields {
|
||||
let next_idx = def_order_map[&f.ident.name];
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::utils::{meets_msrv, snippet_opt, span_lint_and_then};
|
||||
use if_chain::if_chain;
|
||||
use rustc_ast::ast::{Attribute, Item, ItemKind, StructField, Variant, VariantData, VisibilityKind};
|
||||
use rustc_ast::ast::{Attribute, Item, ItemKind, FieldDef, Variant, VariantData, VisibilityKind};
|
||||
use rustc_attr as attr;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||
@ -142,11 +142,11 @@ fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants
|
||||
}
|
||||
|
||||
fn check_manual_non_exhaustive_struct(cx: &EarlyContext<'_>, item: &Item, data: &VariantData) {
|
||||
fn is_private(field: &StructField) -> bool {
|
||||
fn is_private(field: &FieldDef) -> bool {
|
||||
matches!(field.vis.kind, VisibilityKind::Inherited)
|
||||
}
|
||||
|
||||
fn is_non_exhaustive_marker(field: &StructField) -> bool {
|
||||
fn is_non_exhaustive_marker(field: &FieldDef) -> bool {
|
||||
is_private(field) && field.ty.kind.is_unit() && field.ident.map_or(true, |n| n.as_str().starts_with('_'))
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
self.check_missing_docs_attrs(cx, attrs, impl_item.span, article, desc);
|
||||
}
|
||||
|
||||
fn check_struct_field(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::StructField<'_>) {
|
||||
fn check_field_def(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::FieldDef<'_>) {
|
||||
if !sf.is_positional() {
|
||||
let attrs = cx.tcx.hir().attrs(sf.hir_id);
|
||||
self.check_missing_docs_attrs(cx, attrs, sf.span, "a", "struct field");
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::utils::{last_path_segment, span_lint_and_help};
|
||||
use rustc_hir::{
|
||||
intravisit, Body, Expr, ExprKind, FieldPat, FnDecl, HirId, LocalSource, MatchSource, Mutability, Pat, PatKind,
|
||||
intravisit, Body, Expr, ExprKind, PatField, FnDecl, HirId, LocalSource, MatchSource, Mutability, Pat, PatKind,
|
||||
QPath, Stmt, StmtKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
@ -281,7 +281,7 @@ where
|
||||
|
||||
fn find_first_mismatch_in_struct<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
field_pats: &[FieldPat<'_>],
|
||||
field_pats: &[PatField<'_>],
|
||||
field_defs: &[FieldDef],
|
||||
substs_ref: SubstsRef<'tcx>,
|
||||
) -> Option<(Span, Mutability, Level)> {
|
||||
|
@ -58,8 +58,8 @@ impl EarlyLintPass for RedundantFieldNames {
|
||||
if in_external_macro(cx.sess, expr.span) {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::Struct(_, ref fields, _) = expr.kind {
|
||||
for field in fields {
|
||||
if let ExprKind::Struct(ref se) = expr.kind {
|
||||
for field in &se.fields {
|
||||
if field.is_shorthand {
|
||||
continue;
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ fn ident_difference_expr_with_base_location(
|
||||
| (Try(_), Try(_))
|
||||
| (Paren(_), Paren(_))
|
||||
| (Repeat(_, _), Repeat(_, _))
|
||||
| (Struct(_, _, _), Struct(_, _, _))
|
||||
| (Struct(_), Struct(_))
|
||||
| (MacCall(_), MacCall(_))
|
||||
| (LlvmInlineAsm(_), LlvmInlineAsm(_))
|
||||
| (InlineAsm(_), InlineAsm(_))
|
||||
|
@ -271,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
||||
self.check_fn_decl(cx, decl);
|
||||
}
|
||||
|
||||
fn check_struct_field(&mut self, cx: &LateContext<'_>, field: &hir::StructField<'_>) {
|
||||
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
|
||||
self.check_ty(cx, &field.ty, false);
|
||||
}
|
||||
|
||||
@ -821,7 +821,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeComplexity {
|
||||
self.check_fndecl(cx, decl);
|
||||
}
|
||||
|
||||
fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::StructField<'_>) {
|
||||
fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::FieldDef<'_>) {
|
||||
// enum variants are also struct fields now
|
||||
self.check_type(cx, &field.ty);
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec<P<Pat>>, focus_idx: usize)
|
||||
/// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal.
|
||||
fn extend_with_struct_pat(
|
||||
path1: &ast::Path,
|
||||
fps1: &mut Vec<ast::FieldPat>,
|
||||
fps1: &mut Vec<ast::PatField>,
|
||||
rest1: bool,
|
||||
start: usize,
|
||||
alternatives: &mut Vec<P<Pat>>,
|
||||
|
@ -101,12 +101,12 @@ impl<'tcx> LateLintPass<'tcx> for Author {
|
||||
done();
|
||||
}
|
||||
|
||||
fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::StructField<'_>) {
|
||||
fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::FieldDef<'_>) {
|
||||
if !has_attr(cx, field.hir_id) {
|
||||
return;
|
||||
}
|
||||
prelude();
|
||||
PrintVisitor::new("field").visit_struct_field(field);
|
||||
PrintVisitor::new("field").visit_field_def(field);
|
||||
done();
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,8 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx
|
||||
// hir::StructField) {
|
||||
// fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &'tcx
|
||||
// hir::FieldDef) {
|
||||
// if !has_attr(&field.attrs) {
|
||||
// return;
|
||||
// }
|
||||
|
@ -66,7 +66,7 @@ pub fn eq_range_end(l: &RangeEnd, r: &RangeEnd) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eq_field_pat(l: &FieldPat, r: &FieldPat) -> bool {
|
||||
pub fn eq_field_pat(l: &PatField, r: &PatField) -> bool {
|
||||
l.is_placeholder == r.is_placeholder
|
||||
&& eq_id(l.ident, r.ident)
|
||||
&& eq_pat(&l.pat, &r.pat)
|
||||
@ -168,14 +168,16 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
|
||||
(AddrOf(lbk, lm, le), AddrOf(rbk, rm, re)) => lbk == rbk && lm == rm && eq_expr(le, re),
|
||||
(Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp),
|
||||
(MacCall(l), MacCall(r)) => eq_mac_call(l, r),
|
||||
(Struct(lp, lfs, lb), Struct(rp, rfs, rb)) => {
|
||||
eq_path(lp, rp) && eq_struct_rest(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r))
|
||||
(Struct(lse), Struct(rse)) => {
|
||||
eq_path(&lse.path, &rse.path) &&
|
||||
eq_struct_rest(&lse.rest, &rse.rest) &&
|
||||
unordered_over(&lse.fields, &rse.fields, |l, r| eq_field(l, r))
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eq_field(l: &Field, r: &Field) -> bool {
|
||||
pub fn eq_field(l: &ExprField, r: &ExprField) -> bool {
|
||||
l.is_placeholder == r.is_placeholder
|
||||
&& eq_id(l.ident, r.ident)
|
||||
&& eq_expr(&l.expr, &r.expr)
|
||||
@ -359,7 +361,7 @@ pub fn eq_variant_data(l: &VariantData, r: &VariantData) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eq_struct_field(l: &StructField, r: &StructField) -> bool {
|
||||
pub fn eq_struct_field(l: &FieldDef, r: &FieldDef) -> bool {
|
||||
l.is_placeholder == r.is_placeholder
|
||||
&& over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
|
||||
&& eq_vis(&l.vis, &r.vis)
|
||||
|
@ -51,7 +51,7 @@ pub struct Range<'a> {
|
||||
pub fn range<'a>(expr: &'a hir::Expr<'_>) -> Option<Range<'a>> {
|
||||
/// Finds the field named `name` in the field. Always return `Some` for
|
||||
/// convenience.
|
||||
fn get_field<'c>(name: &str, fields: &'c [hir::Field<'_>]) -> Option<&'c hir::Expr<'c>> {
|
||||
fn get_field<'c>(name: &str, fields: &'c [hir::ExprField<'_>]) -> Option<&'c hir::Expr<'c>> {
|
||||
let expr = &fields.iter().find(|field| field.ident.name.as_str() == name)?.expr;
|
||||
|
||||
Some(expr)
|
||||
|
@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::{
|
||||
BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FieldPat, FnRetTy,
|
||||
BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, ExprField, PatField, FnRetTy,
|
||||
GenericArg, GenericArgs, Guard, HirId, InlineAsmOperand, Lifetime, LifetimeName, ParamName, Pat, PatKind, Path,
|
||||
PathSegment, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding,
|
||||
};
|
||||
@ -266,7 +266,7 @@ impl HirEqInterExpr<'_, '_, '_> {
|
||||
over(left, right, |l, r| self.eq_expr(l, r))
|
||||
}
|
||||
|
||||
fn eq_field(&mut self, left: &Field<'_>, right: &Field<'_>) -> bool {
|
||||
fn eq_field(&mut self, left: &ExprField<'_>, right: &ExprField<'_>) -> bool {
|
||||
left.ident.name == right.ident.name && self.eq_expr(&left.expr, &right.expr)
|
||||
}
|
||||
|
||||
@ -290,8 +290,8 @@ impl HirEqInterExpr<'_, '_, '_> {
|
||||
left.name == right.name
|
||||
}
|
||||
|
||||
fn eq_fieldpat(&mut self, left: &FieldPat<'_>, right: &FieldPat<'_>) -> bool {
|
||||
let (FieldPat { ident: li, pat: lp, .. }, FieldPat { ident: ri, pat: rp, .. }) = (&left, &right);
|
||||
fn eq_fieldpat(&mut self, left: &PatField<'_>, right: &PatField<'_>) -> bool {
|
||||
let (PatField { ident: li, pat: lp, .. }, PatField { ident: ri, pat: rp, .. }) = (&left, &right);
|
||||
li.name == ri.name && self.eq_pat(lp, rp)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user