@@ -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,15 +29,14 @@ 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
39
+ ` #[diag (..)] ` must provide a slug as the first
41
40
positional argument (a path to an item in ` rustc_errors::fluent::* ` ). A slug
42
41
uniquely identifies the diagnostic and is also how the compiler knows what
43
42
error message to emit (in the default locale of the compiler, or in the locale
@@ -146,13 +145,10 @@ tcx.sess.emit_err(FieldAlreadyDeclared {
146
145
` #[derive(SessionDiagnostic)] ` and ` #[derive(LintDiagnostic)] ` support the
147
146
following attributes:
148
147
149
- - ` #[error(slug, code = "...")] ` , ` #[warning(slug, code = "...")] ` ,
150
- ` #[fatal(slug, code = "...")] ` or ` #[lint(slug, code = "...")] `
148
+ - ` #[diag(slug, code = "...")] `
151
149
- _ Applied to struct._
152
150
- _ 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 ` .
151
+ - Defines the text and error code to be associated with the diagnostic.
156
152
- Slug (_ Mandatory_ )
157
153
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
158
154
mandatory.
@@ -218,7 +214,7 @@ following attributes:
218
214
` #[derive(SessionSubdiagnostic)] ` )._
219
215
- Adds the subdiagnostic represented by the subdiagnostic struct.
220
216
- ` #[primary_span] ` (_ Optional_ )
221
- - _ Applied to ` Span ` fields._
217
+ - _ Applied to ` Span ` fields on ` SessionSubdiagnostic ` s. Not used for ` LintDiagnostic ` s ._
222
218
- Indicates the primary span of the diagnostic.
223
219
- ` #[skip_arg] ` (_ Optional_ )
224
220
- _ Applied to any field._
0 commit comments