@@ -128,7 +128,9 @@ impl Rewrite for ast::Local {
128
128
129
129
if let Some ( ( init, else_block) ) = self . kind . init_else_opt ( ) {
130
130
// 1 = trailing semicolon;
131
- let nested_shape = shape. sub_width ( 1 ) . unknown_error ( ) ?;
131
+ let nested_shape = shape
132
+ . sub_width ( 1 )
133
+ . max_width_error ( shape. width , self . span ( ) ) ?;
132
134
133
135
result = rewrite_assign_rhs (
134
136
context,
@@ -1862,6 +1864,7 @@ impl Rewrite for ast::FieldDef {
1862
1864
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
1863
1865
self . rewrite_result ( context, shape) . ok ( )
1864
1866
}
1867
+
1865
1868
fn rewrite_result ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> RewriteResult {
1866
1869
rewrite_struct_field ( context, self , shape, 0 )
1867
1870
}
@@ -1912,14 +1915,11 @@ pub(crate) fn rewrite_struct_field(
1912
1915
spacing. push ( ' ' ) ;
1913
1916
}
1914
1917
1915
- // Question. Why don't we immediately return None/Err with ?
1916
- // let orig_ty = shape
1917
- // .offset_left(overhead + spacing.len())
1918
- // .and_then(|ty_shape| field.ty.rewrite(context, ty_shape));
1919
- let ty_shape = shape
1918
+ let orig_ty = shape
1920
1919
. offset_left ( overhead + spacing. len ( ) )
1921
- . max_width_error ( shape. width , field. ty . span ( ) ) ?;
1922
- let orig_ty = field. ty . rewrite_result ( context, ty_shape) ;
1920
+ . unknown_error ( )
1921
+ . and_then ( |ty_shape| field. ty . rewrite_result ( context, ty_shape) ) ;
1922
+
1923
1923
if let Ok ( ref ty) = orig_ty {
1924
1924
if !ty. contains ( '\n' ) && !contains_comment ( context. snippet ( missing_span) ) {
1925
1925
return Ok ( attr_prefix + & spacing + ty) ;
@@ -2101,25 +2101,26 @@ impl Rewrite for ast::FnRetTy {
2101
2101
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
2102
2102
self . rewrite_result ( context, shape) . ok ( )
2103
2103
}
2104
+
2104
2105
fn rewrite_result ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> RewriteResult {
2105
2106
match * self {
2106
2107
ast:: FnRetTy :: Default ( _) => Ok ( String :: new ( ) ) ,
2107
2108
ast:: FnRetTy :: Ty ( ref ty) => {
2109
+ let arrow_width = "-> " . len ( ) ;
2108
2110
if context. config . version ( ) == Version :: One
2109
2111
|| context. config . indent_style ( ) == IndentStyle :: Visual
2110
2112
{
2111
2113
let inner_width = shape
2112
2114
. width
2113
- . checked_sub ( 3 )
2115
+ . checked_sub ( arrow_width )
2114
2116
. max_width_error ( shape. width , self . span ( ) ) ?;
2115
2117
return ty
2116
2118
. rewrite_result ( context, Shape :: legacy ( inner_width, shape. indent + 3 ) )
2117
2119
. map ( |r| format ! ( "-> {}" , r) ) ;
2118
2120
}
2119
2121
2120
- // 3 = "-> "
2121
2122
let shape = shape
2122
- . offset_left ( 3 )
2123
+ . offset_left ( arrow_width )
2123
2124
. max_width_error ( shape. width , self . span ( ) ) ?;
2124
2125
2125
2126
ty. rewrite_result ( context, shape)
0 commit comments