Skip to content

Commit

Permalink
syntax: Box ast::MacArgs in attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Dec 3, 2019
1 parent 8d2f467 commit 73f02fb
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,14 +1017,14 @@ impl<'a> LoweringContext<'a> {
}
}

fn lower_mac_args(&mut self, args: &MacArgs) -> MacArgs {
match *args {
fn lower_mac_args(&mut self, args: &MacArgs) -> AstP<MacArgs> {
AstP(match *args {
MacArgs::Empty => MacArgs::Empty,
MacArgs::Delimited(dspan, delim, ref tokens) =>
MacArgs::Delimited(dspan, delim, self.lower_token_stream(tokens.clone())),
MacArgs::Eq(eq_span, ref tokens) =>
MacArgs::Eq(eq_span, self.lower_token_stream(tokens.clone())),
}
})
}

fn lower_token_stream(&mut self, tokens: TokenStream) -> TokenStream {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'a> StripUnconfigured<'a> {
if !attr.has_name(sym::cfg_attr) {
return vec![attr];
}
if let ast::MacArgs::Empty = attr.get_normal_item().args {
if let ast::MacArgs::Empty = *attr.get_normal_item().args {
self.sess.span_diagnostic
.struct_span_err(
attr.span,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_parse/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,15 +1011,15 @@ impl<'a> Parser<'a> {
}

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

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

fn parse_mac_args_common(&mut self, delimited_only: bool) -> PResult<'a, MacArgs> {
Ok(if self.check(&token::OpenDelim(DelimToken::Paren)) ||
fn parse_mac_args_common(&mut self, delimited_only: bool) -> PResult<'a, P<MacArgs>> {
Ok(P(if self.check(&token::OpenDelim(DelimToken::Paren)) ||
self.check(&token::OpenDelim(DelimToken::Bracket)) ||
self.check(&token::OpenDelim(DelimToken::Brace)) {
match self.parse_token_tree() {
Expand Down Expand Up @@ -1052,7 +1052,7 @@ impl<'a> Parser<'a> {
}
} else {
return self.unexpected();
})
}))
}

fn parse_or_use_outer_attributes(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'a> Parser<'a> {
fn parse_path_allowing_meta(&mut self, style: PathStyle) -> PResult<'a, Path> {
let meta_ident = match self.token.kind {
token::Interpolated(ref nt) => match **nt {
token::NtMeta(ref item) => match item.args {
token::NtMeta(ref item) => match *item.args {
MacArgs::Empty => Some(item.path.clone()),
_ => None,
},
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn check_meta(sess: &ParseSess, attr: &Attribute) {
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
Some((name, _, template, _)) if name != sym::rustc_dummy =>
check_builtin_attribute(sess, attr, name, template),
_ => if let MacArgs::Eq(..) = attr.get_normal_item().args {
_ => if let MacArgs::Eq(..) = *attr.get_normal_item().args {
// All key-value attributes are restricted to meta-item syntax.
parse_meta(sess, attr).map_err(|mut err| err.emit()).ok();
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ impl rustc_serialize::Decodable for AttrId {
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub struct AttrItem {
pub path: Path,
pub args: MacArgs,
pub args: P<MacArgs>,
}

/// Metadata associated with an item.
Expand Down Expand Up @@ -2413,7 +2413,7 @@ pub enum AttrKind {

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

/// `TraitRef`s appear in impls.
///
Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl Attribute {

pub fn is_word(&self) -> bool {
if let AttrKind::Normal(item) = &self.kind {
matches!(item.args, MacArgs::Empty)
matches!(*item.args, MacArgs::Empty)
} else {
false
}
Expand Down Expand Up @@ -354,7 +354,7 @@ crate fn mk_attr_id() -> AttrId {
AttrId(id)
}

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

Expand Down Expand Up @@ -512,8 +512,8 @@ impl MetaItem {
}

impl MetaItemKind {
pub fn mac_args(&self, span: Span) -> MacArgs {
match self {
pub fn mac_args(&self, span: Span) -> P<MacArgs> {
P(match self {
MetaItemKind::Word => MacArgs::Empty,
MetaItemKind::NameValue(lit) => MacArgs::Eq(span, lit.token_tree().into()),
MetaItemKind::List(list) => {
Expand All @@ -528,7 +528,7 @@ impl MetaItemKind {
DelimSpan::from_single(span), MacDelimiter::Parenthesis, TokenStream::new(tts)
)
}
}
})
}

fn token_trees_and_joints(&self, span: Span) -> Vec<TreeAndJoint> {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere

fn print_attr_item(&mut self, item: &ast::AttrItem, span: Span) {
self.ibox(0);
match &item.args {
match &*item.args {
MacArgs::Delimited(_, delim, tokens) => self.print_mac_common(
Some(MacHeader::Path(&item.path)),
false,
Expand All @@ -651,7 +651,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
),
MacArgs::Empty | MacArgs::Eq(..) => {
self.print_path(&item.path, false, 0);
if let MacArgs::Eq(_, tokens) = &item.args {
if let MacArgs::Eq(_, tokens) = &*item.args {
self.space();
self.word_space("=");
self.print_tts(tokens.clone(), true);
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_expand/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
=> panic!("unexpected annotatable"),
})), DUMMY_SP).into();
let item = attr.unwrap_normal_item();
if let MacArgs::Eq(..) = item.args {
if let MacArgs::Eq(..) = *item.args {
self.cx.span_err(span, "key-value macro attributes are not supported");
}
let tok_result =
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_expand/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ crate fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>)
}

let parse_derive_paths = |attr: &ast::Attribute| {
if let MacArgs::Empty = attr.get_normal_item().args {
if let MacArgs::Empty = *attr.get_normal_item().args {
return Ok(Vec::new());
}
rustc_parse::parse_in_attr(cx.parse_sess, attr, |p| p.parse_derive_paths())
Expand Down

0 comments on commit 73f02fb

Please sign in to comment.