Skip to content

Commit 433b1e3

Browse files
committed
Remove Spanned from ast::Mac
1 parent 73d2da0 commit 433b1e3

File tree

17 files changed

+54
-52
lines changed

17 files changed

+54
-52
lines changed

src/librustc/lint/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
13451345
// part of `walk_mac`, and (b) we should be calling
13461346
// `visit_path`, *but* that would require a `NodeId`, and I
13471347
// want to get #53686 fixed quickly. -nmatsakis
1348-
ast_visit::walk_path(self, &mac.node.path);
1348+
ast_visit::walk_path(self, &mac.path);
13491349

13501350
run_early_pass!(self, check_mac, mac);
13511351
}

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ impl EarlyLintPass for KeywordIdents {
14931493
self.check_tokens(cx, mac_def.stream());
14941494
}
14951495
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
1496-
self.check_tokens(cx, mac.node.tts.clone().into());
1496+
self.check_tokens(cx, mac.tts.clone().into());
14971497
}
14981498
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) {
14991499
self.check_ident_token(cx, UnderMacro(false), ident);

src/librustc_passes/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
824824
|this| visit::walk_enum_def(this, enum_definition, generics, item_id))
825825
}
826826

827-
fn visit_mac(&mut self, mac: &Spanned<Mac_>) {
827+
fn visit_mac(&mut self, mac: &Mac) {
828828
// when a new macro kind is added but the author forgets to set it up for expansion
829829
// because that's the only part that won't cause a compiler error
830830
self.session.diagnostic()

src/librustc_resolve/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a> base::Resolver for Resolver<'a> {
186186
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
187187
(&attr.path, MacroKind::Attr, derives.clone(), after_derive),
188188
InvocationKind::Bang { ref mac, .. } =>
189-
(&mac.node.path, MacroKind::Bang, Vec::new(), false),
189+
(&mac.path, MacroKind::Bang, Vec::new(), false),
190190
InvocationKind::Derive { ref path, .. } =>
191191
(path, MacroKind::Derive, Vec::new(), false),
192192
InvocationKind::DeriveContainer { ref derives, .. } => {

src/libsyntax/ast.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1285,19 +1285,18 @@ pub enum Movability {
12851285
Movable,
12861286
}
12871287

1288-
pub type Mac = Spanned<Mac_>;
1289-
12901288
/// Represents a macro invocation. The `Path` indicates which macro
12911289
/// is being invoked, and the vector of token-trees contains the source
12921290
/// of the macro invocation.
12931291
///
12941292
/// N.B., the additional ident for a `macro_rules`-style macro is actually
12951293
/// stored in the enclosing item.
12961294
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1297-
pub struct Mac_ {
1295+
pub struct Mac {
12981296
pub path: Path,
12991297
pub delim: MacDelimiter,
13001298
pub tts: TokenStream,
1299+
pub span: Span,
13011300
pub prior_type_ascription: Option<(Span, bool)>,
13021301
}
13031302

@@ -1308,7 +1307,7 @@ pub enum MacDelimiter {
13081307
Brace,
13091308
}
13101309

1311-
impl Mac_ {
1310+
impl Mac {
13121311
pub fn stream(&self) -> TokenStream {
13131312
self.tts.clone()
13141313
}

src/libsyntax/ext/expand.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -492,22 +492,21 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
492492
InvocationKind::Bang { mac, .. } => match ext {
493493
SyntaxExtensionKind::Bang(expander) => {
494494
self.gate_proc_macro_expansion_kind(span, fragment_kind);
495-
let tok_result = expander.expand(self.cx, span, mac.node.stream());
495+
let tok_result = expander.expand(self.cx, span, mac.stream());
496496
let result =
497-
self.parse_ast_fragment(tok_result, fragment_kind, &mac.node.path, span);
497+
self.parse_ast_fragment(tok_result, fragment_kind, &mac.path, span);
498498
self.gate_proc_macro_expansion(span, &result);
499499
result
500500
}
501501
SyntaxExtensionKind::LegacyBang(expander) => {
502502
let prev = self.cx.current_expansion.prior_type_ascription;
503-
self.cx.current_expansion.prior_type_ascription =
504-
mac.node.prior_type_ascription;
505-
let tok_result = expander.expand(self.cx, span, mac.node.stream());
503+
self.cx.current_expansion.prior_type_ascription = mac.prior_type_ascription;
504+
let tok_result = expander.expand(self.cx, span, mac.stream());
506505
let result = if let Some(result) = fragment_kind.make_from(tok_result) {
507506
result
508507
} else {
509508
let msg = format!("non-{kind} macro in {kind} position: {path}",
510-
kind = fragment_kind.name(), path = mac.node.path);
509+
kind = fragment_kind.name(), path = mac.path);
511510
self.cx.span_err(span, &msg);
512511
self.cx.trace_macros_diag();
513512
fragment_kind.dummy(span)

src/libsyntax/ext/placeholders.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ use rustc_data_structures::fx::FxHashMap;
1414

1515
pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
1616
fn mac_placeholder() -> ast::Mac {
17-
dummy_spanned(ast::Mac_ {
17+
ast::Mac {
1818
path: ast::Path { span: DUMMY_SP, segments: Vec::new() },
1919
tts: TokenStream::empty().into(),
2020
delim: ast::MacDelimiter::Brace,
21+
span: DUMMY_SP,
2122
prior_type_ascription: None,
22-
})
23+
}
2324
}
2425

2526
let ident = ast::Ident::invalid();

src/libsyntax/mut_visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ pub fn noop_visit_attribute<T: MutVisitor>(attr: &mut Attribute, vis: &mut T) {
533533
vis.visit_span(span);
534534
}
535535

536-
pub fn noop_visit_mac<T: MutVisitor>(Spanned { node, span }: &mut Mac, vis: &mut T) {
537-
let Mac_ { path, delim: _, tts, .. } = node;
536+
pub fn noop_visit_mac<T: MutVisitor>(mac: &mut Mac, vis: &mut T) {
537+
let Mac { path, delim: _, tts, span, prior_type_ascription: _ } = mac;
538538
vis.visit_path(path);
539539
vis.visit_tts(tts);
540540
vis.visit_span(span);

src/libsyntax/parse/parser/expr.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use crate::ast::{self, Attribute, AttrStyle, Ident, CaptureBy, BlockCheckMode};
88
use crate::ast::{Expr, ExprKind, RangeLimits, Label, Movability, IsAsync, Arm};
99
use crate::ast::{Ty, TyKind, FunctionRetTy, Arg, FnDecl};
1010
use crate::ast::{BinOpKind, BinOp, UnOp};
11-
use crate::ast::{Mac_, AnonConst, Field};
11+
use crate::ast::{Mac, AnonConst, Field};
1212

1313
use crate::parse::classify;
1414
use crate::parse::token::{self, Token};
1515
use crate::parse::diagnostics::{Error};
1616
use crate::print::pprust;
17-
use crate::source_map::{self, respan, Span};
17+
use crate::source_map::{self, Span};
1818
use crate::symbol::{kw, sym};
1919
use crate::util::parser::{AssocOp, Fixity, prec_let_scrutinee_needs_par};
2020

@@ -1011,12 +1011,13 @@ impl<'a> Parser<'a> {
10111011
// MACRO INVOCATION expression
10121012
let (delim, tts) = self.expect_delimited_token_tree()?;
10131013
hi = self.prev_span;
1014-
ex = ExprKind::Mac(respan(lo.to(hi), Mac_ {
1014+
ex = ExprKind::Mac(Mac {
10151015
path,
10161016
tts,
10171017
delim,
1018+
span: lo.to(hi),
10181019
prior_type_ascription: self.last_type_ascription,
1019-
}));
1020+
});
10201021
} else if self.check(&token::OpenDelim(token::Brace)) {
10211022
if let Some(expr) = self.maybe_parse_struct_expr(lo, &path, &attrs) {
10221023
return expr;

src/libsyntax/parse/parser/item.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::ast::{Visibility, VisibilityKind, Mutability, FnDecl, FnHeader};
1010
use crate::ast::{ForeignItem, ForeignItemKind};
1111
use crate::ast::{Ty, TyKind, GenericBounds, TraitRef};
1212
use crate::ast::{EnumDef, VariantData, StructField, AnonConst};
13-
use crate::ast::{Mac, Mac_, MacDelimiter};
13+
use crate::ast::{Mac, MacDelimiter};
1414
use crate::ext::base::DummyResult;
1515
use crate::parse::token;
1616
use crate::parse::parser::maybe_append;
@@ -530,12 +530,13 @@ impl<'a> Parser<'a> {
530530
}
531531

532532
let hi = self.prev_span;
533-
let mac = respan(mac_lo.to(hi), Mac_ {
533+
let mac = Mac {
534534
path,
535535
tts,
536536
delim,
537+
span: mac_lo.to(hi),
537538
prior_type_ascription: self.last_type_ascription,
538-
});
539+
};
539540
let item =
540541
self.mk_item(lo.to(hi), Ident::invalid(), ItemKind::Mac(mac), visibility, attrs);
541542
return Ok(Some(item));
@@ -604,12 +605,13 @@ impl<'a> Parser<'a> {
604605
self.expect(&token::Semi)?;
605606
}
606607

607-
Ok(Some(respan(lo.to(self.prev_span), Mac_ {
608+
Ok(Some(Mac {
608609
path,
609610
tts,
610611
delim,
612+
span: lo.to(self.prev_span),
611613
prior_type_ascription: self.last_type_ascription,
612-
})))
614+
}))
613615
} else {
614616
Ok(None)
615617
}

src/libsyntax/parse/parser/pat.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{Parser, PResult, PathStyle};
22

33
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
44
use crate::ptr::P;
5-
use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac_};
5+
use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac};
66
use crate::ast::{BindingMode, Ident, Mutability, Path, QSelf, Expr, ExprKind};
77
use crate::parse::token::{self};
88
use crate::print::pprust;
@@ -275,12 +275,13 @@ impl<'a> Parser<'a> {
275275
fn parse_pat_mac_invoc(&mut self, lo: Span, path: Path) -> PResult<'a, PatKind> {
276276
self.bump();
277277
let (delim, tts) = self.expect_delimited_token_tree()?;
278-
let mac = respan(lo.to(self.prev_span), Mac_ {
278+
let mac = Mac {
279279
path,
280280
tts,
281281
delim,
282+
span: lo.to(self.prev_span),
282283
prior_type_ascription: self.last_type_ascription,
283-
});
284+
};
284285
Ok(PatKind::Mac(mac))
285286
}
286287

src/libsyntax/parse/parser/stmt.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::path::PathStyle;
55
use crate::ptr::P;
66
use crate::{maybe_whole, ThinVec};
77
use crate::ast::{self, Stmt, StmtKind, Local, Block, BlockCheckMode, Expr, ExprKind};
8-
use crate::ast::{Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac_, MacDelimiter};
8+
use crate::ast::{Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac, MacDelimiter};
99
use crate::ext::base::DummyResult;
1010
use crate::parse::{classify, DirectoryOwnership};
1111
use crate::parse::diagnostics::Error;
@@ -99,12 +99,13 @@ impl<'a> Parser<'a> {
9999
MacStmtStyle::NoBraces
100100
};
101101

102-
let mac = respan(lo.to(hi), Mac_ {
102+
let mac = Mac {
103103
path,
104104
tts,
105105
delim,
106+
span: lo.to(hi),
106107
prior_type_ascription: self.last_type_ascription,
107-
});
108+
};
108109
let node = if delim == MacDelimiter::Brace ||
109110
self.token == token::Semi || self.token == token::Eof {
110111
StmtKind::Mac(P((mac, style, attrs.into())))

src/libsyntax/parse/parser/ty.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::{maybe_whole, maybe_recover_from_interpolated_ty_qpath};
44
use crate::ptr::P;
55
use crate::ast::{self, Ty, TyKind, MutTy, BareFnTy, FunctionRetTy, GenericParam, Lifetime, Ident};
66
use crate::ast::{TraitBoundModifier, TraitObjectSyntax, GenericBound, GenericBounds, PolyTraitRef};
7-
use crate::ast::{Mutability, AnonConst, FnDecl, Mac_};
7+
use crate::ast::{Mutability, AnonConst, FnDecl, Mac};
88
use crate::parse::token::{self, Token};
9-
use crate::source_map::{respan, Span};
9+
use crate::source_map::Span;
1010
use crate::symbol::{kw};
1111

1212
use rustc_target::spec::abi::Abi;
@@ -175,13 +175,14 @@ impl<'a> Parser<'a> {
175175
if self.eat(&token::Not) {
176176
// Macro invocation in type position
177177
let (delim, tts) = self.expect_delimited_token_tree()?;
178-
let node = Mac_ {
178+
let mac = Mac {
179179
path,
180180
tts,
181181
delim,
182+
span: lo.to(self.prev_span),
182183
prior_type_ascription: self.last_type_ascription,
183184
};
184-
TyKind::Mac(respan(lo.to(self.prev_span), node))
185+
TyKind::Mac(mac)
185186
} else {
186187
// Just a type path or bound list (trait object type) starting with a trait.
187188
// `Type`

src/libsyntax/parse/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ fn ttdelim_span() {
273273
"foo!( fn main() { body } )".to_string(), &sess).unwrap();
274274

275275
let tts: Vec<_> = match expr.node {
276-
ast::ExprKind::Mac(ref mac) => mac.node.stream().trees().collect(),
276+
ast::ExprKind::Mac(ref mac) => mac.stream().trees().collect(),
277277
_ => panic!("not a macro"),
278278
};
279279

src/libsyntax/print/pprust.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ impl<'a> State<'a> {
10671067
}
10681068
ast::ForeignItemKind::Macro(ref m) => {
10691069
self.print_mac(m);
1070-
match m.node.delim {
1070+
match m.delim {
10711071
MacDelimiter::Brace => {},
10721072
_ => self.s.word(";")
10731073
}
@@ -1341,7 +1341,7 @@ impl<'a> State<'a> {
13411341
}
13421342
ast::ItemKind::Mac(ref mac) => {
13431343
self.print_mac(mac);
1344-
match mac.node.delim {
1344+
match mac.delim {
13451345
MacDelimiter::Brace => {}
13461346
_ => self.s.word(";"),
13471347
}
@@ -1554,7 +1554,7 @@ impl<'a> State<'a> {
15541554
}
15551555
ast::TraitItemKind::Macro(ref mac) => {
15561556
self.print_mac(mac);
1557-
match mac.node.delim {
1557+
match mac.delim {
15581558
MacDelimiter::Brace => {}
15591559
_ => self.s.word(";"),
15601560
}
@@ -1591,7 +1591,7 @@ impl<'a> State<'a> {
15911591
}
15921592
ast::ImplItemKind::Macro(ref mac) => {
15931593
self.print_mac(mac);
1594-
match mac.node.delim {
1594+
match mac.delim {
15951595
MacDelimiter::Brace => {}
15961596
_ => self.s.word(";"),
15971597
}
@@ -1749,11 +1749,11 @@ impl<'a> State<'a> {
17491749

17501750
crate fn print_mac(&mut self, m: &ast::Mac) {
17511751
self.print_mac_common(
1752-
Some(MacHeader::Path(&m.node.path)),
1752+
Some(MacHeader::Path(&m.path)),
17531753
true,
17541754
None,
1755-
m.node.delim.to_token(),
1756-
m.node.stream(),
1755+
m.delim.to_token(),
1756+
m.stream(),
17571757
true,
17581758
m.span,
17591759
);

src/libsyntax/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
663663
}
664664

665665
pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a Mac) {
666-
visitor.visit_path(&mac.node.path, DUMMY_NODE_ID);
666+
visitor.visit_path(&mac.path, DUMMY_NODE_ID);
667667
}
668668

669669
pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonConst) {

src/libsyntax_ext/assert.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use errors::{Applicability, DiagnosticBuilder};
22

33
use syntax::ast::{self, *};
4-
use syntax::source_map::Spanned;
54
use syntax::ext::base::*;
65
use syntax::parse::token::{self, TokenKind};
76
use syntax::parse::parser::Parser;
@@ -25,7 +24,7 @@ pub fn expand_assert<'cx>(
2524
};
2625

2726
let sp = sp.apply_mark(cx.current_expansion.id);
28-
let panic_call = Mac_ {
27+
let panic_call = Mac {
2928
path: Path::from_ident(Ident::new(sym::panic, sp)),
3029
tts: custom_message.unwrap_or_else(|| {
3130
TokenStream::from(TokenTree::token(
@@ -37,17 +36,15 @@ pub fn expand_assert<'cx>(
3736
))
3837
}).into(),
3938
delim: MacDelimiter::Parenthesis,
39+
span: sp,
4040
prior_type_ascription: None,
4141
};
4242
let if_expr = cx.expr_if(
4343
sp,
4444
cx.expr(sp, ExprKind::Unary(UnOp::Not, cond_expr)),
4545
cx.expr(
4646
sp,
47-
ExprKind::Mac(Spanned {
48-
span: sp,
49-
node: panic_call,
50-
}),
47+
ExprKind::Mac(panic_call),
5148
),
5249
None,
5350
);

0 commit comments

Comments
 (0)