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 @@ pub fn span_labels(
|
|||||||
applicability: Applicability,
|
applicability: Applicability,
|
||||||
) -> &mut Self);
|
) -> &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 set_span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self);
|
||||||
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
||||||
forward!(pub fn set_arg(
|
forward!(pub fn set_arg(
|
||||||
|
@ -521,7 +521,7 @@ pub(crate) fn push(
|
|||||||
src,
|
src,
|
||||||
Some(sp.into()),
|
Some(sp.into()),
|
||||||
|lint| {
|
|lint| {
|
||||||
let mut err = lint.build(&msg);
|
let mut err = lint.build(msg);
|
||||||
if let Some(new_name) = &renamed {
|
if let Some(new_name) = &renamed {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
@ -548,7 +548,7 @@ pub(crate) fn push(
|
|||||||
} else {
|
} else {
|
||||||
name.to_string()
|
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 {
|
if let Some(suggestion) = suggestion {
|
||||||
db.span_suggestion(
|
db.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
Diagnostic, DiagnosticBuilder, DiagnosticId, EmissionGuarantee, ErrorGuaranteed, MultiSpan,
|
Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, EmissionGuarantee,
|
||||||
|
ErrorGuaranteed, MultiSpan,
|
||||||
};
|
};
|
||||||
use rustc_hir::HirId;
|
use rustc_hir::HirId;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
@ -231,7 +232,7 @@ pub fn new(
|
|||||||
|
|
||||||
impl<'a, G: EmissionGuarantee> LintDiagnosticBuilder<'a, G> {
|
impl<'a, G: EmissionGuarantee> LintDiagnosticBuilder<'a, G> {
|
||||||
/// Return the inner `DiagnosticBuilder`, first setting the primary message to `msg`.
|
/// 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_primary_message(msg);
|
||||||
self.0.set_is_lint();
|
self.0.set_is_lint();
|
||||||
self.0
|
self.0
|
||||||
|
@ -550,7 +550,7 @@ fn recur(
|
|||||||
id,
|
id,
|
||||||
span,
|
span,
|
||||||
|lint| {
|
|lint| {
|
||||||
lint.build(&msg).emit();
|
lint.build(msg).emit();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1163,7 +1163,7 @@ fn check_doc_attrs(
|
|||||||
hir_id,
|
hir_id,
|
||||||
meta.span(),
|
meta.span(),
|
||||||
|lint| {
|
|lint| {
|
||||||
lint.build(&"invalid `doc` attribute").emit();
|
lint.build("invalid `doc` attribute").emit();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
is_valid = false;
|
is_valid = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user