@@ -5,14 +5,17 @@ This chapter is about how to emit compile errors and lints from the compiler.
5
5
6
6
## ` Span `
7
7
8
- ` Span ` is the primary data structure in ` rustc ` used to represent a ___location in
9
- the code being compiled. ` Span ` s are attached to most constructs in HIR and MIR,
10
- allowing for easier error reporting whenever an error comes up.
8
+ [ ` Span ` ] [ span ] is the primary data structure in ` rustc ` used to represent a
9
+ ___location in the code being compiled. ` Span ` s are attached to most constructs in
10
+ HIR and MIR, allowing for easier error reporting whenever an error comes up.
11
11
12
- A ` Span ` can be looked up in a ` CodeMap ` to get a "snippet" useful for
13
- displaying errors with [ ` span_to_snippet ` and other similar methods] [ sptosnip ]
14
- on the ` CodeMap ` .
12
+ [ span ] : https://doc.rust-lang.org/nightly/nightly-rustc/syntax/codemap/struct.Span.html
15
13
14
+ A ` Span ` can be looked up in a [ ` CodeMap ` ] [ codemap ] to get a "snippet" useful
15
+ for displaying errors with [ ` span_to_snippet ` ] [ sptosnip ] and other similar
16
+ methods on the ` CodeMap ` .
17
+
18
+ [ codemap ] : https://doc.rust-lang.org/nightly/nightly-rustc/syntax/codemap/struct.CodeMap.html
16
19
[ sptosnip ] : https://doc.rust-lang.org/nightly/nightly-rustc/syntax/codemap/struct.CodeMap.html#method.span_to_snippet
17
20
18
21
## Error messages
@@ -70,14 +73,16 @@ err.emit();
70
73
## Suggestions
71
74
72
75
We would like to make edition transitions as smooth as possible. To that end,
73
- ` rustfix ` can use compiler suggestions to automatically fix code. For example,
74
- we could use ` rustfix ` to mechanically apply the ` qux ` suggestion from the
75
- previous example. However, not all suggestions are mechanically applicable. We
76
- use the [ ` span_suggestion_with_applicability ` ] [ sswa ] method of
77
- ` DiagnosticBuilder ` to inform the emitter of whether a suggestion is
78
- mechanically applicable or not. This information, in turn, is outputed by
79
- rustc when the error format is ` json ` , which is used by ` rustfix ` .
80
-
76
+ [ ` rustfix ` ] [ rustfix ] can use compiler suggestions to automatically fix
77
+ code. For example, we could use ` rustfix ` to mechanically apply the ` qux `
78
+ suggestion from the previous example. However, not all suggestions are
79
+ mechanically applicable. We use the
80
+ [ ` span_suggestion_with_applicability ` ] [ sswa ] method of ` DiagnosticBuilder ` to
81
+ inform the emitter of whether a suggestion is mechanically applicable or not.
82
+ This information, in turn, is outputed by rustc when the error format is
83
+ ` json ` , which is used by ` rustfix ` .
84
+
85
+ [ rustfix ] : https://github.com/rust-lang-nursery/rustfix/
81
86
[ sswa ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/struct.DiagnosticBuilder.html#method.span_suggestion_with_applicability
82
87
83
88
For example, to make our ` qux ` suggestion machine-applicable, we would do:
0 commit comments