@@ -40,6 +40,34 @@ pub trait IntoDiagnosticArg {
40
40
fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > ;
41
41
}
42
42
43
+ macro_rules! into_diagnostic_arg_using_display {
44
+ ( $( $ty: ty ) ,+ $( , ) ?) => {
45
+ $(
46
+ impl IntoDiagnosticArg for $ty {
47
+ fn into_diagnostic_arg( self ) -> DiagnosticArgValue <' static > {
48
+ self . to_string( ) . into_diagnostic_arg( )
49
+ }
50
+ }
51
+ ) +
52
+ }
53
+ }
54
+
55
+ into_diagnostic_arg_using_display ! (
56
+ i8 ,
57
+ u8 ,
58
+ i16 ,
59
+ u16 ,
60
+ i32 ,
61
+ u32 ,
62
+ i64 ,
63
+ u64 ,
64
+ i128 ,
65
+ u128 ,
66
+ std:: num:: NonZeroU32 ,
67
+ Edition ,
68
+ Ident ,
69
+ ) ;
70
+
43
71
impl IntoDiagnosticArg for bool {
44
72
fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
45
73
if self {
@@ -50,81 +78,9 @@ impl IntoDiagnosticArg for bool {
50
78
}
51
79
}
52
80
53
- impl IntoDiagnosticArg for i8 {
54
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
55
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
56
- }
57
- }
58
-
59
- impl IntoDiagnosticArg for u8 {
81
+ impl IntoDiagnosticArg for char {
60
82
fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
61
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
62
- }
63
- }
64
-
65
- impl IntoDiagnosticArg for i16 {
66
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
67
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
68
- }
69
- }
70
-
71
- impl IntoDiagnosticArg for u16 {
72
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
73
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
74
- }
75
- }
76
-
77
- impl IntoDiagnosticArg for i32 {
78
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
79
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
80
- }
81
- }
82
-
83
- impl IntoDiagnosticArg for u32 {
84
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
85
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
86
- }
87
- }
88
-
89
- impl IntoDiagnosticArg for i64 {
90
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
91
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
92
- }
93
- }
94
-
95
- impl IntoDiagnosticArg for u64 {
96
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
97
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
98
- }
99
- }
100
-
101
- impl IntoDiagnosticArg for i128 {
102
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
103
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
104
- }
105
- }
106
-
107
- impl IntoDiagnosticArg for u128 {
108
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
109
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
110
- }
111
- }
112
-
113
- impl IntoDiagnosticArg for String {
114
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
115
- DiagnosticArgValue :: Str ( Cow :: Owned ( self ) )
116
- }
117
- }
118
-
119
- impl IntoDiagnosticArg for std:: num:: NonZeroU32 {
120
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
121
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
122
- }
123
- }
124
-
125
- impl IntoDiagnosticArg for Edition {
126
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
127
- DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
83
+ DiagnosticArgValue :: Str ( Cow :: Owned ( format ! ( "{:?}" , self ) ) )
128
84
}
129
85
}
130
86
@@ -134,15 +90,15 @@ impl IntoDiagnosticArg for Symbol {
134
90
}
135
91
}
136
92
137
- impl IntoDiagnosticArg for Ident {
93
+ impl < ' a > IntoDiagnosticArg for & ' a str {
138
94
fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
139
95
self . to_string ( ) . into_diagnostic_arg ( )
140
96
}
141
97
}
142
98
143
- impl < ' a > IntoDiagnosticArg for & ' a str {
99
+ impl IntoDiagnosticArg for String {
144
100
fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
145
- self . to_string ( ) . into_diagnostic_arg ( )
101
+ DiagnosticArgValue :: Str ( Cow :: Owned ( self ) )
146
102
}
147
103
}
148
104
0 commit comments