1
Fork 0

Remove Spanned from {ast,hir}::FieldPat

This commit is contained in:
Vadim Petrochenkov 2019-08-15 02:35:36 +03:00
parent 433b1e36e1
commit a6182711ef
24 changed files with 72 additions and 92 deletions

View file

@ -136,7 +136,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
} }
PatKind::Struct(_, ref subpats, _) => { PatKind::Struct(_, ref subpats, _) => {
let pats_exit = self.pats_all(subpats.iter().map(|f| &f.node.pat), pred); let pats_exit = self.pats_all(subpats.iter().map(|f| &f.pat), pred);
self.add_ast_node(pat.hir_id.local_id, &[pats_exit]) self.add_ast_node(pat.hir_id.local_id, &[pats_exit])
} }

View file

@ -704,9 +704,9 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
PatKind::Struct(ref qpath, ref fields, _) => { PatKind::Struct(ref qpath, ref fields, _) => {
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span); visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
for field in fields { for field in fields {
visitor.visit_id(field.node.hir_id); visitor.visit_id(field.hir_id);
visitor.visit_ident(field.node.ident); visitor.visit_ident(field.ident);
visitor.visit_pat(&field.node.pat) visitor.visit_pat(&field.pat)
} }
} }
PatKind::Tuple(ref tuple_elements, _) => { PatKind::Tuple(ref tuple_elements, _) => {

View file

@ -2691,16 +2691,12 @@ impl<'a> LoweringContext<'a> {
let fs = fields let fs = fields
.iter() .iter()
.map(|f| { .map(|f| hir::FieldPat {
Spanned { hir_id: self.next_id(),
span: f.span, ident: f.ident,
node: hir::FieldPat { pat: self.lower_pat(&f.pat),
hir_id: self.next_id(), is_shorthand: f.is_shorthand,
ident: f.node.ident, span: f.span,
pat: self.lower_pat(&f.node.pat),
is_shorthand: f.node.is_shorthand,
},
}
}) })
.collect(); .collect();
hir::PatKind::Struct(qpath, fs, etc) hir::PatKind::Struct(qpath, fs, etc)

View file

@ -877,7 +877,7 @@ impl Pat {
match self.node { match self.node {
PatKind::Binding(.., Some(ref p)) => p.walk_(it), PatKind::Binding(.., Some(ref p)) => p.walk_(it),
PatKind::Struct(_, ref fields, _) => { PatKind::Struct(_, ref fields, _) => {
fields.iter().all(|field| field.node.pat.walk_(it)) fields.iter().all(|field| field.pat.walk_(it))
} }
PatKind::TupleStruct(_, ref s, _) | PatKind::Tuple(ref s, _) => { PatKind::TupleStruct(_, ref s, _) | PatKind::Tuple(ref s, _) => {
s.iter().all(|p| p.walk_(it)) s.iter().all(|p| p.walk_(it))
@ -923,6 +923,7 @@ pub struct FieldPat {
/// The pattern the field is destructured to. /// The pattern the field is destructured to.
pub pat: P<Pat>, pub pat: P<Pat>,
pub is_shorthand: bool, pub is_shorthand: bool,
pub span: Span,
} }
/// Explicit binding annotations given in the HIR for a binding. Note /// Explicit binding annotations given in the HIR for a binding. Note
@ -968,7 +969,7 @@ pub enum PatKind {
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`). /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
/// The `bool` is `true` in the presence of a `..`. /// The `bool` is `true` in the presence of a `..`.
Struct(QPath, HirVec<Spanned<FieldPat>>, bool), Struct(QPath, HirVec<FieldPat>, bool),
/// A tuple struct/variant pattern `Variant(x, y, .., z)`. /// A tuple struct/variant pattern `Variant(x, y, .., z)`.
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position. /// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.

View file

@ -1670,14 +1670,14 @@ impl<'a> State<'a> {
&fields[..], &fields[..],
|s, f| { |s, f| {
s.cbox(INDENT_UNIT); s.cbox(INDENT_UNIT);
if !f.node.is_shorthand { if !f.is_shorthand {
s.print_ident(f.node.ident); s.print_ident(f.ident);
s.word_nbsp(":"); s.word_nbsp(":");
} }
s.print_pat(&f.node.pat); s.print_pat(&f.pat);
s.end() s.end()
}, },
|f| f.node.pat.span); |f| f.pat.span);
if etc { if etc {
if !fields.is_empty() { if !fields.is_empty() {
self.word_space(","); self.word_space(",");

View file

@ -153,8 +153,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty {
} }
} }
impl_stable_hash_for_spanned!(hir::FieldPat);
impl_stable_hash_for_spanned!(hir::BinOpKind); impl_stable_hash_for_spanned!(hir::BinOpKind);
impl_stable_hash_for!(struct hir::Stmt { impl_stable_hash_for!(struct hir::Stmt {
@ -187,8 +185,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr {
impl_stable_hash_for_spanned!(usize); impl_stable_hash_for_spanned!(usize);
impl_stable_hash_for_spanned!(ast::Ident);
impl_stable_hash_for!(struct ast::Ident { impl_stable_hash_for!(struct ast::Ident {
name, name,
span, span,

View file

@ -17,8 +17,7 @@ use crate::util::nodemap::FxHashSet;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use syntax::{ast, source_map}; use syntax::{ast, attr};
use syntax::attr;
use syntax::symbol::sym; use syntax::symbol::sym;
use syntax_pos; use syntax_pos;
@ -119,17 +118,16 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
} }
} }
fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, res: Res, fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, res: Res, pats: &[hir::FieldPat]) {
pats: &[source_map::Spanned<hir::FieldPat>]) {
let variant = match self.tables.node_type(lhs.hir_id).sty { let variant = match self.tables.node_type(lhs.hir_id).sty {
ty::Adt(adt, _) => adt.variant_of_res(res), ty::Adt(adt, _) => adt.variant_of_res(res),
_ => span_bug!(lhs.span, "non-ADT in struct pattern") _ => span_bug!(lhs.span, "non-ADT in struct pattern")
}; };
for pat in pats { for pat in pats {
if let PatKind::Wild = pat.node.pat.node { if let PatKind::Wild = pat.pat.node {
continue; continue;
} }
let index = self.tcx.field_index(pat.node.hir_id, self.tables); let index = self.tcx.field_index(pat.hir_id, self.tables);
self.insert_def_id(variant.fields[index].did); self.insert_def_id(variant.fields[index].did);
} }
} }

View file

@ -418,8 +418,8 @@ fn add_from_pat<'tcx>(ir: &mut IrMaps<'tcx>, pat: &P<hir::Pat>) {
} }
Struct(_, ref fields, _) => { Struct(_, ref fields, _) => {
for field in fields { for field in fields {
if field.node.is_shorthand { if field.is_shorthand {
shorthand_field_ids.insert(field.node.pat.hir_id); shorthand_field_ids.insert(field.pat.hir_id);
} }
} }
} }

View file

@ -1282,11 +1282,11 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
}; };
for fp in field_pats { for fp in field_pats {
let field_ty = self.pat_ty_adjusted(&fp.node.pat)?; // see (*2) let field_ty = self.pat_ty_adjusted(&fp.pat)?; // see (*2)
let f_index = self.tcx.field_index(fp.node.hir_id, self.tables); let f_index = self.tcx.field_index(fp.hir_id, self.tables);
let cmt_field = Rc::new(self.cat_field(pat, cmt.clone(), f_index, let cmt_field = Rc::new(self.cat_field(pat, cmt.clone(), f_index,
fp.node.ident, field_ty)); fp.ident, field_ty));
self.cat_pattern_(cmt_field, &fp.node.pat, op)?; self.cat_pattern_(cmt_field, &fp.pat, op)?;
} }
} }

View file

@ -1207,7 +1207,7 @@ fn resolve_local<'tcx>(
PatKind::Binding(hir::BindingAnnotation::RefMut, ..) => true, PatKind::Binding(hir::BindingAnnotation::RefMut, ..) => true,
PatKind::Struct(_, ref field_pats, _) => { PatKind::Struct(_, ref field_pats, _) => {
field_pats.iter().any(|fp| is_binding_pat(&fp.node.pat)) field_pats.iter().any(|fp| is_binding_pat(&fp.pat))
} }
PatKind::Slice(ref pats1, ref pats2, ref pats3) => { PatKind::Slice(ref pats1, ref pats2, ref pats3) => {

View file

@ -164,7 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
.expect("struct pattern type is not an ADT") .expect("struct pattern type is not an ADT")
.variant_of_res(cx.tables.qpath_res(qpath, pat.hir_id)); .variant_of_res(cx.tables.qpath_res(qpath, pat.hir_id));
for fieldpat in field_pats { for fieldpat in field_pats {
if fieldpat.node.is_shorthand { if fieldpat.is_shorthand {
continue; continue;
} }
if fieldpat.span.ctxt().outer_expn_info().is_some() { if fieldpat.span.ctxt().outer_expn_info().is_some() {
@ -173,9 +173,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
// (Issue #49588) // (Issue #49588)
continue; continue;
} }
if let PatKind::Binding(_, _, ident, None) = fieldpat.node.pat.node { if let PatKind::Binding(_, _, ident, None) = fieldpat.pat.node {
if cx.tcx.find_field_index(ident, &variant) == if cx.tcx.find_field_index(ident, &variant) ==
Some(cx.tcx.field_index(fieldpat.node.hir_id, cx.tables)) { Some(cx.tcx.field_index(fieldpat.hir_id, cx.tables)) {
let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS,
fieldpat.span, fieldpat.span,
&format!("the `{}:` in this pattern is redundant", ident)); &format!("the `{}:` in this pattern is redundant", ident));

View file

@ -645,9 +645,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
fields.iter() fields.iter()
.map(|field| { .map(|field| {
FieldPattern { FieldPattern {
field: Field::new(self.tcx.field_index(field.node.hir_id, field: Field::new(self.tcx.field_index(field.hir_id,
self.tables)), self.tables)),
pattern: self.lower_pattern(&field.node.pat), pattern: self.lower_pattern(&field.pat),
} }
}) })
.collect(); .collect();

View file

@ -1075,8 +1075,8 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
let adt = self.tables.pat_ty(pat).ty_adt_def().unwrap(); let adt = self.tables.pat_ty(pat).ty_adt_def().unwrap();
let variant = adt.variant_of_res(res); let variant = adt.variant_of_res(res);
for field in fields { for field in fields {
let use_ctxt = field.node.ident.span; let use_ctxt = field.ident.span;
let index = self.tcx.field_index(field.node.hir_id, self.tables); let index = self.tcx.field_index(field.hir_id, self.tables);
self.check_field(use_ctxt, field.span, adt, &variant.fields[index]); self.check_field(use_ctxt, field.span, adt, &variant.fields[index]);
} }
} }

View file

@ -32,7 +32,7 @@ use syntax::print::pprust::{
ty_to_string ty_to_string
}; };
use syntax::ptr::P; use syntax::ptr::P;
use syntax::source_map::{Spanned, DUMMY_SP, respan}; use syntax::source_map::{DUMMY_SP, respan};
use syntax::walk_list; use syntax::walk_list;
use syntax_pos::*; use syntax_pos::*;
@ -879,7 +879,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
}; };
let variant = adt.variant_of_res(self.save_ctxt.get_path_res(p.id)); let variant = adt.variant_of_res(self.save_ctxt.get_path_res(p.id));
for &Spanned { node: ref field, .. } in fields { for field in fields {
if let Some(index) = self.tcx.find_field_index(field.ident, variant) { if let Some(index) = self.tcx.find_field_index(field.ident, variant) {
if !self.span.filter_generated(field.ident.span) { if !self.span.filter_generated(field.ident.span) {
let span = self.span_from_span(field.ident.span); let span = self.span_from_span(field.ident.span);

View file

@ -12,7 +12,6 @@ use rustc::traits::{ObligationCause, ObligationCauseCode};
use rustc::ty::{self, Ty, TypeFoldable}; use rustc::ty::{self, Ty, TypeFoldable};
use rustc::ty::subst::Kind; use rustc::ty::subst::Kind;
use syntax::ast; use syntax::ast;
use syntax::source_map::Spanned;
use syntax::util::lev_distance::find_best_match_for_name; use syntax::util::lev_distance::find_best_match_for_name;
use syntax_pos::Span; use syntax_pos::Span;
use syntax_pos::hygiene::DesugaringKind; use syntax_pos::hygiene::DesugaringKind;
@ -1036,7 +1035,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
&self, &self,
pat: &'tcx hir::Pat, pat: &'tcx hir::Pat,
qpath: &hir::QPath, qpath: &hir::QPath,
fields: &'tcx [Spanned<hir::FieldPat>], fields: &'tcx [hir::FieldPat],
etc: bool, etc: bool,
expected: Ty<'tcx>, expected: Ty<'tcx>,
def_bm: ty::BindingMode, def_bm: ty::BindingMode,
@ -1048,7 +1047,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
variant_ty variant_ty
} else { } else {
for field in fields { for field in fields {
self.check_pat_walk(&field.node.pat, self.tcx.types.err, def_bm, discrim_span); self.check_pat_walk(&field.pat, self.tcx.types.err, def_bm, discrim_span);
} }
return self.tcx.types.err; return self.tcx.types.err;
}; };
@ -1206,7 +1205,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
pat_id: hir::HirId, pat_id: hir::HirId,
span: Span, span: Span,
variant: &'tcx ty::VariantDef, variant: &'tcx ty::VariantDef,
fields: &'tcx [Spanned<hir::FieldPat>], fields: &'tcx [hir::FieldPat],
etc: bool, etc: bool,
def_bm: ty::BindingMode, def_bm: ty::BindingMode,
) -> bool { ) -> bool {
@ -1231,7 +1230,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
let mut inexistent_fields = vec![]; let mut inexistent_fields = vec![];
// Typecheck each field. // Typecheck each field.
for &Spanned { node: ref field, span } in fields { for field in fields {
let span = field.span;
let ident = tcx.adjust_ident(field.ident, variant.def_id); let ident = tcx.adjust_ident(field.ident, variant.def_id);
let field_ty = match used_fields.entry(ident) { let field_ty = match used_fields.entry(ident) {
Occupied(occupied) => { Occupied(occupied) => {

View file

@ -283,7 +283,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
} }
hir::PatKind::Struct(_, ref fields, _) => { hir::PatKind::Struct(_, ref fields, _) => {
for field in fields { for field in fields {
self.visit_field_id(field.node.hir_id); self.visit_field_id(field.hir_id);
} }
} }
_ => {} _ => {}

View file

@ -29,7 +29,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
use syntax::ast::{self, AttrStyle, Ident}; use syntax::ast::{self, AttrStyle, Ident};
use syntax::attr; use syntax::attr;
use syntax::ext::base::MacroKind; use syntax::ext::base::MacroKind;
use syntax::source_map::{DUMMY_SP, Spanned}; use syntax::source_map::DUMMY_SP;
use syntax::symbol::{Symbol, kw, sym}; use syntax::symbol::{Symbol, kw, sym};
use syntax::symbol::InternedString; use syntax::symbol::InternedString;
use syntax_pos::{self, Pos, FileName}; use syntax_pos::{self, Pos, FileName};
@ -4102,8 +4102,7 @@ fn name_from_pat(p: &hir::Pat) -> String {
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p), PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
PatKind::Struct(ref name, ref fields, etc) => { PatKind::Struct(ref name, ref fields, etc) => {
format!("{} {{ {}{} }}", qpath_to_string(name), format!("{} {{ {}{} }}", qpath_to_string(name),
fields.iter().map(|&Spanned { node: ref fp, .. }| fields.iter().map(|fp| format!("{}: {}", fp.ident, name_from_pat(&fp.pat)))
format!("{}: {}", fp.ident, name_from_pat(&*fp.pat)))
.collect::<Vec<String>>().join(", "), .collect::<Vec<String>>().join(", "),
if etc { ", .." } else { "" } if etc { ", .." } else { "" }
) )

View file

@ -571,7 +571,7 @@ impl Pat {
match &self.node { match &self.node {
PatKind::Ident(_, _, Some(p)) => p.walk(it), PatKind::Ident(_, _, Some(p)) => p.walk(it),
PatKind::Struct(_, fields, _) => fields.iter().all(|field| field.node.pat.walk(it)), PatKind::Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk(it)),
PatKind::TupleStruct(_, s) | PatKind::Tuple(s) | PatKind::Slice(s) => { PatKind::TupleStruct(_, s) | PatKind::Tuple(s) | PatKind::Slice(s) => {
s.iter().all(|p| p.walk(it)) s.iter().all(|p| p.walk(it))
} }
@ -609,6 +609,7 @@ pub struct FieldPat {
pub is_shorthand: bool, pub is_shorthand: bool,
pub attrs: ThinVec<Attribute>, pub attrs: ThinVec<Attribute>,
pub id: NodeId, pub id: NodeId,
pub span: Span,
} }
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
@ -642,7 +643,7 @@ pub enum PatKind {
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`). /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
/// The `bool` is `true` in the presence of a `..`. /// The `bool` is `true` in the presence of a `..`.
Struct(Path, Vec<Spanned<FieldPat>>, /* recovered */ bool), Struct(Path, Vec<FieldPat>, /* recovered */ bool),
/// A tuple struct/variant pattern (`Variant(x, y, .., z)`). /// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
TupleStruct(Path, Vec<P<Pat>>), TupleStruct(Path, Vec<P<Pat>>),

View file

@ -575,7 +575,7 @@ impl<'a> ExtCtxt<'a> {
self.pat(span, PatKind::TupleStruct(path, subpats)) self.pat(span, PatKind::TupleStruct(path, subpats))
} }
pub fn pat_struct(&self, span: Span, path: ast::Path, pub fn pat_struct(&self, span: Span, path: ast::Path,
field_pats: Vec<Spanned<ast::FieldPat>>) -> P<ast::Pat> { field_pats: Vec<ast::FieldPat>) -> P<ast::Pat> {
self.pat(span, PatKind::Struct(path, field_pats, false)) self.pat(span, PatKind::Struct(path, field_pats, false))
} }
pub fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat> { pub fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat> {

View file

@ -1042,10 +1042,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
} }
PatKind::Struct(path, fields, _etc) => { PatKind::Struct(path, fields, _etc) => {
vis.visit_path(path); vis.visit_path(path);
for Spanned { for FieldPat { ident, pat, is_shorthand: _, attrs, id, span } in fields {
node: FieldPat { ident, pat, is_shorthand: _, attrs, id },
span
} in fields {
vis.visit_ident(ident); vis.visit_ident(ident);
vis.visit_id(id); vis.visit_id(id);
vis.visit_pat(pat); vis.visit_pat(pat);

View file

@ -488,7 +488,7 @@ impl<'a> Parser<'a> {
} }
/// Parses the fields of a struct-like pattern. /// Parses the fields of a struct-like pattern.
fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<Spanned<FieldPat>>, bool)> { fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<FieldPat>, bool)> {
let mut fields = Vec::new(); let mut fields = Vec::new();
let mut etc = false; let mut etc = false;
let mut ate_comma = true; let mut ate_comma = true;
@ -620,11 +620,7 @@ impl<'a> Parser<'a> {
.emit(); .emit();
} }
fn parse_pat_field( fn parse_pat_field(&mut self, lo: Span, attrs: Vec<Attribute>) -> PResult<'a, FieldPat> {
&mut self,
lo: Span,
attrs: Vec<Attribute>
) -> PResult<'a, Spanned<FieldPat>> {
// Check if a colon exists one ahead. This means we're parsing a fieldname. // Check if a colon exists one ahead. This means we're parsing a fieldname.
let hi; let hi;
let (subpat, fieldname, is_shorthand) = if self.look_ahead(1, |t| t == &token::Colon) { let (subpat, fieldname, is_shorthand) = if self.look_ahead(1, |t| t == &token::Colon) {
@ -659,15 +655,13 @@ impl<'a> Parser<'a> {
(subpat, fieldname, true) (subpat, fieldname, true)
}; };
Ok(Spanned { Ok(FieldPat {
ident: fieldname,
pat: subpat,
is_shorthand,
attrs: attrs.into(),
id: ast::DUMMY_NODE_ID,
span: lo.to(hi), span: lo.to(hi),
node: FieldPat {
ident: fieldname,
pat: subpat,
is_shorthand,
attrs: attrs.into(),
id: ast::DUMMY_NODE_ID,
}
}) })
} }

View file

@ -2367,14 +2367,14 @@ impl<'a> State<'a> {
Consistent, &fields[..], Consistent, &fields[..],
|s, f| { |s, f| {
s.cbox(INDENT_UNIT); s.cbox(INDENT_UNIT);
if !f.node.is_shorthand { if !f.is_shorthand {
s.print_ident(f.node.ident); s.print_ident(f.ident);
s.word_nbsp(":"); s.word_nbsp(":");
} }
s.print_pat(&f.node.pat); s.print_pat(&f.pat);
s.end(); s.end();
}, },
|f| f.node.pat.span); |f| f.pat.span);
if etc { if etc {
if !fields.is_empty() { self.word_space(","); } if !fields.is_empty() { self.word_space(","); }
self.s.word(".."); self.s.word("..");

View file

@ -442,9 +442,9 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
PatKind::Struct(ref path, ref fields, _) => { PatKind::Struct(ref path, ref fields, _) => {
visitor.visit_path(path, pattern.id); visitor.visit_path(path, pattern.id);
for field in fields { for field in fields {
walk_list!(visitor, visit_attribute, field.node.attrs.iter()); walk_list!(visitor, visit_attribute, field.attrs.iter());
visitor.visit_ident(field.node.ident); visitor.visit_ident(field.ident);
visitor.visit_pat(&field.node.pat) visitor.visit_pat(&field.pat)
} }
} }
PatKind::Tuple(ref elems) => { PatKind::Tuple(ref elems) => {

View file

@ -187,7 +187,7 @@ use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind};
use syntax::ast::{VariantData, GenericParamKind, GenericArg}; use syntax::ast::{VariantData, GenericParamKind, GenericArg};
use syntax::attr; use syntax::attr;
use syntax::ext::base::{Annotatable, ExtCtxt, SpecialDerives}; use syntax::ext::base::{Annotatable, ExtCtxt, SpecialDerives};
use syntax::source_map::{self, respan}; use syntax::source_map::respan;
use syntax::util::map_in_place::MapInPlace; use syntax::util::map_in_place::MapInPlace;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::{Symbol, kw, sym}; use syntax::symbol::{Symbol, kw, sym};
@ -1610,15 +1610,13 @@ impl<'a> TraitDef<'a> {
if ident.is_none() { if ident.is_none() {
cx.span_bug(sp, "a braced struct with unnamed fields in `derive`"); cx.span_bug(sp, "a braced struct with unnamed fields in `derive`");
} }
source_map::Spanned { ast::FieldPat {
ident: ident.unwrap(),
is_shorthand: false,
attrs: ThinVec::new(),
id: ast::DUMMY_NODE_ID,
span: pat.span.with_ctxt(self.span.ctxt()), span: pat.span.with_ctxt(self.span.ctxt()),
node: ast::FieldPat { pat,
id: ast::DUMMY_NODE_ID,
ident: ident.unwrap(),
pat,
is_shorthand: false,
attrs: ThinVec::new(),
},
} }
}) })
.collect(); .collect();