1 Don't forget the user. Whether human or another program, such as an IDE, a
2 good user experience with the compiler goes a long way into making developer
3 lives better. We don't want users to be baffled by compiler output or
4 learn arcane patterns to compile their program.
6 ## Error, Warning, Help, Note Messages
8 When the compiler detects a problem, it can emit either an error, warning,
11 An `error` is emitted when the compiler detects a problem that makes it unable
12 to compile the program, either because the program is invalid or the
13 programmer has decided to make a specific `warning` into an error.
15 A `warning` is emitted when the compiler detects something odd about a
16 program. For instance, dead code and unused `Result` values.
18 A `help` is emitted following either an `error` or `warning` giving extra
19 information to the user about how to solve their problem.
21 A `note` is for identifying additional circumstances and parts of the code
22 that lead to a warning or error. For example, the borrow checker will note any
23 previous conflicting borrows.
25 * Write in plain simple English. If your message, when shown on a – possibly
26 small – screen (which hasn't been cleaned for a while), cannot be understood
27 by a normal programmer, who just came out of bed after a night partying, it's
29 * `Errors` and `Warnings` should not suggest how to fix the problem. A `Help`
30 message should be emitted instead.
31 * `Error`, `Warning`, `Note`, and `Help` messages start with a lowercase
32 letter and do not end with punctuation.
33 * Error messages should be succinct. Users will see these error messages many
34 times, and more verbose descriptions can be viewed with the `--explain` flag.
35 That said, don't make it so terse that it's hard to understand.
36 * The word "illegal" is illegal. Prefer "invalid" or a more specific word
38 * Errors should document the span of code where they occur – the `span_..`
39 methods allow to easily do this. Also `note` other spans that have contributed
40 to the error if the span isn't too large.
41 * When emitting a message with span, try to reduce the span to the smallest
42 amount possible that still signifies the issue
43 * Try not to emit multiple error messages for the same error. This may require
45 * When the compiler has too little information for a specific error message,
46 lobby for annotations for library code that allow adding more. For example see
47 `#[on_unimplemented]`. Use these annotations when available!
48 * Keep in mind that Rust's learning curve is rather steep, and that the
49 compiler messages are an important learning tool.
53 Error explanations are long form descriptions of error messages provided with
54 the compiler. They are accessible via the `--explain` flag. Each explanation
55 comes with an example of how to trigger it and advice on how to fix it.
57 * All of them are accessible [online](https://github.com/rust-lang/rust/blob/master/src/librustc/diagnostics.rs).
58 * Explanations have full markdown support. Use it, especially to highlight
60 * When talking about the compiler, call it `the compiler`, not `Rust` or
65 * Flags should be orthogonal to each other. For example, if we'd have a
66 json-emitting variant of multiple actions `foo` and `bar`, an additional
67 --json flag is better than adding `--foo-json` and `--bar-json`.
68 * Always give options a long descriptive name, if only for better
69 understandable compiler scripts.
70 * The `--verbose` flag is for adding verbose information to `rustc` output
71 when not compiling a program. For example, using it with the `--version` flag
72 gives information about the hashes of the code.
73 * Experimental flags and options must be guarded behind the `-Z unstable-options` flag.