@@ -84,7 +84,11 @@ use crate::utils::{
8484 trimmed_last_line_width, wrap_str,
8585} ;
8686
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 > {
8892 let chain = Chain :: from_ast ( expr, context) ;
8993 debug ! ( "rewrite_chain {:?} {:?}" , chain, shape) ;
9094
@@ -128,7 +132,7 @@ enum ChainItemKind {
128132}
129133
130134impl ChainItemKind {
131- fn is_block_like ( & self , context : & RewriteContext , reps : & str ) -> bool {
135+ fn is_block_like ( & self , context : & RewriteContext < ' _ > , reps : & str ) -> bool {
132136 match self {
133137 ChainItemKind :: Parent ( ref expr) => utils:: is_block_expr ( context, expr, reps) ,
134138 ChainItemKind :: MethodCall ( ..)
@@ -147,7 +151,7 @@ impl ChainItemKind {
147151 }
148152 }
149153
150- fn from_ast ( context : & RewriteContext , expr : & ast:: Expr ) -> ( ChainItemKind , Span ) {
154+ fn from_ast ( context : & RewriteContext < ' _ > , expr : & ast:: Expr ) -> ( ChainItemKind , Span ) {
151155 let ( kind, span) = match expr. node {
152156 ast:: ExprKind :: MethodCall ( ref segment, ref expressions) => {
153157 let types = if let Some ( ref generic_args) = segment. args {
@@ -182,7 +186,7 @@ impl ChainItemKind {
182186}
183187
184188impl Rewrite for ChainItem {
185- fn rewrite ( & self , context : & RewriteContext , shape : Shape ) -> Option < String > {
189+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
186190 let shape = shape. sub_width ( self . tries ) ?;
187191 let rewrite = match self . kind {
188192 ChainItemKind :: Parent ( ref expr) => expr. rewrite ( context, shape) ?,
@@ -204,7 +208,7 @@ impl Rewrite for ChainItem {
204208}
205209
206210impl ChainItem {
207- fn new ( context : & RewriteContext , expr : & ast:: Expr , tries : usize ) -> ChainItem {
211+ fn new ( context : & RewriteContext < ' _ > , expr : & ast:: Expr , tries : usize ) -> ChainItem {
208212 let ( kind, span) = ChainItemKind :: from_ast ( context, expr) ;
209213 ChainItem { kind, tries, span }
210214 }
@@ -229,7 +233,7 @@ impl ChainItem {
229233 types : & [ ast:: GenericArg ] ,
230234 args : & [ ptr:: P < ast:: Expr > ] ,
231235 span : Span ,
232- context : & RewriteContext ,
236+ context : & RewriteContext < ' _ > ,
233237 shape : Shape ,
234238 ) -> Option < String > {
235239 let type_str = if types. is_empty ( ) {
@@ -254,7 +258,7 @@ struct Chain {
254258}
255259
256260impl Chain {
257- fn from_ast ( expr : & ast:: Expr , context : & RewriteContext ) -> Chain {
261+ fn from_ast ( expr : & ast:: Expr , context : & RewriteContext < ' _ > ) -> Chain {
258262 let subexpr_list = Self :: make_subexpr_list ( expr, context) ;
259263
260264 // Un-parse the expression tree into ChainItems
@@ -376,7 +380,7 @@ impl Chain {
376380
377381 // Returns a Vec of the prefixes of the chain.
378382 // 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 > {
380384 let mut subexpr_list = vec ! [ expr. clone( ) ] ;
381385
382386 while let Some ( subexpr) = Self :: pop_expr_chain ( subexpr_list. last ( ) . unwrap ( ) , context) {
@@ -388,7 +392,7 @@ impl Chain {
388392
389393 // Returns the expression's subexpression, if it exists. When the subexpr
390394 // 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 > {
392396 match expr. node {
393397 ast:: ExprKind :: MethodCall ( _, ref expressions) => {
394398 Some ( Self :: convert_try ( & expressions[ 0 ] , context) )
@@ -400,7 +404,7 @@ impl Chain {
400404 }
401405 }
402406
403- fn convert_try ( expr : & ast:: Expr , context : & RewriteContext ) -> ast:: Expr {
407+ fn convert_try ( expr : & ast:: Expr , context : & RewriteContext < ' _ > ) -> ast:: Expr {
404408 match expr. node {
405409 ast:: ExprKind :: Mac ( ref mac) if context. config . use_try_shorthand ( ) => {
406410 if let Some ( subexpr) = convert_try_mac ( mac, context) {
@@ -415,12 +419,16 @@ impl Chain {
415419}
416420
417421impl Rewrite for Chain {
418- fn rewrite ( & self , context : & RewriteContext , shape : Shape ) -> Option < String > {
422+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
419423 debug ! ( "rewrite chain {:?} {:?}" , self , shape) ;
420424
421425 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+ }
424432 } ;
425433
426434 formatter. format_root ( & self . parent , context, shape) ?;
@@ -455,18 +463,18 @@ trait ChainFormatter {
455463 fn format_root (
456464 & mut self ,
457465 parent : & ChainItem ,
458- context : & RewriteContext ,
466+ context : & RewriteContext < ' _ > ,
459467 shape : Shape ,
460468 ) -> 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 < ( ) > ;
463471 fn format_last_child (
464472 & mut self ,
465- context : & RewriteContext ,
473+ context : & RewriteContext < ' _ > ,
466474 shape : Shape ,
467475 child_shape : Shape ,
468476 ) -> 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 > ;
470478 // Returns `Some` if the chain is only a root, None otherwise.
471479 fn pure_root ( & mut self ) -> Option < String > ;
472480}
@@ -540,7 +548,7 @@ impl<'a> ChainFormatterShared<'a> {
540548 fn format_last_child (
541549 & mut self ,
542550 may_extend : bool ,
543- context : & RewriteContext ,
551+ context : & RewriteContext < ' _ > ,
544552 shape : Shape ,
545553 child_shape : Shape ,
546554 ) -> Option < ( ) > {
@@ -633,7 +641,7 @@ impl<'a> ChainFormatterShared<'a> {
633641 Some ( ( ) )
634642 }
635643
636- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
644+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > {
637645 let connector = if self . fits_single_line {
638646 // Yay, we can put everything on one line.
639647 Cow :: from ( "" )
@@ -682,7 +690,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
682690 fn format_root (
683691 & mut self ,
684692 parent : & ChainItem ,
685- context : & RewriteContext ,
693+ context : & RewriteContext < ' _ > ,
686694 shape : Shape ,
687695 ) -> Option < ( ) > {
688696 let mut root_rewrite: String = parent. rewrite ( context, shape) ?;
@@ -713,7 +721,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
713721 Some ( ( ) )
714722 }
715723
716- fn child_shape ( & self , context : & RewriteContext , shape : Shape ) -> Option < Shape > {
724+ fn child_shape ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < Shape > {
717725 Some (
718726 if self . root_ends_with_block {
719727 shape. block_indent ( 0 )
@@ -724,7 +732,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
724732 )
725733 }
726734
727- fn format_children ( & mut self , context : & RewriteContext , child_shape : Shape ) -> Option < ( ) > {
735+ fn format_children ( & mut self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < ( ) > {
728736 for item in & self . shared . children [ ..self . shared . children . len ( ) - 1 ] {
729737 let rewrite = item. rewrite ( context, child_shape) ?;
730738 self . shared . rewrites . push ( rewrite) ;
@@ -734,15 +742,15 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
734742
735743 fn format_last_child (
736744 & mut self ,
737- context : & RewriteContext ,
745+ context : & RewriteContext < ' _ > ,
738746 shape : Shape ,
739747 child_shape : Shape ,
740748 ) -> Option < ( ) > {
741749 self . shared
742750 . format_last_child ( true , context, shape, child_shape)
743751 }
744752
745- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
753+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > {
746754 self . shared . join_rewrites ( context, child_shape)
747755 }
748756
@@ -771,7 +779,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
771779 fn format_root (
772780 & mut self ,
773781 parent : & ChainItem ,
774- context : & RewriteContext ,
782+ context : & RewriteContext < ' _ > ,
775783 shape : Shape ,
776784 ) -> Option < ( ) > {
777785 let parent_shape = shape. visual_indent ( 0 ) ;
@@ -811,14 +819,14 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
811819 Some ( ( ) )
812820 }
813821
814- fn child_shape ( & self , context : & RewriteContext , shape : Shape ) -> Option < Shape > {
822+ fn child_shape ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < Shape > {
815823 shape
816824 . with_max_width ( context. config )
817825 . offset_left ( self . offset )
818826 . map ( |s| s. visual_indent ( 0 ) )
819827 }
820828
821- fn format_children ( & mut self , context : & RewriteContext , child_shape : Shape ) -> Option < ( ) > {
829+ fn format_children ( & mut self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < ( ) > {
822830 for item in & self . shared . children [ ..self . shared . children . len ( ) - 1 ] {
823831 let rewrite = item. rewrite ( context, child_shape) ?;
824832 self . shared . rewrites . push ( rewrite) ;
@@ -828,15 +836,15 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
828836
829837 fn format_last_child (
830838 & mut self ,
831- context : & RewriteContext ,
839+ context : & RewriteContext < ' _ > ,
832840 shape : Shape ,
833841 child_shape : Shape ,
834842 ) -> Option < ( ) > {
835843 self . shared
836844 . format_last_child ( false , context, shape, child_shape)
837845 }
838846
839- fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
847+ fn join_rewrites ( & self , context : & RewriteContext < ' _ > , child_shape : Shape ) -> Option < String > {
840848 self . shared . join_rewrites ( context, child_shape)
841849 }
842850
0 commit comments