From 4cb474b5ee1bbc8b771cc2a2d88944c06aaaf0f6 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 24 Nov 2017 14:07:37 +1300 Subject: [PATCH] Remove `force_format_strings` in favour of `format_strings` --- Configurations.md | 13 +------- src/config.rs | 1 - src/expr.rs | 31 +------------------ .../configs-force_format_strings-false.rs | 9 ------ .../configs-force_format_strings-true.rs | 8 ----- tests/source/long-match-arms-brace-newline.rs | 1 - tests/source/string-lit.rs | 2 +- .../configs-force_format_strings-false.rs | 9 ------ .../configs-force_format_strings-true.rs | 10 ------ tests/target/long-match-arms-brace-newline.rs | 1 - tests/target/string-lit.rs | 2 +- 11 files changed, 4 insertions(+), 83 deletions(-) delete mode 100644 tests/source/configs-force_format_strings-false.rs delete mode 100644 tests/source/configs-force_format_strings-true.rs delete mode 100644 tests/target/configs-force_format_strings-false.rs delete mode 100644 tests/target/configs-force_format_strings-true.rs diff --git a/Configurations.md b/Configurations.md index 6f56ce6b8bc..946689e940b 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1017,17 +1017,6 @@ extern { } ``` -## `force_format_strings` - -Always format string literals - -- **Default value**: `false` -- **Possible values**: `true`, `false` - -See [`format_strings`](#format_strings). - -See also [`max_width`](#max_width). - ## `format_strings` Format string literals where necessary @@ -1049,7 +1038,7 @@ let lorem = adipiscing elit lorem ipsum dolor sit"; ``` -See also [`force_format_strings`](#force_format_strings), [`max_width`](#max_width). +See also [`max_width`](#max_width). ## `hard_tabs` diff --git a/src/config.rs b/src/config.rs index 59818f237c8..75fff0131f4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -584,7 +584,6 @@ create_config! { expressions. A value of zero means always break \ if-else expressions."; format_strings: bool, false, false, "Format string literals where necessary"; - force_format_strings: bool, false, false, "Always format string literals"; hard_tabs: bool, false, false, "Use tab characters for indentation, spaces for alignment"; wrap_comments: bool, false, false, "Break comments to fit on the line"; comment_width: usize, 80, false, diff --git a/src/expr.rs b/src/expr.rs index f483736855d..ad8cb25b53f 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1739,7 +1739,7 @@ pub fn rewrite_literal(context: &RewriteContext, l: &ast::Lit, shape: Shape) -> fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Option { let string_lit = context.snippet(span); - if !context.config.format_strings() && !context.config.force_format_strings() { + if !context.config.format_strings() { if string_lit .lines() .rev() @@ -1767,12 +1767,6 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt } } - if !context.config.force_format_strings() - && !string_requires_rewrite(context, span, &string_lit, shape) - { - return wrap_str(string_lit, context.config.max_width(), shape); - } - // Remove the quote characters. let str_lit = &string_lit[1..string_lit.len() - 1]; @@ -1783,29 +1777,6 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt ) } -fn string_requires_rewrite( - context: &RewriteContext, - span: Span, - string: &str, - shape: Shape, -) -> bool { - if context.codemap.lookup_char_pos(span.lo()).col.0 != shape.indent.width() { - return true; - } - - for (i, line) in string.lines().enumerate() { - if i == 0 { - if line.len() > shape.width { - return true; - } - } else if line.len() > shape.width + shape.indent.width() { - return true; - } - } - - false -} - pub fn rewrite_call( context: &RewriteContext, callee: &str, diff --git a/tests/source/configs-force_format_strings-false.rs b/tests/source/configs-force_format_strings-false.rs deleted file mode 100644 index 49f32c557b3..00000000000 --- a/tests/source/configs-force_format_strings-false.rs +++ /dev/null @@ -1,9 +0,0 @@ -// rustfmt-force_format_strings: false -// rustfmt-format_strings: false -// rustfmt-max_width: 50 -// rustfmt-error_on_line_overflow: false -// Force format strings - -fn main() { - let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit"; -} diff --git a/tests/source/configs-force_format_strings-true.rs b/tests/source/configs-force_format_strings-true.rs deleted file mode 100644 index 7a87bed4d15..00000000000 --- a/tests/source/configs-force_format_strings-true.rs +++ /dev/null @@ -1,8 +0,0 @@ -// rustfmt-force_format_strings: true -// rustfmt-format_strings: false -// rustfmt-max_width: 50 -// Force format strings - -fn main() { - let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit"; -} diff --git a/tests/source/long-match-arms-brace-newline.rs b/tests/source/long-match-arms-brace-newline.rs index bc5c9deef68..927ada0ffb2 100644 --- a/tests/source/long-match-arms-brace-newline.rs +++ b/tests/source/long-match-arms-brace-newline.rs @@ -1,5 +1,4 @@ // rustfmt-format_strings: true -// rustfmt-force_format_strings: true // rustfmt-max_width: 80 // rustfmt-control_brace_style: AlwaysNextLine diff --git a/tests/source/string-lit.rs b/tests/source/string-lit.rs index b282656d470..e86f65f9f52 100644 --- a/tests/source/string-lit.rs +++ b/tests/source/string-lit.rs @@ -1,4 +1,4 @@ -// rustfmt-force_format_strings: true +// rustfmt-format_strings: true // rustfmt-error_on_line_overflow: false // Long string literals diff --git a/tests/target/configs-force_format_strings-false.rs b/tests/target/configs-force_format_strings-false.rs deleted file mode 100644 index 49f32c557b3..00000000000 --- a/tests/target/configs-force_format_strings-false.rs +++ /dev/null @@ -1,9 +0,0 @@ -// rustfmt-force_format_strings: false -// rustfmt-format_strings: false -// rustfmt-max_width: 50 -// rustfmt-error_on_line_overflow: false -// Force format strings - -fn main() { - let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit"; -} diff --git a/tests/target/configs-force_format_strings-true.rs b/tests/target/configs-force_format_strings-true.rs deleted file mode 100644 index 49ba3e7d46c..00000000000 --- a/tests/target/configs-force_format_strings-true.rs +++ /dev/null @@ -1,10 +0,0 @@ -// rustfmt-force_format_strings: true -// rustfmt-format_strings: false -// rustfmt-max_width: 50 -// Force format strings - -fn main() { - let lorem = "ipsum dolor sit amet \ - consectetur adipiscing elit \ - lorem ipsum dolor sit"; -} diff --git a/tests/target/long-match-arms-brace-newline.rs b/tests/target/long-match-arms-brace-newline.rs index da82d971593..aeb384e7203 100644 --- a/tests/target/long-match-arms-brace-newline.rs +++ b/tests/target/long-match-arms-brace-newline.rs @@ -1,5 +1,4 @@ // rustfmt-format_strings: true -// rustfmt-force_format_strings: true // rustfmt-max_width: 80 // rustfmt-control_brace_style: AlwaysNextLine diff --git a/tests/target/string-lit.rs b/tests/target/string-lit.rs index 97cf0213a16..f60002ac618 100644 --- a/tests/target/string-lit.rs +++ b/tests/target/string-lit.rs @@ -1,4 +1,4 @@ -// rustfmt-force_format_strings: true +// rustfmt-format_strings: true // rustfmt-error_on_line_overflow: false // Long string literals