paupino / rust-decimal

Decimal number implementation written in pure Rust suitable for financial and fixed-precision calculations.
https://docs.rs/rust_decimal/
MIT License
1.03k stars 182 forks source link

Compilation with `serde-str` feature is broken #671

Closed ThinkRedstone closed 3 months ago

ThinkRedstone commented 3 months ago

How to reproduce:

Create a new binary / library with the following dependency:

[dependencies]
rust_decimal = { version = "1.35.0", features = ["serde-str"] }

Now builds will fail with a compilation error originating in rust-decimal:

   Compiling rust_decimal v1.35.0
error[E0283]: type annotations needed
   --> /home/dafner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rust_decimal-1.35.0/src/serde.rs:272:28
    |
272 |                 serializer.serialize_some(decimal.0.as_ref())
    |                            ^^^^^^^^^^^^^^ ------------------ type must be known at this point
    |                            |
    |                            cannot infer type of the type parameter `T` declared on the method `serialize_some`
    |
    = note: cannot satisfy `_: Serialize`
    = help: the following types implement trait `Serialize`:
              &'a T
              &'a mut T
              ()
              (T,)
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
            and 129 others
note: required by a bound in `serialize_some`
   --> /home/dafner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.208/src/ser/mod.rs:808:21
    |
806 |     fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
    |        -------------- required by a bound in this associated function
807 |     where
808 |         T: ?Sized + Serialize;
    |                     ^^^^^^^^^ required by this bound in `Serializer::serialize_some`
help: consider specifying the generic argument
    |
272 |                 serializer.serialize_some::<T>(decimal.0.as_ref())
    |                                          +++++

error[E0283]: type annotations needed
   --> /home/dafner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rust_decimal-1.35.0/src/serde.rs:272:28
    |
272 |                 serializer.serialize_some(decimal.0.as_ref())
    |                            ^^^^^^^^^^^^^^           ------ type must be known at this point
    |                            |
    |                            cannot infer type of the type parameter `T` declared on the method `serialize_some`
    |
    = note: multiple `impl`s satisfying `ArrayString<32>: AsRef<_>` found in the `arrayvec` crate:
            - impl<CAP> AsRef<Path> for ArrayString<CAP>
              where the constant `CAP` has type `usize`;
            - impl<CAP> AsRef<str> for ArrayString<CAP>
              where the constant `CAP` has type `usize`;
help: consider specifying the generic argument
    |
272 |                 serializer.serialize_some::<T>(decimal.0.as_ref())
    |                                          +++++

For more information about this error, try `rustc --explain E0283`.
error: could not compile `rust_decimal` (lib) due to 2 previous errors

My compiler:

rustc 1.80.0 (051478957 2024-07-21)

I'm not sure what introduced this issue, but the newest version without it is v1.27.0. Is this on purpose and I missed some part of documentation?

HaoYang670 commented 3 months ago

I meet same error today, I am using rust 1.82.0 nightly and rust_decimal 1.35.0 as a dependency

HaoYang670 commented 3 months ago

should be same as https://github.com/paupino/rust-decimal/issues/669

miqbalrr commented 3 months ago

i'm facing the same issue.

Tony-Samuels commented 3 months ago

Should be the same as #669, which has a workaround in place until a release is cut.

Leaving this open until the release is out to avoid more dups.

miqbalrr commented 3 months ago

i accidentally compiled my production code after removing the features, Sadly idk why i add the feature before.

paupino commented 3 months ago

I've just published 1.36 which includes the fix for the ArrayVec issue. That should resolve this issue too.