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:
parent
85fbf49ce0
commit
090b16717a
8 changed files with 32 additions and 23 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue