Skip to content

Commit 6686b1e

Browse files
Noratriebdavidtwco
authored andcommitted
Update diagnostics to flat fluent message paths
As implemented in rust-lang/rust#103345
1 parent a262476 commit 6686b1e

File tree

2 files changed

+30
-40
lines changed

2 files changed

+30
-40
lines changed

src/diagnostics/diagnostic-structs.md

+21-29
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ shown below:
1717

1818
```rust,ignore
1919
#[derive(Diagnostic)]
20-
#[diag(hir_analysis::field_already_declared, code = "E0124")]
20+
#[diag(hir_analysis_field_already_declared, code = "E0124")]
2121
pub struct FieldAlreadyDeclared {
2222
pub field_name: Ident,
2323
#[primary_span]
2424
#[label]
2525
pub span: Span,
26-
#[label(hir_analysis::previous_decl_label)]
26+
#[label(hir_analysis_previous_decl_label)]
2727
pub prev_span: Span,
2828
}
2929
```
@@ -113,15 +113,15 @@ In the end, the `Diagnostic` derive will generate an implementation of
113113
```rust,ignore
114114
impl IntoDiagnostic<'_> for FieldAlreadyDeclared {
115115
fn into_diagnostic(self, handler: &'_ rustc_errors::Handler) -> DiagnosticBuilder<'_> {
116-
let mut diag = handler.struct_err(rustc_errors::fluent::hir_analysis::field_already_declared);
116+
let mut diag = handler.struct_err(rustc_errors::fluent::hir_analysis_field_already_declared);
117117
diag.set_span(self.span);
118118
diag.span_label(
119119
self.span,
120-
rustc_errors::fluent::hir_analysis::label
120+
rustc_errors::fluent::hir_analysis_label
121121
);
122122
diag.span_label(
123123
self.prev_span,
124-
rustc_errors::fluent::hir_analysis::previous_decl_label
124+
rustc_errors::fluent::hir_analysis_previous_decl_label
125125
);
126126
diag
127127
}
@@ -151,12 +151,10 @@ following attributes:
151151
- Slug (_Mandatory_)
152152
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
153153
mandatory.
154-
- A path to an item in `rustc_errors::fluent`. Always in a module starting
155-
with a Fluent resource name (which is typically the name of the crate
156-
that the diagnostic is from), e.g.
157-
`rustc_errors::fluent::hir_analysis::field_already_declared`
154+
- A path to an item in `rustc_errors::fluent`, e.g.
155+
`rustc_errors::fluent::hir_analysis_field_already_declared`
158156
(`rustc_errors::fluent` is implicit in the attribute, so just
159-
`hir_analysis::field_already_declared`).
157+
`hir_analysis_field_already_declared`).
160158
- See [translation documentation](./translation.md).
161159
- `code = "..."` (_Optional_)
162160
- Specifies the error code.
@@ -191,14 +189,12 @@ following attributes:
191189
- _Applied to `(Span, MachineApplicability)` or `Span` fields._
192190
- Adds a suggestion subdiagnostic.
193191
- Slug (_Mandatory_)
194-
- A path to an item in `rustc_errors::fluent`. Always in a module starting
195-
with a Fluent resource name (which is typically the name of the crate
196-
that the diagnostic is from), e.g.
197-
`rustc_errors::fluent::hir_analysis::field_already_declared`
192+
- A path to an item in `rustc_errors::fluent`, e.g.
193+
`rustc_errors::fluent::hir_analysis_field_already_declared`
198194
(`rustc_errors::fluent` is implicit in the attribute, so just
199-
`hir_analysis::field_already_declared`). Fluent attributes for all messages
195+
`hir_analysis_field_already_declared`). Fluent attributes for all messages
200196
exist as top-level items in that module (so `hir_analysis_message.attr` is just
201-
`hir_analysis::attr`).
197+
`attr`).
202198
- See [translation documentation](./translation.md).
203199
- Defaults to `rustc_errors::fluent::_subdiag::suggestion` (or
204200
- `.suggestion` in Fluent).
@@ -233,12 +229,12 @@ shown below:
233229
```rust
234230
#[derive(Subdiagnostic)]
235231
pub enum ExpectedReturnTypeLabel<'tcx> {
236-
#[label(hir_analysis::expected_default_return_type)]
232+
#[label(hir_analysis_expected_default_return_type)]
237233
Unit {
238234
#[primary_span]
239235
span: Span,
240236
},
241-
#[label(hir_analysis::expected_return_type)]
237+
#[label(hir_analysis_expected_return_type)]
242238
Other {
243239
#[primary_span]
244240
span: Span,
@@ -315,11 +311,11 @@ impl<'tcx> AddToDiagnostic for ExpectedReturnTypeLabel<'tcx> {
315311
use rustc_errors::{Applicability, IntoDiagnosticArg};
316312
match self {
317313
ExpectedReturnTypeLabel::Unit { span } => {
318-
diag.span_label(span, rustc_errors::fluent::hir_analysis::expected_default_return_type)
314+
diag.span_label(span, rustc_errors::fluent::hir_analysis_expected_default_return_type)
319315
}
320316
ExpectedReturnTypeLabel::Other { span, expected } => {
321317
diag.set_arg("expected", expected);
322-
diag.span_label(span, rustc_errors::fluent::hir_analysis::expected_return_type)
318+
diag.span_label(span, rustc_errors::fluent::hir_analysis_expected_return_type)
323319
}
324320

325321
}
@@ -342,22 +338,18 @@ diagnostic struct.
342338
- Slug (_Mandatory_)
343339
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
344340
mandatory.
345-
- A path to an item in `rustc_errors::fluent`. Always in a module starting
346-
with a Fluent resource name (which is typically the name of the crate
347-
that the diagnostic is from), e.g.
348-
`rustc_errors::fluent::hir_analysis::field_already_declared`
341+
- A path to an item in `rustc_errors::fluent`, e.g.
342+
`rustc_errors::fluent::hir_analysis_field_already_declared`
349343
(`rustc_errors::fluent` is implicit in the attribute, so just
350-
`hir_analysis::field_already_declared`).
344+
`hir_analysis_field_already_declared`).
351345
- See [translation documentation](./translation.md).
352346
- `#[suggestion{,_hidden,_short,_verbose}(slug, code = "...", applicability = "...")]`
353347
- _Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes._
354348
- _Mandatory_
355349
- Defines the type to be representing a suggestion.
356350
- Slug (_Mandatory_)
357-
- A path to an item in `rustc_errors::fluent`. Always in a module starting
358-
with a Fluent resource name (which is typically the name of the crate
359-
that the diagnostic is from), e.g.
360-
`rustc_errors::fluent::hir_analysis::field_already_declared`
351+
- A path to an item in `rustc_errors::fluent`, e.g.
352+
`rustc_errors::fluent::hir_analysis_field_already_declared`
361353
(`rustc_errors::fluent` is implicit in the attribute, so just
362354
`hir_analysis::field_already_declared`). Fluent attributes for all messages
363355
exist as top-level items in that module (so `hir_analysis_message.attr` is just

src/diagnostics/translation.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,12 @@ pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
127127
];
128128

129129
mod fluent_generated {
130-
mod typeck {
131-
pub const field_multiply_specified_in_initializer: DiagnosticMessage =
132-
DiagnosticMessage::new("typeck_field_multiply_specified_in_initializer");
133-
pub const label: SubdiagnosticMessage =
134-
SubdiagnosticMessage::attr("label");
135-
pub const label_previous_use: SubdiagnosticMessage =
136-
SubdiagnosticMessage::attr("previous_use_label");
137-
}
130+
pub const typeck_field_multiply_specified_in_initializer: DiagnosticMessage =
131+
DiagnosticMessage::new("typeck_field_multiply_specified_in_initializer");
132+
pub const label: SubdiagnosticMessage =
133+
SubdiagnosticMessage::attr("label");
134+
pub const label_previous_use: SubdiagnosticMessage =
135+
SubdiagnosticMessage::attr("previous_use_label");
138136
}
139137
```
140138

@@ -143,9 +141,9 @@ mod fluent_generated {
143141

144142
```rust
145143
use rustc_errors::fluent;
146-
let mut err = sess.struct_span_err(span, fluent::typeck::field_multiply_specified_in_initializer);
147-
err.span_label(span, fluent::typeck::label);
148-
err.span_label(previous_use_span, fluent::typeck::previous_use_label);
144+
let mut err = sess.struct_span_err(span, fluent::typeck_field_multiply_specified_in_initializer);
145+
err.span_label(span, fluent::label);
146+
err.span_label(previous_use_span, fluent::previous_use_label);
149147
err.emit();
150148
```
151149

0 commit comments

Comments
 (0)