Skip to content

Commit 5f7bd57

Browse files
authored
Document when errors should have an associated error code (#967)
Document when errors should have an associated error code
1 parent b5af9f0 commit 5f7bd57

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: src/diagnostics.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,23 @@ example of how to trigger it and advice on how to fix it.
7070
Please read [RFC 1567] for details on how to format and write long error
7171
codes.
7272

73-
The descriptions are written in markdown, and all of them are linked in the
73+
The descriptions are written in Markdown, and all of them are linked in the
7474
[`rustc_error_codes`] crate.
7575

76-
TODO: When should an error use an error code, and when shouldn't it?
76+
As a general rule, give an error a code (with an associated explanation) if the
77+
explanation would give more information than the error itself. A lot of the time
78+
it's better to put all the information in the emitted error itself. However,
79+
sometimes that would make the error verbose or there are too many possible
80+
triggers to include useful information for all cases in the error, in which case
81+
it's a good idea to add an explanation.[^estebank]
82+
As always, if you are not sure, just ask your reviewer!
83+
84+
[^estebank]: This rule of thumb was suggested by **@estebank** [here][estebank-comment].
7785

7886
[`rustc_error_codes`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_error_codes/error_codes/index.html
7987
[error index]: https://doc.rust-lang.org/error-index.html
8088
[RFC 1567]: https://github.com/rust-lang/rfcs/blob/master/text/1567-long-error-codes-explanation-normalization.md
89+
[estebank-comment]: https://github.com/rust-lang/rustc-dev-guide/pull/967#issuecomment-733218283
8190

8291
### Lints versus fixed diagnostics
8392

0 commit comments

Comments
 (0)