Convert uses of BuiltinLintDiag::Normal to custom variants
This ensures all diagnostic messages are created at diagnostic emission time, making them translatable.
This commit is contained in:
parent
41a20b4c56
commit
b7abf014ec
20 changed files with 295 additions and 173 deletions
|
@ -1,6 +1,7 @@
|
|||
use crate::errors;
|
||||
use crate::util::expr_to_spanned_string;
|
||||
use ast::token::IdentIsRaw;
|
||||
use lint::BuiltinLintDiag;
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Delimiter};
|
||||
|
@ -509,19 +510,19 @@ fn expand_preparsed_asm(
|
|||
};
|
||||
|
||||
if template_str.contains(".intel_syntax") {
|
||||
ecx.psess().buffer_lint(
|
||||
ecx.psess().buffer_lint_with_diagnostic(
|
||||
lint::builtin::BAD_ASM_STYLE,
|
||||
find_span(".intel_syntax"),
|
||||
ecx.current_expansion.lint_node_id,
|
||||
"avoid using `.intel_syntax`, Intel syntax is the default",
|
||||
BuiltinLintDiag::AvoidUsingIntelSyntax,
|
||||
);
|
||||
}
|
||||
if template_str.contains(".att_syntax") {
|
||||
ecx.psess().buffer_lint(
|
||||
ecx.psess().buffer_lint_with_diagnostic(
|
||||
lint::builtin::BAD_ASM_STYLE,
|
||||
find_span(".att_syntax"),
|
||||
ecx.current_expansion.lint_node_id,
|
||||
"avoid using `.att_syntax`, prefer using `options(att_syntax)` instead",
|
||||
BuiltinLintDiag::AvoidUsingAttSyntax,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use rustc_expand::base::{
|
|||
resolve_path, DummyResult, ExpandResult, ExtCtxt, MacEager, MacResult, MacroExpanderResult,
|
||||
};
|
||||
use rustc_expand::module::DirOwnership;
|
||||
use rustc_lint_defs::BuiltinLintDiag;
|
||||
use rustc_parse::new_parser_from_file;
|
||||
use rustc_parse::parser::{ForceCollect, Parser};
|
||||
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
|
||||
|
@ -143,11 +144,11 @@ pub(crate) fn expand_include<'cx>(
|
|||
fn make_expr(mut self: Box<ExpandInclude<'a>>) -> Option<P<ast::Expr>> {
|
||||
let expr = parse_expr(&mut self.p).ok()?;
|
||||
if self.p.token != token::Eof {
|
||||
self.p.psess.buffer_lint(
|
||||
self.p.psess.buffer_lint_with_diagnostic(
|
||||
INCOMPLETE_INCLUDE,
|
||||
self.p.token.span,
|
||||
self.node_id,
|
||||
"include macro expected single expression in source",
|
||||
BuiltinLintDiag::IncompleteInclude,
|
||||
);
|
||||
}
|
||||
Some(expr)
|
||||
|
|
|
@ -9,6 +9,7 @@ use rustc_ast::{attr, ModKind};
|
|||
use rustc_expand::base::{ExtCtxt, ResolverExpand};
|
||||
use rustc_expand::expand::{AstFragment, ExpansionConfig};
|
||||
use rustc_feature::Features;
|
||||
use rustc_lint_defs::BuiltinLintDiag;
|
||||
use rustc_session::lint::builtin::UNNAMEABLE_TEST_ITEMS;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::hygiene::{AstPass, SyntaxContext, Transparency};
|
||||
|
@ -159,11 +160,11 @@ struct InnerItemLinter<'a> {
|
|||
impl<'a> Visitor<'a> for InnerItemLinter<'_> {
|
||||
fn visit_item(&mut self, i: &'a ast::Item) {
|
||||
if let Some(attr) = attr::find_by_name(&i.attrs, sym::rustc_test_marker) {
|
||||
self.sess.psess.buffer_lint(
|
||||
self.sess.psess.buffer_lint_with_diagnostic(
|
||||
UNNAMEABLE_TEST_ITEMS,
|
||||
attr.span,
|
||||
i.id,
|
||||
crate::fluent_generated::builtin_macros_unnameable_test_items,
|
||||
BuiltinLintDiag::UnnameableTestItems,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
|
|||
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt};
|
||||
use rustc_expand::expand::AstFragment;
|
||||
use rustc_feature::AttributeTemplate;
|
||||
use rustc_lint_defs::builtin::DUPLICATE_MACRO_ATTRIBUTES;
|
||||
use rustc_lint_defs::{builtin::DUPLICATE_MACRO_ATTRIBUTES, BuiltinLintDiag};
|
||||
use rustc_parse::{parser, validate_attr};
|
||||
use rustc_session::errors::report_lit_error;
|
||||
use rustc_span::{BytePos, Span, Symbol};
|
||||
|
@ -42,11 +42,11 @@ pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable,
|
|||
};
|
||||
if let Some(attrs) = attrs {
|
||||
if let Some(attr) = attr::find_by_name(attrs, name) {
|
||||
ecx.psess().buffer_lint(
|
||||
ecx.psess().buffer_lint_with_diagnostic(
|
||||
DUPLICATE_MACRO_ATTRIBUTES,
|
||||
attr.span,
|
||||
ecx.current_expansion.lint_node_id,
|
||||
"duplicated attribute",
|
||||
BuiltinLintDiag::DuplicateMacroAttribute,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue