Skip to content

Commit 90762c2

Browse files
committed
Complete mut_visit.
1 parent 556d20a commit 90762c2

File tree

1 file changed

+79
-11
lines changed

1 file changed

+79
-11
lines changed

compiler/rustc_ast/src/visit.rs

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,9 +1202,10 @@ macro_rules! common_visitor_and_walkers {
12021202
let TyPat { id, kind, span, tokens: _ } = tp;
12031203
try_visit!(visit_id(vis, id));
12041204
match kind {
1205-
TyPatKind::Range(start, end, _include_end) => {
1205+
TyPatKind::Range(start, end, Spanned { span, node: _include_end }) => {
12061206
visit_opt!(vis, visit_anon_const, start);
12071207
visit_opt!(vis, visit_anon_const, end);
1208+
try_visit!(visit_span(vis, span));
12081209
}
12091210
TyPatKind::Or(variants) => walk_list!(vis, visit_ty_pat, variants),
12101211
TyPatKind::Err(_) => {}
@@ -1523,16 +1524,26 @@ macro_rules! common_visitor_and_walkers {
15231524
}
15241525

15251526
pub fn walk_inline_asm<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, asm: &$($lt)? $($mut)? InlineAsm) -> V::Result {
1526-
// FIXME: Visit spans inside all this currently ignored stuff.
15271527
let InlineAsm {
15281528
asm_macro: _,
1529-
template: _,
1530-
template_strs: _,
1529+
template,
1530+
template_strs,
15311531
operands,
1532-
clobber_abis: _,
1532+
clobber_abis,
15331533
options: _,
1534-
line_spans: _,
1534+
line_spans,
15351535
} = asm;
1536+
for piece in template {
1537+
match piece {
1538+
InlineAsmTemplatePiece::String(_str) => {}
1539+
InlineAsmTemplatePiece::Placeholder { operand_idx: _, modifier: _, span } => {
1540+
try_visit!(visit_span(vis, span));
1541+
}
1542+
}
1543+
}
1544+
for (_s1, _s2, span) in template_strs {
1545+
try_visit!(visit_span(vis, span));
1546+
}
15361547
for (op, span) in operands {
15371548
match op {
15381549
InlineAsmOperand::In { expr, reg: _ }
@@ -1553,6 +1564,12 @@ macro_rules! common_visitor_and_walkers {
15531564
}
15541565
try_visit!(visit_span(vis, span));
15551566
}
1567+
for (_s1, span) in clobber_abis {
1568+
try_visit!(visit_span(vis, span))
1569+
}
1570+
for span in line_spans {
1571+
try_visit!(visit_span(vis, span))
1572+
}
15561573
V::Result::output()
15571574
}
15581575

@@ -1565,9 +1582,9 @@ macro_rules! common_visitor_and_walkers {
15651582
vis.visit_path(path)
15661583
}
15671584

1568-
// FIXME: visit the template exhaustively.
15691585
pub fn walk_format_args<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, fmt: &$($lt)? $($mut)? FormatArgs) -> V::Result {
1570-
let FormatArgs { span, template: _, arguments, uncooked_fmt_str: _, is_source_literal: _ } = fmt;
1586+
let FormatArgs { span, template, arguments, uncooked_fmt_str: _, is_source_literal: _ } = fmt;
1587+
15711588
let args = $(${ignore($mut)} arguments.all_args_mut())? $(${ignore($lt)} arguments.all_args())? ;
15721589
for FormatArgument { kind, expr } in args {
15731590
match kind {
@@ -1578,9 +1595,58 @@ macro_rules! common_visitor_and_walkers {
15781595
}
15791596
try_visit!(vis.visit_expr(expr));
15801597
}
1598+
for piece in template {
1599+
match piece {
1600+
FormatArgsPiece::Literal(_symbol) => {}
1601+
FormatArgsPiece::Placeholder(placeholder) => try_visit!(walk_format_placeholder(vis, placeholder)),
1602+
}
1603+
}
15811604
visit_span(vis, span)
15821605
}
15831606

1607+
fn walk_format_placeholder<$($lt,)? V: $Visitor$(<$lt>)?>(
1608+
vis: &mut V,
1609+
placeholder: &$($lt)? $($mut)? FormatPlaceholder,
1610+
) -> V::Result {
1611+
let FormatPlaceholder { argument, span, format_options, format_trait: _ } = placeholder;
1612+
if let Some(span) = span {
1613+
try_visit!(visit_span(vis, span));
1614+
}
1615+
let FormatArgPosition { span, index: _, kind: _ } = argument;
1616+
if let Some(span) = span {
1617+
try_visit!(visit_span(vis, span));
1618+
}
1619+
let FormatOptions {
1620+
width,
1621+
precision,
1622+
alignment: _,
1623+
fill: _,
1624+
sign: _,
1625+
alternate: _,
1626+
zero_pad: _,
1627+
debug_hex: _,
1628+
} = format_options;
1629+
match width {
1630+
None => {}
1631+
Some(FormatCount::Literal(_)) => {}
1632+
Some(FormatCount::Argument(FormatArgPosition { span, index: _, kind: _ })) => {
1633+
if let Some(span) = span {
1634+
try_visit!(visit_span(vis, span));
1635+
}
1636+
}
1637+
}
1638+
match precision {
1639+
None => {}
1640+
Some(FormatCount::Literal(_)) => {}
1641+
Some(FormatCount::Argument(FormatArgPosition { span, index: _, kind: _ })) => {
1642+
if let Some(span) = span {
1643+
try_visit!(visit_span(vis, span));
1644+
}
1645+
}
1646+
}
1647+
V::Result::output()
1648+
}
1649+
15841650
pub fn walk_expr<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, expression: &$($lt)? $($mut)? Expr) -> V::Result {
15851651
let Expr { id, kind, span, attrs, tokens: _ } = expression;
15861652
try_visit!(visit_id(vis, id));
@@ -1601,7 +1667,7 @@ macro_rules! common_visitor_and_walkers {
16011667
try_visit!(visit_expr_fields(vis, fields));
16021668
match rest {
16031669
StructRest::Base(expr) => try_visit!(vis.visit_expr(expr)),
1604-
StructRest::Rest(_span) => {}
1670+
StructRest::Rest(span) => try_visit!(visit_span(vis, span)),
16051671
StructRest::None => {}
16061672
}
16071673
}
@@ -1688,7 +1754,8 @@ macro_rules! common_visitor_and_walkers {
16881754
visit_opt!(vis, visit_label, opt_label);
16891755
try_visit!(vis.visit_block(block));
16901756
}
1691-
ExprKind::Gen(_capt, body, _kind, decl_span) => {
1757+
ExprKind::Gen(capture_clause, body, _kind, decl_span) => {
1758+
try_visit!(vis.visit_capture_by(capture_clause));
16921759
try_visit!(vis.visit_block(body));
16931760
try_visit!(visit_span(vis, decl_span));
16941761
}
@@ -1705,9 +1772,10 @@ macro_rules! common_visitor_and_walkers {
17051772
try_visit!(vis.visit_expr(rhs));
17061773
try_visit!(visit_span(vis, span));
17071774
}
1708-
ExprKind::AssignOp(_op, left_expression, right_expression) => {
1775+
ExprKind::AssignOp(Spanned { span, node: _ }, left_expression, right_expression) => {
17091776
try_visit!(vis.visit_expr(left_expression));
17101777
try_visit!(vis.visit_expr(right_expression));
1778+
try_visit!(visit_span(vis, span));
17111779
}
17121780
ExprKind::Field(subexpression, ident) => {
17131781
try_visit!(vis.visit_expr(subexpression));

0 commit comments

Comments
 (0)