@@ -17,7 +17,7 @@ shown below:
1717
1818``` rust,ignore
1919#[derive(SessionDiagnostic)]
20- #[error(code = "E0124", slug = "typeck-field-already-declared ")]
20+ #[error(typeck::field_already_declared, code = "E0124 ")]
2121pub struct FieldAlreadyDeclared {
2222 pub field_name: Ident,
2323 #[primary_span]
@@ -37,12 +37,13 @@ the `code` sub-attribute. Specifying a `code` isn't mandatory, but if you are
3737porting a diagnostic that uses ` DiagnosticBuilder ` to use ` SessionDiagnostic `
3838then you should keep the code if there was one.
3939
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.
4647
4748In our example, the Fluent message for the "field already declared" diagnostic
4849looks like this:
@@ -54,7 +55,7 @@ typeck-field-already-declared =
5455 .previous-decl-label = `{$field_name}` first declared here
5556```
5657
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
5859by the diagnostic message.
5960
6061Every field of the ` SessionDiagnostic ` which does not have an annotation is
@@ -147,15 +148,22 @@ tcx.sess.emit_err(FieldAlreadyDeclared {
147148### Reference
148149` #[derive(SessionDiagnostic)] ` supports the following attributes:
149150
150- - ` #[error(code = "...", slug = "...")] ` or ` #[warning(code = "...", slug = "...")] `
151+ - ` #[error(slug, code = "...")] ` or ` #[warning(slug, code = "...")] `
151152 - _ Applied to struct._
152153 - _ Mandatory_
153154 - 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_ )
157156 - Uniquely identifies the diagnostic and corresponds to its Fluent message,
158157 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.
159167- ` #[note] ` or ` #[note = "..."] ` (_ Optional_ )
160168 - _ Applied to struct or ` Span ` /` () ` fields._
161169 - Adds a note subdiagnostic.
@@ -215,12 +223,12 @@ shown below:
215223``` rust
216224#[derive(SessionSubdiagnostic )]
217225pub enum ExpectedReturnTypeLabel <'tcx > {
218- #[label(slug = " typeck-expected-default-return-type " )]
226+ #[label(typeck:: expected_default_return_type )]
219227 Unit {
220228 #[primary_span]
221229 span : Span ,
222230 },
223- #[label(slug = " typeck-expected-return-type " )]
231+ #[label(typeck:: expected_return_type )]
224232 Other {
225233 #[primary_span]
226234 span : Span ,
@@ -239,11 +247,12 @@ attribute applied to the struct or each variant, one of:
239247- ` #[help(..)] ` for defining a help
240248- ` #[suggestion{,_hidden,_short,_verbose}(..)] ` for defining a suggestion
241249
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.
247256
248257In our example, the Fluent message for the "expected return type" label
249258looks like this:
@@ -315,13 +324,20 @@ diagnostic struct.
315324### Reference
316325` #[derive(SessionSubdiagnostic)] ` supports the following attributes:
317326
318- - ` #[label(slug = "..." )] ` , ` #[help(slug = "..." )] ` or ` #[note(slug = "..." )] `
327+ - ` #[label(slug)] ` , ` #[help(slug)] ` or ` #[note(slug)] `
319328 - _ Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes._
320329 - _ Mandatory_
321330 - Defines the type to be representing a label, help or note.
322- - ` slug = "..." ` (_ Mandatory_ )
331+ - Slug (_ Mandatory_ )
323332 - Uniquely identifies the diagnostic and corresponds to its Fluent message,
324333 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 ) .
325341- ` #[suggestion{,_hidden,_short,_verbose}(message = "...", code = "...", applicability = "...")] `
326342 - _ Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes._
327343 - _ Mandatory_
0 commit comments