@@ -537,28 +537,19 @@ impl Rewrite for ast::Lifetime {
537537impl Rewrite for ast:: GenericBound {
538538 fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
539539 match * self {
540- ast:: GenericBound :: Trait ( ref poly_trait_ref, trait_bound_modifier ) => {
540+ ast:: GenericBound :: Trait ( ref poly_trait_ref, modifiers ) => {
541541 let snippet = context. snippet ( self . span ( ) ) ;
542542 let has_paren = snippet. starts_with ( '(' ) && snippet. ends_with ( ')' ) ;
543- let rewrite = match trait_bound_modifier {
544- ast:: TraitBoundModifier :: None => poly_trait_ref. rewrite ( context, shape) ,
545- ast:: TraitBoundModifier :: Maybe => poly_trait_ref
546- . rewrite ( context, shape. offset_left ( 1 ) ?)
547- . map ( |s| format ! ( "?{}" , s) ) ,
548- ast:: TraitBoundModifier :: MaybeConst ( _) => poly_trait_ref
549- . rewrite ( context, shape. offset_left ( 7 ) ?)
550- . map ( |s| format ! ( "~const {}" , s) ) ,
551- ast:: TraitBoundModifier :: MaybeConstMaybe => poly_trait_ref
552- . rewrite ( context, shape. offset_left ( 8 ) ?)
553- . map ( |s| format ! ( "~const ?{}" , s) ) ,
554- ast:: TraitBoundModifier :: Negative => poly_trait_ref
555- . rewrite ( context, shape. offset_left ( 1 ) ?)
556- . map ( |s| format ! ( "!{}" , s) ) ,
557- ast:: TraitBoundModifier :: MaybeConstNegative => poly_trait_ref
558- . rewrite ( context, shape. offset_left ( 8 ) ?)
559- . map ( |s| format ! ( "~const !{}" , s) ) ,
560- } ;
561- rewrite. map ( |s| if has_paren { format ! ( "({})" , s) } else { s } )
543+ let mut constness = modifiers. constness . as_str ( ) . to_string ( ) ;
544+ if !constness. is_empty ( ) {
545+ constness. push ( ' ' ) ;
546+ }
547+ let polarity = modifiers. polarity . as_str ( ) ;
548+ let shape = shape. offset_left ( constness. len ( ) + polarity. len ( ) ) ?;
549+ poly_trait_ref
550+ . rewrite ( context, shape)
551+ . map ( |s| format ! ( "{constness}{polarity}{s}" ) )
552+ . map ( |s| if has_paren { format ! ( "({})" , s) } else { s } )
562553 }
563554 ast:: GenericBound :: Outlives ( ref lifetime) => lifetime. rewrite ( context, shape) ,
564555 }
0 commit comments