diff --git a/src/expr.rs b/src/expr.rs index 8f107888cea..e014e506b05 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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 { diff --git a/src/items.rs b/src/items.rs index 9d525f9ba9d..95638a90fc0 100644 --- a/src/items.rs +++ b/src/items.rs @@ -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); diff --git a/src/visitor.rs b/src/visitor.rs index b1859418086..f2b4750460f 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -531,6 +531,10 @@ pub fn push_rewrite(&mut self, span: Span, rewrite: Option) { 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,