From 73d2da08949eb5cd78e8081ea1ec9a068cdbaf6b Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 15 Aug 2019 01:56:44 +0300 Subject: [PATCH 1/3] Remove `Spanned` from `mk_name_value_item_str` and `expr_to_spanned_string` --- src/librustdoc/clean/cfg/tests.rs | 4 ++-- src/librustdoc/clean/mod.rs | 6 +++--- src/libsyntax/ast.rs | 2 -- src/libsyntax/attr/mod.rs | 12 +++++++----- src/libsyntax/ext/base.rs | 8 ++++---- src/libsyntax/ext/expand.rs | 8 +++++--- src/libsyntax/parse/tests.rs | 4 ++-- src/libsyntax_ext/format.rs | 16 ++++++++-------- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/librustdoc/clean/cfg/tests.rs b/src/librustdoc/clean/cfg/tests.rs index 405144b444f09..ec5d86b2c611d 100644 --- a/src/librustdoc/clean/cfg/tests.rs +++ b/src/librustdoc/clean/cfg/tests.rs @@ -3,7 +3,6 @@ use super::*; use syntax_pos::DUMMY_SP; use syntax::ast::*; use syntax::attr; -use syntax::source_map::dummy_spanned; use syntax::symbol::Symbol; use syntax::with_default_globals; @@ -181,7 +180,8 @@ fn test_parse_ok() { let mi = attr::mk_name_value_item_str( Ident::from_str("all"), - dummy_spanned(Symbol::intern("done")) + Symbol::intern("done"), + DUMMY_SP, ); assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done"))); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b281505956d6a..983adc0eae804 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -29,7 +29,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet}; use syntax::ast::{self, AttrStyle, Ident}; use syntax::attr; use syntax::ext::base::MacroKind; -use syntax::source_map::{dummy_spanned, Spanned}; +use syntax::source_map::{DUMMY_SP, Spanned}; use syntax::symbol::{Symbol, kw, sym}; use syntax::symbol::InternedString; use syntax_pos::{self, Pos, FileName}; @@ -930,8 +930,8 @@ impl Attributes { if attr.check_name(sym::enable) { if let Some(feat) = attr.value_str() { let meta = attr::mk_name_value_item_str( - Ident::with_empty_ctxt(sym::target_feature), - dummy_spanned(feat)); + Ident::with_empty_ctxt(sym::target_feature), feat, DUMMY_SP + ); if let Ok(feat_cfg) = Cfg::parse(&meta) { cfg &= feat_cfg; } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f0f090c8e8973..c6d006213ca23 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -939,8 +939,6 @@ pub struct Field { pub id: NodeId, } -pub type SpannedIdent = Spanned; - #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum BlockCheckMode { Default, diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 70b1d3fc73b9a..85c661d320a7b 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -13,7 +13,7 @@ use crate::ast::{AttrId, AttrStyle, Name, Ident, Path, PathSegment}; use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem}; use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam}; use crate::mut_visit::visit_clobber; -use crate::source_map::{BytePos, Spanned, dummy_spanned}; +use crate::source_map::{BytePos, Spanned, DUMMY_SP}; use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration}; use crate::parse::parser::Parser; use crate::parse::{self, ParseSess, PResult}; @@ -328,7 +328,9 @@ impl Attribute { let comment = self.value_str().unwrap(); let meta = mk_name_value_item_str( Ident::with_empty_ctxt(sym::doc), - dummy_spanned(Symbol::intern(&strip_doc_comment_decoration(&comment.as_str())))); + Symbol::intern(&strip_doc_comment_decoration(&comment.as_str())), + DUMMY_SP, + ); f(&Attribute { id: self.id, style: self.style, @@ -345,9 +347,9 @@ impl Attribute { /* Constructors */ -pub fn mk_name_value_item_str(ident: Ident, value: Spanned) -> MetaItem { - let lit_kind = LitKind::Str(value.node, ast::StrStyle::Cooked); - mk_name_value_item(ident, lit_kind, value.span) +pub fn mk_name_value_item_str(ident: Ident, str: Symbol, str_span: Span) -> MetaItem { + let lit_kind = LitKind::Str(str, ast::StrStyle::Cooked); + mk_name_value_item(ident, lit_kind, str_span) } pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 6886b4bf42111..edeca046c7b8f 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -1,6 +1,6 @@ use crate::ast::{self, Attribute, Name, PatKind}; use crate::attr::{HasAttrs, Stability, Deprecation}; -use crate::source_map::{SourceMap, Spanned, respan}; +use crate::source_map::SourceMap; use crate::edition::Edition; use crate::ext::expand::{self, AstFragment, Invocation}; use crate::ext::hygiene::{ExpnId, SyntaxContext, Transparency}; @@ -916,7 +916,7 @@ pub fn expr_to_spanned_string<'a>( cx: &'a mut ExtCtxt<'_>, mut expr: P, err_msg: &str, -) -> Result, Option>> { +) -> Result<(Symbol, ast::StrStyle, Span), Option>> { // Update `expr.span`'s ctxt now in case expr is an `include!` macro invocation. expr.span = expr.span.apply_mark(cx.current_expansion.id); @@ -926,7 +926,7 @@ pub fn expr_to_spanned_string<'a>( Err(match expr.node { ast::ExprKind::Lit(ref l) => match l.node { - ast::LitKind::Str(s, style) => return Ok(respan(expr.span, (s, style))), + ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)), ast::LitKind::Err(_) => None, _ => Some(cx.struct_span_err(l.span, err_msg)) }, @@ -940,7 +940,7 @@ pub fn expr_to_string(cx: &mut ExtCtxt<'_>, expr: P, err_msg: &str) expr_to_spanned_string(cx, expr, err_msg) .map_err(|err| err.map(|mut err| err.emit())) .ok() - .map(|s| s.node) + .map(|(symbol, style, _)| (symbol, style)) } /// Non-fatally assert that `tts` is empty. Note that this function diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 402b42dfbc80d..6cd9b2efdd2f0 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1,7 +1,7 @@ use crate::ast::{self, Block, Ident, LitKind, NodeId, PatKind, Path}; use crate::ast::{MacStmtStyle, StmtKind, ItemKind}; use crate::attr::{self, HasAttrs}; -use crate::source_map::{dummy_spanned, respan}; +use crate::source_map::respan; use crate::config::StripUnconfigured; use crate::ext::base::*; use crate::ext::proc_macro::collect_derives; @@ -1251,13 +1251,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { ast::NestedMetaItem::MetaItem( attr::mk_name_value_item_str( Ident::with_empty_ctxt(sym::file), - dummy_spanned(file), + file, + DUMMY_SP, ), ), ast::NestedMetaItem::MetaItem( attr::mk_name_value_item_str( Ident::with_empty_ctxt(sym::contents), - dummy_spanned(src_interned), + src_interned, + DUMMY_SP, ), ), ]; diff --git a/src/libsyntax/parse/tests.rs b/src/libsyntax/parse/tests.rs index e619fd17fb5bc..443a6434b7891 100644 --- a/src/libsyntax/parse/tests.rs +++ b/src/libsyntax/parse/tests.rs @@ -172,8 +172,8 @@ fn get_spans_of_pat_idents(src: &str) -> Vec { impl<'a> crate::visit::Visitor<'a> for PatIdentVisitor { fn visit_pat(&mut self, p: &'a ast::Pat) { match p.node { - PatKind::Ident(_ , ref spannedident, _) => { - self.spans.push(spannedident.span.clone()); + PatKind::Ident(_ , ref ident, _) => { + self.spans.push(ident.span.clone()); } _ => { crate::visit::walk_pat(self, p); diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index d699b3b1a90c2..83764205a198e 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -846,9 +846,9 @@ pub fn expand_preparsed_format_args( let msg = "format argument must be a string literal"; let fmt_sp = efmt.span; - let fmt = match expr_to_spanned_string(ecx, efmt, msg) { + let (fmt_str, fmt_style, fmt_span) = match expr_to_spanned_string(ecx, efmt, msg) { Ok(mut fmt) if append_newline => { - fmt.node.0 = Symbol::intern(&format!("{}\n", fmt.node.0)); + fmt.0 = Symbol::intern(&format!("{}\n", fmt.0)); fmt } Ok(fmt) => fmt, @@ -875,7 +875,7 @@ pub fn expand_preparsed_format_args( _ => (false, None), }; - let str_style = match fmt.node.1 { + let str_style = match fmt_style { ast::StrStyle::Cooked => None, ast::StrStyle::Raw(raw) => { Some(raw as usize) @@ -981,7 +981,7 @@ pub fn expand_preparsed_format_args( vec![] }; - let fmt_str = &*fmt.node.0.as_str(); // for the suggestions below + let fmt_str = &*fmt_str.as_str(); // for the suggestions below let mut parser = parse::Parser::new(fmt_str, str_style, skips, append_newline); let mut unverified_pieces = Vec::new(); @@ -995,7 +995,7 @@ pub fn expand_preparsed_format_args( if !parser.errors.is_empty() { let err = parser.errors.remove(0); - let sp = fmt.span.from_inner(err.span); + let sp = fmt_span.from_inner(err.span); let mut e = ecx.struct_span_err(sp, &format!("invalid format string: {}", err.description)); e.span_label(sp, err.label + " in format string"); @@ -1003,7 +1003,7 @@ pub fn expand_preparsed_format_args( e.note(¬e); } if let Some((label, span)) = err.secondary_label { - let sp = fmt.span.from_inner(span); + let sp = fmt_span.from_inner(span); e.span_label(sp, label); } e.emit(); @@ -1011,7 +1011,7 @@ pub fn expand_preparsed_format_args( } let arg_spans = parser.arg_places.iter() - .map(|span| fmt.span.from_inner(*span)) + .map(|span| fmt_span.from_inner(*span)) .collect(); let named_pos: FxHashSet = names.values().cloned().collect(); @@ -1034,7 +1034,7 @@ pub fn expand_preparsed_format_args( str_pieces: Vec::with_capacity(unverified_pieces.len()), all_pieces_simple: true, macsp, - fmtsp: fmt.span, + fmtsp: fmt_span, invalid_refs: Vec::new(), arg_spans, arg_with_formatting: Vec::new(), From 433b1e36e19824742175de681b8579c861217207 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 15 Aug 2019 02:13:53 +0300 Subject: [PATCH 2/3] Remove `Spanned` from `ast::Mac` --- src/librustc/lint/context.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_passes/ast_validation.rs | 2 +- src/librustc_resolve/macros.rs | 2 +- src/libsyntax/ast.rs | 7 +++---- src/libsyntax/ext/expand.rs | 11 +++++------ src/libsyntax/ext/placeholders.rs | 5 +++-- src/libsyntax/mut_visit.rs | 4 ++-- src/libsyntax/parse/parser/expr.rs | 9 +++++---- src/libsyntax/parse/parser/item.rs | 12 +++++++----- src/libsyntax/parse/parser/pat.rs | 7 ++++--- src/libsyntax/parse/parser/stmt.rs | 7 ++++--- src/libsyntax/parse/parser/ty.rs | 9 +++++---- src/libsyntax/parse/tests.rs | 2 +- src/libsyntax/print/pprust.rs | 14 +++++++------- src/libsyntax/visit.rs | 2 +- src/libsyntax_ext/assert.rs | 9 +++------ 17 files changed, 54 insertions(+), 52 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 1b73361dcd407..6801fa8d8dbe5 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1345,7 +1345,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> // part of `walk_mac`, and (b) we should be calling // `visit_path`, *but* that would require a `NodeId`, and I // want to get #53686 fixed quickly. -nmatsakis - ast_visit::walk_path(self, &mac.node.path); + ast_visit::walk_path(self, &mac.path); run_early_pass!(self, check_mac, mac); } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index a83d490511562..c34828a6b4525 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1493,7 +1493,7 @@ impl EarlyLintPass for KeywordIdents { self.check_tokens(cx, mac_def.stream()); } fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) { - self.check_tokens(cx, mac.node.tts.clone().into()); + self.check_tokens(cx, mac.tts.clone().into()); } fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) { self.check_ident_token(cx, UnderMacro(false), ident); diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 489806f75a5a8..bd46ca4779a43 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -824,7 +824,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { |this| visit::walk_enum_def(this, enum_definition, generics, item_id)) } - fn visit_mac(&mut self, mac: &Spanned) { + fn visit_mac(&mut self, mac: &Mac) { // when a new macro kind is added but the author forgets to set it up for expansion // because that's the only part that won't cause a compiler error self.session.diagnostic() diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 8e9e1380002cf..71e26dac57c2a 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -186,7 +186,7 @@ impl<'a> base::Resolver for Resolver<'a> { InvocationKind::Attr { ref attr, ref derives, after_derive, .. } => (&attr.path, MacroKind::Attr, derives.clone(), after_derive), InvocationKind::Bang { ref mac, .. } => - (&mac.node.path, MacroKind::Bang, Vec::new(), false), + (&mac.path, MacroKind::Bang, Vec::new(), false), InvocationKind::Derive { ref path, .. } => (path, MacroKind::Derive, Vec::new(), false), InvocationKind::DeriveContainer { ref derives, .. } => { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c6d006213ca23..b8bfa671bcf31 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1285,8 +1285,6 @@ pub enum Movability { Movable, } -pub type Mac = Spanned; - /// Represents a macro invocation. The `Path` indicates which macro /// is being invoked, and the vector of token-trees contains the source /// of the macro invocation. @@ -1294,10 +1292,11 @@ pub type Mac = Spanned; /// N.B., the additional ident for a `macro_rules`-style macro is actually /// stored in the enclosing item. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct Mac_ { +pub struct Mac { pub path: Path, pub delim: MacDelimiter, pub tts: TokenStream, + pub span: Span, pub prior_type_ascription: Option<(Span, bool)>, } @@ -1308,7 +1307,7 @@ pub enum MacDelimiter { Brace, } -impl Mac_ { +impl Mac { pub fn stream(&self) -> TokenStream { self.tts.clone() } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 6cd9b2efdd2f0..97983944931ba 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -492,22 +492,21 @@ impl<'a, 'b> MacroExpander<'a, 'b> { InvocationKind::Bang { mac, .. } => match ext { SyntaxExtensionKind::Bang(expander) => { self.gate_proc_macro_expansion_kind(span, fragment_kind); - let tok_result = expander.expand(self.cx, span, mac.node.stream()); + let tok_result = expander.expand(self.cx, span, mac.stream()); let result = - self.parse_ast_fragment(tok_result, fragment_kind, &mac.node.path, span); + self.parse_ast_fragment(tok_result, fragment_kind, &mac.path, span); self.gate_proc_macro_expansion(span, &result); result } SyntaxExtensionKind::LegacyBang(expander) => { let prev = self.cx.current_expansion.prior_type_ascription; - self.cx.current_expansion.prior_type_ascription = - mac.node.prior_type_ascription; - let tok_result = expander.expand(self.cx, span, mac.node.stream()); + self.cx.current_expansion.prior_type_ascription = mac.prior_type_ascription; + let tok_result = expander.expand(self.cx, span, mac.stream()); let result = if let Some(result) = fragment_kind.make_from(tok_result) { result } else { let msg = format!("non-{kind} macro in {kind} position: {path}", - kind = fragment_kind.name(), path = mac.node.path); + kind = fragment_kind.name(), path = mac.path); self.cx.span_err(span, &msg); self.cx.trace_macros_diag(); fragment_kind.dummy(span) diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index b2b17b0fb2873..2d05f8f0b0047 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -14,12 +14,13 @@ use rustc_data_structures::fx::FxHashMap; pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment { fn mac_placeholder() -> ast::Mac { - dummy_spanned(ast::Mac_ { + ast::Mac { path: ast::Path { span: DUMMY_SP, segments: Vec::new() }, tts: TokenStream::empty().into(), delim: ast::MacDelimiter::Brace, + span: DUMMY_SP, prior_type_ascription: None, - }) + } } let ident = ast::Ident::invalid(); diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 8244698999785..d22c05d9b2eee 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -533,8 +533,8 @@ pub fn noop_visit_attribute(attr: &mut Attribute, vis: &mut T) { vis.visit_span(span); } -pub fn noop_visit_mac(Spanned { node, span }: &mut Mac, vis: &mut T) { - let Mac_ { path, delim: _, tts, .. } = node; +pub fn noop_visit_mac(mac: &mut Mac, vis: &mut T) { + let Mac { path, delim: _, tts, span, prior_type_ascription: _ } = mac; vis.visit_path(path); vis.visit_tts(tts); vis.visit_span(span); diff --git a/src/libsyntax/parse/parser/expr.rs b/src/libsyntax/parse/parser/expr.rs index 7b98d7a18018c..f4b6a926734fb 100644 --- a/src/libsyntax/parse/parser/expr.rs +++ b/src/libsyntax/parse/parser/expr.rs @@ -8,13 +8,13 @@ use crate::ast::{self, Attribute, AttrStyle, Ident, CaptureBy, BlockCheckMode}; use crate::ast::{Expr, ExprKind, RangeLimits, Label, Movability, IsAsync, Arm}; use crate::ast::{Ty, TyKind, FunctionRetTy, Arg, FnDecl}; use crate::ast::{BinOpKind, BinOp, UnOp}; -use crate::ast::{Mac_, AnonConst, Field}; +use crate::ast::{Mac, AnonConst, Field}; use crate::parse::classify; use crate::parse::token::{self, Token}; use crate::parse::diagnostics::{Error}; use crate::print::pprust; -use crate::source_map::{self, respan, Span}; +use crate::source_map::{self, Span}; use crate::symbol::{kw, sym}; use crate::util::parser::{AssocOp, Fixity, prec_let_scrutinee_needs_par}; @@ -1011,12 +1011,13 @@ impl<'a> Parser<'a> { // MACRO INVOCATION expression let (delim, tts) = self.expect_delimited_token_tree()?; hi = self.prev_span; - ex = ExprKind::Mac(respan(lo.to(hi), Mac_ { + ex = ExprKind::Mac(Mac { path, tts, delim, + span: lo.to(hi), prior_type_ascription: self.last_type_ascription, - })); + }); } else if self.check(&token::OpenDelim(token::Brace)) { if let Some(expr) = self.maybe_parse_struct_expr(lo, &path, &attrs) { return expr; diff --git a/src/libsyntax/parse/parser/item.rs b/src/libsyntax/parse/parser/item.rs index 60873ecb13468..72819c9966035 100644 --- a/src/libsyntax/parse/parser/item.rs +++ b/src/libsyntax/parse/parser/item.rs @@ -10,7 +10,7 @@ use crate::ast::{Visibility, VisibilityKind, Mutability, FnDecl, FnHeader}; use crate::ast::{ForeignItem, ForeignItemKind}; use crate::ast::{Ty, TyKind, GenericBounds, TraitRef}; use crate::ast::{EnumDef, VariantData, StructField, AnonConst}; -use crate::ast::{Mac, Mac_, MacDelimiter}; +use crate::ast::{Mac, MacDelimiter}; use crate::ext::base::DummyResult; use crate::parse::token; use crate::parse::parser::maybe_append; @@ -530,12 +530,13 @@ impl<'a> Parser<'a> { } let hi = self.prev_span; - let mac = respan(mac_lo.to(hi), Mac_ { + let mac = Mac { path, tts, delim, + span: mac_lo.to(hi), prior_type_ascription: self.last_type_ascription, - }); + }; let item = self.mk_item(lo.to(hi), Ident::invalid(), ItemKind::Mac(mac), visibility, attrs); return Ok(Some(item)); @@ -604,12 +605,13 @@ impl<'a> Parser<'a> { self.expect(&token::Semi)?; } - Ok(Some(respan(lo.to(self.prev_span), Mac_ { + Ok(Some(Mac { path, tts, delim, + span: lo.to(self.prev_span), prior_type_ascription: self.last_type_ascription, - }))) + })) } else { Ok(None) } diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs index 40aa8d7b46f74..da44ebd841599 100644 --- a/src/libsyntax/parse/parser/pat.rs +++ b/src/libsyntax/parse/parser/pat.rs @@ -2,7 +2,7 @@ use super::{Parser, PResult, PathStyle}; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; use crate::ptr::P; -use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac_}; +use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac}; use crate::ast::{BindingMode, Ident, Mutability, Path, QSelf, Expr, ExprKind}; use crate::parse::token::{self}; use crate::print::pprust; @@ -275,12 +275,13 @@ impl<'a> Parser<'a> { fn parse_pat_mac_invoc(&mut self, lo: Span, path: Path) -> PResult<'a, PatKind> { self.bump(); let (delim, tts) = self.expect_delimited_token_tree()?; - let mac = respan(lo.to(self.prev_span), Mac_ { + let mac = Mac { path, tts, delim, + span: lo.to(self.prev_span), prior_type_ascription: self.last_type_ascription, - }); + }; Ok(PatKind::Mac(mac)) } diff --git a/src/libsyntax/parse/parser/stmt.rs b/src/libsyntax/parse/parser/stmt.rs index 750d8fbbddc00..c911caba4cd41 100644 --- a/src/libsyntax/parse/parser/stmt.rs +++ b/src/libsyntax/parse/parser/stmt.rs @@ -5,7 +5,7 @@ use super::path::PathStyle; use crate::ptr::P; use crate::{maybe_whole, ThinVec}; use crate::ast::{self, Stmt, StmtKind, Local, Block, BlockCheckMode, Expr, ExprKind}; -use crate::ast::{Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac_, MacDelimiter}; +use crate::ast::{Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac, MacDelimiter}; use crate::ext::base::DummyResult; use crate::parse::{classify, DirectoryOwnership}; use crate::parse::diagnostics::Error; @@ -99,12 +99,13 @@ impl<'a> Parser<'a> { MacStmtStyle::NoBraces }; - let mac = respan(lo.to(hi), Mac_ { + let mac = Mac { path, tts, delim, + span: lo.to(hi), prior_type_ascription: self.last_type_ascription, - }); + }; let node = if delim == MacDelimiter::Brace || self.token == token::Semi || self.token == token::Eof { StmtKind::Mac(P((mac, style, attrs.into()))) diff --git a/src/libsyntax/parse/parser/ty.rs b/src/libsyntax/parse/parser/ty.rs index 1eb3d441e698a..337702b8d30c5 100644 --- a/src/libsyntax/parse/parser/ty.rs +++ b/src/libsyntax/parse/parser/ty.rs @@ -4,9 +4,9 @@ use crate::{maybe_whole, maybe_recover_from_interpolated_ty_qpath}; use crate::ptr::P; use crate::ast::{self, Ty, TyKind, MutTy, BareFnTy, FunctionRetTy, GenericParam, Lifetime, Ident}; use crate::ast::{TraitBoundModifier, TraitObjectSyntax, GenericBound, GenericBounds, PolyTraitRef}; -use crate::ast::{Mutability, AnonConst, FnDecl, Mac_}; +use crate::ast::{Mutability, AnonConst, FnDecl, Mac}; use crate::parse::token::{self, Token}; -use crate::source_map::{respan, Span}; +use crate::source_map::Span; use crate::symbol::{kw}; use rustc_target::spec::abi::Abi; @@ -175,13 +175,14 @@ impl<'a> Parser<'a> { if self.eat(&token::Not) { // Macro invocation in type position let (delim, tts) = self.expect_delimited_token_tree()?; - let node = Mac_ { + let mac = Mac { path, tts, delim, + span: lo.to(self.prev_span), prior_type_ascription: self.last_type_ascription, }; - TyKind::Mac(respan(lo.to(self.prev_span), node)) + TyKind::Mac(mac) } else { // Just a type path or bound list (trait object type) starting with a trait. // `Type` diff --git a/src/libsyntax/parse/tests.rs b/src/libsyntax/parse/tests.rs index 443a6434b7891..9edc83a359414 100644 --- a/src/libsyntax/parse/tests.rs +++ b/src/libsyntax/parse/tests.rs @@ -273,7 +273,7 @@ fn ttdelim_span() { "foo!( fn main() { body } )".to_string(), &sess).unwrap(); let tts: Vec<_> = match expr.node { - ast::ExprKind::Mac(ref mac) => mac.node.stream().trees().collect(), + ast::ExprKind::Mac(ref mac) => mac.stream().trees().collect(), _ => panic!("not a macro"), }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 8b97ec3da0bc9..fabbe1ede1bc6 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1067,7 +1067,7 @@ impl<'a> State<'a> { } ast::ForeignItemKind::Macro(ref m) => { self.print_mac(m); - match m.node.delim { + match m.delim { MacDelimiter::Brace => {}, _ => self.s.word(";") } @@ -1341,7 +1341,7 @@ impl<'a> State<'a> { } ast::ItemKind::Mac(ref mac) => { self.print_mac(mac); - match mac.node.delim { + match mac.delim { MacDelimiter::Brace => {} _ => self.s.word(";"), } @@ -1554,7 +1554,7 @@ impl<'a> State<'a> { } ast::TraitItemKind::Macro(ref mac) => { self.print_mac(mac); - match mac.node.delim { + match mac.delim { MacDelimiter::Brace => {} _ => self.s.word(";"), } @@ -1591,7 +1591,7 @@ impl<'a> State<'a> { } ast::ImplItemKind::Macro(ref mac) => { self.print_mac(mac); - match mac.node.delim { + match mac.delim { MacDelimiter::Brace => {} _ => self.s.word(";"), } @@ -1749,11 +1749,11 @@ impl<'a> State<'a> { crate fn print_mac(&mut self, m: &ast::Mac) { self.print_mac_common( - Some(MacHeader::Path(&m.node.path)), + Some(MacHeader::Path(&m.path)), true, None, - m.node.delim.to_token(), - m.node.stream(), + m.delim.to_token(), + m.stream(), true, m.span, ); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 41b8ef16665a4..8c06bf25eb5ca 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -663,7 +663,7 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) { } pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a Mac) { - visitor.visit_path(&mac.node.path, DUMMY_NODE_ID); + visitor.visit_path(&mac.path, DUMMY_NODE_ID); } pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonConst) { diff --git a/src/libsyntax_ext/assert.rs b/src/libsyntax_ext/assert.rs index e3ef39075e236..6301283460ac7 100644 --- a/src/libsyntax_ext/assert.rs +++ b/src/libsyntax_ext/assert.rs @@ -1,7 +1,6 @@ use errors::{Applicability, DiagnosticBuilder}; use syntax::ast::{self, *}; -use syntax::source_map::Spanned; use syntax::ext::base::*; use syntax::parse::token::{self, TokenKind}; use syntax::parse::parser::Parser; @@ -25,7 +24,7 @@ pub fn expand_assert<'cx>( }; let sp = sp.apply_mark(cx.current_expansion.id); - let panic_call = Mac_ { + let panic_call = Mac { path: Path::from_ident(Ident::new(sym::panic, sp)), tts: custom_message.unwrap_or_else(|| { TokenStream::from(TokenTree::token( @@ -37,6 +36,7 @@ pub fn expand_assert<'cx>( )) }).into(), delim: MacDelimiter::Parenthesis, + span: sp, prior_type_ascription: None, }; let if_expr = cx.expr_if( @@ -44,10 +44,7 @@ pub fn expand_assert<'cx>( cx.expr(sp, ExprKind::Unary(UnOp::Not, cond_expr)), cx.expr( sp, - ExprKind::Mac(Spanned { - span: sp, - node: panic_call, - }), + ExprKind::Mac(panic_call), ), None, ); From a6182711efe32d4dd68da2663129e3e2e462d8cb Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 15 Aug 2019 02:35:36 +0300 Subject: [PATCH 3/3] Remove `Spanned` from `{ast,hir}::FieldPat` --- src/librustc/cfg/construct.rs | 2 +- src/librustc/hir/intravisit.rs | 6 +++--- src/librustc/hir/lowering.rs | 16 ++++++---------- src/librustc/hir/mod.rs | 5 +++-- src/librustc/hir/print.rs | 8 ++++---- src/librustc/ich/impls_hir.rs | 4 ---- src/librustc/middle/dead.rs | 10 ++++------ src/librustc/middle/liveness.rs | 4 ++-- src/librustc/middle/mem_categorization.rs | 8 ++++---- src/librustc/middle/region.rs | 2 +- src/librustc_lint/builtin.rs | 6 +++--- src/librustc_mir/hair/pattern/mod.rs | 4 ++-- src/librustc_privacy/lib.rs | 4 ++-- src/librustc_save_analysis/dump_visitor.rs | 4 ++-- src/librustc_typeck/check/_match.rs | 10 +++++----- src/librustc_typeck/check/writeback.rs | 2 +- src/librustdoc/clean/mod.rs | 5 ++--- src/libsyntax/ast.rs | 5 +++-- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/mut_visit.rs | 5 +---- src/libsyntax/parse/parser/pat.rs | 22 ++++++++-------------- src/libsyntax/print/pprust.rs | 8 ++++---- src/libsyntax/visit.rs | 6 +++--- src/libsyntax_ext/deriving/generic/mod.rs | 16 +++++++--------- 24 files changed, 72 insertions(+), 92 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index ca852fe7622cc..7ada56cfa7611 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -136,7 +136,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } 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]) } diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 71d7464540a4c..99fe9f1682f16 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -704,9 +704,9 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { PatKind::Struct(ref qpath, ref fields, _) => { visitor.visit_qpath(qpath, pattern.hir_id, pattern.span); for field in fields { - visitor.visit_id(field.node.hir_id); - visitor.visit_ident(field.node.ident); - visitor.visit_pat(&field.node.pat) + visitor.visit_id(field.hir_id); + visitor.visit_ident(field.ident); + visitor.visit_pat(&field.pat) } } PatKind::Tuple(ref tuple_elements, _) => { diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index a1f38d7dd1342..9e5d6378c4014 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -2691,16 +2691,12 @@ impl<'a> LoweringContext<'a> { let fs = fields .iter() - .map(|f| { - Spanned { - span: f.span, - node: hir::FieldPat { - hir_id: self.next_id(), - ident: f.node.ident, - pat: self.lower_pat(&f.node.pat), - is_shorthand: f.node.is_shorthand, - }, - } + .map(|f| hir::FieldPat { + hir_id: self.next_id(), + ident: f.ident, + pat: self.lower_pat(&f.pat), + is_shorthand: f.is_shorthand, + span: f.span, }) .collect(); hir::PatKind::Struct(qpath, fs, etc) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index dccc2774f5261..7c2f9907217cb 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -877,7 +877,7 @@ impl Pat { match self.node { PatKind::Binding(.., Some(ref p)) => p.walk_(it), 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, _) => { s.iter().all(|p| p.walk_(it)) @@ -923,6 +923,7 @@ pub struct FieldPat { /// The pattern the field is destructured to. pub pat: P, pub is_shorthand: bool, + pub span: Span, } /// 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, ..}`). /// The `bool` is `true` in the presence of a `..`. - Struct(QPath, HirVec>, bool), + Struct(QPath, HirVec, bool), /// A tuple struct/variant pattern `Variant(x, y, .., z)`. /// If the `..` pattern fragment is present, then `Option` denotes its position. diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 0cbfe4d75f1c6..caf8220bbf432 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1670,14 +1670,14 @@ impl<'a> State<'a> { &fields[..], |s, f| { s.cbox(INDENT_UNIT); - if !f.node.is_shorthand { - s.print_ident(f.node.ident); + if !f.is_shorthand { + s.print_ident(f.ident); s.word_nbsp(":"); } - s.print_pat(&f.node.pat); + s.print_pat(&f.pat); s.end() }, - |f| f.node.pat.span); + |f| f.pat.span); if etc { if !fields.is_empty() { self.word_space(","); diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 1fd4e00de497f..60b338010b0db 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -153,8 +153,6 @@ impl<'a> HashStable> for hir::Ty { } } -impl_stable_hash_for_spanned!(hir::FieldPat); - impl_stable_hash_for_spanned!(hir::BinOpKind); impl_stable_hash_for!(struct hir::Stmt { @@ -187,8 +185,6 @@ impl<'a> HashStable> for hir::Expr { impl_stable_hash_for_spanned!(usize); -impl_stable_hash_for_spanned!(ast::Ident); - impl_stable_hash_for!(struct ast::Ident { name, span, diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 1f3adf0092367..8ce8bb52566c6 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -17,8 +17,7 @@ use crate::util::nodemap::FxHashSet; use rustc_data_structures::fx::FxHashMap; -use syntax::{ast, source_map}; -use syntax::attr; +use syntax::{ast, attr}; use syntax::symbol::sym; 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, - pats: &[source_map::Spanned]) { + fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, res: Res, pats: &[hir::FieldPat]) { let variant = match self.tables.node_type(lhs.hir_id).sty { ty::Adt(adt, _) => adt.variant_of_res(res), _ => span_bug!(lhs.span, "non-ADT in struct pattern") }; for pat in pats { - if let PatKind::Wild = pat.node.pat.node { + if let PatKind::Wild = pat.pat.node { 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); } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index daf0d8103a2c0..9c9e8c0bca3b8 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -418,8 +418,8 @@ fn add_from_pat<'tcx>(ir: &mut IrMaps<'tcx>, pat: &P) { } Struct(_, ref fields, _) => { for field in fields { - if field.node.is_shorthand { - shorthand_field_ids.insert(field.node.pat.hir_id); + if field.is_shorthand { + shorthand_field_ids.insert(field.pat.hir_id); } } } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 77d6f3932445b..a55803e255bf6 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -1282,11 +1282,11 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { }; for fp in field_pats { - let field_ty = self.pat_ty_adjusted(&fp.node.pat)?; // see (*2) - let f_index = self.tcx.field_index(fp.node.hir_id, self.tables); + let field_ty = self.pat_ty_adjusted(&fp.pat)?; // see (*2) + 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, - fp.node.ident, field_ty)); - self.cat_pattern_(cmt_field, &fp.node.pat, op)?; + fp.ident, field_ty)); + self.cat_pattern_(cmt_field, &fp.pat, op)?; } } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 88c19715811d7..3d100d2fbf833 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -1207,7 +1207,7 @@ fn resolve_local<'tcx>( PatKind::Binding(hir::BindingAnnotation::RefMut, ..) => true, 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) => { diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index c34828a6b4525..47b4e7c948750 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -164,7 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { .expect("struct pattern type is not an ADT") .variant_of_res(cx.tables.qpath_res(qpath, pat.hir_id)); for fieldpat in field_pats { - if fieldpat.node.is_shorthand { + if fieldpat.is_shorthand { continue; } if fieldpat.span.ctxt().outer_expn_info().is_some() { @@ -173,9 +173,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { // (Issue #49588) 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) == - 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, fieldpat.span, &format!("the `{}:` in this pattern is redundant", ident)); diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 5ecfb84b63236..10223151f5c3b 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -645,9 +645,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { fields.iter() .map(|field| { FieldPattern { - field: Field::new(self.tcx.field_index(field.node.hir_id, + field: Field::new(self.tcx.field_index(field.hir_id, self.tables)), - pattern: self.lower_pattern(&field.node.pat), + pattern: self.lower_pattern(&field.pat), } }) .collect(); diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 852b4898f4ab2..bca77621e553e 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -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 variant = adt.variant_of_res(res); for field in fields { - let use_ctxt = field.node.ident.span; - let index = self.tcx.field_index(field.node.hir_id, self.tables); + let use_ctxt = field.ident.span; + let index = self.tcx.field_index(field.hir_id, self.tables); self.check_field(use_ctxt, field.span, adt, &variant.fields[index]); } } diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index d93c12513c5a1..9068605b0753c 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -32,7 +32,7 @@ use syntax::print::pprust::{ ty_to_string }; 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_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)); - for &Spanned { node: ref field, .. } in fields { + for field in fields { if let Some(index) = self.tcx.find_field_index(field.ident, variant) { if !self.span.filter_generated(field.ident.span) { let span = self.span_from_span(field.ident.span); diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 3a43e764dd08e..99ae777bb631b 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -12,7 +12,6 @@ use rustc::traits::{ObligationCause, ObligationCauseCode}; use rustc::ty::{self, Ty, TypeFoldable}; use rustc::ty::subst::Kind; use syntax::ast; -use syntax::source_map::Spanned; use syntax::util::lev_distance::find_best_match_for_name; use syntax_pos::Span; use syntax_pos::hygiene::DesugaringKind; @@ -1036,7 +1035,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); &self, pat: &'tcx hir::Pat, qpath: &hir::QPath, - fields: &'tcx [Spanned], + fields: &'tcx [hir::FieldPat], etc: bool, expected: Ty<'tcx>, def_bm: ty::BindingMode, @@ -1048,7 +1047,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); variant_ty } else { 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; }; @@ -1206,7 +1205,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); pat_id: hir::HirId, span: Span, variant: &'tcx ty::VariantDef, - fields: &'tcx [Spanned], + fields: &'tcx [hir::FieldPat], etc: bool, def_bm: ty::BindingMode, ) -> bool { @@ -1231,7 +1230,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); let mut inexistent_fields = vec![]; // 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 field_ty = match used_fields.entry(ident) { Occupied(occupied) => { diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 67a8ecaf1da85..a88e32eb34dcd 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -283,7 +283,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> { } hir::PatKind::Struct(_, ref fields, _) => { for field in fields { - self.visit_field_id(field.node.hir_id); + self.visit_field_id(field.hir_id); } } _ => {} diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 983adc0eae804..d5becd2e1a94d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -29,7 +29,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet}; use syntax::ast::{self, AttrStyle, Ident}; use syntax::attr; 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::InternedString; 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::Struct(ref name, ref fields, etc) => { format!("{} {{ {}{} }}", qpath_to_string(name), - fields.iter().map(|&Spanned { node: ref fp, .. }| - format!("{}: {}", fp.ident, name_from_pat(&*fp.pat))) + fields.iter().map(|fp| format!("{}: {}", fp.ident, name_from_pat(&fp.pat))) .collect::>().join(", "), if etc { ", .." } else { "" } ) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b8bfa671bcf31..3ae37f734b77e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -571,7 +571,7 @@ impl Pat { match &self.node { 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) => { s.iter().all(|p| p.walk(it)) } @@ -609,6 +609,7 @@ pub struct FieldPat { pub is_shorthand: bool, pub attrs: ThinVec, pub id: NodeId, + pub span: Span, } #[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, ..}`). /// 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>), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index f18cf86243ea3..38f46ee207cae 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -575,7 +575,7 @@ impl<'a> ExtCtxt<'a> { self.pat(span, PatKind::TupleStruct(path, subpats)) } pub fn pat_struct(&self, span: Span, path: ast::Path, - field_pats: Vec>) -> P { + field_pats: Vec) -> P { self.pat(span, PatKind::Struct(path, field_pats, false)) } pub fn pat_tuple(&self, span: Span, pats: Vec>) -> P { diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index d22c05d9b2eee..acafe327640d0 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -1042,10 +1042,7 @@ pub fn noop_visit_pat(pat: &mut P, vis: &mut T) { } PatKind::Struct(path, fields, _etc) => { vis.visit_path(path); - for Spanned { - node: FieldPat { ident, pat, is_shorthand: _, attrs, id }, - span - } in fields { + for FieldPat { ident, pat, is_shorthand: _, attrs, id, span } in fields { vis.visit_ident(ident); vis.visit_id(id); vis.visit_pat(pat); diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs index da44ebd841599..c3079d2da0ce7 100644 --- a/src/libsyntax/parse/parser/pat.rs +++ b/src/libsyntax/parse/parser/pat.rs @@ -488,7 +488,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; @@ -620,11 +620,7 @@ impl<'a> Parser<'a> { .emit(); } - fn parse_pat_field( - &mut self, - lo: Span, - attrs: Vec - ) -> PResult<'a, Spanned> { + fn parse_pat_field(&mut self, lo: Span, attrs: Vec) -> PResult<'a, FieldPat> { // 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) { @@ -659,15 +655,13 @@ impl<'a> Parser<'a> { (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), - node: FieldPat { - ident: fieldname, - pat: subpat, - is_shorthand, - attrs: attrs.into(), - id: ast::DUMMY_NODE_ID, - } }) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index fabbe1ede1bc6..5955b91384290 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2367,14 +2367,14 @@ impl<'a> State<'a> { Consistent, &fields[..], |s, f| { s.cbox(INDENT_UNIT); - if !f.node.is_shorthand { - s.print_ident(f.node.ident); + if !f.is_shorthand { + s.print_ident(f.ident); s.word_nbsp(":"); } - s.print_pat(&f.node.pat); + s.print_pat(&f.pat); s.end(); }, - |f| f.node.pat.span); + |f| f.pat.span); if etc { if !fields.is_empty() { self.word_space(","); } self.s.word(".."); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 8c06bf25eb5ca..6648347d4aef5 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -442,9 +442,9 @@ 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); for field in fields { - walk_list!(visitor, visit_attribute, field.node.attrs.iter()); - visitor.visit_ident(field.node.ident); - visitor.visit_pat(&field.node.pat) + walk_list!(visitor, visit_attribute, field.attrs.iter()); + visitor.visit_ident(field.ident); + visitor.visit_pat(&field.pat) } } PatKind::Tuple(ref elems) => { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index a454593bc6575..d080dc37a9268 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -187,7 +187,7 @@ use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind}; use syntax::ast::{VariantData, GenericParamKind, GenericArg}; use syntax::attr; 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::ptr::P; use syntax::symbol::{Symbol, kw, sym}; @@ -1610,15 +1610,13 @@ impl<'a> TraitDef<'a> { if ident.is_none() { 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()), - node: ast::FieldPat { - id: ast::DUMMY_NODE_ID, - ident: ident.unwrap(), - pat, - is_shorthand: false, - attrs: ThinVec::new(), - }, + pat, } }) .collect();