@@ -58,16 +58,29 @@ macro_rules! into_diagnostic_arg_using_display {
58
58
}
59
59
}
60
60
61
+ macro_rules! into_diagnostic_arg_for_number {
62
+ ( $( $ty: ty ) ,+ $( , ) ?) => {
63
+ $(
64
+ impl IntoDiagnosticArg for $ty {
65
+ fn into_diagnostic_arg( self ) -> DiagnosticArgValue <' static > {
66
+ // HACK: `FluentNumber` the underline backing struct represent
67
+ // numbers using a f64 which can't represent all the i128 numbers
68
+ // So in order to be able to use fluent selectors and still
69
+ // have all the numbers representable we only convert numbers
70
+ // below a certain threshold.
71
+ if let Ok ( n) = TryInto :: <i128 >:: try_into( self ) && n >= -100 && n <= 100 {
72
+ DiagnosticArgValue :: Number ( n)
73
+ } else {
74
+ self . to_string( ) . into_diagnostic_arg( )
75
+ }
76
+ }
77
+ }
78
+ ) +
79
+ }
80
+ }
81
+
61
82
into_diagnostic_arg_using_display ! (
62
83
ast:: ParamKindOrd ,
63
- i8 ,
64
- u8 ,
65
- i16 ,
66
- u16 ,
67
- u32 ,
68
- i64 ,
69
- i128 ,
70
- u128 ,
71
84
std:: io:: Error ,
72
85
Box <dyn std:: error:: Error >,
73
86
std:: num:: NonZeroU32 ,
@@ -82,17 +95,7 @@ into_diagnostic_arg_using_display!(
82
95
ExitStatus ,
83
96
) ;
84
97
85
- impl IntoDiagnosticArg for i32 {
86
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
87
- DiagnosticArgValue :: Number ( self . into ( ) )
88
- }
89
- }
90
-
91
- impl IntoDiagnosticArg for u64 {
92
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
93
- DiagnosticArgValue :: Number ( self . into ( ) )
94
- }
95
- }
98
+ into_diagnostic_arg_for_number ! ( i8 , u8 , i16 , u16 , i32 , u32 , i64 , u64 , i128 , u128 , isize , usize ) ;
96
99
97
100
impl IntoDiagnosticArg for bool {
98
101
fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
@@ -154,12 +157,6 @@ impl IntoDiagnosticArg for PathBuf {
154
157
}
155
158
}
156
159
157
- impl IntoDiagnosticArg for usize {
158
- fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
159
- DiagnosticArgValue :: Number ( self as i128 )
160
- }
161
- }
162
-
163
160
impl IntoDiagnosticArg for PanicStrategy {
164
161
fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
165
162
DiagnosticArgValue :: Str ( Cow :: Owned ( self . desc ( ) . to_string ( ) ) )
0 commit comments