diff --git a/src/comment.rs b/src/comment.rs index be94e2db2c90..232d3745e59c 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -880,12 +880,6 @@ pub(crate) fn recover_missing_comment_in_span( Some(String::new()) } else { let missing_snippet = context.snippet(span); - let trimmed_missing_snippet = missing_snippet.trim(); - if !trimmed_missing_snippet.starts_with("//") && !trimmed_missing_snippet.starts_with("/*") - { - return None; - }; - let pos = missing_snippet.find('/').unwrap_or(0); // 1 = ` ` let total_width = missing_comment.len() + used_width + 1; diff --git a/src/items.rs b/src/items.rs index 17e67b3f79fb..202eb2cf1179 100644 --- a/src/items.rs +++ b/src/items.rs @@ -664,7 +664,6 @@ pub(crate) fn format_impl( context: &RewriteContext<'_>, item: &ast::Item, offset: Indent, - where_span_end: Option, ) -> Option { if let ast::ItemKind::Impl(_, _, _, ref generics, _, ref self_ty, ref items) = item.node { let mut result = String::with_capacity(128); @@ -691,6 +690,8 @@ pub(crate) fn format_impl( option.compress_where(); } + let misssing_span = mk_sp(self_ty.span.hi(), item.span.hi()); + let where_span_end = context.snippet_provider.opt_span_before(misssing_span, "{"); let where_clause_str = rewrite_where_clause( context, &generics.where_clause, diff --git a/src/visitor.rs b/src/visitor.rs index f317e0154239..5fdd0625dff8 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -5,7 +5,7 @@ use syntax::source_map::{self, BytePos, Pos, SourceMap, Span}; use syntax::{ast, visit}; use crate::attr::*; -use crate::comment::{CodeCharKind, CommentCodeSlices, FindUncommented}; +use crate::comment::{CodeCharKind, CommentCodeSlices}; use crate::config::file_lines::FileName; use crate::config::{BraceStyle, Config, Version}; use crate::expr::{format_expr, ExprType}; @@ -359,13 +359,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { match item.node { ast::ItemKind::Use(ref tree) => self.format_import(item, tree), ast::ItemKind::Impl(..) => { - let snippet = self.snippet(item.span); - let where_span_end = snippet - .find_uncommented("{") - .map(|x| BytePos(x as u32) + source!(self, item.span).lo()); let block_indent = self.block_indent; - let rw = self - .with_context(|ctx| format_impl(&ctx, item, block_indent, where_span_end)); + let rw = self.with_context(|ctx| format_impl(&ctx, item, block_indent)); self.push_rewrite(item.span, rw); } ast::ItemKind::Trait(..) => {