@@ -31,18 +31,31 @@ use crate::utils::{format_mutability, mk_sp, mk_sp_lo_plus_one, rewrite_ident};
3131/// - `[small, ntp]`
3232/// - unary tuple constructor `([small, ntp])`
3333/// - `&[small]`
34- pub ( crate ) fn is_short_pattern ( pat : & ast:: Pat , pat_str : & str ) -> bool {
34+ pub ( crate ) fn is_short_pattern (
35+ context : & RewriteContext < ' _ > ,
36+ pat : & ast:: Pat ,
37+ pat_str : & str ,
38+ ) -> bool {
3539 // We also require that the pattern is reasonably 'small' with its literal width.
36- pat_str. len ( ) <= 20 && !pat_str. contains ( '\n' ) && is_short_pattern_inner ( pat)
40+ pat_str. len ( ) <= 20 && !pat_str. contains ( '\n' ) && is_short_pattern_inner ( context , pat)
3741}
3842
39- fn is_short_pattern_inner ( pat : & ast:: Pat ) -> bool {
40- match pat. kind {
41- ast:: PatKind :: Rest
42- | ast:: PatKind :: Never
43- | ast:: PatKind :: Wild
44- | ast:: PatKind :: Err ( _)
45- | ast:: PatKind :: Lit ( _) => true ,
43+ fn is_short_pattern_inner ( context : & RewriteContext < ' _ > , pat : & ast:: Pat ) -> bool {
44+ match & pat. kind {
45+ ast:: PatKind :: Rest | ast:: PatKind :: Never | ast:: PatKind :: Wild | ast:: PatKind :: Err ( _) => {
46+ true
47+ }
48+ ast:: PatKind :: Lit ( expr) => match & expr. kind {
49+ ast:: ExprKind :: Lit ( _) => true ,
50+ ast:: ExprKind :: Unary ( ast:: UnOp :: Neg , expr) => match & expr. kind {
51+ ast:: ExprKind :: Lit ( _) => true ,
52+ _ => unreachable ! ( ) ,
53+ } ,
54+ ast:: ExprKind :: ConstBlock ( _) | ast:: ExprKind :: Path ( ..) => {
55+ context. config . style_edition ( ) <= StyleEdition :: Edition2024
56+ }
57+ _ => unreachable ! ( ) ,
58+ } ,
4659 ast:: PatKind :: Ident ( _, _, ref pat) => pat. is_none ( ) ,
4760 ast:: PatKind :: Struct ( ..)
4861 | ast:: PatKind :: MacCall ( ..)
@@ -56,8 +69,8 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
5669 ast:: PatKind :: Box ( ref p)
5770 | PatKind :: Deref ( ref p)
5871 | ast:: PatKind :: Ref ( ref p, _)
59- | ast:: PatKind :: Paren ( ref p) => is_short_pattern_inner ( & * p) ,
60- PatKind :: Or ( ref pats) => pats. iter ( ) . all ( |p| is_short_pattern_inner ( p) ) ,
72+ | ast:: PatKind :: Paren ( ref p) => is_short_pattern_inner ( context , & * p) ,
73+ PatKind :: Or ( ref pats) => pats. iter ( ) . all ( |p| is_short_pattern_inner ( context , p) ) ,
6174 }
6275}
6376
@@ -95,7 +108,7 @@ impl Rewrite for Pat {
95108 let use_mixed_layout = pats
96109 . iter ( )
97110 . zip ( pat_strs. iter ( ) )
98- . all ( |( pat, pat_str) | is_short_pattern ( pat, pat_str) ) ;
111+ . all ( |( pat, pat_str) | is_short_pattern ( context , pat, pat_str) ) ;
99112 let items: Vec < _ > = pat_strs. into_iter ( ) . map ( ListItem :: from_str) . collect ( ) ;
100113 let tactic = if use_mixed_layout {
101114 DefinitiveListTactic :: Mixed
0 commit comments