@@ -84,7 +84,7 @@ 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 ( expr : & ast:: Expr , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
88
88
let chain = Chain :: from_ast ( expr, context) ;
89
89
debug ! ( "rewrite_chain {:?} {:?}" , chain, shape) ;
90
90
@@ -128,7 +128,7 @@ enum ChainItemKind {
128
128
}
129
129
130
130
impl ChainItemKind {
131
- fn is_block_like ( & self , context : & RewriteContext , reps : & str ) -> bool {
131
+ fn is_block_like ( & self , context : & RewriteContext < ' _ > , reps : & str ) -> bool {
132
132
match self {
133
133
ChainItemKind :: Parent ( ref expr) => utils:: is_block_expr ( context, expr, reps) ,
134
134
ChainItemKind :: MethodCall ( ..)
@@ -147,7 +147,7 @@ impl ChainItemKind {
147
147
}
148
148
}
149
149
150
- fn from_ast ( context : & RewriteContext , expr : & ast:: Expr ) -> ( ChainItemKind , Span ) {
150
+ fn from_ast ( context : & RewriteContext < ' _ > , expr : & ast:: Expr ) -> ( ChainItemKind , Span ) {
151
151
let ( kind, span) = match expr. node {
152
152
ast:: ExprKind :: MethodCall ( ref segment, ref expressions) => {
153
153
let types = if let Some ( ref generic_args) = segment. args {
@@ -182,7 +182,7 @@ impl ChainItemKind {
182
182
}
183
183
184
184
impl Rewrite for ChainItem {
185
- fn rewrite ( & self , context : & RewriteContext , shape : Shape ) -> Option < String > {
185
+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
186
186
let shape = shape. sub_width ( self . tries ) ?;
187
187
let rewrite = match self . kind {
188
188
ChainItemKind :: Parent ( ref expr) => expr. rewrite ( context, shape) ?,
@@ -204,7 +204,7 @@ impl Rewrite for ChainItem {
204
204
}
205
205
206
206
impl ChainItem {
207
- fn new ( context : & RewriteContext , expr : & ast:: Expr , tries : usize ) -> ChainItem {
207
+ fn new ( context : & RewriteContext < ' _ > , expr : & ast:: Expr , tries : usize ) -> ChainItem {
208
208
let ( kind, span) = ChainItemKind :: from_ast ( context, expr) ;
209
209
ChainItem { kind, tries, span }
210
210
}
@@ -229,7 +229,7 @@ impl ChainItem {
229
229
types : & [ ast:: GenericArg ] ,
230
230
args : & [ ptr:: P < ast:: Expr > ] ,
231
231
span : Span ,
232
- context : & RewriteContext ,
232
+ context : & RewriteContext < ' _ > ,
233
233
shape : Shape ,
234
234
) -> Option < String > {
235
235
let type_str = if types. is_empty ( ) {
@@ -254,7 +254,7 @@ struct Chain {
254
254
}
255
255
256
256
impl Chain {
257
- fn from_ast ( expr : & ast:: Expr , context : & RewriteContext ) -> Chain {
257
+ fn from_ast ( expr : & ast:: Expr , context : & RewriteContext < ' _ > ) -> Chain {
258
258
let subexpr_list = Self :: make_subexpr_list ( expr, context) ;
259
259
260
260
// Un-parse the expression tree into ChainItems
@@ -376,7 +376,7 @@ impl Chain {
376
376
377
377
// Returns a Vec of the prefixes of the chain.
378
378
// 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 > {
379
+ fn make_subexpr_list ( expr : & ast:: Expr , context : & RewriteContext < ' _ > ) -> Vec < ast:: Expr > {
380
380
let mut subexpr_list = vec ! [ expr. clone( ) ] ;
381
381
382
382
while let Some ( subexpr) = Self :: pop_expr_chain ( subexpr_list. last ( ) . unwrap ( ) , context) {
@@ -388,7 +388,7 @@ impl Chain {
388
388
389
389
// Returns the expression's subexpression, if it exists. When the subexpr
390
390
// 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 > {
391
+ fn pop_expr_chain ( expr : & ast:: Expr , context : & RewriteContext < ' _ > ) -> Option < ast:: Expr > {
392
392
match expr. node {
393
393
ast:: ExprKind :: MethodCall ( _, ref expressions) => {
394
394
Some ( Self :: convert_try ( & expressions[ 0 ] , context) )
@@ -400,7 +400,7 @@ impl Chain {
400
400
}
401
401
}
402
402
403
- fn convert_try ( expr : & ast:: Expr , context : & RewriteContext ) -> ast:: Expr {
403
+ fn convert_try ( expr : & ast:: Expr , context : & RewriteContext < ' _ > ) -> ast:: Expr {
404
404
match expr. node {
405
405
ast:: ExprKind :: Mac ( ref mac) if context. config . use_try_shorthand ( ) => {
406
406
if let Some ( subexpr) = convert_try_mac ( mac, context) {
@@ -415,12 +415,12 @@ impl Chain {
415
415
}
416
416
417
417
impl Rewrite for Chain {
418
- fn rewrite ( & self , context : & RewriteContext , shape : Shape ) -> Option < String > {
418
+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
419
419
debug ! ( "rewrite chain {:?} {:?}" , self , shape) ;
420
420
421
421
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 > ,
422
+ IndentStyle :: Block => Box :: new ( ChainFormatterBlock :: new ( self ) ) as Box < dyn ChainFormatter > ,
423
+ IndentStyle :: Visual => Box :: new ( ChainFormatterVisual :: new ( self ) ) as Box < dyn ChainFormatter > ,
424
424
} ;
425
425
426
426
formatter. format_root ( & self . parent , context, shape) ?;
@@ -455,18 +455,18 @@ trait ChainFormatter {
455
455
fn format_root (
456
456
& mut self ,
457
457
parent : & ChainItem ,
458
- context : & RewriteContext ,
458
+ context : & RewriteContext < ' _ > ,
459
459
shape : Shape ,
460
460
) -> Option < ( ) > ;
461
- fn child_shape ( & self , context : & RewriteContext , shape : Shape ) -> Option < Shape > ;
462
- fn format_children ( & mut self , context : & RewriteContext , child_shape : Shape ) -> Option < ( ) > ;
461
+ fn child_shape ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < Shape > ;
462
+ fn format_children ( & mut self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < ( ) > ;
463
463
fn format_last_child (
464
464
& mut self ,
465
- context : & RewriteContext ,
465
+ context : & RewriteContext < ' _ > ,
466
466
shape : Shape ,
467
467
child_shape : Shape ,
468
468
) -> Option < ( ) > ;
469
- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > ;
469
+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > ;
470
470
// Returns `Some` if the chain is only a root, None otherwise.
471
471
fn pure_root ( & mut self ) -> Option < String > ;
472
472
}
@@ -540,7 +540,7 @@ impl<'a> ChainFormatterShared<'a> {
540
540
fn format_last_child (
541
541
& mut self ,
542
542
may_extend : bool ,
543
- context : & RewriteContext ,
543
+ context : & RewriteContext < ' _ > ,
544
544
shape : Shape ,
545
545
child_shape : Shape ,
546
546
) -> Option < ( ) > {
@@ -633,7 +633,7 @@ impl<'a> ChainFormatterShared<'a> {
633
633
Some ( ( ) )
634
634
}
635
635
636
- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
636
+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > {
637
637
let connector = if self . fits_single_line {
638
638
// Yay, we can put everything on one line.
639
639
Cow :: from ( "" )
@@ -682,7 +682,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
682
682
fn format_root (
683
683
& mut self ,
684
684
parent : & ChainItem ,
685
- context : & RewriteContext ,
685
+ context : & RewriteContext < ' _ > ,
686
686
shape : Shape ,
687
687
) -> Option < ( ) > {
688
688
let mut root_rewrite: String = parent. rewrite ( context, shape) ?;
@@ -713,7 +713,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
713
713
Some ( ( ) )
714
714
}
715
715
716
- fn child_shape ( & self , context : & RewriteContext , shape : Shape ) -> Option < Shape > {
716
+ fn child_shape ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < Shape > {
717
717
Some (
718
718
if self . root_ends_with_block {
719
719
shape. block_indent ( 0 )
@@ -724,7 +724,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
724
724
)
725
725
}
726
726
727
- fn format_children ( & mut self , context : & RewriteContext , child_shape : Shape ) -> Option < ( ) > {
727
+ fn format_children ( & mut self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < ( ) > {
728
728
for item in & self . shared . children [ ..self . shared . children . len ( ) - 1 ] {
729
729
let rewrite = item. rewrite ( context, child_shape) ?;
730
730
self . shared . rewrites . push ( rewrite) ;
@@ -734,15 +734,15 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
734
734
735
735
fn format_last_child (
736
736
& mut self ,
737
- context : & RewriteContext ,
737
+ context : & RewriteContext < ' _ > ,
738
738
shape : Shape ,
739
739
child_shape : Shape ,
740
740
) -> Option < ( ) > {
741
741
self . shared
742
742
. format_last_child ( true , context, shape, child_shape)
743
743
}
744
744
745
- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
745
+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > {
746
746
self . shared . join_rewrites ( context, child_shape)
747
747
}
748
748
@@ -771,7 +771,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
771
771
fn format_root (
772
772
& mut self ,
773
773
parent : & ChainItem ,
774
- context : & RewriteContext ,
774
+ context : & RewriteContext < ' _ > ,
775
775
shape : Shape ,
776
776
) -> Option < ( ) > {
777
777
let parent_shape = shape. visual_indent ( 0 ) ;
@@ -811,14 +811,14 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
811
811
Some ( ( ) )
812
812
}
813
813
814
- fn child_shape ( & self , context : & RewriteContext , shape : Shape ) -> Option < Shape > {
814
+ fn child_shape ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < Shape > {
815
815
shape
816
816
. with_max_width ( context. config )
817
817
. offset_left ( self . offset )
818
818
. map ( |s| s. visual_indent ( 0 ) )
819
819
}
820
820
821
- fn format_children ( & mut self , context : & RewriteContext , child_shape : Shape ) -> Option < ( ) > {
821
+ fn format_children ( & mut self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < ( ) > {
822
822
for item in & self . shared . children [ ..self . shared . children . len ( ) - 1 ] {
823
823
let rewrite = item. rewrite ( context, child_shape) ?;
824
824
self . shared . rewrites . push ( rewrite) ;
@@ -828,15 +828,15 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
828
828
829
829
fn format_last_child (
830
830
& mut self ,
831
- context : & RewriteContext ,
831
+ context : & RewriteContext < ' _ > ,
832
832
shape : Shape ,
833
833
child_shape : Shape ,
834
834
) -> Option < ( ) > {
835
835
self . shared
836
836
. format_last_child ( false , context, shape, child_shape)
837
837
}
838
838
839
- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
839
+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > {
840
840
self . shared . join_rewrites ( context, child_shape)
841
841
}
842
842
0 commit comments