move DiagnosticArgFromDisplay into rustc_errors
This commit is contained in:
parent
0ad57d8502
commit
694a010a5c
4 changed files with 36 additions and 31 deletions
|
@ -40,6 +40,26 @@ pub trait IntoDiagnosticArg {
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display);
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for DiagnosticArgFromDisplay<'_> {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
self.0.to_string().into_diagnostic_arg()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&'a dyn fmt::Display> for DiagnosticArgFromDisplay<'a> {
|
||||||
|
fn from(t: &'a dyn fmt::Display) -> Self {
|
||||||
|
DiagnosticArgFromDisplay(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T: fmt::Display> From<&'a T> for DiagnosticArgFromDisplay<'a> {
|
||||||
|
fn from(t: &'a T) -> Self {
|
||||||
|
DiagnosticArgFromDisplay(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! into_diagnostic_arg_using_display {
|
macro_rules! into_diagnostic_arg_using_display {
|
||||||
($( $ty:ty ),+ $(,)?) => {
|
($( $ty:ty ),+ $(,)?) => {
|
||||||
$(
|
$(
|
||||||
|
|
|
@ -371,8 +371,8 @@ impl fmt::Display for ExplicitBug {
|
||||||
impl error::Error for ExplicitBug {}
|
impl error::Error for ExplicitBug {}
|
||||||
|
|
||||||
pub use diagnostic::{
|
pub use diagnostic::{
|
||||||
AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
|
AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgFromDisplay,
|
||||||
DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
|
DiagnosticArgValue, DiagnosticId, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
|
||||||
};
|
};
|
||||||
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder};
|
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder};
|
||||||
use std::backtrace::Backtrace;
|
use std::backtrace::Backtrace;
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
use std::fmt::Display;
|
use rustc_errors::DiagnosticArgFromDisplay;
|
||||||
|
|
||||||
use rustc_errors::IntoDiagnosticArg;
|
|
||||||
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
|
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
|
@ -38,7 +36,7 @@ pub struct ItemIsPrivate<'a> {
|
||||||
#[label]
|
#[label]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub kind: &'a str,
|
pub kind: &'a str,
|
||||||
pub descr: FromDisplay<'a>,
|
pub descr: DiagnosticArgFromDisplay<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SessionDiagnostic)]
|
#[derive(SessionDiagnostic)]
|
||||||
|
@ -58,7 +56,7 @@ pub struct InPublicInterfaceTraits<'a> {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub vis_descr: &'static str,
|
pub vis_descr: &'static str,
|
||||||
pub kind: &'a str,
|
pub kind: &'a str,
|
||||||
pub descr: FromDisplay<'a>,
|
pub descr: DiagnosticArgFromDisplay<'a>,
|
||||||
#[label(privacy::visibility_label)]
|
#[label(privacy::visibility_label)]
|
||||||
pub vis_span: Span,
|
pub vis_span: Span,
|
||||||
}
|
}
|
||||||
|
@ -72,7 +70,7 @@ pub struct InPublicInterface<'a> {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub vis_descr: &'static str,
|
pub vis_descr: &'static str,
|
||||||
pub kind: &'a str,
|
pub kind: &'a str,
|
||||||
pub descr: FromDisplay<'a>,
|
pub descr: DiagnosticArgFromDisplay<'a>,
|
||||||
#[label(privacy::visibility_label)]
|
#[label(privacy::visibility_label)]
|
||||||
pub vis_span: Span,
|
pub vis_span: Span,
|
||||||
}
|
}
|
||||||
|
@ -81,7 +79,7 @@ pub struct InPublicInterface<'a> {
|
||||||
#[lint(privacy::from_private_dep_in_public_interface)]
|
#[lint(privacy::from_private_dep_in_public_interface)]
|
||||||
pub struct FromPrivateDependencyInPublicInterface<'a> {
|
pub struct FromPrivateDependencyInPublicInterface<'a> {
|
||||||
pub kind: &'a str,
|
pub kind: &'a str,
|
||||||
pub descr: FromDisplay<'a>,
|
pub descr: DiagnosticArgFromDisplay<'a>,
|
||||||
pub krate: Symbol,
|
pub krate: Symbol,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,13 +88,5 @@ pub struct FromPrivateDependencyInPublicInterface<'a> {
|
||||||
pub struct PrivateInPublicLint<'a> {
|
pub struct PrivateInPublicLint<'a> {
|
||||||
pub vis_descr: &'static str,
|
pub vis_descr: &'static str,
|
||||||
pub kind: &'a str,
|
pub kind: &'a str,
|
||||||
pub descr: FromDisplay<'a>,
|
pub descr: DiagnosticArgFromDisplay<'a>,
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FromDisplay<'a>(pub &'a dyn Display);
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for FromDisplay<'_> {
|
|
||||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
|
||||||
self.0.to_string().into_diagnostic_arg()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,8 @@ use std::ops::ControlFlow;
|
||||||
use std::{cmp, fmt, mem};
|
use std::{cmp, fmt, mem};
|
||||||
|
|
||||||
use errors::{
|
use errors::{
|
||||||
FieldIsPrivate, FieldIsPrivateLabel, FromDisplay, FromPrivateDependencyInPublicInterface,
|
FieldIsPrivate, FieldIsPrivateLabel, FromPrivateDependencyInPublicInterface, InPublicInterface,
|
||||||
InPublicInterface, InPublicInterfaceTraits, ItemIsPrivate, PrivateInPublicLint,
|
InPublicInterfaceTraits, ItemIsPrivate, PrivateInPublicLint, UnnamedItemIsPrivate,
|
||||||
UnnamedItemIsPrivate,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1080,11 +1079,7 @@ impl<'tcx> TypePrivacyVisitor<'tcx> {
|
||||||
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 {
|
||||||
let is_error = !self.item_is_accessible(def_id);
|
let is_error = !self.item_is_accessible(def_id);
|
||||||
if is_error {
|
if is_error {
|
||||||
self.tcx.sess.emit_err(ItemIsPrivate {
|
self.tcx.sess.emit_err(ItemIsPrivate { span: self.span, kind, descr: descr.into() });
|
||||||
span: self.span,
|
|
||||||
kind,
|
|
||||||
descr: FromDisplay(descr),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
is_error
|
is_error
|
||||||
}
|
}
|
||||||
|
@ -1257,7 +1252,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
|
||||||
let kind = kind.descr(def_id);
|
let kind = kind.descr(def_id);
|
||||||
let _ = match name {
|
let _ = match name {
|
||||||
Some(name) => {
|
Some(name) => {
|
||||||
sess.emit_err(ItemIsPrivate { span, kind, descr: FromDisplay(&name) })
|
sess.emit_err(ItemIsPrivate { span, kind, descr: (&name).into() })
|
||||||
}
|
}
|
||||||
None => sess.emit_err(UnnamedItemIsPrivate { span, kind }),
|
None => sess.emit_err(UnnamedItemIsPrivate { span, kind }),
|
||||||
};
|
};
|
||||||
|
@ -1726,7 +1721,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
||||||
self.tcx.def_span(self.item_def_id.to_def_id()),
|
self.tcx.def_span(self.item_def_id.to_def_id()),
|
||||||
FromPrivateDependencyInPublicInterface {
|
FromPrivateDependencyInPublicInterface {
|
||||||
kind,
|
kind,
|
||||||
descr: FromDisplay(descr),
|
descr: descr.into(),
|
||||||
krate: self.tcx.crate_name(def_id.krate),
|
krate: self.tcx.crate_name(def_id.krate),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -1763,7 +1758,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
||||||
span,
|
span,
|
||||||
vis_descr,
|
vis_descr,
|
||||||
kind,
|
kind,
|
||||||
descr: FromDisplay(descr),
|
descr: descr.into(),
|
||||||
vis_span,
|
vis_span,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -1771,7 +1766,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
||||||
span,
|
span,
|
||||||
vis_descr,
|
vis_descr,
|
||||||
kind,
|
kind,
|
||||||
descr: FromDisplay(descr),
|
descr: descr.into(),
|
||||||
vis_span,
|
vis_span,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1780,7 +1775,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
||||||
lint::builtin::PRIVATE_IN_PUBLIC,
|
lint::builtin::PRIVATE_IN_PUBLIC,
|
||||||
hir_id,
|
hir_id,
|
||||||
span,
|
span,
|
||||||
PrivateInPublicLint { vis_descr, kind, descr: FromDisplay(descr) },
|
PrivateInPublicLint { vis_descr, kind, descr: descr.into() },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue