Skip to content

Commit 73f02fb

Browse files
committed
syntax: Box ast::MacArgs in attributes
1 parent 8d2f467 commit 73f02fb

File tree

10 files changed

+22
-22
lines changed

10 files changed

+22
-22
lines changed

src/librustc/hir/lowering.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1017,14 +1017,14 @@ impl<'a> LoweringContext<'a> {
10171017
}
10181018
}
10191019

1020-
fn lower_mac_args(&mut self, args: &MacArgs) -> MacArgs {
1021-
match *args {
1020+
fn lower_mac_args(&mut self, args: &MacArgs) -> AstP<MacArgs> {
1021+
AstP(match *args {
10221022
MacArgs::Empty => MacArgs::Empty,
10231023
MacArgs::Delimited(dspan, delim, ref tokens) =>
10241024
MacArgs::Delimited(dspan, delim, self.lower_token_stream(tokens.clone())),
10251025
MacArgs::Eq(eq_span, ref tokens) =>
10261026
MacArgs::Eq(eq_span, self.lower_token_stream(tokens.clone())),
1027-
}
1027+
})
10281028
}
10291029

10301030
fn lower_token_stream(&mut self, tokens: TokenStream) -> TokenStream {

src/librustc_parse/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a> StripUnconfigured<'a> {
101101
if !attr.has_name(sym::cfg_attr) {
102102
return vec![attr];
103103
}
104-
if let ast::MacArgs::Empty = attr.get_normal_item().args {
104+
if let ast::MacArgs::Empty = *attr.get_normal_item().args {
105105
self.sess.span_diagnostic
106106
.struct_span_err(
107107
attr.span,

src/librustc_parse/parser/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1011,15 +1011,15 @@ impl<'a> Parser<'a> {
10111011
}
10121012

10131013
fn parse_mac_args(&mut self) -> PResult<'a, P<MacArgs>> {
1014-
self.parse_mac_args_common(true).map(P)
1014+
self.parse_mac_args_common(true)
10151015
}
10161016

1017-
fn parse_attr_args(&mut self) -> PResult<'a, MacArgs> {
1017+
fn parse_attr_args(&mut self) -> PResult<'a, P<MacArgs>> {
10181018
self.parse_mac_args_common(false)
10191019
}
10201020

1021-
fn parse_mac_args_common(&mut self, delimited_only: bool) -> PResult<'a, MacArgs> {
1022-
Ok(if self.check(&token::OpenDelim(DelimToken::Paren)) ||
1021+
fn parse_mac_args_common(&mut self, delimited_only: bool) -> PResult<'a, P<MacArgs>> {
1022+
Ok(P(if self.check(&token::OpenDelim(DelimToken::Paren)) ||
10231023
self.check(&token::OpenDelim(DelimToken::Bracket)) ||
10241024
self.check(&token::OpenDelim(DelimToken::Brace)) {
10251025
match self.parse_token_tree() {
@@ -1052,7 +1052,7 @@ impl<'a> Parser<'a> {
10521052
}
10531053
} else {
10541054
return self.unexpected();
1055-
})
1055+
}))
10561056
}
10571057

10581058
fn parse_or_use_outer_attributes(

src/librustc_parse/parser/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a> Parser<'a> {
115115
fn parse_path_allowing_meta(&mut self, style: PathStyle) -> PResult<'a, Path> {
116116
let meta_ident = match self.token.kind {
117117
token::Interpolated(ref nt) => match **nt {
118-
token::NtMeta(ref item) => match item.args {
118+
token::NtMeta(ref item) => match *item.args {
119119
MacArgs::Empty => Some(item.path.clone()),
120120
_ => None,
121121
},

src/librustc_parse/validate_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn check_meta(sess: &ParseSess, attr: &Attribute) {
1717
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
1818
Some((name, _, template, _)) if name != sym::rustc_dummy =>
1919
check_builtin_attribute(sess, attr, name, template),
20-
_ => if let MacArgs::Eq(..) = attr.get_normal_item().args {
20+
_ => if let MacArgs::Eq(..) = *attr.get_normal_item().args {
2121
// All key-value attributes are restricted to meta-item syntax.
2222
parse_meta(sess, attr).map_err(|mut err| err.emit()).ok();
2323
}

src/libsyntax/ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ impl rustc_serialize::Decodable for AttrId {
23822382
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
23832383
pub struct AttrItem {
23842384
pub path: Path,
2385-
pub args: MacArgs,
2385+
pub args: P<MacArgs>,
23862386
}
23872387

23882388
/// Metadata associated with an item.
@@ -2413,7 +2413,7 @@ pub enum AttrKind {
24132413

24142414
// Receive notifications about the doc comment size changes.
24152415
#[cfg(target_arch = "x86_64")]
2416-
rustc_data_structures::static_assert_size!(AttrKind, 72);
2416+
rustc_data_structures::static_assert_size!(AttrKind, 48);
24172417

24182418
/// `TraitRef`s appear in impls.
24192419
///

src/libsyntax/attr/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl Attribute {
198198

199199
pub fn is_word(&self) -> bool {
200200
if let AttrKind::Normal(item) = &self.kind {
201-
matches!(item.args, MacArgs::Empty)
201+
matches!(*item.args, MacArgs::Empty)
202202
} else {
203203
false
204204
}
@@ -354,7 +354,7 @@ crate fn mk_attr_id() -> AttrId {
354354
AttrId(id)
355355
}
356356

357-
pub fn mk_attr(style: AttrStyle, path: Path, args: MacArgs, span: Span) -> Attribute {
357+
pub fn mk_attr(style: AttrStyle, path: Path, args: P<MacArgs>, span: Span) -> Attribute {
358358
mk_attr_from_item(style, AttrItem { path, args }, span)
359359
}
360360

@@ -512,8 +512,8 @@ impl MetaItem {
512512
}
513513

514514
impl MetaItemKind {
515-
pub fn mac_args(&self, span: Span) -> MacArgs {
516-
match self {
515+
pub fn mac_args(&self, span: Span) -> P<MacArgs> {
516+
P(match self {
517517
MetaItemKind::Word => MacArgs::Empty,
518518
MetaItemKind::NameValue(lit) => MacArgs::Eq(span, lit.token_tree().into()),
519519
MetaItemKind::List(list) => {
@@ -528,7 +528,7 @@ impl MetaItemKind {
528528
DelimSpan::from_single(span), MacDelimiter::Parenthesis, TokenStream::new(tts)
529529
)
530530
}
531-
}
531+
})
532532
}
533533

534534
fn token_trees_and_joints(&self, span: Span) -> Vec<TreeAndJoint> {

src/libsyntax/print/pprust.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
639639

640640
fn print_attr_item(&mut self, item: &ast::AttrItem, span: Span) {
641641
self.ibox(0);
642-
match &item.args {
642+
match &*item.args {
643643
MacArgs::Delimited(_, delim, tokens) => self.print_mac_common(
644644
Some(MacHeader::Path(&item.path)),
645645
false,
@@ -651,7 +651,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
651651
),
652652
MacArgs::Empty | MacArgs::Eq(..) => {
653653
self.print_path(&item.path, false, 0);
654-
if let MacArgs::Eq(_, tokens) = &item.args {
654+
if let MacArgs::Eq(_, tokens) = &*item.args {
655655
self.space();
656656
self.word_space("=");
657657
self.print_tts(tokens.clone(), true);

src/libsyntax_expand/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
642642
=> panic!("unexpected annotatable"),
643643
})), DUMMY_SP).into();
644644
let item = attr.unwrap_normal_item();
645-
if let MacArgs::Eq(..) = item.args {
645+
if let MacArgs::Eq(..) = *item.args {
646646
self.cx.span_err(span, "key-value macro attributes are not supported");
647647
}
648648
let tok_result =

src/libsyntax_expand/proc_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ crate fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>)
183183
}
184184

185185
let parse_derive_paths = |attr: &ast::Attribute| {
186-
if let MacArgs::Empty = attr.get_normal_item().args {
186+
if let MacArgs::Empty = *attr.get_normal_item().args {
187187
return Ok(Vec::new());
188188
}
189189
rustc_parse::parse_in_attr(cx.parse_sess, attr, |p| p.parse_derive_paths())

0 commit comments

Comments
 (0)