diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 005ac8e4521..ee7367d408d 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -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, /* recovered */ bool), + Struct(Path, Vec, /* recovered */ bool), /// A tuple struct/variant pattern (`Variant(x, y, .., z)`). TupleStruct(Path, Vec>), @@ -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, + 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, StructRest), + Struct(P), /// 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, 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, bool), + Struct(Vec, bool), /// Tuple variant. /// /// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`. - Tuple(Vec, NodeId), + Tuple(Vec, 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, _ => &[], diff --git a/compiler/rustc_ast/src/ast_like.rs b/compiler/rustc_ast/src/ast_like.rs index a71f2ac9815..63bc7c49a99 100644 --- a/compiler/rustc_ast/src/ast_like.rs +++ b/compiler/rustc_ast/src/ast_like.rs @@ -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 diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index c286738811c..f426f2c7fec 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -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(dspan: &mut DelimSpan, vis: &mut T) { vis.visit_span(&mut dspan.close); } -pub fn noop_flat_map_field_pattern( - mut fp: FieldPat, +pub fn noop_flat_map_pat_field( + 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(pred: &mut WherePredicate, vis: pub fn noop_visit_variant_data(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(p: &mut PolyTraitRef, vis: &mut vis.visit_span(span); } -pub fn noop_flat_map_struct_field( - mut sf: StructField, +pub fn noop_flat_map_field_def( + 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(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( + 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(pat: &mut P, 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( 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 => {} diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 32b9dd46bae..b1ad29e4ad8 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -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 => {} diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 58425793602..32fb8d1c8f4 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -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> { diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 8cdb68b5c87..edd0c5fb964 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -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 { diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index ef32a992493..44f05cbf436 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -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)) diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index e4e7b24d29e..2451409aac8 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -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), diff --git a/compiler/rustc_ast_passes/src/node_count.rs b/compiler/rustc_ast_passes/src/node_count.rs index fb7e0d3450f..3980e6da682 100644 --- a/compiler/rustc_ast_passes/src/node_count.rs +++ b/compiler/rustc_ast_passes/src/node_count.rs @@ -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, diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 82f6e936b76..cb6f567c551 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -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); diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs index eea4d785dee..025872df017 100644 --- a/compiler/rustc_builtin_macros/src/cfg_eval.rs +++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs @@ -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]> { diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index d498c8e1727..da85cc73ffd 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -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(), diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index dd93fe8350e..05e5c13dab7 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -36,11 +36,11 @@ pub enum Annotatable { Stmt(P), Expr(P), 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) -> Option> { + fn make_expr_fields(self: Box) -> Option> { None } - fn make_field_patterns(self: Box) -> Option> { + fn make_pat_fields(self: Box) -> Option> { None } @@ -446,7 +446,7 @@ pub trait MacResult { None } - fn make_struct_fields(self: Box) -> Option> { + fn make_field_defs(self: Box) -> Option> { None } @@ -630,11 +630,11 @@ impl MacResult for DummyResult { Some(SmallVec::new()) } - fn make_fields(self: Box) -> Option> { + fn make_expr_fields(self: Box) -> Option> { Some(SmallVec::new()) } - fn make_field_patterns(self: Box) -> Option> { + fn make_pat_fields(self: Box) -> Option> { Some(SmallVec::new()) } @@ -646,7 +646,7 @@ impl MacResult for DummyResult { Some(SmallVec::new()) } - fn make_struct_fields(self: Box) -> Option> { + fn make_field_defs(self: Box) -> Option> { Some(SmallVec::new()) } diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index fe67b401fcc..3664ff3ae8a 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -267,8 +267,8 @@ impl<'a> ExtCtxt<'a> { pub fn expr_block(&self, b: P) -> P { self.expr(b.span, ast::ExprKind::Block(b, None)) } - pub fn field_imm(&self, span: Span, ident: Ident, e: P) -> ast::Field { - ast::Field { + pub fn field_imm(&self, span: Span, ident: Ident, e: P) -> 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, + fields: Vec, ) -> P { - 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, + fields: Vec, ) -> P { 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, + field_pats: Vec, ) -> P { self.pat(span, PatKind::Struct(path, field_pats, false)) } diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index a1e5979f62d..0992f598431 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -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]> { diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 98682ba4295..6586ba138fb 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -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) } } diff --git a/compiler/rustc_hir/src/arena.rs b/compiler/rustc_hir/src/arena.rs index c7dc66b70fe..ddf82186169 100644 --- a/compiler/rustc_hir/src/arena.rs +++ b/compiler/rustc_hir/src/arena.rs @@ -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>, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 6f46a19090a..2b84d4658f9 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -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` 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`. - 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, .. }) diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index df63f0d48c3..1ed8ab044fe 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -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>) { diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 9c2766a1631..9eab6cab64d 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -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); diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs index 89a5836d6df..f1f69f1510b 100644 --- a/compiler/rustc_incremental/src/assert_dep_graph.rs +++ b/compiler/rustc_incremental/src/assert_dep_graph.rs @@ -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); } } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index dca5e470e7f..1a8bbb67cfe 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -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); } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index 0c7b843831a..647ecad0469 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -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); }) } diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index 9a64737f3a2..d325b5fe7f8 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -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); }) } diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index b3bdaf5bdc7..5e6b090027c 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -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); }) } diff --git a/compiler/rustc_lint/src/passes.rs b/compiler/rustc_lint/src/passes.rs index ffbed3a0aff..bbe17dcf4b7 100644 --- a/compiler/rustc_lint/src/passes.rs +++ b/compiler/rustc_lint/src/passes.rs @@ -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); diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index 7dc9014d304..a3d891fd1ba 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -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); }); } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 43d63d59ed9..200a5fc1043 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -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), diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 608b0248274..a3f2a8b3c57 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -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 { + fn find_struct_error_after_field_looking_code(&self) -> Option { 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, diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index a28595e6fae..025415036b6 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -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, /* recovered */ bool)> { + fn parse_record_struct_body(&mut self) -> PResult<'a, (Vec, /* 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> { + fn parse_tuple_struct_body(&mut self) -> PResult<'a, Vec> { // This is the case where we find `struct Foo(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, - ) -> 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, - ) -> 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, diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 5a68afdfa59..51c01f5a775 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -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, bool)> { + fn parse_pat_fields(&mut self) -> PResult<'a, (Vec, 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) -> PResult<'a, FieldPat> { + fn parse_pat_field(&mut self, lo: Span, attrs: Vec) -> 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, diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 9c606f3e4d4..775e27e68f8 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -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>) { diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index ca25445486d..c63edf365a1 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -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>) { diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index ccbfc6b1661..2bed8cadeb9 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -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) { diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 3e957aabd77..dd9cb51c858 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -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>) { diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 72be266b338..84240f86b53 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -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); } } diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 65e5b0dddea..d77022a65e4 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -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); } } diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 6ef5e1179de..17f0c39e397 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -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) { + fn collect_field(&mut self, field: &'a FieldDef, index: Option) { 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); } } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 6f24d7e9413..af241ef8afc 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -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); } diff --git a/compiler/rustc_save_analysis/src/dump_visitor.rs b/compiler/rustc_save_analysis/src/dump_visitor.rs index f943753183a..15435df32be 100644 --- a/compiler/rustc_save_analysis/src/dump_visitor.rs +++ b/compiler/rustc_save_analysis/src/dump_visitor.rs @@ -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>>, ) { diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index 042f3183796..2acae29cc25 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -379,7 +379,7 @@ impl<'tcx> SaveContext<'tcx> { } } - pub fn get_field_data(&self, field: &hir::StructField<'_>, scope: hir::HirId) -> Option { + pub fn get_field_data(&self, field: &hir::FieldDef<'_>, scope: hir::HirId) -> Option { 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 { filter!(self.span_utils, field_ref.ident.span); diff --git a/compiler/rustc_save_analysis/src/sig.rs b/compiler/rustc_save_analysis/src/sig.rs index 33db189af37..53150a92664 100644 --- a/compiler/rustc_save_analysis/src/sig.rs +++ b/compiler/rustc_save_analysis/src/sig.rs @@ -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 { +pub fn field_signature(field: &hir::FieldDef<'_>, scx: &SaveContext<'_>) -> Option { 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, scx: &SaveContext<'_>) -> Result { let mut text = String::new(); diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 48740e533da..8951c08bd33 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -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, ) { diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index f8ca916caf1..79c544bd386 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -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> { // 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> { 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::>(); @@ -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) diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index dced4aac049..b172cb9c44b 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -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. diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 539895feddd..ead9d7d6646 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1754,7 +1754,7 @@ impl<'tcx> Clean for ty::Const<'tcx> { } } -impl Clean for hir::StructField<'_> { +impl Clean for hir::FieldDef<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> Item { let what_rustc_thinks = Item::from_hir_id_and_parts( self.hir_id, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 80e2e23eadd..d9e97e02a14 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -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); }); } diff --git a/src/test/ui-fulldeps/pprust-expr-roundtrip.rs b/src/test/ui-fulldeps/pprust-expr-roundtrip.rs index bff92d8607e..ac2d29c9caf 100644 --- a/src/test/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/src/test/ui-fulldeps/pprust-expr-roundtrip.rs @@ -155,7 +155,9 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P)) { }, 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))); diff --git a/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs b/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs index 4f35e13c85a..48aef74e4d3 100644 --- a/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs +++ b/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs @@ -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) -> bool { +fn is_consistent_order<'tcx>(fields: &'tcx [hir::ExprField<'tcx>], def_order_map: &FxHashMap) -> bool { let mut cur_idx = usize::MIN; for f in fields { let next_idx = def_order_map[&f.ident.name]; diff --git a/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs b/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs index 91849e74887..7e6d4d3a216 100644 --- a/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs +++ b/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs @@ -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('_')) } diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index 6ec4c38d0f9..985a66b6cfc 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -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"); diff --git a/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs b/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs index 5539331d046..e76c8624b6f 100644 --- a/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs +++ b/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs @@ -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)> { diff --git a/src/tools/clippy/clippy_lints/src/redundant_field_names.rs b/src/tools/clippy/clippy_lints/src/redundant_field_names.rs index 38dcf7a192c..9688ef39331 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_field_names.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_field_names.rs @@ -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; } diff --git a/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs b/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs index 44521885d20..9acc47deb06 100644 --- a/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs +++ b/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs @@ -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(_)) diff --git a/src/tools/clippy/clippy_lints/src/types/mod.rs b/src/tools/clippy/clippy_lints/src/types/mod.rs index 13da768b0ca..f7a6399a7f0 100644 --- a/src/tools/clippy/clippy_lints/src/types/mod.rs +++ b/src/tools/clippy/clippy_lints/src/types/mod.rs @@ -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); } diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index 7f4f16f8faf..fa613bb7da3 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -276,7 +276,7 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec>, 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, + fps1: &mut Vec, rest1: bool, start: usize, alternatives: &mut Vec>, diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs index 3dd190ba440..c5761480080 100644 --- a/src/tools/clippy/clippy_lints/src/utils/author.rs +++ b/src/tools/clippy/clippy_lints/src/utils/author.rs @@ -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(); } diff --git a/src/tools/clippy/clippy_lints/src/utils/inspector.rs b/src/tools/clippy/clippy_lints/src/utils/inspector.rs index 9e3973e1d51..64ee9e65bb1 100644 --- a/src/tools/clippy/clippy_lints/src/utils/inspector.rs +++ b/src/tools/clippy/clippy_lints/src/utils/inspector.rs @@ -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; // } diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs index 9ef1557ec06..ea9a910d1b9 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs @@ -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) diff --git a/src/tools/clippy/clippy_utils/src/higher.rs b/src/tools/clippy/clippy_utils/src/higher.rs index be22df7109a..0c0e4d3b4ce 100644 --- a/src/tools/clippy/clippy_utils/src/higher.rs +++ b/src/tools/clippy/clippy_utils/src/higher.rs @@ -51,7 +51,7 @@ pub struct Range<'a> { pub fn range<'a>(expr: &'a hir::Expr<'_>) -> Option> { /// 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) diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index e28ad27d9a6..af82f992d56 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -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) }