@@ -23,7 +23,7 @@ pub struct FieldAlreadyDeclared {
23
23
#[primary_span]
24
24
#[label]
25
25
pub span: Span,
26
- #[label = "previous-decl-label" ]
26
+ #[label(typeck::previous_decl_label) ]
27
27
pub prev_span: Span,
28
28
}
29
29
```
@@ -49,13 +49,13 @@ In our example, the Fluent message for the "field already declared" diagnostic
49
49
looks like this:
50
50
51
51
``` fluent
52
- typeck-field-already-declared =
52
+ typeck_field_already_declared =
53
53
field `{$field_name}` is already declared
54
54
.label = field already declared
55
- .previous-decl-label = `{$field_name}` first declared here
55
+ .previous_decl_label = `{$field_name}` first declared here
56
56
```
57
57
58
- ` 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
59
59
by the diagnostic message.
60
60
61
61
Every field of the ` SessionDiagnostic ` which does not have an annotation is
@@ -75,10 +75,10 @@ type `Span`. Applying any of these attributes will create the corresponding
75
75
subdiagnostic with that ` Span ` . These attributes will look for their
76
76
diagnostic message in a Fluent attribute attached to the primary Fluent
77
77
message. In our example, ` #[label] ` will look for
78
- ` typeck-field-already-declared .label` (which has the message "field already
78
+ ` typeck_field_already_declared .label` (which has the message "field already
79
79
declared"). If there is more than one subdiagnostic of the same type, then
80
80
these attributes can also take a value that is the attribute name to look for
81
- (e.g. ` previous-decl-label ` in our example).
81
+ (e.g. ` previous_decl_label ` in our example).
82
82
83
83
Other types have special behavior when used in a ` SessionDiagnostic ` derive:
84
84
@@ -115,18 +115,19 @@ In the end, the `SessionDiagnostic` derive will generate an implementation of
115
115
``` rust,ignore
116
116
impl SessionDiagnostic for FieldAlreadyDeclared {
117
117
fn into_diagnostic(self, sess: &'_ rustc_session::Session) -> DiagnosticBuilder<'_> {
118
- let mut diag = sess.struct_err_with_code(
119
- rustc_errors::DiagnosticMessage::fluent("typeck-field-already-declared"),
120
- rustc_errors::DiagnosticId::Error("E0124")
121
- );
118
+ let mut diag = sess.struct_err(rustc_errors::fluent::typeck::field_already_declared);
122
119
diag.set_span(self.span);
123
120
diag.span_label(
124
121
self.span,
125
- rustc_errors::DiagnosticMessage::fluent_attr("typeck-field-already-declared", "label")
122
+ rustc_errors::DiagnosticMessage::FluentAttr(
123
+ std::borrow::Cow::Borrowed("label")
124
+ )
126
125
);
127
126
diag.span_label(
128
127
self.prev_span,
129
- rustc_errors::DiagnosticMessage::fluent_attr("typeck-field-already-declared", "previous-decl-label")
128
+ rustc_errors::DiagnosticMessage::FluentAttr(
129
+ std::borrow::Cow::Borrowed("previous_decl_label")
130
+ )
130
131
);
131
132
diag
132
133
}
@@ -258,9 +259,9 @@ In our example, the Fluent message for the "expected return type" label
258
259
looks like this:
259
260
260
261
``` fluent
261
- typeck-expected-default-return-type = expected `()` because of default return type
262
+ typeck_expected_default_return_type = expected `()` because of default return type
262
263
263
- typeck-expected-return-type = expected `{$expected}` because of return type
264
+ typeck_expected_return_type = expected `{$expected}` because of return type
264
265
```
265
266
266
267
Using the ` #[primary_span] ` attribute on a field (with type ` Span ` ) will denote
@@ -304,11 +305,11 @@ impl<'tcx> AddToDiagnostic for ExpectedReturnTypeLabel<'tcx> {
304
305
use rustc_errors :: {Applicability , IntoDiagnosticArg };
305
306
match self {
306
307
ExpectedReturnTypeLabel :: Unit { span } => {
307
- diag . span_label (span , DiagnosticMessage :: fluent (" typeck-expected-default-return-type " ))
308
+ diag . span_label (span , DiagnosticMessage :: fluent (" typeck_expected_default_return_type " ))
308
309
}
309
310
ExpectedReturnTypeLabel :: Other { span , expected } => {
310
311
diag . set_arg (" expected" , expected );
311
- diag . span_label (span , DiagnosticMessage :: fluent (" typeck-expected-return-type " ))
312
+ diag . span_label (span , DiagnosticMessage :: fluent (" typeck_expected_return_type " ))
312
313
}
313
314
314
315
}
0 commit comments