Skip to content

Commit 0a61352

Browse files
authored
diagnostics: fix outdated use of string slugs (#1436)
1 parent f3fe248 commit 0a61352

File tree

1 file changed

+69
-42
lines changed

1 file changed

+69
-42
lines changed

Diff for: src/diagnostics/diagnostic-structs.md

+69-42
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ represent optional `#[note]`/`#[help]` subdiagnostics.
9595

9696
Suggestions can be emitted using one of four field attributes:
9797

98-
- `#[suggestion(message = "...", code = "...", applicability = "...")]`
99-
- `#[suggestion_hidden(message = "...", code = "...", applicability = "...")]`
100-
- `#[suggestion_short(message = "...", code = "...", applicability = "...")]`
101-
- `#[suggestion_verbose(message = "...", code = "...", applicability = "...")]`
98+
- `#[suggestion(slug, code = "...", applicability = "...")]`
99+
- `#[suggestion_hidden(slug, code = "...", applicability = "...")]`
100+
- `#[suggestion_short(slug, code = "...", applicability = "...")]`
101+
- `#[suggestion_verbose(slug, code = "...", applicability = "...")]`
102102

103103
Suggestions must be applied on either a `Span` field or a `(Span,
104-
MachineApplicability)` field. Similarly to other field attributes, `message`
105-
specifies the Fluent attribute with the message and defaults to `.suggestion`.
106-
`code` specifies the code that should be suggested as a replacement and is a
107-
format string (e.g. `{field_name}` would be replaced by the value of the
108-
`field_name` field of the struct), not a Fluent identifier. `applicability` can
109-
be used to specify the applicability in the attribute, it cannot be used when
110-
the field's type contains an `Applicability`.
104+
MachineApplicability)` field. Similarly to other field attributes, the slug
105+
specifies the Fluent attribute with the message and defaults to the equivalent
106+
of `.suggestion`. `code` specifies the code that should be suggested as a
107+
replacement and is a format string (e.g. `{field_name}` would be replaced by
108+
the value of the `field_name` field of the struct), not a Fluent identifier.
109+
`applicability` can be used to specify the applicability in the attribute, it
110+
cannot be used when the field's type contains an `Applicability`.
111111

112112
In the end, the `SessionDiagnostic` derive will generate an implementation of
113113
`SessionDiagnostic` that looks like the following:
@@ -143,12 +143,16 @@ tcx.sess.emit_err(FieldAlreadyDeclared {
143143
```
144144

145145
### Reference
146-
`#[derive(SessionDiagnostic)]` supports the following attributes:
146+
`#[derive(SessionDiagnostic)]` and `#[derive(LintDiagnostic)]` support the
147+
following attributes:
147148

148-
- `#[error(slug, code = "...")]` or `#[warning(slug, code = "...")]`
149+
- `#[error(slug, code = "...")]`, `#[warning(slug, code = "...")]`,
150+
`#[fatal(slug, code = "...")]` or `#[lint(slug, code = "...")]`
149151
- _Applied to struct._
150152
- _Mandatory_
151-
- Defines the struct to be representing an error or a warning.
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`.
152156
- Slug (_Mandatory_)
153157
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
154158
mandatory.
@@ -161,34 +165,48 @@ tcx.sess.emit_err(FieldAlreadyDeclared {
161165
- See [translation documentation](./translation.md).
162166
- `code = "..."` (_Optional_)
163167
- Specifies the error code.
164-
- `#[note]` or `#[note(...)]` (_Optional_)
168+
- `#[note]` or `#[note(slug)]` (_Optional_)
165169
- _Applied to struct or `Span`/`()` fields._
166170
- Adds a note subdiagnostic.
167-
- Value is the Fluent attribute (relative to the Fluent message specified by
168-
`slug`) for the note's message
169-
- Defaults to `note`.
171+
- Value is a path to an item in `rustc_errors::fluent` for the note's
172+
message.
173+
- Defaults to equivalent of `.note`.
170174
- If applied to a `Span` field, creates a spanned note.
171-
- `#[help]` or `#[help(...)]` (_Optional_)
175+
- `#[help]` or `#[help(slug)]` (_Optional_)
172176
- _Applied to struct or `Span`/`()` fields._
173177
- Adds a help subdiagnostic.
174-
- Value is the Fluent attribute (relative to the Fluent message specified by
175-
`slug`) for the help's message.
176-
- Defaults to `help`.
178+
- Value is a path to an item in `rustc_errors::fluent` for the note's
179+
message.
180+
- Defaults to equivalent of `.help`.
177181
- If applied to a `Span` field, creates a spanned help.
178-
- `#[label]` or `#[label(...)]` (_Optional_)
182+
- `#[label]` or `#[label(slug)]` (_Optional_)
179183
- _Applied to `Span` fields._
180184
- Adds a label subdiagnostic.
181-
- Value is the Fluent attribute (relative to the Fluent message specified by
182-
`slug`) for the label's message.
183-
- Defaults to `label`.
184-
- `#[suggestion{,_hidden,_short,_verbose}(message = "...", code = "...", applicability = "...")]`
185+
- Value is a path to an item in `rustc_errors::fluent` for the note's
186+
message.
187+
- Defaults to equivalent of `.label`.
188+
- `#[warn_]` or `#[warn_(slug)]` (_Optional_)
189+
- _Applied to `Span` fields._
190+
- Adds a warning subdiagnostic.
191+
- Value is a path to an item in `rustc_errors::fluent` for the note's
192+
message.
193+
- Defaults to equivalent of `.warn`.
194+
- `#[suggestion{,_hidden,_short,_verbose}(slug, code = "...", applicability = "...")]`
185195
(_Optional_)
186196
- _Applied to `(Span, MachineApplicability)` or `Span` fields._
187197
- Adds a suggestion subdiagnostic.
188-
- `message = "..."` (_Mandatory_)
189-
- Value is the Fluent attribute (relative to the Fluent message specified
190-
by `slug`) for the suggestion's message.
191-
- Defaults to `suggestion`.
198+
- Slug (_Mandatory_)
199+
- A path to an item in `rustc_errors::fluent`. Always in a module starting
200+
with a Fluent resource name (which is typically the name of the crate
201+
that the diagnostic is from), e.g.
202+
`rustc_errors::fluent::typeck::field_already_declared`
203+
(`rustc_errors::fluent` is implicit in the attribute, so just
204+
`typeck::field_already_declared`). Fluent attributes for all messages
205+
exist as top-level items in that module (so `typeck_message.attr` is just
206+
`typeck::attr`).
207+
- See [translation documentation](./translation.md).
208+
- Defaults to `rustc_errors::fluent::_subdiag::suggestion` (or
209+
- `.suggestion` in Fluent).
192210
- `code = "..."` (_Mandatory_)
193211
- Value is a format string indicating the code to be suggested as a
194212
replacement.
@@ -273,16 +291,17 @@ Like `SessionDiagnostic`, `SessionSubdiagnostic` supports `Option<T>` and
273291

274292
Suggestions can be emitted using one of four attributes on the type/variant:
275293

276-
- `#[suggestion(message = "...", code = "...", applicability = "...")]`
277-
- `#[suggestion_hidden(message = "...", code = "...", applicability = "...")]`
278-
- `#[suggestion_short(message = "...", code = "...", applicability = "...")]`
279-
- `#[suggestion_verbose(message = "...", code = "...", applicability = "...")]`
294+
- `#[suggestion(..., code = "...", applicability = "...")]`
295+
- `#[suggestion_hidden(..., code = "...", applicability = "...")]`
296+
- `#[suggestion_short(..., code = "...", applicability = "...")]`
297+
- `#[suggestion_verbose(..., code = "...", applicability = "...")]`
280298

281299
Suggestions require `#[primary_span]` be set on a field and can have the
282300
following sub-attributes:
283301

284-
- `message` specifies the Fluent attribute with the message and defaults to
285-
`.suggestion`.
302+
- The first positional argument specifies the path to a item in
303+
`rustc_errors::fluent` corresponding to the Fluent attribute with the message
304+
and defaults to the equivalent of `.suggestion`.
286305
- `code` specifies the code that should be suggested as a replacement and is a
287306
format string (e.g. `{field_name}` would be replaced by the value of the
288307
`field_name` field of the struct), not a Fluent identifier.
@@ -335,14 +354,22 @@ diagnostic struct.
335354
(`rustc_errors::fluent` is implicit in the attribute, so just
336355
`typeck::field_already_declared`).
337356
- See [translation documentation](./translation.md).
338-
- `#[suggestion{,_hidden,_short,_verbose}(message = "...", code = "...", applicability = "...")]`
357+
- `#[suggestion{,_hidden,_short,_verbose}(slug, code = "...", applicability = "...")]`
339358
- _Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes._
340359
- _Mandatory_
341360
- Defines the type to be representing a suggestion.
342-
- `message = "..."` (_Mandatory_)
343-
- Value is the Fluent attribute (relative to the Fluent message specified
344-
by `slug`) for the suggestion's message.
345-
- Defaults to `suggestion`.
361+
- Slug (_Mandatory_)
362+
- A path to an item in `rustc_errors::fluent`. Always in a module starting
363+
with a Fluent resource name (which is typically the name of the crate
364+
that the diagnostic is from), e.g.
365+
`rustc_errors::fluent::typeck::field_already_declared`
366+
(`rustc_errors::fluent` is implicit in the attribute, so just
367+
`typeck::field_already_declared`). Fluent attributes for all messages
368+
exist as top-level items in that module (so `typeck_message.attr` is just
369+
`typeck::attr`).
370+
- See [translation documentation](./translation.md).
371+
- Defaults to `rustc_errors::fluent::_subdiag::suggestion` (or
372+
- `.suggestion` in Fluent).
346373
- `code = "..."` (_Mandatory_)
347374
- Value is a format string indicating the code to be suggested as a
348375
replacement.

0 commit comments

Comments
 (0)