diff options
| author | Nick Cameron <nrc@ncameron.org> | 2017-09-19 07:46:32 +1200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-19 07:46:32 +1200 |
| commit | 8974f89381cffd73c35b0cb91eb4e49a66f93d5c (patch) | |
| tree | 27c06609b252aca7012093f93749255c6421a734 /src | |
| parent | c313fb1ddc34ab76db03fe23b48285348ae22b3e (diff) | |
| parent | 18cd19673d330111a4856640783a2efaf9b9e3f2 (diff) | |
Merge pull request #1980 from topecongiro/less-recover_comment_removed
Run recover_comment_removed() only if the text changed after format
Diffstat (limited to 'src')
| -rw-r--r-- | src/comment.rs | 10 | ||||
| -rw-r--r-- | src/expr.rs | 6 | ||||
| -rw-r--r-- | src/items.rs | 4 |
3 files changed, 7 insertions, 13 deletions
diff --git a/src/comment.rs b/src/comment.rs index 32f46e195c1..953060be226 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -18,7 +18,7 @@ use {Indent, Shape}; use config::Config; use rewrite::RewriteContext; use string::{rewrite_string, StringFormat}; -use utils::{first_line_width, last_line_width, wrap_str}; +use utils::{first_line_width, last_line_width}; fn is_custom_comment(comment: &str) -> bool { if !comment.starts_with("//") { @@ -823,13 +823,11 @@ pub fn recover_comment_removed( new: String, span: Span, context: &RewriteContext, - shape: Shape, ) -> Option<String> { let snippet = context.snippet(span); - if changed_comment_content(&snippet, &new) { - // We missed some comments - // Keep previous formatting if it satisfies the constrains - wrap_str(snippet, context.config.max_width(), shape) + if snippet != new && changed_comment_content(&snippet, &new) { + // We missed some comments. Keep the original text. + Some(snippet) } else { Some(new) } diff --git a/src/expr.rs b/src/expr.rs index 590360f0dbe..e1cf24cdf2b 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -328,7 +328,7 @@ pub fn format_expr( expr_rw .and_then(|expr_str| { - recover_comment_removed(expr_str, expr.span, context, shape) + recover_comment_removed(expr_str, expr.span, context) }) .and_then(|expr_str| { let attrs = outer_attributes(&expr.attrs); @@ -920,9 +920,7 @@ impl Rewrite for ast::Stmt { } ast::StmtKind::Mac(..) | ast::StmtKind::Item(..) => None, }; - result.and_then(|res| { - recover_comment_removed(res, self.span(), context, shape) - }) + result.and_then(|res| recover_comment_removed(res, self.span(), context)) } } diff --git a/src/items.rs b/src/items.rs index 344c7e57af1..13c669d698f 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1488,9 +1488,7 @@ pub fn rewrite_static( lhs, expr, Shape::legacy(remaining_width, offset.block_only()), - ).and_then(|res| { - recover_comment_removed(res, span, context, Shape::indented(offset, context.config)) - }) + ).and_then(|res| recover_comment_removed(res, span, context)) .map(|s| if s.ends_with(';') { s } else { s + ";" }) } else { Some(format!("{}{};", prefix, ty_str)) |
