Add FmtVisitor::from_context()
This commit is contained in:
parent
1d9a10e00e
commit
c0eb8c3212
@ -629,7 +629,7 @@ pub fn rewrite_block_with_visitor(
|
||||
return rw;
|
||||
}
|
||||
|
||||
let mut visitor = FmtVisitor::from_codemap(context.parse_session, context.config, block.span);
|
||||
let mut visitor = FmtVisitor::from_context(context);
|
||||
visitor.block_indent = shape.indent;
|
||||
visitor.is_if_else_block = context.is_if_else_block;
|
||||
match block.rules {
|
||||
|
@ -657,8 +657,7 @@ pub fn format_impl(
|
||||
let open_pos = snippet.find_uncommented("{")? + 1;
|
||||
|
||||
if !items.is_empty() || contains_comment(&snippet[open_pos..]) {
|
||||
let mut visitor =
|
||||
FmtVisitor::from_codemap(context.parse_session, context.config, item.span);
|
||||
let mut visitor = FmtVisitor::from_context(context);
|
||||
visitor.block_indent = offset.block_only().block_indent(context.config);
|
||||
visitor.last_pos = item.span.lo() + BytePos(open_pos as u32);
|
||||
|
||||
@ -1056,8 +1055,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
|
||||
let open_pos = snippet.find_uncommented("{")? + 1;
|
||||
|
||||
if !trait_items.is_empty() || contains_comment(&snippet[open_pos..]) {
|
||||
let mut visitor =
|
||||
FmtVisitor::from_codemap(context.parse_session, context.config, item.span);
|
||||
let mut visitor = FmtVisitor::from_context(context);
|
||||
visitor.block_indent = offset.block_only().block_indent(context.config);
|
||||
visitor.last_pos = item.span.lo() + BytePos(open_pos as u32);
|
||||
|
||||
|
@ -531,6 +531,10 @@ pub fn push_rewrite(&mut self, span: Span, rewrite: Option<String>) {
|
||||
self.last_pos = source!(self, span).hi();
|
||||
}
|
||||
|
||||
pub fn from_context(ctx: &'a RewriteContext) -> FmtVisitor<'a> {
|
||||
FmtVisitor::from_codemap(ctx.parse_session, ctx.config, ctx.snippet_provider)
|
||||
}
|
||||
|
||||
pub fn from_codemap(
|
||||
parse_session: &'a ParseSess,
|
||||
config: &'a Config,
|
||||
|
Loading…
Reference in New Issue
Block a user