mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
middle: translation in LintDiagnosticBuilder
Accept `DiagnosticMessage` in `LintDiagnosticBuilder::build` so that lints can be built with translatable diagnostic messages. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
a9eb9c52f3
commit
7d2eba6311
@ -529,7 +529,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
applicability: Applicability,
|
||||
) -> &mut Self);
|
||||
|
||||
forward!(pub fn set_primary_message(&mut self, msg: impl Into<String>) -> &mut Self);
|
||||
forward!(pub fn set_primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self);
|
||||
forward!(pub fn set_span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self);
|
||||
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
||||
forward!(pub fn set_arg(
|
||||
|
@ -521,7 +521,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||
src,
|
||||
Some(sp.into()),
|
||||
|lint| {
|
||||
let mut err = lint.build(&msg);
|
||||
let mut err = lint.build(msg);
|
||||
if let Some(new_name) = &renamed {
|
||||
err.span_suggestion(
|
||||
sp,
|
||||
@ -548,7 +548,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||
} else {
|
||||
name.to_string()
|
||||
};
|
||||
let mut db = lint.build(&format!("unknown lint: `{}`", name));
|
||||
let mut db = lint.build(format!("unknown lint: `{}`", name));
|
||||
if let Some(suggestion) = suggestion {
|
||||
db.span_suggestion(
|
||||
sp,
|
||||
|
@ -3,7 +3,8 @@ use std::cmp;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_errors::{
|
||||
Diagnostic, DiagnosticBuilder, DiagnosticId, EmissionGuarantee, ErrorGuaranteed, MultiSpan,
|
||||
Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, EmissionGuarantee,
|
||||
ErrorGuaranteed, MultiSpan,
|
||||
};
|
||||
use rustc_hir::HirId;
|
||||
use rustc_index::vec::IndexVec;
|
||||
@ -231,7 +232,7 @@ pub struct LintDiagnosticBuilder<'a, G: EmissionGuarantee>(DiagnosticBuilder<'a,
|
||||
|
||||
impl<'a, G: EmissionGuarantee> LintDiagnosticBuilder<'a, G> {
|
||||
/// Return the inner `DiagnosticBuilder`, first setting the primary message to `msg`.
|
||||
pub fn build(mut self, msg: &str) -> DiagnosticBuilder<'a, G> {
|
||||
pub fn build(mut self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'a, G> {
|
||||
self.0.set_primary_message(msg);
|
||||
self.0.set_is_lint();
|
||||
self.0
|
||||
|
@ -550,7 +550,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
||||
id,
|
||||
span,
|
||||
|lint| {
|
||||
lint.build(&msg).emit();
|
||||
lint.build(msg).emit();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -1163,7 +1163,7 @@ impl CheckAttrVisitor<'_> {
|
||||
hir_id,
|
||||
meta.span(),
|
||||
|lint| {
|
||||
lint.build(&"invalid `doc` attribute").emit();
|
||||
lint.build("invalid `doc` attribute").emit();
|
||||
},
|
||||
);
|
||||
is_valid = false;
|
||||
|
Loading…
Reference in New Issue
Block a user