RustCrypto / formats

Cryptography-related format encoders/decoders: DER, PEM, PKCS, PKIX
229 stars 122 forks source link

x509-cert: Error when targeting WASM #1332

Open OtaK opened 6 months ago

OtaK commented 6 months ago

Hi! I'm currently running into these errors when targeting WASM (wasm32-unknown-unknown) with x509-cert:

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> /home/otak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x509-cert-0.2.5/src/ext/pkix/constraints/basic.rs:17:22
   |
17 |     #[asn1(default = "Default::default")]
   |                      ^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to a specific available implementation
   |
17 |     #[asn1(default = </* self type */ as "Default::default">)]
   |                      +++++++++++++++++++                   +

error[E0283]: type annotations needed
  --> /home/otak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x509-cert-0.2.5/src/ext/pkix/constraints/basic.rs:14:39
   |
14 | #[derive(Clone, Debug, Eq, PartialEq, Sequence)]
   |                                       ^^^^^^^^ cannot infer type
   |
   = note: multiple `impl`s satisfying `bool: PartialEq<_>` found in the following crates: `core`, `serde_json`:
           - impl PartialEq for bool;
           - impl PartialEq<serde_json::value::Value> for bool;
   = note: required for `&bool` to implement `PartialEq<&_>`
   = note: this error originates in the derive macro `Sequence` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> /home/otak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x509-cert-0.2.5/src/ext/pkix/constraints/name.rs:64:19
   |
64 |         default = "Default::default"
   |                   ^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to a specific available implementation
   |
64 |         default = </* self type */ as "Default::default">
   |                   +++++++++++++++++++                   +

error[E0283]: type annotations needed
  --> /home/otak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x509-cert-0.2.5/src/ext/pkix/constraints/name.rs:56:39
   |
56 | #[derive(Clone, Debug, Eq, PartialEq, Sequence)]
   |                                       ^^^^^^^^ cannot infer type
   |
   = note: multiple `impl`s satisfying `u32: PartialEq<_>` found in the following crates: `core`, `serde_json`:
           - impl PartialEq for u32;
           - impl PartialEq<serde_json::value::Value> for u32;
   = note: required for `&u32` to implement `PartialEq<&_>`
   = note: this error originates in the derive macro `Sequence` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> /home/otak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x509-cert-0.2.5/src/ext/pkix/crl/dp.rs:34:19
   |
34 |         default = "Default::default"
   |                   ^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to a specific available implementation
   |
34 |         default = </* self type */ as "Default::default">
   |                   +++++++++++++++++++                   +

error[E0283]: type annotations needed
  --> /home/otak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x509-cert-0.2.5/src/ext/pkix/crl/dp.rs:25:39
   |
25 | #[derive(Clone, Debug, Eq, PartialEq, Sequence)]
   |                                       ^^^^^^^^ cannot infer type
   |
   = note: multiple `impl`s satisfying `bool: PartialEq<_>` found in the following crates: `core`, `serde_json`:
           - impl PartialEq for bool;
           - impl PartialEq<serde_json::value::Value> for bool;
   = note: required for `&bool` to implement `PartialEq<&_>`
   = note: this error originates in the derive macro `Sequence` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> /home/otak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x509-cert-0.2.5/src/ext.rs:32:22
   |
32 |     #[asn1(default = "Default::default")]
   |                      ^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to a specific available implementation
   |
32 |     #[asn1(default = </* self type */ as "Default::default">)]
   |                      +++++++++++++++++++                   +

error[E0283]: type annotations needed
  --> /home/otak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x509-cert-0.2.5/src/ext.rs:27:39
   |
27 | #[derive(Clone, Debug, Eq, PartialEq, Sequence, ValueOrd)]
   |                                       ^^^^^^^^ cannot infer type
   |
   = note: multiple `impl`s satisfying `bool: PartialEq<_>` found in the following crates: `core`, `serde_json`:
           - impl PartialEq for bool;
           - impl PartialEq<serde_json::value::Value> for bool;
   = note: required for `&bool` to implement `PartialEq<&_>`
   = note: this error originates in the derive macro `Sequence` (in Nightly builds, run with -Z macro-backtrace for more info)

I know the 0.3 release train is in full swing, but maybe we could sneak in a fix for this?

Cheers

OtaK commented 6 months ago

As an example, I made a fixed branch (based on tag v0.2.5) here: https://github.com/OtaK/formats/tree/otak/x509-cert-wasm

tarcieri commented 6 months ago

There's something else breaking inference here besides merely "WASM". We build all of our crates on WASM in CI:

https://github.com/RustCrypto/formats/blob/master/.github/workflows/x509-cert.yml#L33-L41

https://github.com/RustCrypto/formats/actions/runs/7602097002/job/20702246159

There is something else in your project, likely another crate which is breaking inference, although I'm not sure how.

The change on your PR looks fine but we literally just flipped over to the 0.3.0-pre release train days ago, which is very annoying.

I suppose we can backport it if need be.

OtaK commented 6 months ago

I think you're right, it might be another crate disabling some features (like std on the der crate?) somewhere in my dependency tree. I'll run my patch for now and I have unfortunately no time to find another fix but I'll revisit later on and keep you updated.

Feel free to close the issue for now or keep it open if you'd like to keep track of this.

tarcieri commented 5 months ago

Your branch looks fine if you want to PR it. We should probably use something less ambiguous to prevent these sorts of inference errors