Skip to content

Commit 84526ab

Browse files
committed
Add get_bytepos_after_visibility()
1 parent af3d793 commit 84526ab

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/items.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,25 @@ pub fn format_struct_struct(
11541154
}
11551155
}
11561156

1157+
/// Returns a bytepos that is after that of `(` in `pub(..)`. If the given visibility does not
1158+
/// contain `pub(..)`, then return the `lo` of the `defualt_span`. Yeah, but for what? Well, we need
1159+
/// to bypass the `(` in the visibility when creating a span of tuple's body or fn's args.
1160+
fn get_bytepos_after_visibility(
1161+
context: &RewriteContext,
1162+
vis: &ast::Visibility,
1163+
default_span: Span,
1164+
terminator: &str,
1165+
) -> BytePos {
1166+
match *vis {
1167+
ast::Visibility::Crate(s, CrateSugar::PubCrate) => context
1168+
.codemap
1169+
.span_after(mk_sp(s.hi(), default_span.hi()), terminator),
1170+
ast::Visibility::Crate(s, CrateSugar::JustCrate) => s.hi(),
1171+
ast::Visibility::Restricted { ref path, .. } => path.span.hi(),
1172+
_ => default_span.lo(),
1173+
}
1174+
}
1175+
11571176
fn format_tuple_struct(
11581177
context: &RewriteContext,
11591178
item_name: &str,

0 commit comments

Comments
 (0)