@@ -1155,6 +1155,25 @@ pub fn format_struct_struct(
1155
1155
}
1156
1156
}
1157
1157
1158
+ /// Returns a bytepos that is after that of `(` in `pub(..)`. If the given visibility does not
1159
+ /// contain `pub(..)`, then return the `lo` of the `defualt_span`. Yeah, but for what? Well, we need
1160
+ /// to bypass the `(` in the visibility when creating a span of tuple's body or fn's args.
1161
+ fn get_bytepos_after_visibility (
1162
+ context : & RewriteContext ,
1163
+ vis : & ast:: Visibility ,
1164
+ default_span : Span ,
1165
+ terminator : & str ,
1166
+ ) -> BytePos {
1167
+ match * vis {
1168
+ ast:: Visibility :: Crate ( s, CrateSugar :: PubCrate ) => context
1169
+ . codemap
1170
+ . span_after ( mk_sp ( s. hi ( ) , default_span. hi ( ) ) , terminator) ,
1171
+ ast:: Visibility :: Crate ( s, CrateSugar :: JustCrate ) => s. hi ( ) ,
1172
+ ast:: Visibility :: Restricted { ref path, .. } => path. span . hi ( ) ,
1173
+ _ => default_span. lo ( ) ,
1174
+ }
1175
+ }
1176
+
1158
1177
fn format_tuple_struct (
1159
1178
context : & RewriteContext ,
1160
1179
item_name : & str ,
@@ -1171,12 +1190,13 @@ fn format_tuple_struct(
1171
1190
result. push_str ( & header_str) ;
1172
1191
1173
1192
let body_lo = if fields. is_empty ( ) {
1174
- context. codemap . span_after ( span, "(" )
1193
+ let lo = get_bytepos_after_visibility ( context, vis, span, ")" ) ;
1194
+ context. codemap . span_after ( mk_sp ( lo, span. hi ( ) ) , "(" )
1175
1195
} else {
1176
1196
fields[ 0 ] . span . lo ( )
1177
1197
} ;
1178
1198
let body_hi = if fields. is_empty ( ) {
1179
- context. codemap . span_after ( span, ")" )
1199
+ context. codemap . span_after ( mk_sp ( body_lo , span. hi ( ) ) , ")" )
1180
1200
} else {
1181
1201
// This is a dirty hack to work around a missing `)` from the span of the last field.
1182
1202
let last_arg_span = fields[ fields. len ( ) - 1 ] . span ;
@@ -1224,7 +1244,10 @@ fn format_tuple_struct(
1224
1244
. to_string ( context. config ) )
1225
1245
}
1226
1246
result. push ( '(' ) ;
1227
- let snippet = context. snippet ( mk_sp ( body_lo, context. codemap . span_before ( span, ")" ) ) ) ;
1247
+ let snippet = context. snippet ( mk_sp (
1248
+ body_lo,
1249
+ context. codemap . span_before ( mk_sp ( body_lo, span. hi ( ) ) , ")" ) ,
1250
+ ) ) ;
1228
1251
if snippet. is_empty ( ) {
1229
1252
// `struct S ()`
1230
1253
} else if snippet. trim_right_matches ( & [ ' ' , '\t' ] [ ..] ) . ends_with ( '\n' ) {
@@ -1766,13 +1789,7 @@ fn rewrite_fn_base(
1766
1789
}
1767
1790
1768
1791
// Skip `pub(crate)`.
1769
- let lo_after_visibility = match fn_sig. visibility {
1770
- ast:: Visibility :: Crate ( s, CrateSugar :: PubCrate ) => {
1771
- context. codemap . span_after ( mk_sp ( s. hi ( ) , span. hi ( ) ) , ")" )
1772
- }
1773
- ast:: Visibility :: Crate ( s, CrateSugar :: JustCrate ) => s. hi ( ) ,
1774
- _ => span. lo ( ) ,
1775
- } ;
1792
+ let lo_after_visibility = get_bytepos_after_visibility ( context, & fn_sig. visibility , span, ")" ) ;
1776
1793
// A conservative estimation, to goal is to be over all parens in generics
1777
1794
let args_start = fn_sig
1778
1795
. generics
0 commit comments