Skip to content

Commit c6c5243

Browse files
committed
Make def_collector a MutVisitor.
1 parent 2fbda8a commit c6c5243

File tree

6 files changed

+217
-138
lines changed

6 files changed

+217
-138
lines changed

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ where
367367
}
368368

369369
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
370-
fn visit_attrs<T: MutVisitor>(vis: &mut T, attrs: &mut AttrVec) {
370+
pub fn visit_attrs<T: MutVisitor>(vis: &mut T, attrs: &mut AttrVec) {
371371
for attr in attrs.iter_mut() {
372372
vis.visit_attribute(attr);
373373
}
@@ -626,7 +626,7 @@ fn walk_local<T: MutVisitor>(vis: &mut T, local: &mut P<Local>) {
626626
vis.visit_span(span);
627627
}
628628

629-
fn walk_attribute<T: MutVisitor>(vis: &mut T, attr: &mut Attribute) {
629+
pub fn walk_attribute<T: MutVisitor>(vis: &mut T, attr: &mut Attribute) {
630630
let Attribute { kind, id: _, style: _, span } = attr;
631631
match kind {
632632
AttrKind::Normal(normal) => {
@@ -825,7 +825,7 @@ fn visit_nonterminal<T: MutVisitor>(vis: &mut T, nt: &mut token::Nonterminal) {
825825
}
826826

827827
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
828-
fn visit_defaultness<T: MutVisitor>(vis: &mut T, defaultness: &mut Defaultness) {
828+
pub fn visit_defaultness<T: MutVisitor>(vis: &mut T, defaultness: &mut Defaultness) {
829829
match defaultness {
830830
Defaultness::Default(span) => vis.visit_span(span),
831831
Defaultness::Final => {}
@@ -879,7 +879,7 @@ fn walk_coroutine_kind<T: MutVisitor>(vis: &mut T, coroutine_kind: &mut Coroutin
879879
}
880880
}
881881

882-
fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
882+
pub fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
883883
match kind {
884884
FnKind::Fn(FnSig { header, decl, span }, generics, body) => {
885885
// Identifier and visibility are visited as a part of the item.
@@ -891,8 +891,9 @@ fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
891891
}
892892
vis.visit_span(span);
893893
}
894-
FnKind::Closure(binder, decl, body) => {
894+
FnKind::Closure(binder, coroutine_kind, decl, body) => {
895895
vis.visit_closure_binder(binder);
896+
coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind));
896897
vis.visit_fn_decl(decl);
897898
vis.visit_expr(body);
898899
}
@@ -905,7 +906,7 @@ fn walk_fn_decl<T: MutVisitor>(vis: &mut T, decl: &mut P<FnDecl>) {
905906
walk_fn_ret_ty(vis, output);
906907
}
907908

908-
fn walk_fn_ret_ty<T: MutVisitor>(vis: &mut T, fn_ret_ty: &mut FnRetTy) {
909+
pub fn walk_fn_ret_ty<T: MutVisitor>(vis: &mut T, fn_ret_ty: &mut FnRetTy) {
909910
match fn_ret_ty {
910911
FnRetTy::Default(span) => vis.visit_span(span),
911912
FnRetTy::Ty(ty) => vis.visit_ty(ty),
@@ -1596,9 +1597,8 @@ pub fn walk_expr<T: MutVisitor>(vis: &mut T, Expr { kind, id, span, attrs, token
15961597
fn_arg_span,
15971598
}) => {
15981599
visit_constness(vis, constness);
1599-
coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind));
16001600
vis.visit_capture_by(capture_clause);
1601-
vis.visit_fn(FnKind::Closure(binder, fn_decl, body), *span, *id);
1601+
vis.visit_fn(FnKind::Closure(binder, coroutine_kind, fn_decl, body), *span, *id);
16021602
vis.visit_span(fn_decl_span);
16031603
vis.visit_span(fn_arg_span);
16041604
}
@@ -1864,5 +1864,10 @@ pub enum FnKind<'a> {
18641864
Fn(&'a mut FnSig, &'a mut Generics, &'a mut Option<P<Block>>),
18651865

18661866
/// E.g., `|x, y| body`.
1867-
Closure(&'a mut ClosureBinder, &'a mut P<FnDecl>, &'a mut P<Expr>),
1867+
Closure(
1868+
&'a mut ClosureBinder,
1869+
&'a mut Option<CoroutineKind>,
1870+
&'a mut P<FnDecl>,
1871+
&'a mut P<Expr>,
1872+
),
18681873
}

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ pub trait ResolverExpand {
999999
fn visit_ast_fragment_with_placeholders(
10001000
&mut self,
10011001
expn_id: LocalExpnId,
1002-
fragment: &AstFragment,
1002+
fragment: &mut AstFragment,
10031003
);
10041004
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind);
10051005

compiler/rustc_expand/src/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ macro_rules! ast_fragments {
130130
T::fragment_to_output(self)
131131
}
132132

133-
pub(crate) fn mut_visit_with<F: MutVisitor>(&mut self, vis: &mut F) {
133+
pub fn mut_visit_with<F: MutVisitor>(&mut self, vis: &mut F) {
134134
match self {
135135
AstFragment::OptExpr(opt_expr) => {
136136
visit_clobber(opt_expr, |opt_expr| {
@@ -602,7 +602,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
602602
if self.monotonic {
603603
self.cx
604604
.resolver
605-
.visit_ast_fragment_with_placeholders(self.cx.current_expansion.id, &fragment);
605+
.visit_ast_fragment_with_placeholders(self.cx.current_expansion.id, &mut fragment);
606606

607607
if self.cx.sess.opts.incremental.is_some() {
608608
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
@@ -186,7 +186,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
186186

187187
pub(crate) fn build_reduced_graph(
188188
&mut self,
189-
fragment: &AstFragment,
189+
fragment: &mut AstFragment,
190190
parent_scope: ParentScope<'ra>,
191191
) -> MacroRulesScopeRef<'ra> {
192192
collect_definitions(self, fragment, parent_scope.expansion);

0 commit comments

Comments
 (0)