Skip to content

Commit 0a70523

Browse files
committed
remove P
1 parent eb15cf0 commit 0a70523

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

clippy_lints/src/single_component_path_imports.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg};
22
use rustc_ast::node_id::{NodeId, NodeMap};
3-
use rustc_ast::ptr::P;
43
use rustc_ast::visit::{Visitor, walk_expr};
54
use rustc_ast::{Crate, Expr, ExprKind, Item, ItemKind, MacroDef, ModKind, Ty, TyKind, UseTreeKind};
65
use rustc_errors::Applicability;
@@ -124,7 +123,7 @@ impl Visitor<'_> for ImportUsageVisitor {
124123
}
125124

126125
impl SingleComponentPathImports {
127-
fn check_mod(&mut self, items: &[P<Item>]) {
126+
fn check_mod(&mut self, items: &[Box<Item>]) {
128127
// keep track of imports reused with `self` keyword, such as `self::crypto_hash` in the example
129128
// below. Removing the `use crypto_hash;` would make this a compile error
130129
// ```

clippy_lints/src/unnested_or_patterns.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ use clippy_utils::msrvs::{self, MsrvStack};
77
use clippy_utils::over;
88
use rustc_ast::PatKind::*;
99
use rustc_ast::mut_visit::*;
10-
use rustc_ast::ptr::P;
1110
use rustc_ast::{self as ast, DUMMY_NODE_ID, Mutability, Pat, PatKind};
1211
use rustc_ast_pretty::pprust;
1312
use rustc_errors::Applicability;
1413
use rustc_lint::{EarlyContext, EarlyLintPass};
1514
use rustc_session::impl_lint_pass;
1615
use rustc_span::DUMMY_SP;
16+
// import needed to shadow `PatKind::Box` glob-imported above
17+
use std::boxed::Box;
1718
use std::cell::Cell;
1819
use std::mem;
1920
use thin_vec::{ThinVec, thin_vec};
@@ -97,7 +98,7 @@ fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) {
9798
return;
9899
}
99100

100-
let mut pat = P(pat.clone());
101+
let mut pat = Box::new(pat.clone());
101102

102103
// Nix all the paren patterns everywhere so that they aren't in our way.
103104
remove_all_parens(&mut pat);
@@ -119,7 +120,7 @@ fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) {
119120
}
120121

121122
/// Remove all `(p)` patterns in `pat`.
122-
fn remove_all_parens(pat: &mut P<Pat>) {
123+
fn remove_all_parens(pat: &mut Box<Pat>) {
123124
#[derive(Default)]
124125
struct Visitor {
125126
/// If is not in the outer most pattern. This is needed to avoid removing the outermost
@@ -142,7 +143,7 @@ fn remove_all_parens(pat: &mut P<Pat>) {
142143
}
143144

144145
/// Insert parens where necessary according to Rust's precedence rules for patterns.
145-
fn insert_necessary_parens(pat: &mut P<Pat>) {
146+
fn insert_necessary_parens(pat: &mut Box<Pat>) {
146147
struct Visitor;
147148
impl MutVisitor for Visitor {
148149
fn visit_pat(&mut self, pat: &mut Pat) {
@@ -154,15 +155,15 @@ fn insert_necessary_parens(pat: &mut P<Pat>) {
154155
Ref(p, Mutability::Not) if matches!(p.kind, Ident(BindingMode::MUT, ..)) => p, // `&(mut x)`
155156
_ => return,
156157
};
157-
target.kind = Paren(P(take_pat(target)));
158+
target.kind = Paren(Box::new(take_pat(target)));
158159
}
159160
}
160161
Visitor.visit_pat(pat);
161162
}
162163

163164
/// Unnest or-patterns `p0 | ... | p1` in the pattern `pat`.
164165
/// For example, this would transform `Some(0) | FOO | Some(2)` into `Some(0 | 2) | FOO`.
165-
fn unnest_or_patterns(pat: &mut P<Pat>) -> bool {
166+
fn unnest_or_patterns(pat: &mut Box<Pat>) -> bool {
166167
struct Visitor {
167168
changed: bool,
168169
}
@@ -222,7 +223,7 @@ macro_rules! always_pat {
222223
/// Focus on `focus_idx` in `alternatives`,
223224
/// attempting to extend it with elements of the same constructor `C`
224225
/// in `alternatives[focus_idx + 1..]`.
225-
fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: usize) -> bool {
226+
fn transform_with_focus_on_idx(alternatives: &mut ThinVec<Box<Pat>>, focus_idx: usize) -> bool {
226227
// Extract the kind; we'll need to make some changes in it.
227228
let mut focus_kind = mem::replace(&mut alternatives[focus_idx].kind, Wild);
228229
// We'll focus on `alternatives[focus_idx]`,
@@ -303,12 +304,12 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: us
303304
/// So when we fixate on some `ident_k: pat_k`, we try to find `ident_k` in the other pattern
304305
/// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal.
305306
fn extend_with_struct_pat(
306-
qself1: Option<&P<ast::QSelf>>,
307+
qself1: Option<&Box<ast::QSelf>>,
307308
path1: &ast::Path,
308309
fps1: &mut [ast::PatField],
309310
rest1: ast::PatFieldsRest,
310311
start: usize,
311-
alternatives: &mut ThinVec<P<Pat>>,
312+
alternatives: &mut ThinVec<Box<Pat>>,
312313
) -> bool {
313314
(0..fps1.len()).any(|idx| {
314315
let pos_in_2 = Cell::new(None); // The element `k`.
@@ -346,11 +347,11 @@ fn extend_with_struct_pat(
346347
/// while also requiring `ps1[..n] ~ ps2[..n]` (pre) and `ps1[n + 1..] ~ ps2[n + 1..]` (post),
347348
/// where `~` denotes semantic equality.
348349
fn extend_with_matching_product(
349-
targets: &mut [P<Pat>],
350+
targets: &mut [Box<Pat>],
350351
start: usize,
351-
alternatives: &mut ThinVec<P<Pat>>,
352-
predicate: impl Fn(&PatKind, &[P<Pat>], usize) -> bool,
353-
extract: impl Fn(PatKind) -> ThinVec<P<Pat>>,
352+
alternatives: &mut ThinVec<Box<Pat>>,
353+
predicate: impl Fn(&PatKind, &[Box<Pat>], usize) -> bool,
354+
extract: impl Fn(PatKind) -> ThinVec<Box<Pat>>,
354355
) -> bool {
355356
(0..targets.len()).any(|idx| {
356357
let tail_or = drain_matching(
@@ -377,14 +378,14 @@ fn take_pat(from: &mut Pat) -> Pat {
377378

378379
/// Extend `target` as an or-pattern with the alternatives
379380
/// in `tail_or` if there are any and return if there were.
380-
fn extend_with_tail_or(target: &mut Pat, tail_or: ThinVec<P<Pat>>) -> bool {
381-
fn extend(target: &mut Pat, mut tail_or: ThinVec<P<Pat>>) {
381+
fn extend_with_tail_or(target: &mut Pat, tail_or: ThinVec<Box<Pat>>) -> bool {
382+
fn extend(target: &mut Pat, mut tail_or: ThinVec<Box<Pat>>) {
382383
match target {
383384
// On an existing or-pattern in the target, append to it.
384385
Pat { kind: Or(ps), .. } => ps.append(&mut tail_or),
385386
// Otherwise convert the target to an or-pattern.
386387
target => {
387-
let mut init_or = thin_vec![P(take_pat(target))];
388+
let mut init_or = thin_vec![Box::new(take_pat(target))];
388389
init_or.append(&mut tail_or);
389390
target.kind = Or(init_or);
390391
},
@@ -403,10 +404,10 @@ fn extend_with_tail_or(target: &mut Pat, tail_or: ThinVec<P<Pat>>) -> bool {
403404
// Only elements beginning with `start` are considered for extraction.
404405
fn drain_matching(
405406
start: usize,
406-
alternatives: &mut ThinVec<P<Pat>>,
407+
alternatives: &mut ThinVec<Box<Pat>>,
407408
predicate: impl Fn(&PatKind) -> bool,
408-
extract: impl Fn(PatKind) -> P<Pat>,
409-
) -> ThinVec<P<Pat>> {
409+
extract: impl Fn(PatKind) -> Box<Pat>,
410+
) -> ThinVec<Box<Pat>> {
410411
let mut tail_or = ThinVec::new();
411412
let mut idx = 0;
412413

@@ -438,15 +439,15 @@ fn drain_matching(
438439
fn extend_with_matching(
439440
target: &mut Pat,
440441
start: usize,
441-
alternatives: &mut ThinVec<P<Pat>>,
442+
alternatives: &mut ThinVec<Box<Pat>>,
442443
predicate: impl Fn(&PatKind) -> bool,
443-
extract: impl Fn(PatKind) -> P<Pat>,
444+
extract: impl Fn(PatKind) -> Box<Pat>,
444445
) -> bool {
445446
extend_with_tail_or(target, drain_matching(start, alternatives, predicate, extract))
446447
}
447448

448449
/// Are the patterns in `ps1` and `ps2` equal save for `ps1[idx]` compared to `ps2[idx]`?
449-
fn eq_pre_post(ps1: &[P<Pat>], ps2: &[P<Pat>], idx: usize) -> bool {
450+
fn eq_pre_post(ps1: &[Box<Pat>], ps2: &[Box<Pat>], idx: usize) -> bool {
450451
ps1.len() == ps2.len()
451452
&& ps1[idx].is_rest() == ps2[idx].is_rest() // Avoid `[x, ..] | [x, 0]` => `[x, .. | 0]`.
452453
&& over(&ps1[..idx], &ps2[..idx], |l, r| eq_pat(l, r))

clippy_utils/src/ast_utils/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
66

77
use crate::{both, over};
8-
use rustc_ast::ptr::P;
98
use rustc_ast::{self as ast, *};
109
use rustc_span::symbol::Ident;
1110
use std::mem;
@@ -83,11 +82,11 @@ pub fn eq_field_pat(l: &PatField, r: &PatField) -> bool {
8382
&& over(&l.attrs, &r.attrs, eq_attr)
8483
}
8584

86-
pub fn eq_qself(l: &P<QSelf>, r: &P<QSelf>) -> bool {
85+
pub fn eq_qself(l: &Box<QSelf>, r: &Box<QSelf>) -> bool {
8786
l.position == r.position && eq_ty(&l.ty, &r.ty)
8887
}
8988

90-
pub fn eq_maybe_qself(l: Option<&P<QSelf>>, r: Option<&P<QSelf>>) -> bool {
89+
pub fn eq_maybe_qself(l: Option<&Box<QSelf>>, r: Option<&Box<QSelf>>) -> bool {
9190
match (l, r) {
9291
(Some(l), Some(r)) => eq_qself(l, r),
9392
(None, None) => true,
@@ -130,7 +129,7 @@ pub fn eq_generic_arg(l: &GenericArg, r: &GenericArg) -> bool {
130129
}
131130
}
132131

133-
pub fn eq_expr_opt(l: Option<&P<Expr>>, r: Option<&P<Expr>>) -> bool {
132+
pub fn eq_expr_opt(l: Option<&Box<Expr>>, r: Option<&Box<Expr>>) -> bool {
134133
both(l, r, |l, r| eq_expr(l, r))
135134
}
136135

@@ -727,7 +726,7 @@ pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool {
727726
}
728727

729728
#[expect(clippy::ref_option, reason = "This is the type how it is stored in the AST")]
730-
pub fn eq_opt_fn_contract(l: &Option<P<FnContract>>, r: &Option<P<FnContract>>) -> bool {
729+
pub fn eq_opt_fn_contract(l: &Option<Box<FnContract>>, r: &Option<Box<FnContract>>) -> bool {
731730
match (l, r) {
732731
(Some(l), Some(r)) => {
733732
eq_expr_opt(l.requires.as_ref(), r.requires.as_ref()) && eq_expr_opt(l.ensures.as_ref(), r.ensures.as_ref())

0 commit comments

Comments
 (0)