1
Fork 0

Generate lint diagnostic message from BuiltinLintDiag

Translation of the lint message happens when the actual diagnostic is
created, not when the lint is buffered. Generating the message from
BuiltinLintDiag ensures that all required data to construct the message
is preserved in the LintBuffer, eventually allowing the messages to be
moved to fluent.

Remove the `msg` field from BufferedEarlyLint, it is either generated
from the data in the BuiltinLintDiag or stored inside
BuiltinLintDiag::Normal.
This commit is contained in:
Xiretza 2024-04-14 17:59:54 +00:00
parent 2482f3c17c
commit c227f35a9c
26 changed files with 212 additions and 130 deletions

View file

@ -27,7 +27,6 @@ use std::ops::{Deref, DerefMut};
use thin_vec::thin_vec;
use crate::errors;
use crate::fluent_generated as fluent;
/// Is `self` allowed semantically as the first parameter in an `FnDecl`?
enum SelfSemantic {
@ -770,7 +769,6 @@ impl<'a> AstValidator<'a> {
MISSING_ABI,
id,
span,
fluent::ast_passes_extern_without_abi,
BuiltinLintDiag::MissingAbi(span, abi::Abi::FALLBACK),
)
}
@ -1428,17 +1426,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
Self::check_decl_no_pat(&sig.decl, |span, ident, mut_ident| {
if mut_ident && matches!(ctxt, FnCtxt::Assoc(_)) {
if let Some(ident) = ident {
let msg = match ctxt {
FnCtxt::Foreign => fluent::ast_passes_pattern_in_foreign,
_ => fluent::ast_passes_pattern_in_bodiless,
};
let diag = BuiltinLintDiag::PatternsInFnsWithoutBody(span, ident);
self.lint_buffer.buffer_lint_with_diagnostic(
PATTERNS_IN_FNS_WITHOUT_BODY,
id,
span,
msg,
diag,
BuiltinLintDiag::PatternsInFnsWithoutBody {
span,
ident,
is_foreign: matches!(ctxt, FnCtxt::Foreign),
},
)
}
} else {
@ -1514,7 +1510,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
DEPRECATED_WHERE_CLAUSE_LOCATION,
item.id,
err.span,
fluent::ast_passes_deprecated_where_clause_location,
BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg),
);
}