Skip to content

Commit f146711

Browse files
committed
Make error_on_line_overflow false by default
And improve docs, the error message, etc. I think false is the better default since such errors should only occur due to a bug in Rustfmt and therefore most users should not be notified of it happening (although to be clear, it might be a 'bug' which only occurs with pathological input and therefore we won't fix it). The error has proven to be confusing and annoying in the past. Closes #1080
1 parent 48e5bc1 commit f146711

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

Configurations.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,12 @@ Don't reformat anything
579579

580580
## `error_on_line_overflow`
581581

582-
Error if unable to get all lines within `max_width`, except for comments and string literals.
582+
Error if Rustfmt is unable to get all lines within `max_width`, except for comments and string
583+
literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by
584+
refactoring your code to avoid long/complex expressions, usually by extracting a local variable or
585+
using a shorter name.
583586

584-
- **Default value**: `true`
587+
- **Default value**: `false`
585588
- **Possible values**: `true`, `false`
586589
- **Stable**: No
587590

src/config/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ create_config! {
134134
disable_all_formatting: bool, false, false, "Don't reformat anything";
135135
skip_children: bool, false, false, "Don't reformat out of line modules";
136136
hide_parse_errors: bool, false, false, "Hide errors from the parser";
137-
error_on_line_overflow: bool, true, false, "Error if unable to get all lines within max_width";
137+
error_on_line_overflow: bool, false, false, "Error if unable to get all lines within max_width";
138138
error_on_unformatted: bool, false, false,
139139
"Error if unable to get comments or string literals within max_width, \
140140
or they are left with trailing whitespaces";

src/lib.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub enum ErrorKind {
101101
LineOverflow(usize, usize),
102102
// Line ends in whitespace
103103
TrailingWhitespace,
104-
// TO-DO or FIX-ME item without an issue number
104+
// TODO or FIXME item without an issue number
105105
BadIssue(Issue),
106106
// License check has failed
107107
LicenseCheck,
@@ -112,8 +112,8 @@ impl fmt::Display for ErrorKind {
112112
match *self {
113113
ErrorKind::LineOverflow(found, maximum) => write!(
114114
fmt,
115-
"line exceeded maximum width (maximum: {}, found: {})",
116-
maximum, found
115+
"line formatted, but exceeded maximum width (maximum: {} (see `max_width` option), found: {})",
116+
maximum, found,
117117
),
118118
ErrorKind::TrailingWhitespace => write!(fmt, "left behind trailing whitespace"),
119119
ErrorKind::BadIssue(issue) => write!(fmt, "found {}", issue),
@@ -134,10 +134,9 @@ pub struct FormattingError {
134134
impl FormattingError {
135135
fn msg_prefix(&self) -> &str {
136136
match self.kind {
137-
ErrorKind::LineOverflow(..)
138-
| ErrorKind::TrailingWhitespace
139-
| ErrorKind::LicenseCheck => "error:",
140-
ErrorKind::BadIssue(_) => "WARNING:",
137+
ErrorKind::LineOverflow(..) | ErrorKind::TrailingWhitespace => "internal error:",
138+
ErrorKind::LicenseCheck => "error:",
139+
ErrorKind::BadIssue(_) => "warning:",
141140
}
142141
}
143142

tests/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ fn stdin_formatting_smoke_test() {
283283
fn format_lines_errors_are_reported() {
284284
let long_identifier = String::from_utf8(vec![b'a'; 239]).unwrap();
285285
let input = Input::Text(format!("fn {}() {{}}", long_identifier));
286-
let config = Config::default();
286+
let mut config = Config::default();
287+
config.set().error_on_line_overflow(true);
287288
let (error_summary, _file_map, _report) =
288289
format_input::<io::Stdout>(input, &config, None).unwrap();
289290
assert!(error_summary.has_formatting_errors());
@@ -293,7 +294,9 @@ fn format_lines_errors_are_reported() {
293294
fn format_lines_errors_are_reported_with_tabs() {
294295
let long_identifier = String::from_utf8(vec![b'a'; 97]).unwrap();
295296
let input = Input::Text(format!("fn a() {{\n\t{}\n}}", long_identifier));
296-
let config = Config::from_toml("hard_tabs = true", Path::new("")).unwrap();
297+
let mut config = Config::default();
298+
config.set().error_on_line_overflow(true);
299+
config.set().hard_tabs(true);
297300
let (error_summary, _file_map, _report) =
298301
format_input::<io::Stdout>(input, &config, None).unwrap();
299302
assert!(error_summary.has_formatting_errors());

0 commit comments

Comments
 (0)