Skip to content

Commit c26af94

Browse files
committed
Make def_collector a MutVisitor.
1 parent 969869b commit c26af94

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 => {
@@ -807,7 +807,7 @@ macro_rules! common_visitor_and_walkers {
807807
visit_foreign_items(vis, items)
808808
}
809809

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

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

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ pub trait ResolverExpand {
10461046
fn visit_ast_fragment_with_placeholders(
10471047
&mut self,
10481048
expn_id: LocalExpnId,
1049-
fragment: &AstFragment,
1049+
fragment: &mut AstFragment,
10501050
);
10511051
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind);
10521052

compiler/rustc_expand/src/expand.rs

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

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

668668
if self.cx.sess.opts.incremental.is_some() {
669669
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
@@ -190,7 +190,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
190190

191191
pub(crate) fn build_reduced_graph(
192192
&mut self,
193-
fragment: &AstFragment,
193+
fragment: &mut AstFragment,
194194
parent_scope: ParentScope<'ra>,
195195
) -> MacroRulesScopeRef<'ra> {
196196
collect_definitions(self, fragment, parent_scope.expansion);

0 commit comments

Comments
 (0)