Always pass the visitor as the first argument to walk* functions

This commit is contained in:
Oli Scherer 2024-07-17 11:23:35 +00:00
parent 754bdef793
commit 8d290058c9
10 changed files with 294 additions and 282 deletions

File diff suppressed because it is too large Load Diff

View File

@ -212,18 +212,18 @@ impl MutVisitor for CfgEval<'_> {
#[instrument(level = "trace", skip(self))] #[instrument(level = "trace", skip(self))]
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) { fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
self.0.configure_expr(expr, false); self.0.configure_expr(expr, false);
mut_visit::walk_expr(expr, self); mut_visit::walk_expr(self, expr);
} }
#[instrument(level = "trace", skip(self))] #[instrument(level = "trace", skip(self))]
fn visit_method_receiver_expr(&mut self, expr: &mut P<ast::Expr>) { fn visit_method_receiver_expr(&mut self, expr: &mut P<ast::Expr>) {
self.0.configure_expr(expr, true); self.0.configure_expr(expr, true);
mut_visit::walk_expr(expr, self); mut_visit::walk_expr(self, expr);
} }
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> { fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
let mut expr = configure!(self, expr); let mut expr = configure!(self, expr);
mut_visit::walk_expr(&mut expr, self); mut_visit::walk_expr(self, &mut expr);
Some(expr) Some(expr)
} }
@ -231,15 +231,18 @@ fn flat_map_generic_param(
&mut self, &mut self,
param: ast::GenericParam, param: ast::GenericParam,
) -> SmallVec<[ast::GenericParam; 1]> { ) -> SmallVec<[ast::GenericParam; 1]> {
mut_visit::walk_flat_map_generic_param(configure!(self, param), self) let param = configure!(self, param);
mut_visit::walk_flat_map_generic_param(self, param)
} }
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
mut_visit::walk_flat_map_stmt(configure!(self, stmt), self) let stmt = configure!(self, stmt);
mut_visit::walk_flat_map_stmt(self, stmt)
} }
fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> { fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
mut_visit::walk_flat_map_item(configure!(self, item), None, self) let item = configure!(self, item);
mut_visit::walk_flat_map_item(self, item, None)
} }
fn flat_map_assoc_item( fn flat_map_assoc_item(
@ -247,37 +250,45 @@ fn flat_map_assoc_item(
item: P<ast::AssocItem>, item: P<ast::AssocItem>,
ctxt: AssocCtxt, ctxt: AssocCtxt,
) -> SmallVec<[P<ast::AssocItem>; 1]> { ) -> SmallVec<[P<ast::AssocItem>; 1]> {
mut_visit::walk_flat_map_item(configure!(self, item), Some(ctxt), self) let item = configure!(self, item);
mut_visit::walk_flat_map_item(self, item, Some(ctxt))
} }
fn flat_map_foreign_item( fn flat_map_foreign_item(
&mut self, &mut self,
foreign_item: P<ast::ForeignItem>, foreign_item: P<ast::ForeignItem>,
) -> SmallVec<[P<ast::ForeignItem>; 1]> { ) -> SmallVec<[P<ast::ForeignItem>; 1]> {
mut_visit::walk_flat_map_item(configure!(self, foreign_item), None, self) let foreign_item = configure!(self, foreign_item);
mut_visit::walk_flat_map_item(self, foreign_item, None)
} }
fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> { fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {
mut_visit::walk_flat_map_arm(configure!(self, arm), self) let arm = configure!(self, arm);
mut_visit::walk_flat_map_arm(self, arm)
} }
fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> { fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> {
mut_visit::walk_flat_map_expr_field(configure!(self, field), self) let field = configure!(self, field);
mut_visit::walk_flat_map_expr_field(self, field)
} }
fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> { fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> {
mut_visit::walk_flat_map_pat_field(configure!(self, fp), self) let fp = configure!(self, fp);
mut_visit::walk_flat_map_pat_field(self, fp)
} }
fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> { fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> {
mut_visit::walk_flat_map_param(configure!(self, p), self) let p = configure!(self, p);
mut_visit::walk_flat_map_param(self, p)
} }
fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> { fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> {
mut_visit::walk_flat_map_field_def(configure!(self, sf), self) let sf = configure!(self, sf);
mut_visit::walk_flat_map_field_def(self, sf)
} }
fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> { fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> {
mut_visit::walk_flat_map_variant(configure!(self, variant), self) let variant = configure!(self, variant);
mut_visit::walk_flat_map_variant(self, variant)
} }
} }

View File

@ -122,7 +122,7 @@ fn add_test_cases(&mut self, node_id: ast::NodeId, span: Span, prev_tests: Vec<T
impl<'a> MutVisitor for TestHarnessGenerator<'a> { impl<'a> MutVisitor for TestHarnessGenerator<'a> {
fn visit_crate(&mut self, c: &mut ast::Crate) { fn visit_crate(&mut self, c: &mut ast::Crate) {
let prev_tests = mem::take(&mut self.tests); let prev_tests = mem::take(&mut self.tests);
walk_crate(c, self); walk_crate(self, c);
self.add_test_cases(ast::CRATE_NODE_ID, c.spans.inner_span, prev_tests); self.add_test_cases(ast::CRATE_NODE_ID, c.spans.inner_span, prev_tests);
// Create a main function to run our tests // Create a main function to run our tests
@ -192,7 +192,7 @@ struct EntryPointCleaner<'a> {
impl<'a> MutVisitor for EntryPointCleaner<'a> { impl<'a> MutVisitor for EntryPointCleaner<'a> {
fn flat_map_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> { fn flat_map_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
self.depth += 1; self.depth += 1;
let item = walk_flat_map_item(i, None, self).expect_one("noop did something"); let item = walk_flat_map_item(self, i, None).expect_one("noop did something");
self.depth -= 1; self.depth -= 1;
// Remove any #[rustc_main] or #[start] from the AST so it doesn't // Remove any #[rustc_main] or #[start] from the AST so it doesn't

View File

@ -1149,7 +1149,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_items() fragment.make_items()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_item(self, None, visitor) walk_flat_map_item(visitor, self, None)
} }
fn is_mac_call(&self) -> bool { fn is_mac_call(&self) -> bool {
matches!(self.kind, ItemKind::MacCall(..)) matches!(self.kind, ItemKind::MacCall(..))
@ -1293,7 +1293,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_trait_items() fragment.make_trait_items()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_item(self.wrapped, Some(AssocCtxt::Trait), visitor) walk_flat_map_item(visitor, self.wrapped, Some(AssocCtxt::Trait))
} }
fn is_mac_call(&self) -> bool { fn is_mac_call(&self) -> bool {
matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
@ -1334,7 +1334,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_impl_items() fragment.make_impl_items()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_item(self.wrapped, Some(AssocCtxt::Impl), visitor) walk_flat_map_item(visitor, self.wrapped, Some(AssocCtxt::Impl))
} }
fn is_mac_call(&self) -> bool { fn is_mac_call(&self) -> bool {
matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
@ -1372,7 +1372,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_foreign_items() fragment.make_foreign_items()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_item(self, None, visitor) walk_flat_map_item(visitor, self, None)
} }
fn is_mac_call(&self) -> bool { fn is_mac_call(&self) -> bool {
matches!(self.kind, ForeignItemKind::MacCall(..)) matches!(self.kind, ForeignItemKind::MacCall(..))
@ -1395,7 +1395,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_variants() fragment.make_variants()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_variant(self, visitor) walk_flat_map_variant(visitor, self)
} }
} }
@ -1408,7 +1408,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_field_defs() fragment.make_field_defs()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_field_def(self, visitor) walk_flat_map_field_def(visitor, self)
} }
} }
@ -1421,7 +1421,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_pat_fields() fragment.make_pat_fields()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_pat_field(self, visitor) walk_flat_map_pat_field(visitor, self)
} }
} }
@ -1434,7 +1434,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_expr_fields() fragment.make_expr_fields()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_expr_field(self, visitor) walk_flat_map_expr_field(visitor, self)
} }
} }
@ -1447,7 +1447,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_params() fragment.make_params()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_param(self, visitor) walk_flat_map_param(visitor, self)
} }
} }
@ -1460,7 +1460,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_generic_params() fragment.make_generic_params()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_generic_param(self, visitor) walk_flat_map_generic_param(visitor, self)
} }
} }
@ -1473,7 +1473,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_arms() fragment.make_arms()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_arm(self, visitor) walk_flat_map_arm(visitor, self)
} }
} }
@ -1487,7 +1487,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_stmts() fragment.make_stmts()
} }
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_stmt(self, visitor) walk_flat_map_stmt(visitor, self)
} }
fn is_mac_call(&self) -> bool { fn is_mac_call(&self) -> bool {
match &self.kind { match &self.kind {
@ -1561,7 +1561,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_crate() fragment.make_crate()
} }
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) { fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
walk_crate(self, visitor) walk_crate(visitor, self)
} }
fn expand_cfg_false( fn expand_cfg_false(
&mut self, &mut self,
@ -1587,7 +1587,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_ty() fragment.make_ty()
} }
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) { fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
walk_ty(self, visitor) walk_ty(visitor, self)
} }
fn is_mac_call(&self) -> bool { fn is_mac_call(&self) -> bool {
matches!(self.kind, ast::TyKind::MacCall(..)) matches!(self.kind, ast::TyKind::MacCall(..))
@ -1611,7 +1611,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_pat() fragment.make_pat()
} }
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) { fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
walk_pat(self, visitor) walk_pat(visitor, self)
} }
fn is_mac_call(&self) -> bool { fn is_mac_call(&self) -> bool {
matches!(self.kind, PatKind::MacCall(..)) matches!(self.kind, PatKind::MacCall(..))
@ -1639,7 +1639,7 @@ fn descr() -> &'static str {
"an expression" "an expression"
} }
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) { fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
walk_expr(self, visitor) walk_expr(visitor, self)
} }
fn is_mac_call(&self) -> bool { fn is_mac_call(&self) -> bool {
matches!(self.kind, ExprKind::MacCall(..)) matches!(self.kind, ExprKind::MacCall(..))
@ -1665,7 +1665,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_opt_expr() fragment.make_opt_expr()
} }
fn walk_flat_map<V: MutVisitor>(mut self, visitor: &mut V) -> Self::OutputTy { fn walk_flat_map<V: MutVisitor>(mut self, visitor: &mut V) -> Self::OutputTy {
walk_expr(&mut self.wrapped, visitor); walk_expr(visitor, &mut self.wrapped);
Some(self.wrapped) Some(self.wrapped)
} }
fn is_mac_call(&self) -> bool { fn is_mac_call(&self) -> bool {
@ -1705,7 +1705,7 @@ fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
AstNodeWrapper::new(fragment.make_method_receiver_expr(), MethodReceiverTag) AstNodeWrapper::new(fragment.make_method_receiver_expr(), MethodReceiverTag)
} }
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) { fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
walk_expr(&mut self.wrapped, visitor) walk_expr(visitor, &mut self.wrapped)
} }
fn is_mac_call(&self) -> bool { fn is_mac_call(&self) -> bool {
matches!(self.wrapped.kind, ast::ExprKind::MacCall(..)) matches!(self.wrapped.kind, ast::ExprKind::MacCall(..))
@ -2147,11 +2147,11 @@ fn flat_map_generic_param(
self.cx.current_expansion.is_trailing_mac = true; self.cx.current_expansion.is_trailing_mac = true;
// Don't use `assign_id` for this statement - it may get removed // Don't use `assign_id` for this statement - it may get removed
// entirely due to a `#[cfg]` on the contained expression // entirely due to a `#[cfg]` on the contained expression
let res = walk_flat_map_stmt(node, self); let res = walk_flat_map_stmt(self, node);
self.cx.current_expansion.is_trailing_mac = false; self.cx.current_expansion.is_trailing_mac = false;
res res
} }
_ => walk_flat_map_stmt(node, self), _ => walk_flat_map_stmt(self, node),
}; };
} }
@ -2195,7 +2195,7 @@ fn visit_block(&mut self, node: &mut P<ast::Block>) {
&mut self.cx.current_expansion.dir_ownership, &mut self.cx.current_expansion.dir_ownership,
DirOwnership::UnownedViaBlock, DirOwnership::UnownedViaBlock,
); );
walk_block(node, self); walk_block(self, node);
self.cx.current_expansion.dir_ownership = orig_dir_ownership; self.cx.current_expansion.dir_ownership = orig_dir_ownership;
} }

View File

@ -333,7 +333,7 @@ pub(super) fn transcribe<'a>(
// jump back out of the Delimited, pop the result_stack and add the new results back to // jump back out of the Delimited, pop the result_stack and add the new results back to
// the previous results (from outside the Delimited). // the previous results (from outside the Delimited).
mbe::TokenTree::Delimited(mut span, spacing, delimited) => { mbe::TokenTree::Delimited(mut span, spacing, delimited) => {
mut_visit::visit_delim_span(&mut span, &mut marker); mut_visit::visit_delim_span(&mut marker, &mut span);
stack.push(Frame::new_delimited(delimited, span, *spacing)); stack.push(Frame::new_delimited(delimited, span, *spacing));
result_stack.push(mem::take(&mut result)); result_stack.push(mem::take(&mut result));
} }
@ -342,7 +342,7 @@ pub(super) fn transcribe<'a>(
// preserve syntax context. // preserve syntax context.
mbe::TokenTree::Token(token) => { mbe::TokenTree::Token(token) => {
let mut token = token.clone(); let mut token = token.clone();
mut_visit::visit_token(&mut token, &mut marker); mut_visit::visit_token(&mut marker, &mut token);
let tt = TokenTree::Token(token, Spacing::Alone); let tt = TokenTree::Token(token, Spacing::Alone);
result.push(tt); result.push(tt);
} }

View File

@ -209,7 +209,7 @@ impl MutVisitor for PlaceholderExpander {
if arm.is_placeholder { if arm.is_placeholder {
self.remove(arm.id).make_arms() self.remove(arm.id).make_arms()
} else { } else {
walk_flat_map_arm(arm, self) walk_flat_map_arm(self, arm)
} }
} }
@ -217,7 +217,7 @@ impl MutVisitor for PlaceholderExpander {
if field.is_placeholder { if field.is_placeholder {
self.remove(field.id).make_expr_fields() self.remove(field.id).make_expr_fields()
} else { } else {
walk_flat_map_expr_field(field, self) walk_flat_map_expr_field(self, field)
} }
} }
@ -225,7 +225,7 @@ impl MutVisitor for PlaceholderExpander {
if fp.is_placeholder { if fp.is_placeholder {
self.remove(fp.id).make_pat_fields() self.remove(fp.id).make_pat_fields()
} else { } else {
walk_flat_map_pat_field(fp, self) walk_flat_map_pat_field(self, fp)
} }
} }
@ -236,7 +236,7 @@ fn flat_map_generic_param(
if param.is_placeholder { if param.is_placeholder {
self.remove(param.id).make_generic_params() self.remove(param.id).make_generic_params()
} else { } else {
walk_flat_map_generic_param(param, self) walk_flat_map_generic_param(self, param)
} }
} }
@ -244,7 +244,7 @@ fn flat_map_generic_param(
if p.is_placeholder { if p.is_placeholder {
self.remove(p.id).make_params() self.remove(p.id).make_params()
} else { } else {
walk_flat_map_param(p, self) walk_flat_map_param(self, p)
} }
} }
@ -252,7 +252,7 @@ fn flat_map_generic_param(
if sf.is_placeholder { if sf.is_placeholder {
self.remove(sf.id).make_field_defs() self.remove(sf.id).make_field_defs()
} else { } else {
walk_flat_map_field_def(sf, self) walk_flat_map_field_def(self, sf)
} }
} }
@ -260,14 +260,14 @@ fn flat_map_generic_param(
if variant.is_placeholder { if variant.is_placeholder {
self.remove(variant.id).make_variants() self.remove(variant.id).make_variants()
} else { } else {
walk_flat_map_variant(variant, self) walk_flat_map_variant(self, variant)
} }
} }
fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> { fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
match item.kind { match item.kind {
ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(), ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(),
_ => walk_flat_map_item(item, None, self), _ => walk_flat_map_item(self, item, None),
} }
} }
@ -284,7 +284,7 @@ fn flat_map_assoc_item(
AssocCtxt::Impl => it.make_impl_items(), AssocCtxt::Impl => it.make_impl_items(),
} }
} }
_ => walk_flat_map_item(item, Some(ctxt), self), _ => walk_flat_map_item(self, item, Some(ctxt)),
} }
} }
@ -294,35 +294,35 @@ fn flat_map_foreign_item(
) -> SmallVec<[P<ast::ForeignItem>; 1]> { ) -> SmallVec<[P<ast::ForeignItem>; 1]> {
match item.kind { match item.kind {
ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(), ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(),
_ => walk_flat_map_item(item, None, self), _ => walk_flat_map_item(self, item, None),
} }
} }
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) { fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
match expr.kind { match expr.kind {
ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr(), ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr(),
_ => walk_expr(expr, self), _ => walk_expr(self, expr),
} }
} }
fn visit_method_receiver_expr(&mut self, expr: &mut P<ast::Expr>) { fn visit_method_receiver_expr(&mut self, expr: &mut P<ast::Expr>) {
match expr.kind { match expr.kind {
ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_method_receiver_expr(), ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_method_receiver_expr(),
_ => walk_expr(expr, self), _ => walk_expr(self, expr),
} }
} }
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> { fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
match expr.kind { match expr.kind {
ast::ExprKind::MacCall(_) => self.remove(expr.id).make_opt_expr(), ast::ExprKind::MacCall(_) => self.remove(expr.id).make_opt_expr(),
_ => noop_filter_map_expr(expr, self), _ => noop_filter_map_expr(self, expr),
} }
} }
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
let (style, mut stmts) = match stmt.kind { let (style, mut stmts) = match stmt.kind {
ast::StmtKind::MacCall(mac) => (mac.style, self.remove(stmt.id).make_stmts()), ast::StmtKind::MacCall(mac) => (mac.style, self.remove(stmt.id).make_stmts()),
_ => return walk_flat_map_stmt(stmt, self), _ => return walk_flat_map_stmt(self, stmt),
}; };
if style == ast::MacStmtStyle::Semicolon { if style == ast::MacStmtStyle::Semicolon {
@ -368,14 +368,14 @@ fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
fn visit_pat(&mut self, pat: &mut P<ast::Pat>) { fn visit_pat(&mut self, pat: &mut P<ast::Pat>) {
match pat.kind { match pat.kind {
ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat(), ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat(),
_ => walk_pat(pat, self), _ => walk_pat(self, pat),
} }
} }
fn visit_ty(&mut self, ty: &mut P<ast::Ty>) { fn visit_ty(&mut self, ty: &mut P<ast::Ty>) {
match ty.kind { match ty.kind {
ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty(), ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty(),
_ => walk_ty(ty, self), _ => walk_ty(self, ty),
} }
} }
@ -383,7 +383,7 @@ fn visit_crate(&mut self, krate: &mut ast::Crate) {
if krate.is_placeholder { if krate.is_placeholder {
*krate = self.remove(krate.id).make_crate(); *krate = self.remove(krate.id).make_crate();
} else { } else {
walk_crate(krate, self) walk_crate(self, krate)
} }
} }
} }

View File

@ -3939,14 +3939,14 @@ fn visit_expr(&mut self, e: &mut P<Expr>) {
} }
} }
ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => { ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => {
mut_visit::walk_expr(e, self); mut_visit::walk_expr(self, e);
} }
ExprKind::Binary(Spanned { node: BinOpKind::Or, span: or_span }, _, _) ExprKind::Binary(Spanned { node: BinOpKind::Or, span: or_span }, _, _)
if let None | Some(NotSupportedOr(_)) = self.forbid_let_reason => if let None | Some(NotSupportedOr(_)) = self.forbid_let_reason =>
{ {
let forbid_let_reason = self.forbid_let_reason; let forbid_let_reason = self.forbid_let_reason;
self.forbid_let_reason = Some(NotSupportedOr(or_span)); self.forbid_let_reason = Some(NotSupportedOr(or_span));
mut_visit::walk_expr(e, self); mut_visit::walk_expr(self, e);
self.forbid_let_reason = forbid_let_reason; self.forbid_let_reason = forbid_let_reason;
} }
ExprKind::Paren(ref inner) ExprKind::Paren(ref inner)
@ -3954,7 +3954,7 @@ fn visit_expr(&mut self, e: &mut P<Expr>) {
{ {
let forbid_let_reason = self.forbid_let_reason; let forbid_let_reason = self.forbid_let_reason;
self.forbid_let_reason = Some(NotSupportedParentheses(inner.span)); self.forbid_let_reason = Some(NotSupportedParentheses(inner.span));
mut_visit::walk_expr(e, self); mut_visit::walk_expr(self, e);
self.forbid_let_reason = forbid_let_reason; self.forbid_let_reason = forbid_let_reason;
} }
ExprKind::Assign(ref lhs, _, span) => { ExprKind::Assign(ref lhs, _, span) => {
@ -3972,7 +3972,7 @@ fn visit_expr(&mut self, e: &mut P<Expr>) {
} }
let comparison = self.comparison; let comparison = self.comparison;
self.comparison = Some(errors::MaybeComparison { span: span.shrink_to_hi() }); self.comparison = Some(errors::MaybeComparison { span: span.shrink_to_hi() });
mut_visit::walk_expr(e, self); mut_visit::walk_expr(self, e);
self.forbid_let_reason = forbid_let_reason; self.forbid_let_reason = forbid_let_reason;
self.missing_let = missing_let; self.missing_let = missing_let;
self.comparison = comparison; self.comparison = comparison;
@ -3992,7 +3992,7 @@ fn visit_expr(&mut self, e: &mut P<Expr>) {
| ExprKind::Paren(_) => { | ExprKind::Paren(_) => {
let forbid_let_reason = self.forbid_let_reason; let forbid_let_reason = self.forbid_let_reason;
self.forbid_let_reason = Some(OtherForbidden); self.forbid_let_reason = Some(OtherForbidden);
mut_visit::walk_expr(e, self); mut_visit::walk_expr(self, e);
self.forbid_let_reason = forbid_let_reason; self.forbid_let_reason = forbid_let_reason;
} }
ExprKind::Cast(ref mut op, _) | ExprKind::Type(ref mut op, _) => { ExprKind::Cast(ref mut op, _) | ExprKind::Type(ref mut op, _) => {

View File

@ -810,7 +810,7 @@ fn visit_pat(&mut self, pat: &mut P<Pat>) {
self.0 = true; self.0 = true;
*m = Mutability::Mut; *m = Mutability::Mut;
} }
walk_pat(pat, self); walk_pat(self, pat);
} }
} }

View File

@ -121,7 +121,7 @@ fn remove_all_parens(pat: &mut P<Pat>) {
struct Visitor; struct Visitor;
impl MutVisitor for Visitor { impl MutVisitor for Visitor {
fn visit_pat(&mut self, pat: &mut P<Pat>) { fn visit_pat(&mut self, pat: &mut P<Pat>) {
walk_pat(pat, self); walk_pat(self, pat);
let inner = match &mut pat.kind { let inner = match &mut pat.kind {
Paren(i) => mem::replace(&mut i.kind, Wild), Paren(i) => mem::replace(&mut i.kind, Wild),
_ => return, _ => return,
@ -138,7 +138,7 @@ fn insert_necessary_parens(pat: &mut P<Pat>) {
impl MutVisitor for Visitor { impl MutVisitor for Visitor {
fn visit_pat(&mut self, pat: &mut P<Pat>) { fn visit_pat(&mut self, pat: &mut P<Pat>) {
use ast::BindingMode; use ast::BindingMode;
walk_pat(pat, self); walk_pat(self, pat);
let target = match &mut pat.kind { let target = match &mut pat.kind {
// `i @ a | b`, `box a | b`, and `& mut? a | b`. // `i @ a | b`, `box a | b`, and `& mut? a | b`.
Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p, Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p,
@ -160,7 +160,7 @@ struct Visitor {
impl MutVisitor for Visitor { impl MutVisitor for Visitor {
fn visit_pat(&mut self, p: &mut P<Pat>) { fn visit_pat(&mut self, p: &mut P<Pat>) {
// This is a bottom up transformation, so recurse first. // This is a bottom up transformation, so recurse first.
walk_pat(p, self); walk_pat(self, p);
// Don't have an or-pattern? Just quit early on. // Don't have an or-pattern? Just quit early on.
let Or(alternatives) = &mut p.kind else { return }; let Or(alternatives) = &mut p.kind else { return };
@ -189,7 +189,7 @@ fn visit_pat(&mut self, p: &mut P<Pat>) {
// Deal with `Some(Some(0)) | Some(Some(1))`. // Deal with `Some(Some(0)) | Some(Some(1))`.
if this_level_changed { if this_level_changed {
walk_pat(p, self); walk_pat(self, p);
} }
} }
} }

View File

@ -46,9 +46,11 @@
fn parse_expr(psess: &ParseSess, src: &str) -> Option<P<Expr>> { fn parse_expr(psess: &ParseSess, src: &str) -> Option<P<Expr>> {
let src_as_string = src.to_string(); let src_as_string = src.to_string();
let mut p = unwrap_or_emit_fatal( let mut p = unwrap_or_emit_fatal(new_parser_from_source_str(
new_parser_from_source_str(psess, FileName::Custom(src_as_string.clone()), src_as_string) psess,
); FileName::Custom(src_as_string.clone()),
src_as_string,
));
p.parse_expr().map_err(|e| e.cancel()).ok() p.parse_expr().map_err(|e| e.cancel()).ok()
} }
@ -181,10 +183,9 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
18 => { 18 => {
let pat = let pat =
P(Pat { id: DUMMY_NODE_ID, kind: PatKind::Wild, span: DUMMY_SP, tokens: None }); P(Pat { id: DUMMY_NODE_ID, kind: PatKind::Wild, span: DUMMY_SP, tokens: None });
iter_exprs( iter_exprs(depth - 1, &mut |e| {
depth - 1, g(ExprKind::Let(pat.clone(), e, DUMMY_SP, Recovered::No))
&mut |e| g(ExprKind::Let(pat.clone(), e, DUMMY_SP, Recovered::No)) })
)
} }
_ => panic!("bad counter value in iter_exprs"), _ => panic!("bad counter value in iter_exprs"),
} }
@ -202,7 +203,7 @@ fn visit_expr(&mut self, e: &mut P<Expr>) {
ExprKind::Paren(inner) => *e = inner, ExprKind::Paren(inner) => *e = inner,
_ => {} _ => {}
}; };
mut_visit::walk_expr(e, self); mut_visit::walk_expr(self, e);
} }
} }
@ -211,7 +212,7 @@ fn visit_expr(&mut self, e: &mut P<Expr>) {
impl MutVisitor for AddParens { impl MutVisitor for AddParens {
fn visit_expr(&mut self, e: &mut P<Expr>) { fn visit_expr(&mut self, e: &mut P<Expr>) {
mut_visit::walk_expr(e, self); mut_visit::walk_expr(self, e);
visit_clobber(e, |e| { visit_clobber(e, |e| {
P(Expr { P(Expr {
id: DUMMY_NODE_ID, id: DUMMY_NODE_ID,