Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document changes introduced by kind-less SessionDiagnostics #1440

Merged
merged 1 commit into from
Aug 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions src/diagnostics/diagnostic-structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ shown below:

```rust,ignore
#[derive(SessionDiagnostic)]
#[error(typeck::field_already_declared, code = "E0124")]
#[diag(typeck::field_already_declared, code = "E0124")]
pub struct FieldAlreadyDeclared {
pub field_name: Ident,
#[primary_span]
Expand All @@ -29,21 +29,19 @@ pub struct FieldAlreadyDeclared {
```

`SessionDiagnostic` can only be applied to structs. Every `SessionDiagnostic`
has to have one attribute applied to the struct itself: either `#[error(..)]`
for defining errors, or `#[warning(..)]` for defining warnings.
has to have one attribute, `#[diag(...)]`, applied to the struct itself.

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

Both `#[error(..)]` and `#[warning(..)]` must provide a slug as the first
positional argument (a path to an item in `rustc_errors::fluent::*`). A slug
uniquely identifies the diagnostic and is also how the compiler knows what
error message to emit (in the default locale of the compiler, or in the locale
requested by the user). See [translation documentation](./translation.md) to
learn more about how translatable error messages are written and how slug
items are generated.
`#[diag(..)]` must provide a slug as the first positional argument (a path to an
item in `rustc_errors::fluent::*`). A slug uniquely identifies the diagnostic
and is also how the compiler knows what error message to emit (in the default
locale of the compiler, or in the locale requested by the user). See
[translation documentation](./translation.md) to learn more about how
translatable error messages are written and how slug items are generated.

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

- `#[error(slug, code = "...")]`, `#[warning(slug, code = "...")]`,
`#[fatal(slug, code = "...")]` or `#[lint(slug, code = "...")]`
- `#[diag(slug, code = "...")]`
- _Applied to struct._
- _Mandatory_
- Defines the struct to be representing an error, fatal error, a warning or a
lint. Errors, fatal errors and warnings only supported by
`SessionDiagnostic`, and lints by `LintDiagnostic`.
- Defines the text and error code to be associated with the diagnostic.
- Slug (_Mandatory_)
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
mandatory.
Expand Down Expand Up @@ -218,7 +213,7 @@ following attributes:
`#[derive(SessionSubdiagnostic)]`)._
- Adds the subdiagnostic represented by the subdiagnostic struct.
- `#[primary_span]` (_Optional_)
- _Applied to `Span` fields._
- _Applied to `Span` fields on `SessionSubdiagnostic`s. Not used for `LintDiagnostic`s._
- Indicates the primary span of the diagnostic.
- `#[skip_arg]` (_Optional_)
- _Applied to any field._
Expand Down