7373The descriptions are written in markdown, and all of them are linked in the
7474[ ` librustc_error_codes ` ] crate.
7575
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?
7777
7878[ `librustc_error_codes` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_error_codes/error_codes/index.html
7979[ 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
8282### Lints versus fixed diagnostics
8383
8484Some 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.
8687
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.
9091
9192See the ` deny ` [ lint level] ( #diagnostic-levels ) below for guidelines when to
9293use an error-level lint instead of a fixed error.
@@ -104,16 +105,18 @@ use an error-level lint instead of a fixed error.
104105 flag. That said, don't make it so terse that it's hard to understand.
105106- The word "illegal" is illegal. Prefer "invalid" or a more specific word
106107 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_* `
108110 methods allow to easily do this. Also ` note ` other spans that have
109111 contributed to the error if the span isn't too large.
110112- When emitting a message with span, try to reduce the span to the smallest
111113 amount possible that still signifies the issue
112114- Try not to emit multiple error messages for the same error. This may require
113115 detecting duplicates.
114116- 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
117120 annotations when available!
118121- Keep in mind that Rust's learning curve is rather steep, and that the
119122 compiler messages are an important learning tool.
@@ -183,9 +186,13 @@ Guidelines for different diagnostic levels:
183186 rustfmt.
184187
185188- ` 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.
189196
190197- ` note ` : emitted to identify additional circumstances and parts of the code
191198 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:
215222More information about lint levels can be found in the [ rustc
216223book] [ rustc-lint-levels ] and the [ reference] [ reference-diagnostics ] .
217224
225+ [ `rustc_errors::Applicability` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/enum.Applicability.html
218226[ reference-diagnostics ] : https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#lint-check-attributes
219227[ rustc-lint-levels ] : https://doc.rust-lang.org/nightly/rustc/lints/levels.html
220228
0 commit comments