errors: lint on LintDiagnosticBuilder::build
Apply the `#[rustc_lint_diagnostics]` attribute to `LintDiagnosticBuilder::build` so that diagnostic migration lints will trigger for it. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
06f480661f
commit
c3fdf74885
4 changed files with 39 additions and 24 deletions
|
@ -10,3 +10,12 @@ privacy-unnamed-item-is-private = {$kind} is private
|
||||||
privacy-in-public-interface = {$vis_descr} {$kind} `{$descr}` in public interface
|
privacy-in-public-interface = {$vis_descr} {$kind} `{$descr}` in public interface
|
||||||
.label = can't leak {$vis_descr} {$kind}
|
.label = can't leak {$vis_descr} {$kind}
|
||||||
.visibility-label = `{$descr}` declared as {$vis_descr}
|
.visibility-label = `{$descr}` declared as {$vis_descr}
|
||||||
|
|
||||||
|
privacy-from-private-dep-in-public-interface =
|
||||||
|
{$kind} `{$descr}` from private dependency '{$krate}' in public interface
|
||||||
|
|
||||||
|
private-in-public-lint =
|
||||||
|
{$vis_descr} {$kind} `{$descr}` in public interface (error {$kind ->
|
||||||
|
[trait] E0445
|
||||||
|
*[other] E0446
|
||||||
|
})
|
||||||
|
|
|
@ -595,6 +595,7 @@ macro_rules! error_code {
|
||||||
pub struct LintDiagnosticBuilder<'a, G: EmissionGuarantee>(DiagnosticBuilder<'a, G>);
|
pub struct LintDiagnosticBuilder<'a, G: EmissionGuarantee>(DiagnosticBuilder<'a, G>);
|
||||||
|
|
||||||
impl<'a, G: EmissionGuarantee> LintDiagnosticBuilder<'a, G> {
|
impl<'a, G: EmissionGuarantee> LintDiagnosticBuilder<'a, G> {
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
/// 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: impl Into<DiagnosticMessage>) -> 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);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
|
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
#[derive(SessionDiagnostic)]
|
#[derive(SessionDiagnostic)]
|
||||||
|
@ -73,3 +73,19 @@ pub struct InPublicInterface<'a> {
|
||||||
#[label(privacy::visibility_label)]
|
#[label(privacy::visibility_label)]
|
||||||
pub vis_span: Span,
|
pub vis_span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[lint(privacy::from_private_dep_in_public_interface)]
|
||||||
|
pub struct FromPrivateDependencyInPublicInterface<'a> {
|
||||||
|
pub kind: &'a str,
|
||||||
|
pub descr: String,
|
||||||
|
pub krate: Symbol,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[lint(privacy::private_in_public_lint)]
|
||||||
|
pub struct PrivateInPublicLint<'a> {
|
||||||
|
pub vis_descr: &'static str,
|
||||||
|
pub kind: &'a str,
|
||||||
|
pub descr: String,
|
||||||
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ use std::ops::ControlFlow;
|
||||||
use std::{cmp, fmt, mem};
|
use std::{cmp, fmt, mem};
|
||||||
|
|
||||||
use errors::{
|
use errors::{
|
||||||
FieldIsPrivate, FieldIsPrivateLabel, InPublicInterface, InPublicInterfaceTraits, ItemIsPrivate,
|
FieldIsPrivate, FieldIsPrivateLabel, FromPrivateDependencyInPublicInterface, InPublicInterface,
|
||||||
UnnamedItemIsPrivate,
|
InPublicInterfaceTraits, ItemIsPrivate, PrivateInPublicLint, UnnamedItemIsPrivate,
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1716,19 +1716,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
||||||
|
|
||||||
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
|
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
|
||||||
if self.leaks_private_dep(def_id) {
|
if self.leaks_private_dep(def_id) {
|
||||||
self.tcx.struct_span_lint_hir(
|
self.tcx.emit_spanned_lint(
|
||||||
lint::builtin::EXPORTED_PRIVATE_DEPENDENCIES,
|
lint::builtin::EXPORTED_PRIVATE_DEPENDENCIES,
|
||||||
self.tcx.hir().local_def_id_to_hir_id(self.item_def_id),
|
self.tcx.hir().local_def_id_to_hir_id(self.item_def_id),
|
||||||
self.tcx.def_span(self.item_def_id.to_def_id()),
|
self.tcx.def_span(self.item_def_id.to_def_id()),
|
||||||
|lint| {
|
FromPrivateDependencyInPublicInterface {
|
||||||
lint.build(&format!(
|
kind,
|
||||||
"{} `{}` from private dependency '{}' in public \
|
descr: descr.to_string(),
|
||||||
interface",
|
krate: self.tcx.crate_name(def_id.krate),
|
||||||
kind,
|
|
||||||
descr,
|
|
||||||
self.tcx.crate_name(def_id.krate)
|
|
||||||
))
|
|
||||||
.emit();
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1754,12 +1749,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let span = self.tcx.def_span(self.item_def_id.to_def_id());
|
let span = self.tcx.def_span(self.item_def_id.to_def_id());
|
||||||
|
let descr = descr.to_string();
|
||||||
if self.has_old_errors
|
if self.has_old_errors
|
||||||
|| self.in_assoc_ty
|
|| self.in_assoc_ty
|
||||||
|| self.tcx.resolutions(()).has_pub_restricted
|
|| self.tcx.resolutions(()).has_pub_restricted
|
||||||
{
|
{
|
||||||
let descr = descr.to_string();
|
let descr = descr.to_string();
|
||||||
let vis_span = self.tcx.def_span(def_id);
|
let vis_span =
|
||||||
|
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id));
|
||||||
if kind == "trait" {
|
if kind == "trait" {
|
||||||
self.tcx.sess.emit_err(InPublicInterfaceTraits {
|
self.tcx.sess.emit_err(InPublicInterfaceTraits {
|
||||||
span,
|
span,
|
||||||
|
@ -1778,19 +1775,11 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let err_code = if kind == "trait" { "E0445" } else { "E0446" };
|
self.tcx.emit_spanned_lint(
|
||||||
self.tcx.struct_span_lint_hir(
|
|
||||||
lint::builtin::PRIVATE_IN_PUBLIC,
|
lint::builtin::PRIVATE_IN_PUBLIC,
|
||||||
hir_id,
|
hir_id,
|
||||||
span,
|
span,
|
||||||
|lint| {
|
PrivateInPublicLint { vis_descr, kind, descr },
|
||||||
lint.build(&format!(
|
|
||||||
"{} (error {})",
|
|
||||||
format!("{} {} `{}` in public interface", vis_descr, kind, descr),
|
|
||||||
err_code
|
|
||||||
))
|
|
||||||
.emit();
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue