Skip to content

Commit c2371da

Browse files
Xiretzacompiler-errors
authored andcommitted
Document changes introduced by kind-less SessionDiagnostics
1 parent 0a61352 commit c2371da

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/diagnostics/diagnostic-structs.md

+11-16
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,21 +29,19 @@ 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
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.
4745

4846
In our example, the Fluent message for the "field already declared" diagnostic
4947
looks like this:
@@ -146,13 +144,10 @@ tcx.sess.emit_err(FieldAlreadyDeclared {
146144
`#[derive(SessionDiagnostic)]` and `#[derive(LintDiagnostic)]` support the
147145
following attributes:
148146

149-
- `#[error(slug, code = "...")]`, `#[warning(slug, code = "...")]`,
150-
`#[fatal(slug, code = "...")]` or `#[lint(slug, code = "...")]`
147+
- `#[diag(slug, code = "...")]`
151148
- _Applied to struct._
152149
- _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.
156151
- Slug (_Mandatory_)
157152
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
158153
mandatory.
@@ -218,7 +213,7 @@ following attributes:
218213
`#[derive(SessionSubdiagnostic)]`)._
219214
- Adds the subdiagnostic represented by the subdiagnostic struct.
220215
- `#[primary_span]` (_Optional_)
221-
- _Applied to `Span` fields._
216+
- _Applied to `Span` fields on `SessionSubdiagnostic`s. Not used for `LintDiagnostic`s._
222217
- Indicates the primary span of the diagnostic.
223218
- `#[skip_arg]` (_Optional_)
224219
- _Applied to any field._

0 commit comments

Comments
 (0)