@@ -958,20 +958,19 @@ fn format_impl_ref_and_type(
958
958
offset : Indent ,
959
959
) -> Option < String > {
960
960
let ast:: Impl {
961
- safety,
962
- polarity,
963
- defaultness,
964
- constness,
965
- ref generics,
966
- of_trait : ref trait_ref,
967
- ref self_ty,
968
- ..
969
- } = * iimpl;
961
+ generics,
962
+ of_trait,
963
+ self_ty,
964
+ items : _,
965
+ } = iimpl;
970
966
let mut result = String :: with_capacity ( 128 ) ;
971
967
972
968
result. push_str ( & format_visibility ( context, & item. vis ) ) ;
973
- result. push_str ( format_defaultness ( defaultness) ) ;
974
- result. push_str ( format_safety ( safety) ) ;
969
+
970
+ if let Some ( of_trait) = of_trait. as_deref ( ) {
971
+ result. push_str ( format_defaultness ( of_trait. defaultness ) ) ;
972
+ result. push_str ( format_safety ( of_trait. safety ) ) ;
973
+ }
975
974
976
975
let shape = if context. config . style_edition ( ) >= StyleEdition :: Edition2024 {
977
976
Shape :: indented ( offset + last_line_width ( & result) , context. config )
@@ -984,28 +983,24 @@ fn format_impl_ref_and_type(
984
983
} ;
985
984
let generics_str = rewrite_generics ( context, "impl" , generics, shape) . ok ( ) ?;
986
985
result. push_str ( & generics_str) ;
987
- result. push_str ( format_constness_right ( constness) ) ;
988
986
989
- let polarity_str = match polarity {
990
- ast:: ImplPolarity :: Negative ( _) => "!" ,
991
- ast:: ImplPolarity :: Positive => "" ,
992
- } ;
993
-
994
- let polarity_overhead;
995
987
let trait_ref_overhead;
996
- if let Some ( ref trait_ref) = * trait_ref {
988
+ if let Some ( of_trait) = of_trait. as_deref ( ) {
989
+ result. push_str ( format_constness_right ( of_trait. constness ) ) ;
990
+ let polarity_str = match of_trait. polarity {
991
+ ast:: ImplPolarity :: Negative ( _) => "!" ,
992
+ ast:: ImplPolarity :: Positive => "" ,
993
+ } ;
997
994
let result_len = last_line_width ( & result) ;
998
995
result. push_str ( & rewrite_trait_ref (
999
996
context,
1000
- trait_ref,
997
+ & of_trait . trait_ref ,
1001
998
offset,
1002
999
polarity_str,
1003
1000
result_len,
1004
1001
) ?) ;
1005
- polarity_overhead = 0 ; // already written
1006
1002
trait_ref_overhead = " for" . len ( ) ;
1007
1003
} else {
1008
- polarity_overhead = polarity_str. len ( ) ;
1009
1004
trait_ref_overhead = 0 ;
1010
1005
}
1011
1006
@@ -1020,17 +1015,15 @@ fn format_impl_ref_and_type(
1020
1015
} else {
1021
1016
0
1022
1017
} ;
1023
- let used_space =
1024
- last_line_width ( & result) + polarity_overhead + trait_ref_overhead + curly_brace_overhead;
1018
+ let used_space = last_line_width ( & result) + trait_ref_overhead + curly_brace_overhead;
1025
1019
// 1 = space before the type.
1026
1020
let budget = context. budget ( used_space + 1 ) ;
1027
1021
if let Some ( self_ty_str) = self_ty. rewrite ( context, Shape :: legacy ( budget, offset) ) {
1028
1022
if !self_ty_str. contains ( '\n' ) {
1029
- if trait_ref . is_some ( ) {
1023
+ if of_trait . is_some ( ) {
1030
1024
result. push_str ( " for " ) ;
1031
1025
} else {
1032
1026
result. push ( ' ' ) ;
1033
- result. push_str ( polarity_str) ;
1034
1027
}
1035
1028
result. push_str ( & self_ty_str) ;
1036
1029
return Some ( result) ;
@@ -1042,12 +1035,10 @@ fn format_impl_ref_and_type(
1042
1035
// Add indentation of one additional tab.
1043
1036
let new_line_offset = offset. block_indent ( context. config ) ;
1044
1037
result. push_str ( & new_line_offset. to_string ( context. config ) ) ;
1045
- if trait_ref . is_some ( ) {
1038
+ if of_trait . is_some ( ) {
1046
1039
result. push_str ( "for " ) ;
1047
- } else {
1048
- result. push_str ( polarity_str) ;
1049
1040
}
1050
- let budget = context. budget ( last_line_width ( & result) + polarity_overhead ) ;
1041
+ let budget = context. budget ( last_line_width ( & result) ) ;
1051
1042
let type_offset = match context. config . indent_style ( ) {
1052
1043
IndentStyle :: Visual => new_line_offset + trait_ref_overhead,
1053
1044
IndentStyle :: Block => new_line_offset,
0 commit comments