Skip to content

Commit 74563b4

Browse files
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.
1 parent 6187684 commit 74563b4

File tree

7 files changed

+57
-26
lines changed

7 files changed

+57
-26
lines changed

src/librustc/error_codes.rs

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

src/librustc_metadata/error_codes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,6 @@ register_diagnostics! {
9797
E0464, // multiple matching crates for `..`
9898
E0465, // multiple .. candidates for `..` found
9999
E0519, // local crate and dependency have same (crate-name, disambiguator)
100-
E0523, // two dependencies have same (crate-name, disambiguator) but different SVH
100+
// two dependencies have same (crate-name, disambiguator) but different SVH
101+
E0523,
101102
}

src/librustc_typeck/error_codes.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4930,15 +4930,16 @@ register_diagnostics! {
49304930
// E0245, // not a trait
49314931
// E0246, // invalid recursive type
49324932
// E0247,
4933-
// E0248, // value used as a type, now reported earlier during resolution as E0412
4933+
// E0248, // value used as a type, now reported earlier during resolution
4934+
// as E0412
49344935
// E0249,
49354936
// E0319, // trait impls for defaulted traits allowed just for structs/enums
49364937
// E0372, // coherence not object safe
49374938
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
49384939
// between structures with the same definition
49394940
// E0558, // replaced with a generic attribute input check
49404941
E0533, // `{}` does not name a unit variant, unit struct or a constant
4941-
// E0563, // cannot determine a type for this `impl Trait`: {} // removed in 6383de15
4942+
// E0563, // cannot determine a type for this `impl Trait` removed in 6383de15
49424943
E0564, // only named lifetimes are allowed in `impl Trait`,
49434944
// but `{}` was found in the type `{}`
49444945
E0587, // type has conflicting packed and align representation hints
@@ -4947,8 +4948,8 @@ register_diagnostics! {
49474948
// E0612, // merged into E0609
49484949
// E0613, // Removed (merged with E0609)
49494950
E0627, // yield statement outside of generator literal
4950-
E0632, // cannot provide explicit type parameters when `impl Trait` is used in
4951-
// argument position.
4951+
E0632, // cannot provide explicit type parameters when `impl Trait` is used
4952+
// in argument position.
49524953
E0634, // type has conflicting packed representaton hints
49534954
E0640, // infer outlives requirements
49544955
E0641, // cannot cast to/from a pointer with an unknown kind

src/libsyntax/error_codes.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Error messages for EXXXX errors.
2-
// Each message should start and end with a new line, and be wrapped to 80 characters.
3-
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
4-
register_long_diagnostics! {
2+
// Each message should start and end with a new line, and be wrapped to 80
3+
// characters. In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use
4+
// `:set tw=0` to disable.
5+
register_diagnostics! {
56

67
E0178: r##"
78
In types, the `+` type operator has low precedence, so it is often necessary
@@ -432,15 +433,19 @@ register_diagnostics! {
432433
E0546, // missing 'feature'
433434
E0547, // missing 'issue'
434435
// E0548, // replaced with a generic attribute input check
435-
E0549, // rustc_deprecated attribute must be paired with either stable or unstable attribute
436+
// rustc_deprecated attribute must be paired with either stable or unstable
437+
// attribute
438+
E0549,
436439
E0550, // multiple deprecated attributes
437440
E0551, // incorrect meta item
438441
E0553, // multiple rustc_const_unstable attributes
439442
// E0555, // replaced with a generic attribute input check
440443
E0556, // malformed feature, expected just one word
441444
E0584, // file for module `..` found at both .. and ..
442445
E0629, // missing 'feature' (rustc_const_unstable)
443-
E0630, // rustc_const_unstable attribute must be paired with stable/unstable attribute
446+
// rustc_const_unstable attribute must be paired with stable/unstable
447+
// attribute
448+
E0630,
444449
E0693, // incorrect `repr(align)` attribute format
445450
E0694, // an unknown tool name found in scoped attributes
446451
E0703, // invalid ABI

src/libsyntax/feature_gate/removed.rs

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ declare_features! (
9494
/// Allows defining `existential type`s.
9595
(removed, existential_type, "1.38.0", Some(63063), None,
9696
Some("removed in favor of `#![feature(type_alias_impl_trait)]`")),
97+
/// Allows using the macros:
98+
/// + `__diagnostic_used`
99+
/// + `__register_diagnostic`
100+
/// +`__build_diagnostic_array`
101+
(removed, rustc_diagnostic_macros, "1.38.0", None, None, None),
97102

98103
// -------------------------------------------------------------------------
99104
// feature-group-end: removed features

src/libsyntax_ext/error_codes.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use syntax::register_long_diagnostics;
22

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

src/tools/tidy/src/style.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
1616
use std::path::Path;
1717

18+
const ERROR_CODE_COLS: usize = 80;
1819
const COLS: usize = 100;
1920

2021
const LINES: usize = 3000;
@@ -51,7 +52,13 @@ enum LIUState {
5152
/// Lines of this form are allowed to be overlength, because Markdown
5253
/// offers no way to split a line in the middle of a URL, and the lengths
5354
/// of URLs to external references are beyond our control.
54-
fn line_is_url(line: &str) -> bool {
55+
fn line_is_url(columns: usize, line: &str) -> bool {
56+
// more basic check for error_codes.rs, to avoid complexity in implementing two state machines
57+
if columns == ERROR_CODE_COLS {
58+
return line.starts_with("[") &&
59+
line.contains("]:") && line.contains("http");
60+
}
61+
5562
use self::LIUState::*;
5663
let mut state: LIUState = EXP_COMMENT_START;
5764
let is_url = |w: &str| w.starts_with("http://") || w.starts_with("https://");
@@ -75,7 +82,7 @@ fn line_is_url(line: &str) -> bool {
7582
=> state = EXP_END,
7683

7784
(_, w)
78-
if w.len() > COLS && is_url(w)
85+
if w.len() > columns && is_url(w)
7986
=> state = EXP_END,
8087

8188
(_, _) => {}
@@ -88,8 +95,8 @@ fn line_is_url(line: &str) -> bool {
8895
/// Returns `true` if `line` is allowed to be longer than the normal limit.
8996
/// Currently there is only one exception, for long URLs, but more
9097
/// may be added in the future.
91-
fn long_line_is_ok(line: &str) -> bool {
92-
if line_is_url(line) {
98+
fn long_line_is_ok(max_columns: usize, line: &str) -> bool {
99+
if line_is_url(max_columns, line) {
93100
return true;
94101
}
95102

@@ -144,6 +151,12 @@ pub fn check(path: &Path, bad: &mut bool) {
144151
tidy_error!(bad, "{}: empty file", file.display());
145152
}
146153

154+
let max_columns = if filename == "error_codes.rs" {
155+
ERROR_CODE_COLS
156+
} else {
157+
COLS
158+
};
159+
147160
let can_contain = contents.contains("// ignore-tidy-") ||
148161
contents.contains("# ignore-tidy-");
149162
let mut skip_cr = contains_ignore_directive(can_contain, &contents, "cr");
@@ -162,11 +175,12 @@ pub fn check(path: &Path, bad: &mut bool) {
162175
let mut err = |msg: &str| {
163176
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
164177
};
165-
if line.chars().count() > COLS && !long_line_is_ok(line) {
178+
if line.chars().count() > max_columns &&
179+
!long_line_is_ok(max_columns, line) {
166180
suppressible_tidy_err!(
167181
err,
168182
skip_line_length,
169-
&format!("line longer than {} chars", COLS)
183+
&format!("line longer than {} chars", max_columns)
170184
);
171185
}
172186
if line.contains('\t') {

0 commit comments

Comments
 (0)