From 1ae2d417b88798dc94d60c59f67722e8d8d81f01 Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Tue, 1 Sep 2015 20:42:07 +0200 Subject: [PATCH] Remove faulty shortcut in `rewrite_string_lit` Rustfmt would leave the literal unchanged when it did not exceed the column limit in its original position, not considering its position after formatting. --- src/comment.rs | 2 +- src/expr.rs | 10 ++-------- tests/source/string-lit.rs | 3 +++ tests/target/string-lit.rs | 5 +++++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/comment.rs b/src/comment.rs index f692337cacc..e6e083d84bc 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -354,7 +354,7 @@ mod test { check("/* comment */ some text /* more commentary */ result", "result", Some(46)); check("sup // sup", "p", Some(2)); check("sup", "x", None); - check("π? /**/ π is nice!", "π is nice", Some(9)); + check(r#"π? /**/ π is nice!"#, r#"π is nice"#, Some(9)); check("/*sup yo? \n sup*/ sup", "p", Some(20)); check("hel/*lohello*/lo", "hello", None); check("acb", "ab", None); diff --git a/src/expr.rs b/src/expr.rs index 0945433319c..20c56ccd34f 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -20,7 +20,7 @@ use types::rewrite_path; use items::{span_lo_for_arg, span_hi_for_arg, rewrite_fn_input}; use syntax::{ast, ptr}; -use syntax::codemap::{CodeMap, Pos, Span, BytePos, mk_sp}; +use syntax::codemap::{CodeMap, Span, BytePos, mk_sp}; use syntax::visit::Visitor; impl Rewrite for ast::Expr { @@ -831,13 +831,7 @@ fn rewrite_string_lit(context: &RewriteContext, if context.config.format_strings == false { return Some(context.snippet(span)); } - // Check if there is anything to fix: we always try to fixup multi-line - // strings, or if the string is too long for the line. - let l_loc = context.codemap.lookup_char_pos(span.lo); - let r_loc = context.codemap.lookup_char_pos(span.hi); - if l_loc.line == r_loc.line && r_loc.col.to_usize() <= context.config.max_width { - return Some(context.snippet(span)); - } + let fmt = StringFormat { opener: "\"", closer: "\"", diff --git a/tests/source/string-lit.rs b/tests/source/string-lit.rs index 0c4a371df17..d7e57ea65c7 100644 --- a/tests/source/string-lit.rs +++ b/tests/source/string-lit.rs @@ -22,5 +22,8 @@ not remove formatting"#; + let xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = + funktion("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"); + "stuff" } diff --git a/tests/target/string-lit.rs b/tests/target/string-lit.rs index f90461030ac..2107d902e19 100644 --- a/tests/target/string-lit.rs +++ b/tests/target/string-lit.rs @@ -25,5 +25,10 @@ not remove formatting"#; + let xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = funktion("yyyyyyyyyyyyyyyyyyyyy\ + yyyyyyyyyyyyyyyyyyyyy\ + yyyyyyyyyyyyyyyyyyyyy\ + yyyyyyyyyy"); + "stuff" }