Skip to content

Commit 291df97

Browse files
authored
Rollup merge of #98624 - davidtwco:translation-on-lints, r=compiler-errors
lints: mostly translatable diagnostics As lints are created slightly differently than other diagnostics, intended to try make them translatable first and then look into the applicability of diagnostic structs but ended up just making most of the diagnostics in the crate translatable (which will still be useful if I do make a lot of them structs later anyway). r? ``@compiler-errors``
2 parents 8fa1ed8 + 9ff6c77 commit 291df97

30 files changed

+1114
-708
lines changed

Diff for: compiler/rustc_error_messages/locales/en-US/lint.ftl

+400
Large diffs are not rendered by default.

Diff for: compiler/rustc_error_messages/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ pub use unic_langid::{langid, LanguageIdentifier};
3131

3232
// Generates `DEFAULT_LOCALE_RESOURCES` static and `fluent_generated` module.
3333
fluent_messages! {
34+
borrowck => "../locales/en-US/borrowck.ftl",
35+
builtin_macros => "../locales/en-US/builtin_macros.ftl",
36+
lint => "../locales/en-US/lint.ftl",
3437
parser => "../locales/en-US/parser.ftl",
3538
privacy => "../locales/en-US/privacy.ftl",
3639
typeck => "../locales/en-US/typeck.ftl",
37-
builtin_macros => "../locales/en-US/builtin_macros.ftl",
38-
borrowck => "../locales/en-US/borrowck.ftl",
3940
}
4041

4142
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};

Diff for: compiler/rustc_errors/src/diagnostic.rs

+83-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_error_messages::FluentValue;
88
use rustc_lint_defs::{Applicability, LintExpectationId};
99
use rustc_span::edition::LATEST_STABLE_EDITION;
1010
use rustc_span::symbol::{Ident, Symbol};
11-
use rustc_span::{Span, DUMMY_SP};
11+
use rustc_span::{edition::Edition, Span, DUMMY_SP};
1212
use std::borrow::Cow;
1313
use std::fmt;
1414
use std::hash::{Hash, Hasher};
@@ -39,12 +39,94 @@ pub trait IntoDiagnosticArg {
3939
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
4040
}
4141

42+
impl IntoDiagnosticArg for bool {
43+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
44+
if self {
45+
DiagnosticArgValue::Str(Cow::Borrowed("true"))
46+
} else {
47+
DiagnosticArgValue::Str(Cow::Borrowed("false"))
48+
}
49+
}
50+
}
51+
52+
impl IntoDiagnosticArg for i8 {
53+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
54+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
55+
}
56+
}
57+
58+
impl IntoDiagnosticArg for u8 {
59+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
60+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
61+
}
62+
}
63+
64+
impl IntoDiagnosticArg for i16 {
65+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
66+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
67+
}
68+
}
69+
70+
impl IntoDiagnosticArg for u16 {
71+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
72+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
73+
}
74+
}
75+
76+
impl IntoDiagnosticArg for i32 {
77+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
78+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
79+
}
80+
}
81+
82+
impl IntoDiagnosticArg for u32 {
83+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
84+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
85+
}
86+
}
87+
88+
impl IntoDiagnosticArg for i64 {
89+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
90+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
91+
}
92+
}
93+
94+
impl IntoDiagnosticArg for u64 {
95+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
96+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
97+
}
98+
}
99+
100+
impl IntoDiagnosticArg for i128 {
101+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
102+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
103+
}
104+
}
105+
106+
impl IntoDiagnosticArg for u128 {
107+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
108+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
109+
}
110+
}
111+
42112
impl IntoDiagnosticArg for String {
43113
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
44114
DiagnosticArgValue::Str(Cow::Owned(self))
45115
}
46116
}
47117

118+
impl IntoDiagnosticArg for std::num::NonZeroU32 {
119+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
120+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
121+
}
122+
}
123+
124+
impl IntoDiagnosticArg for Edition {
125+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
126+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
127+
}
128+
}
129+
48130
impl IntoDiagnosticArg for Symbol {
49131
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
50132
self.to_ident_string().into_diagnostic_arg()

Diff for: compiler/rustc_errors/src/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
529529
applicability: Applicability,
530530
) -> &mut Self);
531531

532-
forward!(pub fn set_primary_message(&mut self, msg: impl Into<String>) -> &mut Self);
532+
forward!(pub fn set_primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self);
533533
forward!(pub fn set_span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self);
534534
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
535535
forward!(pub fn set_arg(

Diff for: compiler/rustc_lint/src/array_into_iter.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{LateContext, LateLintPass, LintContext};
2-
use rustc_errors::Applicability;
2+
use rustc_errors::{fluent, Applicability};
33
use rustc_hir as hir;
44
use rustc_middle::ty;
55
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
@@ -120,31 +120,30 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
120120
_ => bug!("array type coerced to something other than array or slice"),
121121
};
122122
cx.struct_span_lint(ARRAY_INTO_ITER, call.ident.span, |lint| {
123-
let mut diag = lint.build(&format!(
124-
"this method call resolves to `<&{} as IntoIterator>::into_iter` \
125-
(due to backwards compatibility), \
126-
but will resolve to <{} as IntoIterator>::into_iter in Rust 2021",
127-
target, target,
128-
));
123+
let mut diag = lint.build(fluent::lint::array_into_iter);
124+
diag.set_arg("target", target);
129125
diag.span_suggestion(
130126
call.ident.span,
131-
"use `.iter()` instead of `.into_iter()` to avoid ambiguity",
127+
fluent::lint::use_iter_suggestion,
132128
"iter",
133129
Applicability::MachineApplicable,
134130
);
135131
if self.for_expr_span == expr.span {
136132
diag.span_suggestion(
137133
receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
138-
"or remove `.into_iter()` to iterate by value",
134+
fluent::lint::remove_into_iter_suggestion,
139135
"",
140136
Applicability::MaybeIncorrect,
141137
);
142138
} else if receiver_ty.is_array() {
143139
diag.multipart_suggestion(
144-
"or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value",
140+
fluent::lint::use_explicit_into_iter_suggestion,
145141
vec![
146142
(expr.span.shrink_to_lo(), "IntoIterator::into_iter(".into()),
147-
(receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()), ")".into()),
143+
(
144+
receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
145+
")".into(),
146+
),
148147
],
149148
Applicability::MaybeIncorrect,
150149
);

0 commit comments

Comments
 (0)