From 5f0dd44b3b1b142582d3dc8264cb2b8dd8f7c7f0 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 12 Jun 2025 00:02:12 +0800 Subject: avoid `&mut P` in `visit_expr` etc methods --- compiler/rustc_ast/src/ast.rs | 26 ++++++++++++++++++++++---- compiler/rustc_ast/src/mut_visit.rs | 6 +++--- 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'compiler/rustc_ast/src') diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index cf40c3f7f6f..760e43ef10f 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -693,6 +693,12 @@ impl Pat { } } +impl From> for Pat { + fn from(value: P) -> Self { + *value + } +} + /// A single field in a struct pattern. /// /// Patterns like the fields of `Foo { x, ref y, ref mut z }` @@ -1522,17 +1528,23 @@ impl Expr { ) } - /// Creates a dummy `P`. + /// Creates a dummy `Expr`. /// /// Should only be used when it will be replaced afterwards or as a return value when an error was encountered. - pub fn dummy() -> P { - P(Expr { + pub fn dummy() -> Expr { + Expr { id: DUMMY_NODE_ID, kind: ExprKind::Dummy, span: DUMMY_SP, attrs: ThinVec::new(), tokens: None, - }) + } + } +} + +impl From> for Expr { + fn from(value: P) -> Self { + *value } } @@ -2343,6 +2355,12 @@ impl Clone for Ty { } } +impl From> for Ty { + fn from(value: P) -> Self { + *value + } +} + impl Ty { pub fn peel_refs(&self) -> &Self { let mut final_ty = self; diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 71a47dcfcba..07fbe8045fc 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -168,7 +168,7 @@ pub trait MutVisitor: Sized + MutVisitorResult { walk_flat_map_arm(self, arm) } - fn visit_pat(&mut self, p: &mut P) { + fn visit_pat(&mut self, p: &mut Pat) { walk_pat(self, p); } @@ -176,7 +176,7 @@ pub trait MutVisitor: Sized + MutVisitorResult { walk_anon_const(self, c); } - fn visit_expr(&mut self, e: &mut P) { + fn visit_expr(&mut self, e: &mut Expr) { walk_expr(self, e); } @@ -194,7 +194,7 @@ pub trait MutVisitor: Sized + MutVisitorResult { walk_generic_arg(self, arg); } - fn visit_ty(&mut self, t: &mut P) { + fn visit_ty(&mut self, t: &mut Ty) { walk_ty(self, t); } -- cgit 1.4.1-3-g733a5