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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 7 additions & 5 deletions
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
}

0 commit comments

Comments
 (0)