Skip to content

Commit

Permalink
Rollup merge of #121423 - nnethercote:rm-UntranslatableDiagnosticTriv…
Browse files Browse the repository at this point in the history
…ial, r=davidtwco

Remove the `UntranslatableDiagnosticTrivial` lint.

It's a specialized form of the `UntranslatableDiagnostic` lint that is deny-by-default.

Now that `UntranslatableDiagnostic` has been changed from allow-by-default to deny-by-default, the trivial variant is no longer needed.

r? ``@davidtwco``
  • Loading branch information
GuillaumeGomez authored Feb 28, 2024
2 parents c5dafe6 + 5e29e26 commit 587d828
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 88 deletions.
83 changes: 1 addition & 82 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use crate::lints::{
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
QueryInstability, SpanUseEqCtxtDiag, TyQualified, TykindDiag, TykindKind, UntranslatableDiag,
UntranslatableDiagnosticTrivial,
};
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
use rustc_ast as ast;
Expand Down Expand Up @@ -361,15 +360,7 @@ declare_tool_lint! {
report_in_external_macro: true
}

declare_tool_lint! {
/// The `untranslatable_diagnostic_trivial` lint detects diagnostics created using only static strings.
pub rustc::UNTRANSLATABLE_DIAGNOSTIC_TRIVIAL,
Deny,
"prevent creation of diagnostics which cannot be translated, which use only static strings",
report_in_external_macro: true
}

declare_lint_pass!(Diagnostics => [ UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE_OF_IMPL, UNTRANSLATABLE_DIAGNOSTIC_TRIVIAL ]);
declare_lint_pass!(Diagnostics => [UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE_OF_IMPL]);

impl LateLintPass<'_> for Diagnostics {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
Expand Down Expand Up @@ -425,78 +416,6 @@ impl LateLintPass<'_> for Diagnostics {
}
}

impl EarlyLintPass for Diagnostics {
#[allow(unused_must_use)]
fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) {
// Looking for a straight chain of method calls from 'struct_span_err' to 'emit'.
let ast::StmtKind::Semi(expr) = &stmt.kind else {
return;
};
let ast::ExprKind::MethodCall(meth) = &expr.kind else {
return;
};
if meth.seg.ident.name != sym::emit || !meth.args.is_empty() {
return;
}
let mut segments = vec![];
let mut cur = &meth.receiver;
let fake = &[].into();
loop {
match &cur.kind {
ast::ExprKind::Call(func, args) => {
if let ast::ExprKind::Path(_, path) = &func.kind {
segments.push((path.segments.last().unwrap().ident.name, args))
}
break;
}
ast::ExprKind::MethodCall(method) => {
segments.push((method.seg.ident.name, &method.args));
cur = &method.receiver;
}
ast::ExprKind::MacCall(mac) => {
segments.push((mac.path.segments.last().unwrap().ident.name, fake));
break;
}
_ => {
break;
}
}
}
segments.reverse();
if segments.is_empty() {
return;
}
if segments[0].0.as_str() != "struct_span_err" {
return;
}
if !segments.iter().all(|(name, args)| {
let arg = match name.as_str() {
"struct_span_err" | "span_note" | "span_label" | "span_help" if args.len() == 2 => {
&args[1]
}
"note" | "help" if args.len() == 1 => &args[0],
_ => {
return false;
}
};
if let ast::ExprKind::Lit(lit) = arg.kind
&& let ast::token::LitKind::Str = lit.kind
{
true
} else {
false
}
}) {
return;
}
cx.emit_span_lint(
UNTRANSLATABLE_DIAGNOSTIC_TRIVIAL,
stmt.span,
UntranslatableDiagnosticTrivial,
);
}
}

declare_tool_lint! {
/// The `bad_opt_access` lint detects accessing options by field instead of
/// the wrapper function.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ fn register_internals(store: &mut LintStore) {
store.register_lints(&TyTyKind::get_lints());
store.register_late_mod_pass(|_| Box::new(TyTyKind));
store.register_lints(&Diagnostics::get_lints());
store.register_early_pass(|| Box::new(Diagnostics));
store.register_late_mod_pass(|_| Box::new(Diagnostics));
store.register_lints(&BadOptAccess::get_lints());
store.register_late_mod_pass(|_| Box::new(BadOptAccess));
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,6 @@ pub struct DiagOutOfImpl;
#[diag(lint_untranslatable_diag)]
pub struct UntranslatableDiag;

#[derive(LintDiagnostic)]
#[diag(lint_trivial_untranslatable_diag)]
pub struct UntranslatableDiagnosticTrivial;

#[derive(LintDiagnostic)]
#[diag(lint_bad_opt_access)]
pub struct BadOptAccessDiag<'a> {
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/clippy_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
clippy::missing_panics_doc,
rustc::diagnostic_outside_of_impl,
rustc::untranslatable_diagnostic,
rustc::untranslatable_diagnostic_trivial
)]

extern crate rustc_ast;
Expand Down

0 comments on commit 587d828

Please sign in to comment.