Skip to content

Commit 1ae2d41

Browse files
committed
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.
1 parent 81c8c02 commit 1ae2d41

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ mod test {
354354
check("/* comment */ some text /* more commentary */ result", "result", Some(46));
355355
check("sup // sup", "p", Some(2));
356356
check("sup", "x", None);
357-
check("π? /**/ π is nice!", "π is nice", Some(9));
357+
check(r#"π? /**/ π is nice!"#, r#"π is nice"#, Some(9));
358358
check("/*sup yo? \n sup*/ sup", "p", Some(20));
359359
check("hel/*lohello*/lo", "hello", None);
360360
check("acb", "ab", None);

src/expr.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use types::rewrite_path;
2020
use items::{span_lo_for_arg, span_hi_for_arg, rewrite_fn_input};
2121

2222
use syntax::{ast, ptr};
23-
use syntax::codemap::{CodeMap, Pos, Span, BytePos, mk_sp};
23+
use syntax::codemap::{CodeMap, Span, BytePos, mk_sp};
2424
use syntax::visit::Visitor;
2525

2626
impl Rewrite for ast::Expr {
@@ -831,13 +831,7 @@ fn rewrite_string_lit(context: &RewriteContext,
831831
if context.config.format_strings == false {
832832
return Some(context.snippet(span));
833833
}
834-
// Check if there is anything to fix: we always try to fixup multi-line
835-
// strings, or if the string is too long for the line.
836-
let l_loc = context.codemap.lookup_char_pos(span.lo);
837-
let r_loc = context.codemap.lookup_char_pos(span.hi);
838-
if l_loc.line == r_loc.line && r_loc.col.to_usize() <= context.config.max_width {
839-
return Some(context.snippet(span));
840-
}
834+
841835
let fmt = StringFormat {
842836
opener: "\"",
843837
closer: "\"",

tests/source/string-lit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ not
2222
remove
2323
formatting"#;
2424

25+
let xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx =
26+
funktion("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy");
27+
2528
"stuff"
2629
}

tests/target/string-lit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@ not
2525
remove
2626
formatting"#;
2727

28+
let xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = funktion("yyyyyyyyyyyyyyyyyyyyy\
29+
yyyyyyyyyyyyyyyyyyyyy\
30+
yyyyyyyyyyyyyyyyyyyyy\
31+
yyyyyyyyyy");
32+
2833
"stuff"
2934
}

0 commit comments

Comments
 (0)