Rollup merge of #76132 - Aaron1011:mac-call-stmt, r=petrochenkov
Factor out StmtKind::MacCall fields into `MacCallStmt` struct In PR #76130, I add a fourth field, which makes using a tuple variant somewhat unwieldy.
This commit is contained in:
commit
738b8eadfd
@ -922,9 +922,13 @@ impl Stmt {
|
||||
pub fn add_trailing_semicolon(mut self) -> Self {
|
||||
self.kind = match self.kind {
|
||||
StmtKind::Expr(expr) => StmtKind::Semi(expr),
|
||||
StmtKind::MacCall(mac) => StmtKind::MacCall(
|
||||
mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)),
|
||||
),
|
||||
StmtKind::MacCall(mac) => {
|
||||
StmtKind::MacCall(mac.map(|MacCallStmt { mac, style: _, attrs }| MacCallStmt {
|
||||
mac,
|
||||
style: MacStmtStyle::Semicolon,
|
||||
attrs,
|
||||
}))
|
||||
}
|
||||
kind => kind,
|
||||
};
|
||||
self
|
||||
@ -958,7 +962,14 @@ pub enum StmtKind {
|
||||
/// Just a trailing semi-colon.
|
||||
Empty,
|
||||
/// Macro.
|
||||
MacCall(P<(MacCall, MacStmtStyle, AttrVec)>),
|
||||
MacCall(P<MacCallStmt>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct MacCallStmt {
|
||||
pub mac: MacCall,
|
||||
pub style: MacStmtStyle,
|
||||
pub attrs: AttrVec,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]
|
||||
|
@ -16,7 +16,6 @@ use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
||||
use std::iter;
|
||||
use std::ops::DerefMut;
|
||||
|
||||
pub struct MarkedAttrs(GrowableBitSet<AttrId>);
|
||||
|
||||
@ -634,10 +633,7 @@ impl HasAttrs for StmtKind {
|
||||
StmtKind::Local(ref local) => local.attrs(),
|
||||
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
|
||||
StmtKind::Empty | StmtKind::Item(..) => &[],
|
||||
StmtKind::MacCall(ref mac) => {
|
||||
let (_, _, ref attrs) = **mac;
|
||||
attrs.attrs()
|
||||
}
|
||||
StmtKind::MacCall(ref mac) => mac.attrs.attrs(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -647,8 +643,7 @@ impl HasAttrs for StmtKind {
|
||||
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f),
|
||||
StmtKind::Empty | StmtKind::Item(..) => {}
|
||||
StmtKind::MacCall(mac) => {
|
||||
let (_mac, _style, attrs) = mac.deref_mut();
|
||||
attrs.visit_attrs(f);
|
||||
mac.attrs.visit_attrs(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1305,7 +1305,7 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
|
||||
StmtKind::Semi(expr) => vis.filter_map_expr(expr).into_iter().map(StmtKind::Semi).collect(),
|
||||
StmtKind::Empty => smallvec![StmtKind::Empty],
|
||||
StmtKind::MacCall(mut mac) => {
|
||||
let (mac_, _semi, attrs) = mac.deref_mut();
|
||||
let MacCallStmt { mac: mac_, style: _, attrs } = mac.deref_mut();
|
||||
vis.visit_mac(mac_);
|
||||
visit_thin_attrs(attrs, vis);
|
||||
smallvec![StmtKind::MacCall(mac)]
|
||||
|
@ -692,7 +692,7 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
|
||||
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => visitor.visit_expr(expr),
|
||||
StmtKind::Empty => {}
|
||||
StmtKind::MacCall(ref mac) => {
|
||||
let (ref mac, _, ref attrs) = **mac;
|
||||
let MacCallStmt { ref mac, style: _, ref attrs } = **mac;
|
||||
visitor.visit_mac(mac);
|
||||
for attr in attrs.iter() {
|
||||
visitor.visit_attribute(attr);
|
||||
|
@ -1507,11 +1507,10 @@ impl<'a> State<'a> {
|
||||
self.s.word(";");
|
||||
}
|
||||
ast::StmtKind::MacCall(ref mac) => {
|
||||
let (ref mac, style, ref attrs) = **mac;
|
||||
self.space_if_not_bol();
|
||||
self.print_outer_attributes(attrs);
|
||||
self.print_mac(mac);
|
||||
if style == ast::MacStmtStyle::Semicolon {
|
||||
self.print_outer_attributes(&mac.attrs);
|
||||
self.print_mac(&mac.mac);
|
||||
if mac.style == ast::MacStmtStyle::Semicolon {
|
||||
self.s.word(";");
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ use rustc_ast::token;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::visit::{self, AssocCtxt, Visitor};
|
||||
use rustc_ast::{self as ast, AttrItem, Block, LitKind, NodeId, PatKind, Path};
|
||||
use rustc_ast::{ItemKind, MacArgs, MacStmtStyle, StmtKind};
|
||||
use rustc_ast::{ItemKind, MacArgs, MacCallStmt, MacStmtStyle, StmtKind};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_attr::{self as attr, is_builtin_attr, HasAttrs};
|
||||
use rustc_data_structures::map_in_place::MapInPlace;
|
||||
@ -1363,7 +1363,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||
}
|
||||
|
||||
if let StmtKind::MacCall(mac) = stmt.kind {
|
||||
let (mac, style, attrs) = mac.into_inner();
|
||||
let MacCallStmt { mac, style, attrs } = mac.into_inner();
|
||||
self.check_attributes(&attrs);
|
||||
let mut placeholder =
|
||||
self.collect_bang(mac, stmt.span, AstFragmentKind::Stmts).make_stmts();
|
||||
|
@ -92,7 +92,11 @@ pub fn placeholder(
|
||||
AstFragment::Ty(P(ast::Ty { id, span, kind: ast::TyKind::MacCall(mac_placeholder()) }))
|
||||
}
|
||||
AstFragmentKind::Stmts => AstFragment::Stmts(smallvec![{
|
||||
let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ast::AttrVec::new()));
|
||||
let mac = P(ast::MacCallStmt {
|
||||
mac: mac_placeholder(),
|
||||
style: ast::MacStmtStyle::Braces,
|
||||
attrs: ast::AttrVec::new(),
|
||||
});
|
||||
ast::Stmt { id, span, kind: ast::StmtKind::MacCall(mac) }
|
||||
}]),
|
||||
AstFragmentKind::Arms => AstFragment::Arms(smallvec![ast::Arm {
|
||||
@ -293,7 +297,7 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
|
||||
|
||||
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
|
||||
let (style, mut stmts) = match stmt.kind {
|
||||
ast::StmtKind::MacCall(mac) => (mac.1, self.remove(stmt.id).make_stmts()),
|
||||
ast::StmtKind::MacCall(mac) => (mac.style, self.remove(stmt.id).make_stmts()),
|
||||
_ => return noop_flat_map_stmt(stmt, self),
|
||||
};
|
||||
|
||||
|
@ -10,7 +10,7 @@ use rustc_ast as ast;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, TokenKind};
|
||||
use rustc_ast::util::classify;
|
||||
use rustc_ast::{AttrStyle, AttrVec, Attribute, MacCall, MacStmtStyle};
|
||||
use rustc_ast::{AttrStyle, AttrVec, Attribute, MacCall, MacCallStmt, MacStmtStyle};
|
||||
use rustc_ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKind, DUMMY_NODE_ID};
|
||||
use rustc_errors::{Applicability, PResult};
|
||||
use rustc_span::source_map::{BytePos, Span};
|
||||
@ -107,7 +107,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
let kind = if delim == token::Brace || self.token == token::Semi || self.token == token::Eof
|
||||
{
|
||||
StmtKind::MacCall(P((mac, style, attrs)))
|
||||
StmtKind::MacCall(P(MacCallStmt { mac, style, attrs }))
|
||||
} else {
|
||||
// Since none of the above applied, this is an expression statement macro.
|
||||
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac), AttrVec::new());
|
||||
|
@ -191,7 +191,7 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
|
||||
(Item(l), Item(r)) => eq_item(l, r, eq_item_kind),
|
||||
(Expr(l), Expr(r)) | (Semi(l), Semi(r)) => eq_expr(l, r),
|
||||
(Empty, Empty) => true,
|
||||
(MacCall(l), MacCall(r)) => l.1 == r.1 && eq_mac_call(&l.0, &r.0) && over(&l.2, &r.2, |l, r| eq_attr(l, r)),
|
||||
(MacCall(l), MacCall(r)) => l.style == r.style && eq_mac_call(&l.mac, &r.mac) && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user