Skip to content

Commit cc5bac8

Browse files
committed
Update slug style to use _ instead of -
Due to changes by rust-lang/rust#100377
1 parent 452b5ab commit cc5bac8

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

src/diagnostics/diagnostic-structs.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct FieldAlreadyDeclared {
2323
#[primary_span]
2424
#[label]
2525
pub span: Span,
26-
#[label = "previous-decl-label"]
26+
#[label(typeck::previous_decl_label)]
2727
pub prev_span: Span,
2828
}
2929
```
@@ -49,13 +49,13 @@ In our example, the Fluent message for the "field already declared" diagnostic
4949
looks like this:
5050

5151
```fluent
52-
typeck-field-already-declared =
52+
typeck_field_already_declared =
5353
field `{$field_name}` is already declared
5454
.label = field already declared
55-
.previous-decl-label = `{$field_name}` first declared here
55+
.previous_decl_label = `{$field_name}` first declared here
5656
```
5757

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
5959
by the diagnostic message.
6060

6161
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
7575
subdiagnostic with that `Span`. These attributes will look for their
7676
diagnostic message in a Fluent attribute attached to the primary Fluent
7777
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
7979
declared"). If there is more than one subdiagnostic of the same type, then
8080
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).
8282

8383
Other types have special behavior when used in a `SessionDiagnostic` derive:
8484

@@ -115,18 +115,19 @@ In the end, the `SessionDiagnostic` derive will generate an implementation of
115115
```rust,ignore
116116
impl SessionDiagnostic for FieldAlreadyDeclared {
117117
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);
122119
diag.set_span(self.span);
123120
diag.span_label(
124121
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+
)
126125
);
127126
diag.span_label(
128127
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+
)
130131
);
131132
diag
132133
}
@@ -258,9 +259,9 @@ In our example, the Fluent message for the "expected return type" label
258259
looks like this:
259260

260261
```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
262263
263-
typeck-expected-return-type = expected `{$expected}` because of return type
264+
typeck_expected_return_type = expected `{$expected}` because of return type
264265
```
265266

266267
Using the `#[primary_span]` attribute on a field (with type `Span`) will denote
@@ -304,11 +305,11 @@ impl<'tcx> AddToDiagnostic for ExpectedReturnTypeLabel<'tcx> {
304305
use rustc_errors::{Applicability, IntoDiagnosticArg};
305306
match self {
306307
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"))
308309
}
309310
ExpectedReturnTypeLabel::Other { span, expected } => {
310311
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"))
312313
}
313314

314315
}

src/diagnostics/translation.md

+16-9
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,31 @@ Diagnostic messages are defined in Fluent resources. A combined set of Fluent
3232
resources for a given locale (e.g. `en-US`) is known as Fluent bundle.
3333

3434
```fluent
35-
typeck-address-of-temporary-taken = cannot take address of a temporary
35+
typeck_address_of_temporary_taken = cannot take address of a temporary
3636
```
3737

38-
In the above example, `typeck-address-of-temporary-taken` is the identifier for
38+
In the above example, `typeck_address_of_temporary_taken` is the identifier for
3939
a Fluent message and corresponds to the diagnostic message in English. Other
4040
Fluent resources can be written which would correspond to a message in another
4141
language. Each diagnostic therefore has at least one Fluent message.
4242

4343
```fluent
44-
typeck-address-of-temporary-taken = cannot take address of a temporary
44+
typeck_address_of_temporary_taken = cannot take address of a temporary
4545
.label = temporary value
4646
```
4747

4848
By convention, diagnostic messages for subdiagnostics are specified as
4949
"attributes" on Fluent messages (additional related messages, denoted by the
5050
`.<attribute-name>` syntax). In the above example, `label` is an attribute of
51-
`typeck-address-of-temporary-taken` which corresponds to the message for the
51+
`typeck_address_of_temporary_taken` which corresponds to the message for the
5252
label added to this diagnostic.
5353

5454
Diagnostic messages often interpolate additional context into the message shown
5555
to the user, such as the name of a type or of a variable. Additional context to
5656
Fluent messages is provided as an "argument" to the diagnostic.
5757

5858
```fluent
59-
typeck-struct-expr-non-exhaustive =
59+
typeck_struct_expr_non_exhaustive =
6060
cannot create non-exhaustive {$what} using struct expression
6161
```
6262

@@ -67,6 +67,13 @@ discussed in detail later).
6767
You can consult the [Fluent] documentation for other usage examples of Fluent
6868
and its syntax.
6969

70+
### Guideline for message naming
71+
Usually, fluent uses `-` for separating words inside a message name. However,
72+
`_` is accepted by fluent as well. As `_` fits Rust's use cases better, due to
73+
the identifiers on the Rust side using `_` as well, inside rustc, `-` is not
74+
allowed for separating words, and instead `_` is recommended. The only exception
75+
is for leading `-`s, for message names like `-passes_see_issue`.
76+
7077
### Guidelines for writing translatable messages
7178
For a message to be translatable into different languages, all of the
7279
information required by any language must be provided to the diagnostic as an
@@ -106,10 +113,10 @@ fluent_messages! {
106113
For example, given the following Fluent...
107114

108115
```fluent
109-
typeck-field-multiply-specified-in-initializer =
116+
typeck_field_multiply_specified_in_initializer =
110117
field `{$ident}` specified more than once
111118
.label = used more than once
112-
.label-previous-use = first use of `{$ident}`
119+
.label_previous_use = first use of `{$ident}`
113120
```
114121

115122
...then the `fluent_messages` macro will generate:
@@ -122,11 +129,11 @@ pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
122129
mod fluent_generated {
123130
mod typeck {
124131
pub const field_multiply_specified_in_initializer: DiagnosticMessage =
125-
DiagnosticMessage::new("typeck-field-multiply-specified-in-initializer");
132+
DiagnosticMessage::new("typeck_field_multiply_specified_in_initializer");
126133
pub const label: SubdiagnosticMessage =
127134
SubdiagnosticMessage::attr("label");
128135
pub const label_previous_use: SubdiagnosticMessage =
129-
SubdiagnosticMessage::attr("previous-use-label");
136+
SubdiagnosticMessage::attr("previous_use_label");
130137
}
131138
}
132139
```

0 commit comments

Comments
 (0)