Skip to content

Commit 7d2eba6

Browse files
committed
middle: translation in LintDiagnosticBuilder
Accept `DiagnosticMessage` in `LintDiagnosticBuilder::build` so that lints can be built with translatable diagnostic messages. Signed-off-by: David Wood <[email protected]>
1 parent a9eb9c5 commit 7d2eba6

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

compiler/rustc_errors/src/diagnostic_builder.rs

Lines changed: 1 addition & 1 deletion
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(

compiler/rustc_lint/src/levels.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl<'s> LintLevelsBuilder<'s> {
521521
src,
522522
Some(sp.into()),
523523
|lint| {
524-
let mut err = lint.build(&msg);
524+
let mut err = lint.build(msg);
525525
if let Some(new_name) = &renamed {
526526
err.span_suggestion(
527527
sp,
@@ -548,7 +548,7 @@ impl<'s> LintLevelsBuilder<'s> {
548548
} else {
549549
name.to_string()
550550
};
551-
let mut db = lint.build(&format!("unknown lint: `{}`", name));
551+
let mut db = lint.build(format!("unknown lint: `{}`", name));
552552
if let Some(suggestion) = suggestion {
553553
db.span_suggestion(
554554
sp,

compiler/rustc_middle/src/lint.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::cmp;
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
55
use rustc_errors::{
6-
Diagnostic, DiagnosticBuilder, DiagnosticId, EmissionGuarantee, ErrorGuaranteed, MultiSpan,
6+
Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, EmissionGuarantee,
7+
ErrorGuaranteed, MultiSpan,
78
};
89
use rustc_hir::HirId;
910
use rustc_index::vec::IndexVec;
@@ -231,7 +232,7 @@ pub struct LintDiagnosticBuilder<'a, G: EmissionGuarantee>(DiagnosticBuilder<'a,
231232

232233
impl<'a, G: EmissionGuarantee> LintDiagnosticBuilder<'a, G> {
233234
/// Return the inner `DiagnosticBuilder`, first setting the primary message to `msg`.
234-
pub fn build(mut self, msg: &str) -> DiagnosticBuilder<'a, G> {
235+
pub fn build(mut self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'a, G> {
235236
self.0.set_primary_message(msg);
236237
self.0.set_is_lint();
237238
self.0

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
550550
id,
551551
span,
552552
|lint| {
553-
lint.build(&msg).emit();
553+
lint.build(msg).emit();
554554
},
555555
);
556556
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ impl CheckAttrVisitor<'_> {
11631163
hir_id,
11641164
meta.span(),
11651165
|lint| {
1166-
lint.build(&"invalid `doc` attribute").emit();
1166+
lint.build("invalid `doc` attribute").emit();
11671167
},
11681168
);
11691169
is_valid = false;

0 commit comments

Comments
 (0)