Skip to content

Commit c14998d

Browse files
committed
Rewrite the untranslatable_diagnostic lint.
Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This commit changes it to check calls to any function with a `impl Into<{D,Subd}iagnosticMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. The commit also adds `#[allow(rustc::untranslatable_diagnostic)`] attributes to places that need it that are caught by the improved lint. These places that might be easy to convert to translatable diagnostics. Finally, it also: - Expands and corrects some comments. - Does some minor formatting improvements. - Adds missing `DecorateLint` cases to `tests/ui-fulldeps/internal-lints/diagnostics.rs`.
1 parent 5f7c52e commit c14998d

File tree

35 files changed

+224
-60
lines changed

35 files changed

+224
-60
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::collections::hash_map::Entry;
2222
use std::fmt::Write;
2323

2424
impl<'a, 'hir> LoweringContext<'a, 'hir> {
25+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
2526
pub(crate) fn lower_inline_asm(
2627
&mut self,
2728
sp: Span,

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14991499
}
15001500
}
15011501

1502+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
15021503
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
15031504
let is_async_gen = match self.coroutine_kind {
15041505
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,6 +2272,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22722272
self.expr_block(block)
22732273
}
22742274

2275+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
22752276
fn lower_array_length(&mut self, c: &AnonConst) -> hir::ArrayLen {
22762277
match c.value.kind {
22772278
ExprKind::Underscore => {

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::errors;
1717
macro_rules! gate {
1818
($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {{
1919
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
20+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
2021
feature_err(&$visitor.sess, sym::$feature, $span, $explain).emit();
2122
}
2223
}};
@@ -34,6 +35,7 @@ macro_rules! gate {
3435
macro_rules! gate_alt {
3536
($visitor:expr, $has_feature:expr, $name:expr, $span:expr, $explain:expr) => {{
3637
if !$has_feature && !$span.allows_unstable($name) {
38+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
3739
feature_err(&$visitor.sess, $name, $span, $explain).emit();
3840
}
3941
}};
@@ -73,6 +75,7 @@ struct PostExpansionVisitor<'a> {
7375
}
7476

7577
impl<'a> PostExpansionVisitor<'a> {
78+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
7679
fn check_abi(&self, abi: ast::StrLit, constness: ast::Const) {
7780
let ast::StrLit { symbol_unescaped, span, .. } = abi;
7881

@@ -579,6 +582,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
579582
if let Ok(snippet) = sm.span_to_snippet(span)
580583
&& snippet == "!"
581584
{
585+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
582586
feature_err(sess, sym::never_patterns, span, "`!` patterns are experimental")
583587
.emit();
584588
} else {

compiler/rustc_attr/src/builtin.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ pub struct Condition {
516516
}
517517

518518
/// Tests if a cfg-pattern matches the cfg set
519+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
519520
pub fn cfg_matches(
520521
cfg: &ast::MetaItem,
521522
sess: &Session,
@@ -566,6 +567,7 @@ fn try_gate_cfg(name: Symbol, span: Span, sess: &Session, features: Option<&Feat
566567
}
567568
}
568569

570+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
569571
fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &Session, features: &Features) {
570572
let (cfg, feature, has_feature) = gated_cfg;
571573
if !has_feature(features) && !cfg_span.allows_unstable(*feature) {
@@ -592,6 +594,7 @@ fn parse_version(s: Symbol) -> Option<RustcVersion> {
592594

593595
/// Evaluate a cfg-like condition (with `any` and `all`), using `eval` to
594596
/// evaluate individual items.
597+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
595598
pub fn eval_condition(
596599
cfg: &ast::MetaItem,
597600
sess: &Session,

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10081008
self.borrow_spans(span, borrow.reserve_location)
10091009
}
10101010

1011+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
10111012
fn explain_captures(
10121013
&mut self,
10131014
err: &mut Diag<'_>,

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
201201
// For generic associated types (GATs) which implied 'static requirement
202202
// from higher-ranked trait bounds (HRTB). Try to locate span of the trait
203203
// and the span which bounded to the trait for adding 'static lifetime suggestion
204+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
204205
fn suggest_static_lifetime_for_gat_from_hrtb(
205206
&self,
206207
diag: &mut Diag<'_>,
@@ -822,6 +823,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
822823
/// LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + 'a {
823824
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
824825
/// ```
826+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
825827
fn add_static_impl_trait_suggestion(
826828
&self,
827829
diag: &mut Diag<'_>,
@@ -972,6 +974,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
972974
self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty);
973975
}
974976

977+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
975978
#[instrument(skip(self, err), level = "debug")]
976979
fn suggest_constrain_dyn_trait_in_impl(
977980
&self,
@@ -1034,6 +1037,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10341037
suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag);
10351038
}
10361039

1040+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
10371041
fn suggest_move_on_borrowing_closure(&self, diag: &mut Diag<'_>) {
10381042
let map = self.infcx.tcx.hir();
10391043
let body_id = map.body_owned_by(self.mir_def_id());

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl<'tcx> NonConstOp<'tcx> for FloatingPointOp {
6262
}
6363
}
6464

65+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
6566
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
6667
feature_err(
6768
&ccx.tcx.sess,
@@ -556,6 +557,7 @@ impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
556557
Status::Unstable(sym::const_mut_refs)
557558
}
558559

560+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
559561
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
560562
feature_err(
561563
&ccx.tcx.sess,
@@ -589,6 +591,7 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess {
589591
}
590592
}
591593

594+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
592595
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
593596
let mut err = feature_err(
594597
&ccx.tcx.sess,
@@ -632,6 +635,7 @@ pub mod ty {
632635
}
633636
}
634637

638+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
635639
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
636640
feature_err(
637641
&ccx.tcx.sess,

compiler/rustc_driver_impl/src/args.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ impl Expander {
9797
/// **Note:** This function doesn't interpret argument 0 in any special way.
9898
/// If this function is intended to be used with command line arguments,
9999
/// `argv[0]` must be removed prior to calling it manually.
100+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
100101
pub fn arg_expand_all(early_dcx: &EarlyDiagCtxt, at_args: &[String]) -> Vec<String> {
101102
let mut expander = Expander::default();
102103
for arg in at_args {

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//!
55
//! This API is completely unstable and subject to change.
66
7+
#![allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
78
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
89
#![doc(rust_logo)]
910
#![feature(rustdoc_internals)]

0 commit comments

Comments
 (0)