@@ -55,6 +55,19 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
5555 }
5656}
5757
58+ struct RangeOperand < ' a > ( & ' a Option < ptr:: P < ast:: Expr > > ) ;
59+
60+ impl < ' a > Rewrite for RangeOperand < ' a > {
61+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
62+ match & self . 0 {
63+ None => Some ( "" . to_owned ( ) ) ,
64+ Some ( ref exp) => {
65+ exp. rewrite ( context, shape)
66+ }
67+ }
68+ }
69+ }
70+
5871impl Rewrite for Pat {
5972 fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
6073 match self . kind {
@@ -180,16 +193,6 @@ impl Rewrite for Pat {
180193 }
181194 }
182195 PatKind :: Range ( ref lhs, ref rhs, ref end_kind) => {
183- impl Rewrite for Option < ptr:: P < ast:: Expr > > {
184- fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
185- match & self {
186- None => Some ( "" . to_owned ( ) ) ,
187- Some ( ref exp) => {
188- exp. rewrite ( context, shape)
189- }
190- }
191- }
192- }
193196 let infix = match end_kind. node {
194197 RangeEnd :: Included ( RangeSyntax :: DotDotDot ) => "..." ,
195198 RangeEnd :: Included ( RangeSyntax :: DotDotEq ) => "..=" ,
@@ -209,8 +212,8 @@ impl Rewrite for Pat {
209212 infix. to_owned ( )
210213 } ;
211214 rewrite_pair (
212- lhs,
213- rhs,
215+ & RangeOperand ( lhs) ,
216+ & RangeOperand ( rhs) ,
214217 PairParts :: infix ( & infix) ,
215218 context,
216219 shape,
0 commit comments