Skip to content

Commit 738b8ea

Browse files
authored
Rollup merge of rust-lang#76132 - Aaron1011:mac-call-stmt, r=petrochenkov
Factor out StmtKind::MacCall fields into `MacCallStmt` struct In PR rust-lang#76130, I add a fourth field, which makes using a tuple variant somewhat unwieldy.
2 parents 9a05582 + ee19021 commit 738b8ea

File tree

9 files changed

+33
-24
lines changed

9 files changed

+33
-24
lines changed

compiler/rustc_ast/src/ast.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -922,9 +922,13 @@ impl Stmt {
922922
pub fn add_trailing_semicolon(mut self) -> Self {
923923
self.kind = match self.kind {
924924
StmtKind::Expr(expr) => StmtKind::Semi(expr),
925-
StmtKind::MacCall(mac) => StmtKind::MacCall(
926-
mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)),
927-
),
925+
StmtKind::MacCall(mac) => {
926+
StmtKind::MacCall(mac.map(|MacCallStmt { mac, style: _, attrs }| MacCallStmt {
927+
mac,
928+
style: MacStmtStyle::Semicolon,
929+
attrs,
930+
}))
931+
}
928932
kind => kind,
929933
};
930934
self
@@ -958,7 +962,14 @@ pub enum StmtKind {
958962
/// Just a trailing semi-colon.
959963
Empty,
960964
/// Macro.
961-
MacCall(P<(MacCall, MacStmtStyle, AttrVec)>),
965+
MacCall(P<MacCallStmt>),
966+
}
967+
968+
#[derive(Clone, Encodable, Decodable, Debug)]
969+
pub struct MacCallStmt {
970+
pub mac: MacCall,
971+
pub style: MacStmtStyle,
972+
pub attrs: AttrVec,
962973
}
963974

964975
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]

compiler/rustc_ast/src/attr/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_span::symbol::{sym, Ident, Symbol};
1616
use rustc_span::Span;
1717

1818
use std::iter;
19-
use std::ops::DerefMut;
2019

2120
pub struct MarkedAttrs(GrowableBitSet<AttrId>);
2221

@@ -634,10 +633,7 @@ impl HasAttrs for StmtKind {
634633
StmtKind::Local(ref local) => local.attrs(),
635634
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
636635
StmtKind::Empty | StmtKind::Item(..) => &[],
637-
StmtKind::MacCall(ref mac) => {
638-
let (_, _, ref attrs) = **mac;
639-
attrs.attrs()
640-
}
636+
StmtKind::MacCall(ref mac) => mac.attrs.attrs(),
641637
}
642638
}
643639

@@ -647,8 +643,7 @@ impl HasAttrs for StmtKind {
647643
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f),
648644
StmtKind::Empty | StmtKind::Item(..) => {}
649645
StmtKind::MacCall(mac) => {
650-
let (_mac, _style, attrs) = mac.deref_mut();
651-
attrs.visit_attrs(f);
646+
mac.attrs.visit_attrs(f);
652647
}
653648
}
654649
}

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
13051305
StmtKind::Semi(expr) => vis.filter_map_expr(expr).into_iter().map(StmtKind::Semi).collect(),
13061306
StmtKind::Empty => smallvec![StmtKind::Empty],
13071307
StmtKind::MacCall(mut mac) => {
1308-
let (mac_, _semi, attrs) = mac.deref_mut();
1308+
let MacCallStmt { mac: mac_, style: _, attrs } = mac.deref_mut();
13091309
vis.visit_mac(mac_);
13101310
visit_thin_attrs(attrs, vis);
13111311
smallvec![StmtKind::MacCall(mac)]

compiler/rustc_ast/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
692692
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => visitor.visit_expr(expr),
693693
StmtKind::Empty => {}
694694
StmtKind::MacCall(ref mac) => {
695-
let (ref mac, _, ref attrs) = **mac;
695+
let MacCallStmt { ref mac, style: _, ref attrs } = **mac;
696696
visitor.visit_mac(mac);
697697
for attr in attrs.iter() {
698698
visitor.visit_attribute(attr);

compiler/rustc_ast_pretty/src/pprust.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1507,11 +1507,10 @@ impl<'a> State<'a> {
15071507
self.s.word(";");
15081508
}
15091509
ast::StmtKind::MacCall(ref mac) => {
1510-
let (ref mac, style, ref attrs) = **mac;
15111510
self.space_if_not_bol();
1512-
self.print_outer_attributes(attrs);
1513-
self.print_mac(mac);
1514-
if style == ast::MacStmtStyle::Semicolon {
1511+
self.print_outer_attributes(&mac.attrs);
1512+
self.print_mac(&mac.mac);
1513+
if mac.style == ast::MacStmtStyle::Semicolon {
15151514
self.s.word(";");
15161515
}
15171516
}

compiler/rustc_expand/src/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast::token;
1313
use rustc_ast::tokenstream::TokenStream;
1414
use rustc_ast::visit::{self, AssocCtxt, Visitor};
1515
use rustc_ast::{self as ast, AttrItem, Block, LitKind, NodeId, PatKind, Path};
16-
use rustc_ast::{ItemKind, MacArgs, MacStmtStyle, StmtKind};
16+
use rustc_ast::{ItemKind, MacArgs, MacCallStmt, MacStmtStyle, StmtKind};
1717
use rustc_ast_pretty::pprust;
1818
use rustc_attr::{self as attr, is_builtin_attr, HasAttrs};
1919
use rustc_data_structures::map_in_place::MapInPlace;
@@ -1363,7 +1363,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13631363
}
13641364

13651365
if let StmtKind::MacCall(mac) = stmt.kind {
1366-
let (mac, style, attrs) = mac.into_inner();
1366+
let MacCallStmt { mac, style, attrs } = mac.into_inner();
13671367
self.check_attributes(&attrs);
13681368
let mut placeholder =
13691369
self.collect_bang(mac, stmt.span, AstFragmentKind::Stmts).make_stmts();

compiler/rustc_expand/src/placeholders.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ pub fn placeholder(
9292
AstFragment::Ty(P(ast::Ty { id, span, kind: ast::TyKind::MacCall(mac_placeholder()) }))
9393
}
9494
AstFragmentKind::Stmts => AstFragment::Stmts(smallvec![{
95-
let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ast::AttrVec::new()));
95+
let mac = P(ast::MacCallStmt {
96+
mac: mac_placeholder(),
97+
style: ast::MacStmtStyle::Braces,
98+
attrs: ast::AttrVec::new(),
99+
});
96100
ast::Stmt { id, span, kind: ast::StmtKind::MacCall(mac) }
97101
}]),
98102
AstFragmentKind::Arms => AstFragment::Arms(smallvec![ast::Arm {
@@ -293,7 +297,7 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
293297

294298
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
295299
let (style, mut stmts) = match stmt.kind {
296-
ast::StmtKind::MacCall(mac) => (mac.1, self.remove(stmt.id).make_stmts()),
300+
ast::StmtKind::MacCall(mac) => (mac.style, self.remove(stmt.id).make_stmts()),
297301
_ => return noop_flat_map_stmt(stmt, self),
298302
};
299303

compiler/rustc_parse/src/parser/stmt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_ast as ast;
1010
use rustc_ast::ptr::P;
1111
use rustc_ast::token::{self, TokenKind};
1212
use rustc_ast::util::classify;
13-
use rustc_ast::{AttrStyle, AttrVec, Attribute, MacCall, MacStmtStyle};
13+
use rustc_ast::{AttrStyle, AttrVec, Attribute, MacCall, MacCallStmt, MacStmtStyle};
1414
use rustc_ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKind, DUMMY_NODE_ID};
1515
use rustc_errors::{Applicability, PResult};
1616
use rustc_span::source_map::{BytePos, Span};
@@ -107,7 +107,7 @@ impl<'a> Parser<'a> {
107107

108108
let kind = if delim == token::Brace || self.token == token::Semi || self.token == token::Eof
109109
{
110-
StmtKind::MacCall(P((mac, style, attrs)))
110+
StmtKind::MacCall(P(MacCallStmt { mac, style, attrs }))
111111
} else {
112112
// Since none of the above applied, this is an expression statement macro.
113113
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac), AttrVec::new());

src/tools/clippy/clippy_lints/src/utils/ast_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
191191
(Item(l), Item(r)) => eq_item(l, r, eq_item_kind),
192192
(Expr(l), Expr(r)) | (Semi(l), Semi(r)) => eq_expr(l, r),
193193
(Empty, Empty) => true,
194-
(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)),
194+
(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)),
195195
_ => false,
196196
}
197197
}

0 commit comments

Comments
 (0)