Remove force_format_strings in favour of format_strings

This commit is contained in:
Nick Cameron 2017-11-24 14:07:37 +13:00
parent 8a7b6b8806
commit 4cb474b5ee
11 changed files with 4 additions and 83 deletions

View File

@ -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`

View File

@ -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,

View File

@ -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<String> {
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,

View File

@ -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";
}

View File

@ -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";
}

View File

@ -1,5 +1,4 @@
// rustfmt-format_strings: true
// rustfmt-force_format_strings: true
// rustfmt-max_width: 80
// rustfmt-control_brace_style: AlwaysNextLine

View File

@ -1,4 +1,4 @@
// rustfmt-force_format_strings: true
// rustfmt-format_strings: true
// rustfmt-error_on_line_overflow: false
// Long string literals

View File

@ -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";
}

View File

@ -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";
}

View File

@ -1,5 +1,4 @@
// rustfmt-format_strings: true
// rustfmt-force_format_strings: true
// rustfmt-max_width: 80
// rustfmt-control_brace_style: AlwaysNextLine

View File

@ -1,4 +1,4 @@
// rustfmt-force_format_strings: true
// rustfmt-format_strings: true
// rustfmt-error_on_line_overflow: false
// Long string literals