@@ -84,7 +84,11 @@ use crate::utils::{
84
84
trimmed_last_line_width, wrap_str,
85
85
} ;
86
86
87
- pub fn rewrite_chain ( expr : & ast:: Expr , context : & RewriteContext , shape : Shape ) -> Option < String > {
87
+ pub fn rewrite_chain (
88
+ expr : & ast:: Expr ,
89
+ context : & RewriteContext < ' _ > ,
90
+ shape : Shape ,
91
+ ) -> Option < String > {
88
92
let chain = Chain :: from_ast ( expr, context) ;
89
93
debug ! ( "rewrite_chain {:?} {:?}" , chain, shape) ;
90
94
@@ -128,7 +132,7 @@ enum ChainItemKind {
128
132
}
129
133
130
134
impl ChainItemKind {
131
- fn is_block_like ( & self , context : & RewriteContext , reps : & str ) -> bool {
135
+ fn is_block_like ( & self , context : & RewriteContext < ' _ > , reps : & str ) -> bool {
132
136
match self {
133
137
ChainItemKind :: Parent ( ref expr) => utils:: is_block_expr ( context, expr, reps) ,
134
138
ChainItemKind :: MethodCall ( ..)
@@ -147,7 +151,7 @@ impl ChainItemKind {
147
151
}
148
152
}
149
153
150
- fn from_ast ( context : & RewriteContext , expr : & ast:: Expr ) -> ( ChainItemKind , Span ) {
154
+ fn from_ast ( context : & RewriteContext < ' _ > , expr : & ast:: Expr ) -> ( ChainItemKind , Span ) {
151
155
let ( kind, span) = match expr. node {
152
156
ast:: ExprKind :: MethodCall ( ref segment, ref expressions) => {
153
157
let types = if let Some ( ref generic_args) = segment. args {
@@ -182,7 +186,7 @@ impl ChainItemKind {
182
186
}
183
187
184
188
impl Rewrite for ChainItem {
185
- fn rewrite ( & self , context : & RewriteContext , shape : Shape ) -> Option < String > {
189
+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
186
190
let shape = shape. sub_width ( self . tries ) ?;
187
191
let rewrite = match self . kind {
188
192
ChainItemKind :: Parent ( ref expr) => expr. rewrite ( context, shape) ?,
@@ -204,7 +208,7 @@ impl Rewrite for ChainItem {
204
208
}
205
209
206
210
impl ChainItem {
207
- fn new ( context : & RewriteContext , expr : & ast:: Expr , tries : usize ) -> ChainItem {
211
+ fn new ( context : & RewriteContext < ' _ > , expr : & ast:: Expr , tries : usize ) -> ChainItem {
208
212
let ( kind, span) = ChainItemKind :: from_ast ( context, expr) ;
209
213
ChainItem { kind, tries, span }
210
214
}
@@ -229,7 +233,7 @@ impl ChainItem {
229
233
types : & [ ast:: GenericArg ] ,
230
234
args : & [ ptr:: P < ast:: Expr > ] ,
231
235
span : Span ,
232
- context : & RewriteContext ,
236
+ context : & RewriteContext < ' _ > ,
233
237
shape : Shape ,
234
238
) -> Option < String > {
235
239
let type_str = if types. is_empty ( ) {
@@ -254,7 +258,7 @@ struct Chain {
254
258
}
255
259
256
260
impl Chain {
257
- fn from_ast ( expr : & ast:: Expr , context : & RewriteContext ) -> Chain {
261
+ fn from_ast ( expr : & ast:: Expr , context : & RewriteContext < ' _ > ) -> Chain {
258
262
let subexpr_list = Self :: make_subexpr_list ( expr, context) ;
259
263
260
264
// Un-parse the expression tree into ChainItems
@@ -376,7 +380,7 @@ impl Chain {
376
380
377
381
// Returns a Vec of the prefixes of the chain.
378
382
// E.g., for input `a.b.c` we return [`a.b.c`, `a.b`, 'a']
379
- fn make_subexpr_list ( expr : & ast:: Expr , context : & RewriteContext ) -> Vec < ast:: Expr > {
383
+ fn make_subexpr_list ( expr : & ast:: Expr , context : & RewriteContext < ' _ > ) -> Vec < ast:: Expr > {
380
384
let mut subexpr_list = vec ! [ expr. clone( ) ] ;
381
385
382
386
while let Some ( subexpr) = Self :: pop_expr_chain ( subexpr_list. last ( ) . unwrap ( ) , context) {
@@ -388,7 +392,7 @@ impl Chain {
388
392
389
393
// Returns the expression's subexpression, if it exists. When the subexpr
390
394
// is a try! macro, we'll convert it to shorthand when the option is set.
391
- fn pop_expr_chain ( expr : & ast:: Expr , context : & RewriteContext ) -> Option < ast:: Expr > {
395
+ fn pop_expr_chain ( expr : & ast:: Expr , context : & RewriteContext < ' _ > ) -> Option < ast:: Expr > {
392
396
match expr. node {
393
397
ast:: ExprKind :: MethodCall ( _, ref expressions) => {
394
398
Some ( Self :: convert_try ( & expressions[ 0 ] , context) )
@@ -400,7 +404,7 @@ impl Chain {
400
404
}
401
405
}
402
406
403
- fn convert_try ( expr : & ast:: Expr , context : & RewriteContext ) -> ast:: Expr {
407
+ fn convert_try ( expr : & ast:: Expr , context : & RewriteContext < ' _ > ) -> ast:: Expr {
404
408
match expr. node {
405
409
ast:: ExprKind :: Mac ( ref mac) if context. config . use_try_shorthand ( ) => {
406
410
if let Some ( subexpr) = convert_try_mac ( mac, context) {
@@ -415,12 +419,16 @@ impl Chain {
415
419
}
416
420
417
421
impl Rewrite for Chain {
418
- fn rewrite ( & self , context : & RewriteContext , shape : Shape ) -> Option < String > {
422
+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
419
423
debug ! ( "rewrite chain {:?} {:?}" , self , shape) ;
420
424
421
425
let mut formatter = match context. config . indent_style ( ) {
422
- IndentStyle :: Block => Box :: new ( ChainFormatterBlock :: new ( self ) ) as Box < ChainFormatter > ,
423
- IndentStyle :: Visual => Box :: new ( ChainFormatterVisual :: new ( self ) ) as Box < ChainFormatter > ,
426
+ IndentStyle :: Block => {
427
+ Box :: new ( ChainFormatterBlock :: new ( self ) ) as Box < dyn ChainFormatter >
428
+ }
429
+ IndentStyle :: Visual => {
430
+ Box :: new ( ChainFormatterVisual :: new ( self ) ) as Box < dyn ChainFormatter >
431
+ }
424
432
} ;
425
433
426
434
formatter. format_root ( & self . parent , context, shape) ?;
@@ -455,18 +463,18 @@ trait ChainFormatter {
455
463
fn format_root (
456
464
& mut self ,
457
465
parent : & ChainItem ,
458
- context : & RewriteContext ,
466
+ context : & RewriteContext < ' _ > ,
459
467
shape : Shape ,
460
468
) -> Option < ( ) > ;
461
- fn child_shape ( & self , context : & RewriteContext , shape : Shape ) -> Option < Shape > ;
462
- fn format_children ( & mut self , context : & RewriteContext , child_shape : Shape ) -> Option < ( ) > ;
469
+ fn child_shape ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < Shape > ;
470
+ fn format_children ( & mut self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < ( ) > ;
463
471
fn format_last_child (
464
472
& mut self ,
465
- context : & RewriteContext ,
473
+ context : & RewriteContext < ' _ > ,
466
474
shape : Shape ,
467
475
child_shape : Shape ,
468
476
) -> Option < ( ) > ;
469
- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > ;
477
+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > ;
470
478
// Returns `Some` if the chain is only a root, None otherwise.
471
479
fn pure_root ( & mut self ) -> Option < String > ;
472
480
}
@@ -540,7 +548,7 @@ impl<'a> ChainFormatterShared<'a> {
540
548
fn format_last_child (
541
549
& mut self ,
542
550
may_extend : bool ,
543
- context : & RewriteContext ,
551
+ context : & RewriteContext < ' _ > ,
544
552
shape : Shape ,
545
553
child_shape : Shape ,
546
554
) -> Option < ( ) > {
@@ -633,7 +641,7 @@ impl<'a> ChainFormatterShared<'a> {
633
641
Some ( ( ) )
634
642
}
635
643
636
- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
644
+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > {
637
645
let connector = if self . fits_single_line {
638
646
// Yay, we can put everything on one line.
639
647
Cow :: from ( "" )
@@ -682,7 +690,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
682
690
fn format_root (
683
691
& mut self ,
684
692
parent : & ChainItem ,
685
- context : & RewriteContext ,
693
+ context : & RewriteContext < ' _ > ,
686
694
shape : Shape ,
687
695
) -> Option < ( ) > {
688
696
let mut root_rewrite: String = parent. rewrite ( context, shape) ?;
@@ -713,7 +721,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
713
721
Some ( ( ) )
714
722
}
715
723
716
- fn child_shape ( & self , context : & RewriteContext , shape : Shape ) -> Option < Shape > {
724
+ fn child_shape ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < Shape > {
717
725
Some (
718
726
if self . root_ends_with_block {
719
727
shape. block_indent ( 0 )
@@ -724,7 +732,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
724
732
)
725
733
}
726
734
727
- fn format_children ( & mut self , context : & RewriteContext , child_shape : Shape ) -> Option < ( ) > {
735
+ fn format_children ( & mut self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < ( ) > {
728
736
for item in & self . shared . children [ ..self . shared . children . len ( ) - 1 ] {
729
737
let rewrite = item. rewrite ( context, child_shape) ?;
730
738
self . shared . rewrites . push ( rewrite) ;
@@ -734,15 +742,15 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
734
742
735
743
fn format_last_child (
736
744
& mut self ,
737
- context : & RewriteContext ,
745
+ context : & RewriteContext < ' _ > ,
738
746
shape : Shape ,
739
747
child_shape : Shape ,
740
748
) -> Option < ( ) > {
741
749
self . shared
742
750
. format_last_child ( true , context, shape, child_shape)
743
751
}
744
752
745
- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
753
+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > {
746
754
self . shared . join_rewrites ( context, child_shape)
747
755
}
748
756
@@ -771,7 +779,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
771
779
fn format_root (
772
780
& mut self ,
773
781
parent : & ChainItem ,
774
- context : & RewriteContext ,
782
+ context : & RewriteContext < ' _ > ,
775
783
shape : Shape ,
776
784
) -> Option < ( ) > {
777
785
let parent_shape = shape. visual_indent ( 0 ) ;
@@ -811,14 +819,14 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
811
819
Some ( ( ) )
812
820
}
813
821
814
- fn child_shape ( & self , context : & RewriteContext , shape : Shape ) -> Option < Shape > {
822
+ fn child_shape ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < Shape > {
815
823
shape
816
824
. with_max_width ( context. config )
817
825
. offset_left ( self . offset )
818
826
. map ( |s| s. visual_indent ( 0 ) )
819
827
}
820
828
821
- fn format_children ( & mut self , context : & RewriteContext , child_shape : Shape ) -> Option < ( ) > {
829
+ fn format_children ( & mut self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < ( ) > {
822
830
for item in & self . shared . children [ ..self . shared . children . len ( ) - 1 ] {
823
831
let rewrite = item. rewrite ( context, child_shape) ?;
824
832
self . shared . rewrites . push ( rewrite) ;
@@ -828,15 +836,15 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
828
836
829
837
fn format_last_child (
830
838
& mut self ,
831
- context : & RewriteContext ,
839
+ context : & RewriteContext < ' _ > ,
832
840
shape : Shape ,
833
841
child_shape : Shape ,
834
842
) -> Option < ( ) > {
835
843
self . shared
836
844
. format_last_child ( false , context, shape, child_shape)
837
845
}
838
846
839
- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
847
+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > {
840
848
self . shared . join_rewrites ( context, child_shape)
841
849
}
842
850
0 commit comments