diff options
| author | bors <bors@rust-lang.org> | 2024-01-27 10:14:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-01-27 10:14:36 +0000 |
| commit | 7df6f4a15e29bf2f28d81ebcd5b5894a2014fcd6 (patch) | |
| tree | 742d1a8a60bf3b8d61327b2ad288d6b0cabc8dc1 /compiler/rustc_errors | |
| parent | 8b6a431b3d3066a54dffc7f16bf658cf5690efc9 (diff) | |
| parent | 574d35fbeb22885f79edde4e8b696326bb19d247 (diff) | |
| download | rust-7df6f4a15e29bf2f28d81ebcd5b5894a2014fcd6.tar.gz rust-7df6f4a15e29bf2f28d81ebcd5b5894a2014fcd6.zip | |
Auto merge of #120417 - matthiaskrgr:rollup-5rszkmd, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #118182 (Properly recover from trailing attr in body) - #119641 (Remove feature not required by `Ipv6Addr::to_cononical` doctest) - #119957 (fix: correct suggestion arg for impl trait) - #120386 (ScopeTree: remove destruction_scopes as unused) - #120398 (Improve handling of numbers in `IntoDiagnosticArg`) - #120399 (Remove myself from review rotation) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_impls.rs | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index f6679ae9bb3..d58d05095cd 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -58,16 +58,29 @@ macro_rules! into_diagnostic_arg_using_display { } } +macro_rules! into_diagnostic_arg_for_number { + ($( $ty:ty ),+ $(,)?) => { + $( + impl IntoDiagnosticArg for $ty { + fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + // HACK: `FluentNumber` the underline backing struct represent + // numbers using a f64 which can't represent all the i128 numbers + // So in order to be able to use fluent selectors and still + // have all the numbers representable we only convert numbers + // below a certain threshold. + if let Ok(n) = TryInto::<i128>::try_into(self) && n >= -100 && n <= 100 { + DiagnosticArgValue::Number(n) + } else { + self.to_string().into_diagnostic_arg() + } + } + } + )+ + } +} + into_diagnostic_arg_using_display!( ast::ParamKindOrd, - i8, - u8, - i16, - u16, - u32, - i64, - i128, - u128, std::io::Error, Box<dyn std::error::Error>, std::num::NonZeroU32, @@ -82,17 +95,7 @@ into_diagnostic_arg_using_display!( ExitStatus, ); -impl IntoDiagnosticArg for i32 { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { - DiagnosticArgValue::Number(self.into()) - } -} - -impl IntoDiagnosticArg for u64 { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { - DiagnosticArgValue::Number(self.into()) - } -} +into_diagnostic_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize); impl IntoDiagnosticArg for bool { fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { @@ -154,12 +157,6 @@ impl IntoDiagnosticArg for PathBuf { } } -impl IntoDiagnosticArg for usize { - fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { - DiagnosticArgValue::Number(self as i128) - } -} - impl IntoDiagnosticArg for PanicStrategy { fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string())) |
