Rollup merge of #121382 - nnethercote:rework-untranslatable_diagnostic-lint, r=davidtwco
Rework `untranslatable_diagnostic` lint Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This PR changes it to check calls to any function with an `impl Into<{D,Subd}iagnosticMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. It also lets us add `#[rustc_lint_diagnostics]` to a number of functions that don't have an `impl Into<{D,Subd}iagnosticMessage>`, such as `Diag::span`. r? ``@davidtwco``
This commit is contained in:
commit
efe9deace8
42 changed files with 305 additions and 89 deletions
|
@ -1493,6 +1493,8 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
|
|||
};
|
||||
|
||||
if crate_matches {
|
||||
// FIXME: make this translatable
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
sess.psess.buffer_lint_with_diagnostic(
|
||||
PROC_MACRO_BACK_COMPAT,
|
||||
item.ident.span,
|
||||
|
|
|
@ -239,6 +239,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||
/// Gives a compiler warning when the `cfg_attr` contains no attributes and
|
||||
/// is in the original source file. Gives a compiler error if the syntax of
|
||||
/// the attribute is incorrect.
|
||||
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
||||
pub(crate) fn expand_cfg_attr(&self, attr: &Attribute, recursive: bool) -> Vec<Attribute> {
|
||||
let Some((cfg_predicate, expanded_attrs)) =
|
||||
rustc_parse::parse_cfg_attr(attr, &self.sess.psess)
|
||||
|
@ -273,6 +274,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
||||
fn expand_cfg_attr_item(
|
||||
&self,
|
||||
attr: &Attribute,
|
||||
|
@ -371,6 +373,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||
}
|
||||
|
||||
/// If attributes are not allowed on expressions, emit an error for `attr`
|
||||
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
|
||||
if self.features.is_some_and(|features| !features.stmt_expr_attributes)
|
||||
|
@ -384,7 +387,6 @@ impl<'a> StripUnconfigured<'a> {
|
|||
);
|
||||
|
||||
if attr.is_doc_comment() {
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
err.help("`///` is for documentation comments. For a plain comment, use `//`.");
|
||||
}
|
||||
|
||||
|
|
|
@ -783,6 +783,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
})
|
||||
}
|
||||
|
||||
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
||||
fn gate_proc_macro_attr_item(&self, span: Span, item: &Annotatable) {
|
||||
let kind = match item {
|
||||
Annotatable::Item(_)
|
||||
|
@ -825,6 +826,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
}
|
||||
|
||||
impl<'ast, 'a> Visitor<'ast> for GateProcMacroInput<'a> {
|
||||
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
||||
fn visit_item(&mut self, item: &'ast ast::Item) {
|
||||
match &item.kind {
|
||||
ItemKind::Mod(_, mod_kind)
|
||||
|
@ -1689,6 +1691,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
|||
|
||||
// Detect use of feature-gated or invalid attributes on macro invocations
|
||||
// since they will not be detected after macro expansion.
|
||||
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
||||
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
|
||||
let features = self.cx.ecfg.features;
|
||||
let mut attrs = attrs.iter().peekable();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#![feature(associated_type_defaults)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(lint_reasons)]
|
||||
#![feature(macro_metavar_expr)]
|
||||
#![feature(map_try_insert)]
|
||||
#![feature(proc_macro_diagnostic)]
|
||||
|
|
|
@ -517,6 +517,9 @@ impl server::FreeFunctions for Rustc<'_, '_> {
|
|||
Diag::new(&self.psess().dcx, diagnostic.level.to_internal(), message);
|
||||
diag.span(MultiSpan::from_spans(diagnostic.spans));
|
||||
for child in diagnostic.children {
|
||||
// This message comes from another diagnostic, and we are just reconstructing the
|
||||
// diagnostic, so there's no need for translation.
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
diag.sub(child.level.to_internal(), child.message, MultiSpan::from_spans(child.spans));
|
||||
}
|
||||
diag.emit();
|
||||
|
|
|
@ -178,6 +178,7 @@ impl<T: Write> Write for Shared<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(rustc::untranslatable_diagnostic)] // no translation needed for tests
|
||||
fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &str) {
|
||||
create_default_session_globals_then(|| {
|
||||
let (handler, source_map, output) = create_test_handler();
|
||||
|
@ -192,7 +193,6 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
|
|||
println!("text: {:?}", source_map.span_to_snippet(span));
|
||||
}
|
||||
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
handler.span_err(msp, "foo");
|
||||
|
||||
assert!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue