diff --git a/Configurations.md b/Configurations.md index 1c6a8048017a..ca804b2f7f25 100644 --- a/Configurations.md +++ b/Configurations.md @@ -579,9 +579,12 @@ Don't reformat anything ## `error_on_line_overflow` -Error if unable to get all lines within `max_width`, except for comments and string literals. +Error if Rustfmt is unable to get all lines within `max_width`, except for comments and string +literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by +refactoring your code to avoid long/complex expressions, usually by extracting a local variable or +using a shorter name. -- **Default value**: `true` +- **Default value**: `false` - **Possible values**: `true`, `false` - **Stable**: No diff --git a/src/config/mod.rs b/src/config/mod.rs index 6680c76aa647..7b96c2f671e1 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -134,7 +134,7 @@ create_config! { disable_all_formatting: bool, false, false, "Don't reformat anything"; skip_children: bool, false, false, "Don't reformat out of line modules"; hide_parse_errors: bool, false, false, "Hide errors from the parser"; - error_on_line_overflow: bool, true, false, "Error if unable to get all lines within max_width"; + error_on_line_overflow: bool, false, false, "Error if unable to get all lines within max_width"; error_on_unformatted: bool, false, false, "Error if unable to get comments or string literals within max_width, \ or they are left with trailing whitespaces"; diff --git a/src/lib.rs b/src/lib.rs index 6129dd494b93..9a7d0d2f8817 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,7 +101,7 @@ pub enum ErrorKind { LineOverflow(usize, usize), // Line ends in whitespace TrailingWhitespace, - // TO-DO or FIX-ME item without an issue number + // TODO or FIXME item without an issue number BadIssue(Issue), // License check has failed LicenseCheck, @@ -112,8 +112,8 @@ impl fmt::Display for ErrorKind { match *self { ErrorKind::LineOverflow(found, maximum) => write!( fmt, - "line exceeded maximum width (maximum: {}, found: {})", - maximum, found + "line formatted, but exceeded maximum width (maximum: {} (see `max_width` option), found: {})", + maximum, found, ), ErrorKind::TrailingWhitespace => write!(fmt, "left behind trailing whitespace"), ErrorKind::BadIssue(issue) => write!(fmt, "found {}", issue), @@ -134,10 +134,9 @@ pub struct FormattingError { impl FormattingError { fn msg_prefix(&self) -> &str { match self.kind { - ErrorKind::LineOverflow(..) - | ErrorKind::TrailingWhitespace - | ErrorKind::LicenseCheck => "error:", - ErrorKind::BadIssue(_) => "WARNING:", + ErrorKind::LineOverflow(..) | ErrorKind::TrailingWhitespace => "internal error:", + ErrorKind::LicenseCheck => "error:", + ErrorKind::BadIssue(_) => "warning:", } } diff --git a/tests/lib.rs b/tests/lib.rs index 3b73247f7f88..3e388af00224 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -283,7 +283,8 @@ fn stdin_formatting_smoke_test() { fn format_lines_errors_are_reported() { let long_identifier = String::from_utf8(vec![b'a'; 239]).unwrap(); let input = Input::Text(format!("fn {}() {{}}", long_identifier)); - let config = Config::default(); + let mut config = Config::default(); + config.set().error_on_line_overflow(true); let (error_summary, _file_map, _report) = format_input::(input, &config, None).unwrap(); assert!(error_summary.has_formatting_errors()); @@ -293,7 +294,9 @@ fn format_lines_errors_are_reported() { fn format_lines_errors_are_reported_with_tabs() { let long_identifier = String::from_utf8(vec![b'a'; 97]).unwrap(); let input = Input::Text(format!("fn a() {{\n\t{}\n}}", long_identifier)); - let config = Config::from_toml("hard_tabs = true", Path::new("")).unwrap(); + let mut config = Config::default(); + config.set().error_on_line_overflow(true); + config.set().hard_tabs(true); let (error_summary, _file_map, _report) = format_input::(input, &config, None).unwrap(); assert!(error_summary.has_formatting_errors());