@@ -17,7 +17,7 @@ shown below:
17
17
18
18
``` rust,ignore
19
19
#[derive(SessionDiagnostic)]
20
- #[error(code = "E0124", slug = "typeck-field-already-declared ")]
20
+ #[error(typeck::field_already_declared, code = "E0124 ")]
21
21
pub struct FieldAlreadyDeclared {
22
22
pub field_name: Ident,
23
23
#[primary_span]
@@ -37,12 +37,13 @@ the `code` sub-attribute. Specifying a `code` isn't mandatory, but if you are
37
37
porting a diagnostic that uses ` DiagnosticBuilder ` to use ` SessionDiagnostic `
38
38
then you should keep the code if there was one.
39
39
40
- Both ` #[error(..)] ` and ` #[warning(..)] ` must set a value for the ` slug `
41
- sub-attribute. ` slug ` uniquely identifies the diagnostic and is also how the
42
- compiler knows what error message to emit (in the default locale of the
43
- compiler, or in the locale requested by the user). See [ translation
44
- documentation] ( ./translation.md ) to learn more about how translatable error
45
- messages are written.
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.
46
47
47
48
In our example, the Fluent message for the "field already declared" diagnostic
48
49
looks like this:
@@ -54,7 +55,7 @@ typeck-field-already-declared =
54
55
.previous-decl-label = `{$field_name}` first declared here
55
56
```
56
57
57
- ` typeck-field-already-declared ` is the ` slug ` from our example and is followed
58
+ ` typeck-field-already-declared ` is the slug from our example and is followed
58
59
by the diagnostic message.
59
60
60
61
Every field of the ` SessionDiagnostic ` which does not have an annotation is
@@ -147,15 +148,22 @@ tcx.sess.emit_err(FieldAlreadyDeclared {
147
148
### Reference
148
149
` #[derive(SessionDiagnostic)] ` supports the following attributes:
149
150
150
- - ` #[error(code = "...", slug = "...")] ` or ` #[warning(code = "...", slug = "...")] `
151
+ - ` #[error(slug, code = "...")] ` or ` #[warning(slug, code = "...")] `
151
152
- _ Applied to struct._
152
153
- _ Mandatory_
153
154
- Defines the struct to be representing an error or a warning.
154
- - ` code = "..." ` (_ Optional_ )
155
- - Specifies the error code.
156
- - ` slug = "..." ` (_ Mandatory_ )
155
+ - Slug (_ Mandatory_ )
157
156
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
158
157
mandatory.
158
+ - A path to an item in ` rustc_errors::fluent ` . Always in a module starting
159
+ with a Fluent resource name (which is typically the name of the crate
160
+ that the diagnostic is from), e.g.
161
+ ` rustc_errors::fluent::typeck::field_already_declared `
162
+ (` rustc_errors::fluent ` is implicit in the attribute, so just
163
+ ` typeck::field_already_declared ` ).
164
+ - See [ translation documentation] ( ./translation.md ) .
165
+ - ` code = "..." ` (_ Optional_ )
166
+ - Specifies the error code.
159
167
- ` #[note] ` or ` #[note = "..."] ` (_ Optional_ )
160
168
- _ Applied to struct or ` Span ` /` () ` fields._
161
169
- Adds a note subdiagnostic.
@@ -215,12 +223,12 @@ shown below:
215
223
``` rust
216
224
#[derive(SessionSubdiagnostic )]
217
225
pub enum ExpectedReturnTypeLabel <'tcx > {
218
- #[label(slug = " typeck-expected-default-return-type " )]
226
+ #[label(typeck:: expected_default_return_type )]
219
227
Unit {
220
228
#[primary_span]
221
229
span : Span ,
222
230
},
223
- #[label(slug = " typeck-expected-return-type " )]
231
+ #[label(typeck:: expected_return_type )]
224
232
Other {
225
233
#[primary_span]
226
234
span : Span ,
@@ -239,11 +247,12 @@ attribute applied to the struct or each variant, one of:
239
247
- ` #[help(..)] ` for defining a help
240
248
- ` #[suggestion{,_hidden,_short,_verbose}(..)] ` for defining a suggestion
241
249
242
- All of the above must have a value set for the ` slug ` sub-attribute. ` slug `
243
- uniquely identifies the diagnostic and is also how the compiler knows what
244
- error message to emit (in the default locale of the compiler, or in the locale
245
- requested by the user). See [ translation documentation] ( ./translation.md ) to
246
- learn more about how translatable error messages are written.
250
+ All of the above must provide a slug as the first positional argument (a path
251
+ to an item in ` rustc_errors::fluent::* ` ). A slug uniquely identifies the
252
+ diagnostic and is also how the compiler knows what error message to emit (in
253
+ the default locale of the compiler, or in the locale requested by the user).
254
+ See [ translation documentation] ( ./translation.md ) to learn more about how
255
+ translatable error messages are written and how slug items are generated.
247
256
248
257
In our example, the Fluent message for the "expected return type" label
249
258
looks like this:
@@ -315,13 +324,20 @@ diagnostic struct.
315
324
### Reference
316
325
` #[derive(SessionSubdiagnostic)] ` supports the following attributes:
317
326
318
- - ` #[label(slug = "..." )] ` , ` #[help(slug = "..." )] ` or ` #[note(slug = "..." )] `
327
+ - ` #[label(slug)] ` , ` #[help(slug)] ` or ` #[note(slug)] `
319
328
- _ Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes._
320
329
- _ Mandatory_
321
330
- Defines the type to be representing a label, help or note.
322
- - ` slug = "..." ` (_ Mandatory_ )
331
+ - Slug (_ Mandatory_ )
323
332
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
324
333
mandatory.
334
+ - A path to an item in ` rustc_errors::fluent ` . Always in a module starting
335
+ with a Fluent resource name (which is typically the name of the crate
336
+ that the diagnostic is from), e.g.
337
+ ` rustc_errors::fluent::typeck::field_already_declared `
338
+ (` rustc_errors::fluent ` is implicit in the attribute, so just
339
+ ` typeck::field_already_declared ` ).
340
+ - See [ translation documentation] ( ./translation.md ) .
325
341
- ` #[suggestion{,_hidden,_short,_verbose}(message = "...", code = "...", applicability = "...")] `
326
342
- _ Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes._
327
343
- _ Mandatory_
0 commit comments