Skip to content

Commit edc1c81

Browse files
committed
Document changes introduced by kind-less SessionDiagnostics
1 parent 0a61352 commit edc1c81

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/diagnostics/diagnostic-structs.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ shown below:
1717

1818
```rust,ignore
1919
#[derive(SessionDiagnostic)]
20-
#[error(typeck::field_already_declared, code = "E0124")]
20+
#[diag(typeck::field_already_declared, code = "E0124")]
2121
pub struct FieldAlreadyDeclared {
2222
pub field_name: Ident,
2323
#[primary_span]
@@ -29,15 +29,14 @@ pub struct FieldAlreadyDeclared {
2929
```
3030

3131
`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.
3433

3534
If an error has an error code (e.g. "E0624"), then that can be specified using
3635
the `code` sub-attribute. Specifying a `code` isn't mandatory, but if you are
3736
porting a diagnostic that uses `DiagnosticBuilder` to use `SessionDiagnostic`
3837
then you should keep the code if there was one.
3938

40-
Both `#[error(..)]` and `#[warning(..)]` must provide a slug as the first
39+
`#[diag(..)]` must provide a slug as the first
4140
positional argument (a path to an item in `rustc_errors::fluent::*`). A slug
4241
uniquely identifies the diagnostic and is also how the compiler knows what
4342
error message to emit (in the default locale of the compiler, or in the locale
@@ -146,13 +145,10 @@ tcx.sess.emit_err(FieldAlreadyDeclared {
146145
`#[derive(SessionDiagnostic)]` and `#[derive(LintDiagnostic)]` support the
147146
following attributes:
148147

149-
- `#[error(slug, code = "...")]`, `#[warning(slug, code = "...")]`,
150-
`#[fatal(slug, code = "...")]` or `#[lint(slug, code = "...")]`
148+
- `#[diag(slug, code = "...")]`
151149
- _Applied to struct._
152150
- _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.
156152
- Slug (_Mandatory_)
157153
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
158154
mandatory.
@@ -218,7 +214,7 @@ following attributes:
218214
`#[derive(SessionSubdiagnostic)]`)._
219215
- Adds the subdiagnostic represented by the subdiagnostic struct.
220216
- `#[primary_span]` (_Optional_)
221-
- _Applied to `Span` fields._
217+
- _Applied to `Span` fields on `SessionSubdiagnostic`s. Not used for `LintDiagnostic`s._
222218
- Indicates the primary span of the diagnostic.
223219
- `#[skip_arg]` (_Optional_)
224220
- _Applied to any field._

0 commit comments

Comments
 (0)