Skip to content

Commit 8abc7c8

Browse files
committed
Make def_collector a MutVisitor.
1 parent b9964b1 commit 8abc7c8

File tree

6 files changed

+190
-123
lines changed

6 files changed

+190
-123
lines changed

compiler/rustc_ast/src/visit.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ macro_rules! common_visitor_and_walkers {
527527
}
528528
}
529529

530-
fn visit_defaultness<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, defaultness: &$($lt)? $($mut)? Defaultness) -> V::Result {
530+
pub fn visit_defaultness<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, defaultness: &$($lt)? $($mut)? Defaultness) -> V::Result {
531531
match defaultness {
532532
Defaultness::Default(span) => visit_span(vis, span),
533533
Defaultness::Final => {
@@ -808,7 +808,7 @@ macro_rules! common_visitor_and_walkers {
808808
visit_foreign_items(vis, items)
809809
}
810810

811-
fn walk_define_opaques<$($lt,)? V: $Visitor$(<$lt>)?>(
811+
pub fn walk_define_opaques<$($lt,)? V: $Visitor$(<$lt>)?>(
812812
visitor: &mut V,
813813
define_opaque: &$($lt)? $($mut)? Option<ThinVec<(NodeId, Path)>>,
814814
) -> V::Result {
@@ -1226,6 +1226,27 @@ macro_rules! common_visitor_and_walkers {
12261226
V::Result::output()
12271227
}
12281228

1229+
pub fn walk_stmt<$($lt,)? V: $Visitor$(<$lt>)?>(
1230+
vis: &mut V,
1231+
statement: &$($lt)? $($mut)? Stmt,
1232+
) -> V::Result {
1233+
let Stmt { id, kind, span } = statement;
1234+
try_visit!(visit_id(vis, id));
1235+
match kind {
1236+
StmtKind::Let(local) => try_visit!(vis.visit_local(local)),
1237+
StmtKind::Item(item) => try_visit!(vis.visit_item(item)),
1238+
StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(vis.visit_expr(expr)),
1239+
StmtKind::Empty => {}
1240+
StmtKind::MacCall(mac) => {
1241+
let MacCallStmt { mac, attrs, style: _, tokens: _ } = &$($mut)? **mac;
1242+
walk_list!(vis, visit_attribute, attrs);
1243+
try_visit!(vis.visit_mac_call(mac));
1244+
}
1245+
}
1246+
try_visit!(visit_span(vis, span));
1247+
V::Result::output()
1248+
}
1249+
12291250
pub fn walk_path<$($lt,)? V: $Visitor$(<$lt>)?>(
12301251
vis: &mut V,
12311252
path: &$($lt)? $($mut)? Path,
@@ -1945,20 +1966,3 @@ fn visit_nested_use_tree<'a, V: Visitor<'a>>(
19451966
) -> V::Result {
19461967
vis.visit_nested_use_tree(nested_tree, nested_id)
19471968
}
1948-
1949-
pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result {
1950-
let Stmt { id, kind, span: _ } = statement;
1951-
try_visit!(visit_id(visitor, id));
1952-
match kind {
1953-
StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
1954-
StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),
1955-
StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(visitor.visit_expr(expr)),
1956-
StmtKind::Empty => {}
1957-
StmtKind::MacCall(mac) => {
1958-
let MacCallStmt { mac, attrs, style: _, tokens: _ } = &**mac;
1959-
walk_list!(visitor, visit_attribute, attrs);
1960-
try_visit!(visitor.visit_mac_call(mac));
1961-
}
1962-
}
1963-
V::Result::output()
1964-
}

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ pub trait ResolverExpand {
10661066
fn visit_ast_fragment_with_placeholders(
10671067
&mut self,
10681068
expn_id: LocalExpnId,
1069-
fragment: &AstFragment,
1069+
fragment: &mut AstFragment,
10701070
);
10711071
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind);
10721072

compiler/rustc_expand/src/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ macro_rules! ast_fragments {
137137
T::fragment_to_output(self)
138138
}
139139

140-
pub(crate) fn mut_visit_with(&mut self, vis: &mut impl MutVisitor) {
140+
pub fn mut_visit_with(&mut self, vis: &mut impl MutVisitor) {
141141
match self {
142142
AstFragment::OptExpr(opt_expr) => {
143143
if let Some(expr) = opt_expr.take() {
@@ -664,7 +664,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
664664
if self.monotonic {
665665
self.cx
666666
.resolver
667-
.visit_ast_fragment_with_placeholders(self.cx.current_expansion.id, &fragment);
667+
.visit_ast_fragment_with_placeholders(self.cx.current_expansion.id, &mut fragment);
668668

669669
if self.cx.sess.opts.incremental.is_some() {
670670
for (invoc, _) in invocations.iter_mut() {

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
179179

180180
pub(crate) fn build_reduced_graph(
181181
&mut self,
182-
fragment: &AstFragment,
182+
fragment: &mut AstFragment,
183183
parent_scope: ParentScope<'ra>,
184184
) -> MacroRulesScopeRef<'ra> {
185185
collect_definitions(self, fragment, parent_scope.expansion);

0 commit comments

Comments
 (0)