Restrict error code length to 80 columns

The global restriction is 100, but since error codes are printed out via
--explain we want to restrict them to just 80 columns.
This commit is contained in:
Mark Rousskov 2019-09-03 21:25:06 -04:00
parent 618768492f
commit 74563b4166
7 changed files with 57 additions and 26 deletions

View file

@ -1,7 +1,8 @@
// Error messages for EXXXX errors.
// Each message should start and end with a new line, and be wrapped to 80 characters.
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
register_long_diagnostics! {
// Each message should start and end with a new line, and be wrapped to 80
// characters. In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use
// `:set tw=0` to disable.
syntax::register_diagnostics! {
E0038: r##"
Trait objects like `Box<Trait>` can only be constructed when certain
requirements are satisfied by the trait in question.
@ -2206,7 +2207,8 @@ register_diagnostics! {
// E0305, // expected constant
E0311, // thing may not live long enough
E0312, // lifetime of reference outlives lifetime of borrowed content
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable
E0313, // lifetime of borrowed pointer outlives lifetime of captured
// variable
E0314, // closure outlives stack frame
E0315, // cannot invoke closure outside of its lifetime
E0316, // nested quantification of lifetimes
@ -2223,12 +2225,13 @@ register_diagnostics! {
E0483, // lifetime of operand does not outlive the operation
E0484, // reference is not valid at the time of borrow
E0485, // automatically reference is not valid at the time of borrow
E0486, // type of expression contains references that are not valid during...
E0486, // type of expression contains references that are not valid during..
E0487, // unsafe use of destructor: destructor might be called while...
E0488, // lifetime of variable does not enclose its declaration
E0489, // type/lifetime parameter not in scope here
E0490, // a value of type `..` is borrowed for too long
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
E0495, // cannot infer an appropriate lifetime due to conflicting
// requirements
E0566, // conflicting representation hints
E0623, // lifetime mismatch where both parameters are anonymous regions
E0628, // generators cannot have explicit parameters
@ -2239,7 +2242,8 @@ register_diagnostics! {
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
E0697, // closures cannot be static
E0707, // multiple elided lifetimes used in arguments of `async fn`
E0708, // `async` non-`move` closures with parameters are not currently supported
E0708, // `async` non-`move` closures with parameters are not currently
// supported
E0709, // multiple different lifetimes used in arguments of `async fn`
E0710, // an unknown tool name found in scoped lint
E0711, // a feature has been declared with conflicting stability attributes

View file

@ -97,5 +97,6 @@ register_diagnostics! {
E0464, // multiple matching crates for `..`
E0465, // multiple .. candidates for `..` found
E0519, // local crate and dependency have same (crate-name, disambiguator)
E0523, // two dependencies have same (crate-name, disambiguator) but different SVH
// two dependencies have same (crate-name, disambiguator) but different SVH
E0523,
}

View file

@ -4930,7 +4930,8 @@ register_diagnostics! {
// E0245, // not a trait
// E0246, // invalid recursive type
// E0247,
// E0248, // value used as a type, now reported earlier during resolution as E0412
// E0248, // value used as a type, now reported earlier during resolution
// as E0412
// E0249,
// E0319, // trait impls for defaulted traits allowed just for structs/enums
// E0372, // coherence not object safe
@ -4938,7 +4939,7 @@ register_diagnostics! {
// between structures with the same definition
// E0558, // replaced with a generic attribute input check
E0533, // `{}` does not name a unit variant, unit struct or a constant
// E0563, // cannot determine a type for this `impl Trait`: {} // removed in 6383de15
// E0563, // cannot determine a type for this `impl Trait` removed in 6383de15
E0564, // only named lifetimes are allowed in `impl Trait`,
// but `{}` was found in the type `{}`
E0587, // type has conflicting packed and align representation hints
@ -4947,8 +4948,8 @@ register_diagnostics! {
// E0612, // merged into E0609
// E0613, // Removed (merged with E0609)
E0627, // yield statement outside of generator literal
E0632, // cannot provide explicit type parameters when `impl Trait` is used in
// argument position.
E0632, // cannot provide explicit type parameters when `impl Trait` is used
// in argument position.
E0634, // type has conflicting packed representaton hints
E0640, // infer outlives requirements
E0641, // cannot cast to/from a pointer with an unknown kind

View file

@ -1,7 +1,8 @@
// Error messages for EXXXX errors.
// Each message should start and end with a new line, and be wrapped to 80 characters.
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
register_long_diagnostics! {
// Each message should start and end with a new line, and be wrapped to 80
// characters. In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use
// `:set tw=0` to disable.
register_diagnostics! {
E0178: r##"
In types, the `+` type operator has low precedence, so it is often necessary
@ -432,7 +433,9 @@ register_diagnostics! {
E0546, // missing 'feature'
E0547, // missing 'issue'
// E0548, // replaced with a generic attribute input check
E0549, // rustc_deprecated attribute must be paired with either stable or unstable attribute
// rustc_deprecated attribute must be paired with either stable or unstable
// attribute
E0549,
E0550, // multiple deprecated attributes
E0551, // incorrect meta item
E0553, // multiple rustc_const_unstable attributes
@ -440,7 +443,9 @@ register_diagnostics! {
E0556, // malformed feature, expected just one word
E0584, // file for module `..` found at both .. and ..
E0629, // missing 'feature' (rustc_const_unstable)
E0630, // rustc_const_unstable attribute must be paired with stable/unstable attribute
// rustc_const_unstable attribute must be paired with stable/unstable
// attribute
E0630,
E0693, // incorrect `repr(align)` attribute format
E0694, // an unknown tool name found in scoped attributes
E0703, // invalid ABI

View file

@ -94,6 +94,11 @@ declare_features! (
/// Allows defining `existential type`s.
(removed, existential_type, "1.38.0", Some(63063), None,
Some("removed in favor of `#![feature(type_alias_impl_trait)]`")),
/// Allows using the macros:
/// + `__diagnostic_used`
/// + `__register_diagnostic`
/// +`__build_diagnostic_array`
(removed, rustc_diagnostic_macros, "1.38.0", None, None, None),
// -------------------------------------------------------------------------
// feature-group-end: removed features

View file

@ -1,9 +1,10 @@
use syntax::register_long_diagnostics;
// Error messages for EXXXX errors.
// Each message should start and end with a new line, and be wrapped to 80 characters.
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
register_long_diagnostics! {
// Each message should start and end with a new line, and be wrapped to 80
// characters. In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use
// `:set tw=0` to disable.
syntax::register_diagnostics! {
E0660: r##"
The argument to the `asm` macro is not well-formed.

View file

@ -15,6 +15,7 @@
use std::path::Path;
const ERROR_CODE_COLS: usize = 80;
const COLS: usize = 100;
const LINES: usize = 3000;
@ -51,7 +52,13 @@ enum LIUState {
/// Lines of this form are allowed to be overlength, because Markdown
/// offers no way to split a line in the middle of a URL, and the lengths
/// of URLs to external references are beyond our control.
fn line_is_url(line: &str) -> bool {
fn line_is_url(columns: usize, line: &str) -> bool {
// more basic check for error_codes.rs, to avoid complexity in implementing two state machines
if columns == ERROR_CODE_COLS {
return line.starts_with("[") &&
line.contains("]:") && line.contains("http");
}
use self::LIUState::*;
let mut state: LIUState = EXP_COMMENT_START;
let is_url = |w: &str| w.starts_with("http://") || w.starts_with("https://");
@ -75,7 +82,7 @@ fn line_is_url(line: &str) -> bool {
=> state = EXP_END,
(_, w)
if w.len() > COLS && is_url(w)
if w.len() > columns && is_url(w)
=> state = EXP_END,
(_, _) => {}
@ -88,8 +95,8 @@ fn line_is_url(line: &str) -> bool {
/// Returns `true` if `line` is allowed to be longer than the normal limit.
/// Currently there is only one exception, for long URLs, but more
/// may be added in the future.
fn long_line_is_ok(line: &str) -> bool {
if line_is_url(line) {
fn long_line_is_ok(max_columns: usize, line: &str) -> bool {
if line_is_url(max_columns, line) {
return true;
}
@ -144,6 +151,12 @@ pub fn check(path: &Path, bad: &mut bool) {
tidy_error!(bad, "{}: empty file", file.display());
}
let max_columns = if filename == "error_codes.rs" {
ERROR_CODE_COLS
} else {
COLS
};
let can_contain = contents.contains("// ignore-tidy-") ||
contents.contains("# ignore-tidy-");
let mut skip_cr = contains_ignore_directive(can_contain, &contents, "cr");
@ -162,11 +175,12 @@ pub fn check(path: &Path, bad: &mut bool) {
let mut err = |msg: &str| {
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
};
if line.chars().count() > COLS && !long_line_is_ok(line) {
if line.chars().count() > max_columns &&
!long_line_is_ok(max_columns, line) {
suppressible_tidy_err!(
err,
skip_line_length,
&format!("line longer than {} chars", COLS)
&format!("line longer than {} chars", max_columns)
);
}
if line.contains('\t') {