diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-30 14:46:51 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-01 19:18:45 +1100 |
| commit | 26eb6da4e7f19fd1408eac2c67891f3dbfc47e5a (patch) | |
| tree | 2d192b06ae0b9de3e20f2902c766a4a8b6aa2797 /compiler/rustc_errors | |
| parent | 3db37fb78a9a6b76373faf85c2976a2916599f85 (diff) | |
| download | rust-26eb6da4e7f19fd1408eac2c67891f3dbfc47e5a.tar.gz rust-26eb6da4e7f19fd1408eac2c67891f3dbfc47e5a.zip | |
Fit more values into `DiagnosticArgValue::Number`.
It contains an `i128`, but when creating them we convert any number outside the range -100..100 to a string, because Fluent uses an `f64`. It's all a bit strange. This commit changes the `i128` to an `i32`, which fits safely in Fluent's `f64`, and removes the -100..100 range check. This means that only integers outside the range of `i32` will be converted to strings.
Diffstat (limited to 'compiler/rustc_errors')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_impls.rs | 8 |
2 files changed, 6 insertions, 7 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index b87eef07fd5..249155ba7c6 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -33,7 +33,10 @@ pub type DiagnosticArgName = Cow<'static, str>; #[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] pub enum DiagnosticArgValue { Str(Cow<'static, str>), - Number(i128), + // This gets converted to a `FluentNumber`, which is an `f64`. An `i32` + // safely fits in an `f64`. Any integers bigger than that will be converted + // to strings in `into_diagnostic_arg` and stored using the `Str` variant. + Number(i32), StrListSepByAnd(Vec<Cow<'static, str>>), } diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index faab3fc663a..15effd3cbec 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -63,12 +63,8 @@ macro_rules! into_diagnostic_arg_for_number { $( impl IntoDiagnosticArg for $ty { fn into_diagnostic_arg(self) -> DiagnosticArgValue { - // 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 { + // Convert to a string if it won't fit into `Number`. + if let Ok(n) = TryInto::<i32>::try_into(self) { DiagnosticArgValue::Number(n) } else { self.to_string().into_diagnostic_arg() |
