@@ -17,7 +17,7 @@ shown below:
17
17
18
18
``` rust,ignore
19
19
#[derive(SessionDiagnostic)]
20
- #[error (typeck::field_already_declared, code = "E0124")]
20
+ #[diag (typeck::field_already_declared, code = "E0124")]
21
21
pub struct FieldAlreadyDeclared {
22
22
pub field_name: Ident,
23
23
#[primary_span]
@@ -29,21 +29,19 @@ pub struct FieldAlreadyDeclared {
29
29
```
30
30
31
31
` SessionDiagnostic ` can only be applied to structs. Every ` SessionDiagnostic `
32
- has to have one attribute applied to the struct itself: either ` #[error(..)] `
33
- for defining errors, or ` #[warning(..)] ` for defining warnings.
32
+ has to have one attribute, ` #[diag(...)] ` , applied to the struct itself.
34
33
35
34
If an error has an error code (e.g. "E0624"), then that can be specified using
36
35
the ` code ` sub-attribute. Specifying a ` code ` isn't mandatory, but if you are
37
36
porting a diagnostic that uses ` DiagnosticBuilder ` to use ` SessionDiagnostic `
38
37
then you should keep the code if there was one.
39
38
40
- Both ` #[error(..)] ` and ` #[warning(..)] ` must provide a slug as the first
41
- positional argument (a path to an item in ` rustc_errors::fluent::* ` ). A slug
42
- uniquely identifies the diagnostic and is also how the compiler knows what
43
- error message to emit (in the default locale of the compiler, or in the locale
44
- requested by the user). See [ translation documentation] ( ./translation.md ) to
45
- learn more about how translatable error messages are written and how slug
46
- items are generated.
39
+ ` #[diag(..)] ` must provide a slug as the first positional argument (a path to an
40
+ item in ` rustc_errors::fluent::* ` ). A slug uniquely identifies the diagnostic
41
+ and is also how the compiler knows what error message to emit (in the default
42
+ locale of the compiler, or in the locale requested by the user). See
43
+ [ translation documentation] ( ./translation.md ) to learn more about how
44
+ translatable error messages are written and how slug items are generated.
47
45
48
46
In our example, the Fluent message for the "field already declared" diagnostic
49
47
looks like this:
@@ -146,13 +144,10 @@ tcx.sess.emit_err(FieldAlreadyDeclared {
146
144
` #[derive(SessionDiagnostic)] ` and ` #[derive(LintDiagnostic)] ` support the
147
145
following attributes:
148
146
149
- - ` #[error(slug, code = "...")] ` , ` #[warning(slug, code = "...")] ` ,
150
- ` #[fatal(slug, code = "...")] ` or ` #[lint(slug, code = "...")] `
147
+ - ` #[diag(slug, code = "...")] `
151
148
- _ Applied to struct._
152
149
- _ Mandatory_
153
- - Defines the struct to be representing an error, fatal error, a warning or a
154
- lint. Errors, fatal errors and warnings only supported by
155
- ` SessionDiagnostic ` , and lints by ` LintDiagnostic ` .
150
+ - Defines the text and error code to be associated with the diagnostic.
156
151
- Slug (_ Mandatory_ )
157
152
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
158
153
mandatory.
@@ -218,7 +213,7 @@ following attributes:
218
213
` #[derive(SessionSubdiagnostic)] ` )._
219
214
- Adds the subdiagnostic represented by the subdiagnostic struct.
220
215
- ` #[primary_span] ` (_ Optional_ )
221
- - _ Applied to ` Span ` fields._
216
+ - _ Applied to ` Span ` fields on ` SessionSubdiagnostic ` s. Not used for ` LintDiagnostic ` s ._
222
217
- Indicates the primary span of the diagnostic.
223
218
- ` #[skip_arg] ` (_ Optional_ )
224
219
- _ Applied to any field._
0 commit comments