typeck: use typed fluent identifiers for diags
Use new typed Fluent identifiers for the "missing type parameters" diagnostic in the typeck crate which was manually creating `DiagnosticMessage`s previously. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
552eb3295a
commit
ce9901fcee
1 changed files with 9 additions and 9 deletions
|
@ -1,7 +1,5 @@
|
||||||
//! Errors emitted by typeck.
|
//! Errors emitted by typeck.
|
||||||
use rustc_errors::{
|
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
||||||
error_code, Applicability, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed,
|
|
||||||
};
|
|
||||||
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
|
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
|
||||||
use rustc_middle::ty::Ty;
|
use rustc_middle::ty::Ty;
|
||||||
use rustc_session::{parse::ParseSess, SessionDiagnostic};
|
use rustc_session::{parse::ParseSess, SessionDiagnostic};
|
||||||
|
@ -264,10 +262,9 @@ pub struct MissingTypeParams {
|
||||||
// Manual implementation of `SessionDiagnostic` to be able to call `span_to_snippet`.
|
// Manual implementation of `SessionDiagnostic` to be able to call `span_to_snippet`.
|
||||||
impl<'a> SessionDiagnostic<'a> for MissingTypeParams {
|
impl<'a> SessionDiagnostic<'a> for MissingTypeParams {
|
||||||
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||||
static SLUG: &'static str = "typeck-missing-type-params";
|
|
||||||
let mut err = sess.span_diagnostic.struct_span_err_with_code(
|
let mut err = sess.span_diagnostic.struct_span_err_with_code(
|
||||||
self.span,
|
self.span,
|
||||||
DiagnosticMessage::fluent(SLUG),
|
rustc_errors::fluent::typeck::missing_type_params,
|
||||||
error_code!(E0393),
|
error_code!(E0393),
|
||||||
);
|
);
|
||||||
err.set_arg("parameterCount", self.missing_type_params.len());
|
err.set_arg("parameterCount", self.missing_type_params.len());
|
||||||
|
@ -280,7 +277,7 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams {
|
||||||
.join(", "),
|
.join(", "),
|
||||||
);
|
);
|
||||||
|
|
||||||
err.span_label(self.def_span, DiagnosticMessage::fluent_attr(SLUG, "label"));
|
err.span_label(self.def_span, rustc_errors::fluent::typeck::missing_type_params_label);
|
||||||
|
|
||||||
let mut suggested = false;
|
let mut suggested = false;
|
||||||
if let (Ok(snippet), true) = (
|
if let (Ok(snippet), true) = (
|
||||||
|
@ -298,7 +295,7 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams {
|
||||||
// least we can clue them to the correct syntax `Iterator<Type>`.
|
// least we can clue them to the correct syntax `Iterator<Type>`.
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
DiagnosticMessage::fluent_attr(SLUG, "suggestion"),
|
rustc_errors::fluent::typeck::missing_type_params_suggestion,
|
||||||
format!("{}<{}>", snippet, self.missing_type_params.join(", ")),
|
format!("{}<{}>", snippet, self.missing_type_params.join(", ")),
|
||||||
Applicability::HasPlaceholders,
|
Applicability::HasPlaceholders,
|
||||||
);
|
);
|
||||||
|
@ -306,10 +303,13 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !suggested {
|
if !suggested {
|
||||||
err.span_label(self.span, DiagnosticMessage::fluent_attr(SLUG, "no-suggestion-label"));
|
err.span_label(
|
||||||
|
self.span,
|
||||||
|
rustc_errors::fluent::typeck::missing_type_params_no_suggestion_label,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
err.note(DiagnosticMessage::fluent_attr(SLUG, "note"));
|
err.note(rustc_errors::fluent::typeck::missing_type_params_note);
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue