Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove P<> from visit_s in ast MutVisitor #132112

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub trait MutVisitor: Sized {
walk_flat_map_item(self, i)
}

fn visit_fn_decl(&mut self, d: &mut P<FnDecl>) {
fn visit_fn_decl(&mut self, d: &mut FnDecl) {
walk_fn_decl(self, d);
}

Expand All @@ -136,7 +136,7 @@ pub trait MutVisitor: Sized {
walk_closure_binder(self, b);
}

fn visit_block(&mut self, b: &mut P<Block>) {
fn visit_block(&mut self, b: &mut Block) {
walk_block(self, b);
}

Expand All @@ -148,21 +148,21 @@ pub trait MutVisitor: Sized {
walk_flat_map_arm(self, arm)
}

fn visit_pat(&mut self, p: &mut P<Pat>) {
fn visit_pat(&mut self, p: &mut Pat) {
walk_pat(self, p);
}

fn visit_anon_const(&mut self, c: &mut AnonConst) {
walk_anon_const(self, c);
}

fn visit_expr(&mut self, e: &mut P<Expr>) {
fn visit_expr(&mut self, e: &mut Expr) {
walk_expr(self, e);
}

/// This method is a hack to workaround unstable of `stmt_expr_attributes`.
/// It can be removed once that feature is stabilized.
fn visit_method_receiver_expr(&mut self, ex: &mut P<Expr>) {
fn visit_method_receiver_expr(&mut self, ex: &mut Expr) {
self.visit_expr(ex)
}

Expand All @@ -174,7 +174,7 @@ pub trait MutVisitor: Sized {
walk_generic_arg(self, arg);
}

fn visit_ty(&mut self, t: &mut P<Ty>) {
fn visit_ty(&mut self, t: &mut Ty) {
walk_ty(self, t);
}

Expand Down Expand Up @@ -222,7 +222,7 @@ pub trait MutVisitor: Sized {
walk_parenthesized_parameter_data(self, p);
}

fn visit_local(&mut self, l: &mut P<Local>) {
fn visit_local(&mut self, l: &mut Local) {
walk_local(self, l);
}

Expand Down Expand Up @@ -476,8 +476,8 @@ fn walk_assoc_item_constraint<T: MutVisitor>(
vis.visit_span(span);
}

pub fn walk_ty<T: MutVisitor>(vis: &mut T, ty: &mut P<Ty>) {
let Ty { id, kind, span, tokens } = ty.deref_mut();
pub fn walk_ty<T: MutVisitor>(vis: &mut T, ty: &mut Ty) {
let Ty { id, kind, span, tokens } = ty;
vis.visit_id(id);
match kind {
TyKind::Err(_guar) => {}
Expand Down Expand Up @@ -605,8 +605,8 @@ fn walk_parenthesized_parameter_data<T: MutVisitor>(vis: &mut T, args: &mut Pare
vis.visit_span(inputs_span);
}

fn walk_local<T: MutVisitor>(vis: &mut T, local: &mut P<Local>) {
let Local { id, pat, ty, kind, span, colon_sp, attrs, tokens } = local.deref_mut();
fn walk_local<T: MutVisitor>(vis: &mut T, local: &mut Local) {
let Local { id, pat, ty, kind, span, colon_sp, attrs, tokens } = local;
vis.visit_id(id);
visit_attrs(vis, attrs);
vis.visit_pat(pat);
Expand Down Expand Up @@ -898,8 +898,8 @@ fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
}
}

fn walk_fn_decl<T: MutVisitor>(vis: &mut T, decl: &mut P<FnDecl>) {
let FnDecl { inputs, output } = decl.deref_mut();
fn walk_fn_decl<T: MutVisitor>(vis: &mut T, decl: &mut FnDecl) {
let FnDecl { inputs, output } = decl;
inputs.flat_map_in_place(|param| vis.flat_map_param(param));
walk_fn_ret_ty(vis, output);
}
Expand Down Expand Up @@ -1071,8 +1071,8 @@ fn walk_mt<T: MutVisitor>(vis: &mut T, MutTy { ty, mutbl: _ }: &mut MutTy) {
vis.visit_ty(ty);
}

pub fn walk_block<T: MutVisitor>(vis: &mut T, block: &mut P<Block>) {
let Block { id, stmts, rules: _, span, tokens, could_be_bare_literal: _ } = block.deref_mut();
pub fn walk_block<T: MutVisitor>(vis: &mut T, block: &mut Block) {
let Block { id, stmts, rules: _, span, tokens, could_be_bare_literal: _ } = block;
vis.visit_id(id);
stmts.flat_map_in_place(|stmt| vis.flat_map_stmt(stmt));
visit_lazy_tts(vis, tokens);
Expand Down Expand Up @@ -1333,8 +1333,8 @@ impl WalkItemKind for ForeignItemKind {
}
}

pub fn walk_pat<T: MutVisitor>(vis: &mut T, pat: &mut P<Pat>) {
let Pat { id, kind, span, tokens } = pat.deref_mut();
pub fn walk_pat<T: MutVisitor>(vis: &mut T, pat: &mut Pat) {
let Pat { id, kind, span, tokens } = pat;
vis.visit_id(id);
match kind {
PatKind::Err(_guar) => {}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/cfg_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ impl CfgEval<'_> {

impl MutVisitor for CfgEval<'_> {
#[instrument(level = "trace", skip(self))]
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
fn visit_expr(&mut self, expr: &mut ast::Expr) {
self.0.configure_expr(expr, false);
mut_visit::walk_expr(self, expr);
}

#[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 ast::Expr) {
self.0.configure_expr(expr, true);
mut_visit::walk_expr(self, expr);
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ast::HasAttrs;
use ast::ptr::P;
use rustc_ast::mut_visit::MutVisitor;
use rustc_ast::visit::BoundKind;
use rustc_ast::{
Expand Down Expand Up @@ -373,11 +372,11 @@ struct TypeSubstitution<'a> {
}

impl<'a> ast::mut_visit::MutVisitor for TypeSubstitution<'a> {
fn visit_ty(&mut self, ty: &mut P<ast::Ty>) {
fn visit_ty(&mut self, ty: &mut ast::Ty) {
if let Some(name) = ty.kind.is_simple_path()
&& name == self.from_name
{
**ty = self.to_ty.clone();
*ty = self.to_ty.clone();
self.rewritten = true;
} else {
ast::mut_visit::walk_ty(self, ty);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Conditional compilation stripping.

use rustc_ast::ptr::P;
use rustc_ast::token::{Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::{
AttrTokenStream, AttrTokenTree, LazyAttrTokenStream, Spacing, TokenTree,
Expand Down Expand Up @@ -428,7 +427,7 @@ impl<'a> StripUnconfigured<'a> {
}

#[instrument(level = "trace", skip(self))]
pub fn configure_expr(&self, expr: &mut P<ast::Expr>, method_receiver: bool) {
pub fn configure_expr(&self, expr: &mut ast::Expr, method_receiver: bool) {
if !method_receiver {
for attr in expr.attrs.iter() {
self.maybe_emit_expr_attr_err(attr);
Expand Down
45 changes: 21 additions & 24 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1586,14 +1586,14 @@ impl InvocationCollectorNode for ast::Crate {
}
}

impl InvocationCollectorNode for P<ast::Ty> {
type OutputTy = P<ast::Ty>;
impl InvocationCollectorNode for ast::Ty {
type OutputTy = ast::Ty;
const KIND: AstFragmentKind = AstFragmentKind::Ty;
fn to_annotatable(self) -> Annotatable {
unreachable!()
}
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_ty()
fragment.make_ty().into_inner()
}
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
walk_ty(visitor, self)
Expand All @@ -1602,22 +1602,21 @@ impl InvocationCollectorNode for P<ast::Ty> {
matches!(self.kind, ast::TyKind::MacCall(..))
}
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
match self.kind {
TyKind::MacCall(mac) => (mac, AttrVec::new(), AddSemicolon::No),
_ => unreachable!(),
}
}
}

impl InvocationCollectorNode for P<ast::Pat> {
type OutputTy = P<ast::Pat>;
impl InvocationCollectorNode for ast::Pat {
type OutputTy = ast::Pat;
const KIND: AstFragmentKind = AstFragmentKind::Pat;
fn to_annotatable(self) -> Annotatable {
unreachable!()
}
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_pat()
fragment.make_pat().into_inner()
}
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
walk_pat(visitor, self)
Expand All @@ -1626,23 +1625,22 @@ impl InvocationCollectorNode for P<ast::Pat> {
matches!(self.kind, PatKind::MacCall(..))
}
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
match self.kind {
PatKind::MacCall(mac) => (mac, AttrVec::new(), AddSemicolon::No),
_ => unreachable!(),
}
}
}

impl InvocationCollectorNode for P<ast::Expr> {
type OutputTy = P<ast::Expr>;
impl InvocationCollectorNode for ast::Expr {
type OutputTy = ast::Expr;
type AttrsTy = ast::AttrVec;
const KIND: AstFragmentKind = AstFragmentKind::Expr;
fn to_annotatable(self) -> Annotatable {
Annotatable::Expr(self)
Annotatable::Expr(P(self))
}
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_expr()
fragment.make_expr().into_inner()
}
fn descr() -> &'static str {
"an expression"
Expand All @@ -1654,9 +1652,8 @@ impl InvocationCollectorNode for P<ast::Expr> {
matches!(self.kind, ExprKind::MacCall(..))
}
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
match self.kind {
ExprKind::MacCall(mac) => (mac, self.attrs, AddSemicolon::No),
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -2170,35 +2167,35 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
self.visit_node(node)
}

fn visit_ty(&mut self, node: &mut P<ast::Ty>) {
fn visit_ty(&mut self, node: &mut ast::Ty) {
self.visit_node(node)
}

fn visit_pat(&mut self, node: &mut P<ast::Pat>) {
fn visit_pat(&mut self, node: &mut ast::Pat) {
self.visit_node(node)
}

fn visit_expr(&mut self, node: &mut P<ast::Expr>) {
fn visit_expr(&mut self, node: &mut ast::Expr) {
// FIXME: Feature gating is performed inconsistently between `Expr` and `OptExpr`.
if let Some(attr) = node.attrs.first() {
self.cfg().maybe_emit_expr_attr_err(attr);
}
self.visit_node(node)
}

fn visit_method_receiver_expr(&mut self, node: &mut P<ast::Expr>) {
fn visit_method_receiver_expr(&mut self, node: &mut ast::Expr) {
visit_clobber(node, |node| {
let mut wrapper = AstNodeWrapper::new(node, MethodReceiverTag);
let mut wrapper = AstNodeWrapper::new(P(node), MethodReceiverTag);
self.visit_node(&mut wrapper);
wrapper.wrapped
wrapper.wrapped.into_inner()
})
}

fn filter_map_expr(&mut self, node: P<ast::Expr>) -> Option<P<ast::Expr>> {
self.flat_map_node(AstNodeWrapper::new(node, OptExprTag))
}

fn visit_block(&mut self, node: &mut P<ast::Block>) {
fn visit_block(&mut self, node: &mut ast::Block) {
let orig_dir_ownership = mem::replace(
&mut self.cx.current_expansion.dir_ownership,
DirOwnership::UnownedViaBlock,
Expand Down
18 changes: 10 additions & 8 deletions compiler/rustc_expand/src/placeholders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,18 @@ impl MutVisitor for PlaceholderExpander {
}
}

fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
fn visit_expr(&mut self, expr: &mut ast::Expr) {
match expr.kind {
ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr(),
ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr().into_inner(),
_ => 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 ast::Expr) {
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().into_inner()
}
_ => walk_expr(self, expr),
}
}
Expand Down Expand Up @@ -367,16 +369,16 @@ impl MutVisitor for PlaceholderExpander {
stmts
}

fn visit_pat(&mut self, pat: &mut P<ast::Pat>) {
fn visit_pat(&mut self, pat: &mut ast::Pat) {
match pat.kind {
ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat(),
ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat().into_inner(),
_ => walk_pat(self, pat),
}
}

fn visit_ty(&mut self, ty: &mut P<ast::Ty>) {
fn visit_ty(&mut self, ty: &mut ast::Ty) {
match ty.kind {
ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty(),
ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty().into_inner(),
_ => walk_ty(self, ty),
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3927,7 +3927,7 @@ impl<'a> CondChecker<'a> {
}

impl MutVisitor for CondChecker<'_> {
fn visit_expr(&mut self, e: &mut P<Expr>) {
fn visit_expr(&mut self, e: &mut Expr) {
use ForbiddenLetReason::*;

let span = e.span;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ impl<'a> Parser<'a> {
fn make_all_value_bindings_mutable(pat: &mut P<Pat>) -> bool {
struct AddMut(bool);
impl MutVisitor for AddMut {
fn visit_pat(&mut self, pat: &mut P<Pat>) {
fn visit_pat(&mut self, pat: &mut Pat) {
if let PatKind::Ident(BindingMode(ByRef::No, m @ Mutability::Not), ..) =
&mut pat.kind
{
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) {
fn remove_all_parens(pat: &mut P<Pat>) {
struct Visitor;
impl MutVisitor for Visitor {
fn visit_pat(&mut self, pat: &mut P<Pat>) {
fn visit_pat(&mut self, pat: &mut Pat) {
walk_pat(self, pat);
let inner = match &mut pat.kind {
Paren(i) => mem::replace(&mut i.kind, Wild),
Expand All @@ -138,7 +138,7 @@ fn remove_all_parens(pat: &mut P<Pat>) {
fn insert_necessary_parens(pat: &mut P<Pat>) {
struct Visitor;
impl MutVisitor for Visitor {
fn visit_pat(&mut self, pat: &mut P<Pat>) {
fn visit_pat(&mut self, pat: &mut Pat) {
use ast::BindingMode;
walk_pat(self, pat);
let target = match &mut pat.kind {
Expand All @@ -160,7 +160,7 @@ fn unnest_or_patterns(pat: &mut P<Pat>) -> bool {
changed: bool,
}
impl MutVisitor for Visitor {
fn visit_pat(&mut self, p: &mut P<Pat>) {
fn visit_pat(&mut self, p: &mut Pat) {
// This is a bottom up transformation, so recurse first.
walk_pat(self, p);

Expand Down
Loading
Loading