Update diagnostics to flat fluent message paths

As implemented in rust-lang/rust#103345
This commit is contained in:
Nilstrieb 2022-10-21 14:28:53 +02:00 committed by David Wood
parent 2cfe23241b
commit 015da9686e
2 changed files with 30 additions and 40 deletions

View File

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

View File

@ -127,15 +127,13 @@ pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
]; ];
mod fluent_generated { mod fluent_generated {
mod typeck { pub const typeck_field_multiply_specified_in_initializer: DiagnosticMessage =
pub const field_multiply_specified_in_initializer: DiagnosticMessage =
DiagnosticMessage::new("typeck_field_multiply_specified_in_initializer"); DiagnosticMessage::new("typeck_field_multiply_specified_in_initializer");
pub const label: SubdiagnosticMessage = pub const label: SubdiagnosticMessage =
SubdiagnosticMessage::attr("label"); SubdiagnosticMessage::attr("label");
pub const label_previous_use: SubdiagnosticMessage = pub const label_previous_use: SubdiagnosticMessage =
SubdiagnosticMessage::attr("previous_use_label"); SubdiagnosticMessage::attr("previous_use_label");
} }
}
``` ```
`rustc_error_messages::fluent_generated` is re-exported and primarily used as `rustc_error_messages::fluent_generated` is re-exported and primarily used as
@ -143,9 +141,9 @@ mod fluent_generated {
```rust ```rust
use rustc_errors::fluent; use rustc_errors::fluent;
let mut err = sess.struct_span_err(span, fluent::typeck::field_multiply_specified_in_initializer); 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(span, fluent::label);
err.span_label(previous_use_span, fluent::typeck::previous_use_label); err.span_label(previous_use_span, fluent::previous_use_label);
err.emit(); err.emit();
``` ```