73
73
The descriptions are written in markdown, and all of them are linked in the
74
74
[ ` librustc_error_codes ` ] crate.
75
75
76
- <!-- TODO: When should an error use an error code, and when shouldn't it? -->
76
+ TODO: When should an error use an error code, and when shouldn't it?
77
77
78
78
[ `librustc_error_codes` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_error_codes/error_codes/index.html
79
79
[ error index ] : https://doc.rust-lang.org/error-index.html
@@ -82,11 +82,12 @@ The descriptions are written in markdown, and all of them are linked in the
82
82
### Lints versus fixed diagnostics
83
83
84
84
Some messages are emitted via [ lints] ( #lints ) , where the user can control the
85
- level. Some are hard-coded such that the user cannot control the level.
85
+ level. Most diagnostics are hard-coded such that the user cannot control the
86
+ level.
86
87
87
- Hard-coded warnings should be avoided for normal code, preferring to use lints
88
- instead. Some cases, such as warnings with CLI flags will require the use of
89
- hard-coded warnings.
88
+ Hard-coded warnings (those using the ` span_warn ` methods) should be avoided
89
+ for normal code, preferring to use lints instead. Some cases, such as warnings
90
+ with CLI flags, will require the use of hard-coded warnings.
90
91
91
92
See the ` deny ` [ lint level] ( #diagnostic-levels ) below for guidelines when to
92
93
use an error-level lint instead of a fixed error.
@@ -104,16 +105,18 @@ use an error-level lint instead of a fixed error.
104
105
flag. That said, don't make it so terse that it's hard to understand.
105
106
- The word "illegal" is illegal. Prefer "invalid" or a more specific word
106
107
instead.
107
- - Errors should document the span of code where they occur – the ` librustc_errors::diagnostic_builder::DiagnosticBuilder ` ` span_* `
108
+ - Errors should document the span of code where they occur – the
109
+ [ ` rustc_errors::diagnostic_builder::DiagnosticBuilder ` ] [ diagbuild ] ` span_* `
108
110
methods allow to easily do this. Also ` note ` other spans that have
109
111
contributed to the error if the span isn't too large.
110
112
- When emitting a message with span, try to reduce the span to the smallest
111
113
amount possible that still signifies the issue
112
114
- Try not to emit multiple error messages for the same error. This may require
113
115
detecting duplicates.
114
116
- When the compiler has too little information for a specific error message,
115
- lobby for annotations for library code that allow adding more. For example
116
- see [ ` #[rustc_on_unimplemented] ` ] ( #rustc_on_unimplemented ) . Use these
117
+ consult with the compiler team to add new attributes for library code that
118
+ allow adding more information. For example see
119
+ [ ` #[rustc_on_unimplemented] ` ] ( #rustc_on_unimplemented ) . Use these
117
120
annotations when available!
118
121
- Keep in mind that Rust's learning curve is rather steep, and that the
119
122
compiler messages are an important learning tool.
@@ -183,9 +186,13 @@ Guidelines for different diagnostic levels:
183
186
rustfmt.
184
187
185
188
- ` help ` : emitted following an ` error ` or ` warning ` to give additional
186
- information to the user about how to solve their problem. The error or
187
- warning portion should * not* suggest how to fix the problem, only the "help"
188
- sub-diagnostic should.
189
+ information to the user about how to solve their problem. These messages
190
+ often include a suggestion string and [ ` rustc_errors::Applicability ` ]
191
+ confidence level to guide automated source fixes by tools. See the
192
+ [ Suggestions] ( #suggestions ) section for more details.
193
+
194
+ The error or warning portion should * not* suggest how to fix the problem,
195
+ only the "help" sub-diagnostic should.
189
196
190
197
- ` note ` : emitted to identify additional circumstances and parts of the code
191
198
that caused the warning or error. For example, the borrow checker will note
@@ -215,6 +222,7 @@ Not to be confused with *lint levels*, whose guidelines are:
215
222
More information about lint levels can be found in the [ rustc
216
223
book] [ rustc-lint-levels ] and the [ reference] [ reference-diagnostics ] .
217
224
225
+ [ `rustc_errors::Applicability` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/enum.Applicability.html
218
226
[ reference-diagnostics ] : https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#lint-check-attributes
219
227
[ rustc-lint-levels ] : https://doc.rust-lang.org/nightly/rustc/lints/levels.html
220
228
0 commit comments