mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-29 03:37:26 +03:00
Rollup merge of #142371 - fee1-dead-contrib:push-xqlkumzurkus, r=petrochenkov
avoid `&mut P<T>` in `visit_expr` etc methods trying a different way than rust-lang/rust#141636 r? ghost
This commit is contained in:
@@ -710,6 +710,12 @@ pub fn descr(&self) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<P<Pat>> for Pat {
|
||||
fn from(value: P<Pat>) -> Self {
|
||||
*value
|
||||
}
|
||||
}
|
||||
|
||||
/// A single field in a struct pattern.
|
||||
///
|
||||
/// Patterns like the fields of `Foo { x, ref y, ref mut z }`
|
||||
@@ -1553,17 +1559,23 @@ pub fn is_approximately_pattern(&self) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a dummy `P<Expr>`.
|
||||
/// 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<Expr> {
|
||||
P(Expr {
|
||||
pub fn dummy() -> Expr {
|
||||
Expr {
|
||||
id: DUMMY_NODE_ID,
|
||||
kind: ExprKind::Dummy,
|
||||
span: DUMMY_SP,
|
||||
attrs: ThinVec::new(),
|
||||
tokens: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<P<Expr>> for Expr {
|
||||
fn from(value: P<Expr>) -> Self {
|
||||
*value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2374,6 +2386,12 @@ fn clone(&self) -> Self {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<P<Ty>> for Ty {
|
||||
fn from(value: P<Ty>) -> Self {
|
||||
*value
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty {
|
||||
pub fn peel_refs(&self) -> &Self {
|
||||
let mut final_ty = self;
|
||||
|
||||
@@ -168,7 +168,7 @@ fn visit_arm(&mut self, arm: &mut Arm) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ 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);
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ fn visit_generic_arg(&mut self, arg: &mut GenericArg) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ fn configure_annotatable(mut self, annotatable: Annotatable) -> Annotatable {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<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);
|
||||
|
||||
@@ -1768,7 +1768,7 @@ fn expand_cfg_false(
|
||||
}
|
||||
}
|
||||
|
||||
impl InvocationCollectorNode for P<ast::Ty> {
|
||||
impl InvocationCollectorNode for ast::Ty {
|
||||
type OutputTy = P<ast::Ty>;
|
||||
const KIND: AstFragmentKind = AstFragmentKind::Ty;
|
||||
fn to_annotatable(self) -> Annotatable {
|
||||
@@ -1791,7 +1791,7 @@ fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) {
|
||||
}
|
||||
}
|
||||
|
||||
impl InvocationCollectorNode for P<ast::Pat> {
|
||||
impl InvocationCollectorNode for ast::Pat {
|
||||
type OutputTy = P<ast::Pat>;
|
||||
const KIND: AstFragmentKind = AstFragmentKind::Pat;
|
||||
fn to_annotatable(self) -> Annotatable {
|
||||
@@ -1814,11 +1814,11 @@ fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) {
|
||||
}
|
||||
}
|
||||
|
||||
impl InvocationCollectorNode for P<ast::Expr> {
|
||||
impl InvocationCollectorNode for ast::Expr {
|
||||
type OutputTy = P<ast::Expr>;
|
||||
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()
|
||||
@@ -1955,29 +1955,29 @@ fn dummy() -> Self {
|
||||
}
|
||||
}
|
||||
|
||||
impl DummyAstNode for P<ast::Ty> {
|
||||
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<ast::Pat> {
|
||||
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<ast::Expr> {
|
||||
impl DummyAstNode for ast::Expr {
|
||||
fn dummy() -> Self {
|
||||
ast::Expr::dummy()
|
||||
}
|
||||
@@ -1985,7 +1985,7 @@ fn dummy() -> Self {
|
||||
|
||||
impl DummyAstNode for AstNodeWrapper<P<ast::Expr>, MethodReceiverTag> {
|
||||
fn dummy() -> Self {
|
||||
AstNodeWrapper::new(ast::Expr::dummy(), MethodReceiverTag)
|
||||
AstNodeWrapper::new(P(ast::Expr::dummy()), MethodReceiverTag)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2272,7 +2272,7 @@ fn flat_map_node<Node: InvocationCollectorNode<OutputTy: Default>>(
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_node<Node: InvocationCollectorNode<OutputTy = Node> + DummyAstNode>(
|
||||
fn visit_node<Node: InvocationCollectorNode<OutputTy: Into<Node>> + DummyAstNode>(
|
||||
&mut self,
|
||||
node: &mut Node,
|
||||
) {
|
||||
@@ -2297,6 +2297,7 @@ fn visit_node<Node: InvocationCollectorNode<OutputTy = Node> + DummyAstNode>(
|
||||
*node = self
|
||||
.collect_attr((attr, pos, derives), n.to_annotatable(), Node::KIND)
|
||||
.make_ast::<Node>()
|
||||
.into()
|
||||
}
|
||||
},
|
||||
None if node.is_mac_call() => {
|
||||
@@ -2304,7 +2305,7 @@ fn visit_node<Node: InvocationCollectorNode<OutputTy = Node> + DummyAstNode>(
|
||||
let (mac, attrs, _) = n.take_mac_call();
|
||||
self.check_attributes(&attrs, &mac);
|
||||
|
||||
*node = self.collect_bang(mac, Node::KIND).make_ast::<Node>()
|
||||
*node = self.collect_bang(mac, Node::KIND).make_ast::<Node>().into()
|
||||
}
|
||||
None if node.delegation().is_some() => unreachable!(),
|
||||
None => {
|
||||
@@ -2414,15 +2415,15 @@ fn visit_crate(&mut self, node: &mut ast::Crate) {
|
||||
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);
|
||||
|
||||
@@ -332,9 +332,9 @@ fn flat_map_foreign_item(
|
||||
}
|
||||
}
|
||||
|
||||
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(),
|
||||
_ => walk_expr(self, expr),
|
||||
}
|
||||
}
|
||||
@@ -399,16 +399,16 @@ fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
|
||||
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(),
|
||||
_ => 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(),
|
||||
_ => walk_ty(self, ty),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4087,7 +4087,7 @@ fn new(parser: &'a Parser<'a>, let_chains_policy: LetChainsPolicy) -> Self {
|
||||
}
|
||||
|
||||
impl MutVisitor for CondChecker<'_> {
|
||||
fn visit_expr(&mut self, e: &mut P<Expr>) {
|
||||
fn visit_expr(&mut self, e: &mut Expr) {
|
||||
self.depth += 1;
|
||||
use ForbiddenLetReason::*;
|
||||
|
||||
|
||||
@@ -1094,7 +1094,7 @@ fn parse_pat_ident_mut(&mut self) -> PResult<'a, PatKind> {
|
||||
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
|
||||
{
|
||||
|
||||
@@ -128,7 +128,7 @@ struct Visitor {
|
||||
}
|
||||
|
||||
impl MutVisitor for Visitor {
|
||||
fn visit_pat(&mut self, pat: &mut P<Pat>) {
|
||||
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 visit_pat(&mut self, 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 {
|
||||
@@ -167,7 +167,7 @@ struct Visitor {
|
||||
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);
|
||||
|
||||
|
||||
@@ -187,9 +187,9 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
|
||||
struct RemoveParens;
|
||||
|
||||
impl MutVisitor for RemoveParens {
|
||||
fn visit_expr(&mut self, e: &mut P<Expr>) {
|
||||
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 @@ fn visit_expr(&mut self, e: &mut P<Expr>) {
|
||||
struct AddParens;
|
||||
|
||||
impl MutVisitor for AddParens {
|
||||
fn visit_expr(&mut self, e: &mut P<Expr>) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
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;
|
||||
|
||||
@@ -157,7 +156,7 @@
|
||||
struct Unparenthesize;
|
||||
|
||||
impl MutVisitor for Unparenthesize {
|
||||
fn visit_expr(&mut self, e: &mut P<Expr>) {
|
||||
fn visit_expr(&mut self, e: &mut Expr) {
|
||||
while let ExprKind::Paren(paren) = &mut e.kind {
|
||||
*e = mem::replace(paren, Expr::dummy());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user