diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index cf40c3f7f6f8e..760e43ef10fc9 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 71a47dcfcba2b..07fbe8045fc2f 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);
}
diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs
index da01e3e9607bb..fe44350863c9a 100644
--- a/compiler/rustc_builtin_macros/src/cfg_eval.rs
+++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs
@@ -155,7 +155,7 @@ impl CfgEval<'_> {
impl MutVisitor for CfgEval<'_> {
#[instrument(level = "trace", skip(self))]
- fn visit_expr(&mut self, expr: &mut P) {
+ fn visit_expr(&mut self, expr: &mut ast::Expr) {
self.0.configure_expr(expr, false);
mut_visit::walk_expr(self, expr);
}
diff --git a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs
index 0794192621a93..3a20b39798d7b 100644
--- a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs
@@ -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::{
@@ -378,11 +377,11 @@ struct TypeSubstitution<'a> {
}
impl<'a> ast::mut_visit::MutVisitor for TypeSubstitution<'a> {
- fn visit_ty(&mut self, ty: &mut P) {
+ 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);
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs
index 569165a64e520..301da8e604b8b 100644
--- a/compiler/rustc_expand/src/expand.rs
+++ b/compiler/rustc_expand/src/expand.rs
@@ -1668,7 +1668,7 @@ impl InvocationCollectorNode for ast::Crate {
}
}
-impl InvocationCollectorNode for P {
+impl InvocationCollectorNode for ast::Ty {
type OutputTy = P;
const KIND: AstFragmentKind = AstFragmentKind::Ty;
fn to_annotatable(self) -> Annotatable {
@@ -1691,7 +1691,7 @@ impl InvocationCollectorNode for P {
}
}
-impl InvocationCollectorNode for P {
+impl InvocationCollectorNode for ast::Pat {
type OutputTy = P;
const KIND: AstFragmentKind = AstFragmentKind::Pat;
fn to_annotatable(self) -> Annotatable {
@@ -1714,11 +1714,11 @@ impl InvocationCollectorNode for P {
}
}
-impl InvocationCollectorNode for P {
+impl InvocationCollectorNode for ast::Expr {
type OutputTy = P;
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()
@@ -1855,29 +1855,29 @@ impl DummyAstNode for ast::Crate {
}
}
-impl DummyAstNode for P {
+impl DummyAstNode for ast::Ty {
fn dummy() -> Self {
- P(ast::Ty {
+ ast::Ty {
id: DUMMY_NODE_ID,
kind: TyKind::Dummy,
span: Default::default(),
tokens: Default::default(),
- })
+ }
}
}
-impl DummyAstNode for P {
+impl DummyAstNode for ast::Pat {
fn dummy() -> Self {
- P(ast::Pat {
+ ast::Pat {
id: DUMMY_NODE_ID,
kind: PatKind::Wild,
span: Default::default(),
tokens: Default::default(),
- })
+ }
}
}
-impl DummyAstNode for P {
+impl DummyAstNode for ast::Expr {
fn dummy() -> Self {
ast::Expr::dummy()
}
@@ -1885,7 +1885,7 @@ impl DummyAstNode for P {
impl DummyAstNode for AstNodeWrapper, MethodReceiverTag> {
fn dummy() -> Self {
- AstNodeWrapper::new(ast::Expr::dummy(), MethodReceiverTag)
+ AstNodeWrapper::new(P(ast::Expr::dummy()), MethodReceiverTag)
}
}
@@ -2172,7 +2172,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
}
}
- fn visit_node + DummyAstNode>(
+ fn visit_node> + DummyAstNode>(
&mut self,
node: &mut Node,
) {
@@ -2197,6 +2197,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
*node = self
.collect_attr((attr, pos, derives), n.to_annotatable(), Node::KIND)
.make_ast::()
+ .into()
}
},
None if node.is_mac_call() => {
@@ -2204,7 +2205,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
let (mac, attrs, _) = n.take_mac_call();
self.check_attributes(&attrs, &mac);
- *node = self.collect_bang(mac, Node::KIND).make_ast::()
+ *node = self.collect_bang(mac, Node::KIND).make_ast::().into()
}
None if node.delegation().is_some() => unreachable!(),
None => {
@@ -2314,15 +2315,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
self.visit_node(node)
}
- fn visit_ty(&mut self, node: &mut P) {
+ fn visit_ty(&mut self, node: &mut ast::Ty) {
self.visit_node(node)
}
- fn visit_pat(&mut self, node: &mut P) {
+ fn visit_pat(&mut self, node: &mut ast::Pat) {
self.visit_node(node)
}
- fn visit_expr(&mut self, node: &mut P) {
+ 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);
diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs
index 3dcb20c8c7682..2c486a02bdf18 100644
--- a/compiler/rustc_expand/src/placeholders.rs
+++ b/compiler/rustc_expand/src/placeholders.rs
@@ -332,9 +332,9 @@ impl MutVisitor for PlaceholderExpander {
}
}
- fn visit_expr(&mut self, expr: &mut P) {
+ 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(),
_ => walk_expr(self, expr),
}
}
@@ -399,16 +399,16 @@ impl MutVisitor for PlaceholderExpander {
stmts
}
- fn visit_pat(&mut self, pat: &mut P) {
+ 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(),
_ => walk_pat(self, pat),
}
}
- fn visit_ty(&mut self, ty: &mut P) {
+ 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(),
_ => walk_ty(self, ty),
}
}
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 93489aa8ee948..93c76c47f060b 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -4087,7 +4087,7 @@ impl<'a> CondChecker<'a> {
}
impl MutVisitor for CondChecker<'_> {
- fn visit_expr(&mut self, e: &mut P) {
+ fn visit_expr(&mut self, e: &mut Expr) {
self.depth += 1;
use ForbiddenLetReason::*;
diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs
index 7a226136e2353..64653ee2a04c9 100644
--- a/compiler/rustc_parse/src/parser/pat.rs
+++ b/compiler/rustc_parse/src/parser/pat.rs
@@ -1094,7 +1094,7 @@ impl<'a> Parser<'a> {
fn make_all_value_bindings_mutable(pat: &mut P) -> bool {
struct AddMut(bool);
impl MutVisitor for AddMut {
- fn visit_pat(&mut self, pat: &mut P) {
+ fn visit_pat(&mut self, pat: &mut Pat) {
if let PatKind::Ident(BindingMode(ByRef::No, m @ Mutability::Not), ..) =
&mut pat.kind
{
diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs
index b839b6f56728c..bd8420917f5e6 100644
--- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs
+++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs
@@ -128,7 +128,7 @@ fn remove_all_parens(pat: &mut P) {
}
impl MutVisitor for Visitor {
- fn visit_pat(&mut self, pat: &mut P) {
+ fn visit_pat(&mut self, pat: &mut Pat) {
let is_inner = mem::replace(&mut self.is_inner, true);
walk_pat(self, pat);
let inner = match &mut pat.kind {
@@ -145,7 +145,7 @@ fn remove_all_parens(pat: &mut P) {
fn insert_necessary_parens(pat: &mut P) {
struct Visitor;
impl MutVisitor for Visitor {
- fn visit_pat(&mut self, pat: &mut P) {
+ fn visit_pat(&mut self, pat: &mut Pat) {
use ast::BindingMode;
walk_pat(self, pat);
let target = match &mut pat.kind {
@@ -167,7 +167,7 @@ fn unnest_or_patterns(pat: &mut P) -> bool {
changed: bool,
}
impl MutVisitor for Visitor {
- fn visit_pat(&mut self, p: &mut P) {
+ fn visit_pat(&mut self, p: &mut Pat) {
// This is a bottom up transformation, so recurse first.
walk_pat(self, p);
diff --git a/tests/ui-fulldeps/pprust-expr-roundtrip.rs b/tests/ui-fulldeps/pprust-expr-roundtrip.rs
index f5cfa9e0bccff..8bca20852add4 100644
--- a/tests/ui-fulldeps/pprust-expr-roundtrip.rs
+++ b/tests/ui-fulldeps/pprust-expr-roundtrip.rs
@@ -187,9 +187,9 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P)) {
struct RemoveParens;
impl MutVisitor for RemoveParens {
- fn visit_expr(&mut self, e: &mut P) {
+ fn visit_expr(&mut self, e: &mut Expr) {
match e.kind.clone() {
- ExprKind::Paren(inner) => *e = inner,
+ ExprKind::Paren(inner) => *e = *inner,
_ => {}
};
mut_visit::walk_expr(self, e);
@@ -200,11 +200,11 @@ impl MutVisitor for RemoveParens {
struct AddParens;
impl MutVisitor for AddParens {
- fn visit_expr(&mut self, e: &mut P) {
+ fn visit_expr(&mut self, e: &mut Expr) {
mut_visit::walk_expr(self, e);
let expr = std::mem::replace(e, Expr::dummy());
- e.kind = ExprKind::Paren(expr);
+ e.kind = ExprKind::Paren(P(expr));
}
}
diff --git a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
index c566ac459e0d2..2047f8dc76546 100644
--- a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
+++ b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
@@ -43,7 +43,6 @@ use std::process::ExitCode;
use parser::parse_expr;
use rustc_ast::ast::{Expr, ExprKind};
use rustc_ast::mut_visit::{self, MutVisitor};
-use rustc_ast::ptr::P;
use rustc_ast_pretty::pprust;
use rustc_session::parse::ParseSess;
@@ -152,7 +151,7 @@ static EXPRS: &[&str] = &[
struct Unparenthesize;
impl MutVisitor for Unparenthesize {
- fn visit_expr(&mut self, e: &mut P) {
+ fn visit_expr(&mut self, e: &mut Expr) {
while let ExprKind::Paren(paren) = &mut e.kind {
*e = mem::replace(paren, Expr::dummy());
}