Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update diagnostics to flat fluent message paths #1489

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 21 additions & 29 deletions src/diagnostics/diagnostic-structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ shown below:

```rust,ignore
#[derive(Diagnostic)]
#[diag(hir_analysis::field_already_declared, code = "E0124")]
#[diag(hir_analysis_field_already_declared, code = "E0124")]
pub struct FieldAlreadyDeclared {
pub field_name: Ident,
#[primary_span]
#[label]
pub span: Span,
#[label(hir_analysis::previous_decl_label)]
#[label(hir_analysis_previous_decl_label)]
pub prev_span: Span,
}
```
Expand Down Expand Up @@ -113,15 +113,15 @@ In the end, the `Diagnostic` derive will generate an implementation of
```rust,ignore
impl IntoDiagnostic<'_> for FieldAlreadyDeclared {
fn into_diagnostic(self, handler: &'_ rustc_errors::Handler) -> DiagnosticBuilder<'_> {
let mut diag = handler.struct_err(rustc_errors::fluent::hir_analysis::field_already_declared);
let mut diag = handler.struct_err(rustc_errors::fluent::hir_analysis_field_already_declared);
diag.set_span(self.span);
diag.span_label(
self.span,
rustc_errors::fluent::hir_analysis::label
rustc_errors::fluent::hir_analysis_label
);
diag.span_label(
self.prev_span,
rustc_errors::fluent::hir_analysis::previous_decl_label
rustc_errors::fluent::hir_analysis_previous_decl_label
);
diag
}
Expand Down Expand Up @@ -151,12 +151,10 @@ following attributes:
- Slug (_Mandatory_)
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
mandatory.
- A path to an item in `rustc_errors::fluent`. Always in a module starting
with a Fluent resource name (which is typically the name of the crate
that the diagnostic is from), e.g.
`rustc_errors::fluent::hir_analysis::field_already_declared`
- A path to an item in `rustc_errors::fluent`, e.g.
`rustc_errors::fluent::hir_analysis_field_already_declared`
(`rustc_errors::fluent` is implicit in the attribute, so just
`hir_analysis::field_already_declared`).
`hir_analysis_field_already_declared`).
- See [translation documentation](./translation.md).
- `code = "..."` (_Optional_)
- Specifies the error code.
Expand Down Expand Up @@ -191,14 +189,12 @@ following attributes:
- _Applied to `(Span, MachineApplicability)` or `Span` fields._
- Adds a suggestion subdiagnostic.
- Slug (_Mandatory_)
- A path to an item in `rustc_errors::fluent`. Always in a module starting
with a Fluent resource name (which is typically the name of the crate
that the diagnostic is from), e.g.
`rustc_errors::fluent::hir_analysis::field_already_declared`
- A path to an item in `rustc_errors::fluent`, e.g.
`rustc_errors::fluent::hir_analysis_field_already_declared`
(`rustc_errors::fluent` is implicit in the attribute, so just
`hir_analysis::field_already_declared`). Fluent attributes for all messages
`hir_analysis_field_already_declared`). Fluent attributes for all messages
exist as top-level items in that module (so `hir_analysis_message.attr` is just
`hir_analysis::attr`).
`attr`).
- See [translation documentation](./translation.md).
- Defaults to `rustc_errors::fluent::_subdiag::suggestion` (or
- `.suggestion` in Fluent).
Expand Down Expand Up @@ -233,12 +229,12 @@ shown below:
```rust
#[derive(Subdiagnostic)]
pub enum ExpectedReturnTypeLabel<'tcx> {
#[label(hir_analysis::expected_default_return_type)]
#[label(hir_analysis_expected_default_return_type)]
Unit {
#[primary_span]
span: Span,
},
#[label(hir_analysis::expected_return_type)]
#[label(hir_analysis_expected_return_type)]
Other {
#[primary_span]
span: Span,
Expand Down Expand Up @@ -315,11 +311,11 @@ impl<'tcx> AddToDiagnostic for ExpectedReturnTypeLabel<'tcx> {
use rustc_errors::{Applicability, IntoDiagnosticArg};
match self {
ExpectedReturnTypeLabel::Unit { span } => {
diag.span_label(span, rustc_errors::fluent::hir_analysis::expected_default_return_type)
diag.span_label(span, rustc_errors::fluent::hir_analysis_expected_default_return_type)
}
ExpectedReturnTypeLabel::Other { span, expected } => {
diag.set_arg("expected", expected);
diag.span_label(span, rustc_errors::fluent::hir_analysis::expected_return_type)
diag.span_label(span, rustc_errors::fluent::hir_analysis_expected_return_type)
}

}
Expand All @@ -342,22 +338,18 @@ diagnostic struct.
- Slug (_Mandatory_)
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
mandatory.
- A path to an item in `rustc_errors::fluent`. Always in a module starting
with a Fluent resource name (which is typically the name of the crate
that the diagnostic is from), e.g.
`rustc_errors::fluent::hir_analysis::field_already_declared`
- A path to an item in `rustc_errors::fluent`, e.g.
`rustc_errors::fluent::hir_analysis_field_already_declared`
(`rustc_errors::fluent` is implicit in the attribute, so just
`hir_analysis::field_already_declared`).
`hir_analysis_field_already_declared`).
- See [translation documentation](./translation.md).
- `#[suggestion{,_hidden,_short,_verbose}(slug, code = "...", applicability = "...")]`
- _Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes._
- _Mandatory_
- Defines the type to be representing a suggestion.
- Slug (_Mandatory_)
- A path to an item in `rustc_errors::fluent`. Always in a module starting
with a Fluent resource name (which is typically the name of the crate
that the diagnostic is from), e.g.
`rustc_errors::fluent::hir_analysis::field_already_declared`
- A path to an item in `rustc_errors::fluent`, e.g.
`rustc_errors::fluent::hir_analysis_field_already_declared`
(`rustc_errors::fluent` is implicit in the attribute, so just
`hir_analysis::field_already_declared`). Fluent attributes for all messages
exist as top-level items in that module (so `hir_analysis_message.attr` is just
Expand Down
20 changes: 9 additions & 11 deletions src/diagnostics/translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,12 @@ pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
];

mod fluent_generated {
mod typeck {
pub const field_multiply_specified_in_initializer: DiagnosticMessage =
DiagnosticMessage::new("typeck_field_multiply_specified_in_initializer");
pub const label: SubdiagnosticMessage =
SubdiagnosticMessage::attr("label");
pub const label_previous_use: SubdiagnosticMessage =
SubdiagnosticMessage::attr("previous_use_label");
}
pub const typeck_field_multiply_specified_in_initializer: DiagnosticMessage =
DiagnosticMessage::new("typeck_field_multiply_specified_in_initializer");
pub const label: SubdiagnosticMessage =
SubdiagnosticMessage::attr("label");
pub const label_previous_use: SubdiagnosticMessage =
SubdiagnosticMessage::attr("previous_use_label");
}
```

Expand All @@ -143,9 +141,9 @@ mod fluent_generated {

```rust
use rustc_errors::fluent;
let mut err = sess.struct_span_err(span, fluent::typeck::field_multiply_specified_in_initializer);
err.span_label(span, fluent::typeck::label);
err.span_label(previous_use_span, fluent::typeck::previous_use_label);
let mut err = sess.struct_span_err(span, fluent::typeck_field_multiply_specified_in_initializer);
err.span_label(span, fluent::label);
err.span_label(previous_use_span, fluent::previous_use_label);
err.emit();
```

Expand Down