@@ -7,13 +7,14 @@ use clippy_utils::msrvs::{self, MsrvStack};
77use  clippy_utils:: over; 
88use  rustc_ast:: PatKind :: * ; 
99use  rustc_ast:: mut_visit:: * ; 
10- use  rustc_ast:: ptr:: P ; 
1110use  rustc_ast:: { self  as  ast,  DUMMY_NODE_ID ,  Mutability ,  Pat ,  PatKind } ; 
1211use  rustc_ast_pretty:: pprust; 
1312use  rustc_errors:: Applicability ; 
1413use  rustc_lint:: { EarlyContext ,  EarlyLintPass } ; 
1514use  rustc_session:: impl_lint_pass; 
1615use  rustc_span:: DUMMY_SP ; 
16+ // import needed to shadow `PatKind::Box` glob-imported above 
17+ use  std:: boxed:: Box ; 
1718use  std:: cell:: Cell ; 
1819use  std:: mem; 
1920use  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. 
305306fn  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. 
348349fn  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. 
404405fn  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(
438439fn  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) ) 
0 commit comments