@@ -13,4 +13,109 @@ fn main() {
1313
1414 if let XXXXXXXXX { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzz} = xxxxxxx ( )
1515 && let Foo = bar ( ) { todo ! ( ) }
16- }
16+ }
17+
18+ fn test_single_line_let_chain ( ) {
19+ // first item in let-chain is an ident
20+ if a && let Some ( b) = foo ( ) {
21+ }
22+
23+ // first item in let-chain is a unary ! with an ident
24+ let unary_not = if !from_hir_call
25+ && let Some ( p) = parent
26+ {
27+ } ;
28+
29+ // first item in let-chain is a unary * with an ident
30+ let unary_deref = if * some_deref
31+ && let Some ( p) = parent
32+ {
33+ } ;
34+
35+ // first item in let-chain is a unary - (neg) with an ident
36+ let unary_neg = if -some_ident
37+ && let Some ( p) = parent
38+ {
39+ } ;
40+
41+ // first item in let-chain is a try (?) with an ident
42+ let try_ = if some_try?
43+ && let Some ( p) = parent
44+ {
45+ } ;
46+
47+ // first item in let-chain is an ident wrapped in parens
48+ let in_parens = if ( some_ident)
49+ && let Some ( p) = parent
50+ {
51+ } ;
52+
53+ // first item in let-chain is a ref & with an ident
54+ let _ref = if & some_ref
55+ && let Some ( p) = parent
56+ {
57+ } ;
58+
59+ // first item in let-chain is a ref &mut with an ident
60+ let mut_ref = if & mut some_ref
61+ && let Some ( p) = parent
62+ {
63+ } ;
64+
65+ // chain unary ref and try
66+ let chain_of_unary_ref_and_try = if !& * some_ref?
67+ && let Some ( p) = parent {
68+ } ;
69+ }
70+
71+ fn test_multi_line_let_chain ( ) {
72+ // Can only single line the let-chain if the first item is an ident
73+ if let Some ( x) = y && a {
74+
75+ }
76+
77+ // More than one let-chain must be formatted on multiple lines
78+ if let Some ( x) = y && let Some ( a) = b {
79+
80+ }
81+
82+ // The ident isn't long enough so we don't wrap the first let-chain
83+ if a && let Some ( x) = y && let Some ( a) = b {
84+
85+ }
86+
87+ // The ident is long enough so both let-chains are wrapped
88+ if aaa && let Some ( x) = y && let Some ( a) = b {
89+
90+ }
91+
92+ // function call
93+ if a ( ) && let Some ( x) = y {
94+
95+ }
96+
97+ // bool literal
98+ if true && let Some ( x) = y {
99+
100+ }
101+
102+ // cast to a bool
103+ if 1 as bool && let Some ( x) = y {
104+
105+ }
106+
107+ // matches! macro call
108+ if matches ! ( a, some_type) && let Some ( x) = y {
109+
110+ }
111+
112+ // block expression returning bool
113+ if { true } && let Some ( x) = y {
114+
115+ }
116+
117+ // field access
118+ if a. x && let Some ( x) = y {
119+
120+ }
121+ }
0 commit comments