errors: impl IntoDiagnosticArg
for char
Implements `IntoDiagnosticArg` for `char` using its `Debug` implementation and introduces a macro for those types which just delegate the implementation to `ToString`. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
116819f54f
commit
06f480661f
1 changed files with 33 additions and 77 deletions
|
@ -40,6 +40,34 @@ pub trait IntoDiagnosticArg {
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! into_diagnostic_arg_using_display {
|
||||||
|
($( $ty:ty ),+ $(,)?) => {
|
||||||
|
$(
|
||||||
|
impl IntoDiagnosticArg for $ty {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
self.to_string().into_diagnostic_arg()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
into_diagnostic_arg_using_display!(
|
||||||
|
i8,
|
||||||
|
u8,
|
||||||
|
i16,
|
||||||
|
u16,
|
||||||
|
i32,
|
||||||
|
u32,
|
||||||
|
i64,
|
||||||
|
u64,
|
||||||
|
i128,
|
||||||
|
u128,
|
||||||
|
std::num::NonZeroU32,
|
||||||
|
Edition,
|
||||||
|
Ident,
|
||||||
|
);
|
||||||
|
|
||||||
impl IntoDiagnosticArg for bool {
|
impl IntoDiagnosticArg for bool {
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
if self {
|
if self {
|
||||||
|
@ -50,81 +78,9 @@ impl IntoDiagnosticArg for bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoDiagnosticArg for i8 {
|
impl IntoDiagnosticArg for char {
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self)))
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for u8 {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for i16 {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for u16 {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for i32 {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for u32 {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for i64 {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for u64 {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for i128 {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for u128 {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for String {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for std::num::NonZeroU32 {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for Edition {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,15 +90,15 @@ impl IntoDiagnosticArg for Symbol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoDiagnosticArg for Ident {
|
impl<'a> IntoDiagnosticArg for &'a str {
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
self.to_string().into_diagnostic_arg()
|
self.to_string().into_diagnostic_arg()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> IntoDiagnosticArg for &'a str {
|
impl IntoDiagnosticArg for String {
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
self.to_string().into_diagnostic_arg()
|
DiagnosticArgValue::Str(Cow::Owned(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue