1
Fork 0

Auto merge of #124417 - Xiretza:translate-early-lints, r=fmease

Make early lints translatable

<del>Requires https://github.com/projectfluent/fluent-rs/pull/353.</del> 5134a04eaa

r? diagnostics
This commit is contained in:
bors 2024-05-21 21:36:09 +00:00
commit 791adf759c
80 changed files with 2114 additions and 907 deletions

View file

@ -370,11 +370,10 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
let content = self.str_from(content_start);
if contains_text_flow_control_chars(content) {
let span = self.mk_sp(start, self.pos);
self.psess.buffer_lint_with_diagnostic(
self.psess.buffer_lint(
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
span,
ast::CRATE_NODE_ID,
"unicode codepoint changing visible direction of text present in comment",
BuiltinLintDiag::UnicodeTextFlow(span, content.to_string()),
);
}
@ -723,12 +722,11 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
self.dcx().emit_err(errors::UnknownPrefix { span: prefix_span, prefix, sugg });
} else {
// Before Rust 2021, only emit a lint for migration.
self.psess.buffer_lint_with_diagnostic(
self.psess.buffer_lint(
RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
prefix_span,
ast::CRATE_NODE_ID,
format!("prefix `{prefix}` is unknown"),
BuiltinLintDiag::ReservedPrefix(prefix_span),
BuiltinLintDiag::ReservedPrefix(prefix_span, prefix.to_string()),
);
}
}

View file

@ -1913,11 +1913,10 @@ impl<'a> Parser<'a> {
| ExprKind::Block(_, None)
)
{
self.psess.buffer_lint_with_diagnostic(
self.psess.buffer_lint(
BREAK_WITH_LABEL_AND_LOOP,
lo.to(expr.span),
ast::CRATE_NODE_ID,
"this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression",
BuiltinLintDiag::BreakWithLabelAndLoop(expr.span),
);
}

View file

@ -10,6 +10,7 @@ use rustc_errors::{Applicability, FatalError, PResult};
use rustc_feature::{AttributeTemplate, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
use rustc_session::errors::report_lit_error;
use rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT;
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::parse::ParseSess;
use rustc_span::{sym, Span, Symbol};
@ -176,37 +177,26 @@ fn emit_malformed_attribute(
};
let error_msg = format!("malformed `{name}` attribute input");
let mut msg = "attribute must be of the form ".to_owned();
let mut suggestions = vec![];
let mut first = true;
let inner = if style == ast::AttrStyle::Inner { "!" } else { "" };
if template.word {
first = false;
let code = format!("#{inner}[{name}]");
msg.push_str(&format!("`{code}`"));
suggestions.push(code);
suggestions.push(format!("#{inner}[{name}]"));
}
if let Some(descr) = template.list {
if !first {
msg.push_str(" or ");
}
first = false;
let code = format!("#{inner}[{name}({descr})]");
msg.push_str(&format!("`{code}`"));
suggestions.push(code);
suggestions.push(format!("#{inner}[{name}({descr})]"));
}
if let Some(descr) = template.name_value_str {
if !first {
msg.push_str(" or ");
}
let code = format!("#{inner}[{name} = \"{descr}\"]");
msg.push_str(&format!("`{code}`"));
suggestions.push(code);
suggestions.push(format!("#{inner}[{name} = \"{descr}\"]"));
}
suggestions.sort();
if should_warn(name) {
psess.buffer_lint(ILL_FORMED_ATTRIBUTE_INPUT, span, ast::CRATE_NODE_ID, msg);
psess.buffer_lint(
ILL_FORMED_ATTRIBUTE_INPUT,
span,
ast::CRATE_NODE_ID,
BuiltinLintDiag::IllFormedAttributeInput { suggestions: suggestions.clone() },
);
} else {
suggestions.sort();
psess
.dcx
.struct_span_err(span, error_msg)