futursolo / stylist-rs

A CSS-in-Rust styling solution for WebAssembly Applications
https://crates.io/crates/stylist
MIT License
366 stars 22 forks source link

Error when compiling with stylist 0.12.1 in workspaces #129

Closed WorldSEnder closed 1 year ago

WorldSEnder commented 1 year ago

Disclaimer: This is a reproduction of an issue on discord, mainly here for discoverability.

When upgrading to 0.12.1, the following error occurs during compilation:

   Compiling stylist v0.12.1
error[E0308]: mismatched types
   --> /home/martin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stylist-0.12.1/src/manager/mod.rs:244:38
    |
244 |         .map_err(|e| Error::Web(Some(e)))
    |                                 ---- ^ expected `()`, found `JsValue`
    |                                 |
    |                                 arguments to this enum variant are incorrect
    |
help: the type constructed contains `JsValue` due to the type of the argument passed
   --> /home/martin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stylist-0.12.1/src/manager/mod.rs:244:33
    |
244 |         .map_err(|e| Error::Web(Some(e)))
    |                                 ^^^^^-^
    |                                      |
    |                                      this argument influences the type of `Some`
note: tuple variant defined here
   --> /home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:572:5
    |
572 |     Some(#[stable(feature = "rust1", since = "1.0.0")] T),
    |     ^^^^

error[E0277]: `?` couldn't convert the error to `()`
   --> /home/martin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stylist-0.12.1/src/manager/mod.rs:255:91
    |
255 |             if let Some(m) = document.query_selector(&format!("style[data-style={}]", id))? {
    |                                                                                           ^ the trait `From<JsValue>` is not implemented for `()`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `FromResidual<R>`:
              <Result<T, F> as FromResidual<Result<Infallible, E>>>
              <Result<T, F> as FromResidual<Yeet<E>>>
    = note: required for `Result<(), ()>` to implement `FromResidual<Result<Infallible, JsValue>>`

error[E0277]: `?` couldn't convert the error to `()`
   --> /home/martin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stylist-0.12.1/src/manager/mod.rs:257:44
    |
257 |                     parent.remove_child(&m)?;
    |                                            ^ the trait `From<JsValue>` is not implemented for `()`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `FromResidual<R>`:
              <Result<T, F> as FromResidual<Result<Infallible, E>>>
              <Result<T, F> as FromResidual<Yeet<E>>>
    = note: required for `Result<(), ()>` to implement `FromResidual<Result<Infallible, JsValue>>`

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `stylist` (lib) due to 3 previous errors

This occurs, to the best of my knowledge, only when stylist is used in a workspace with crates targeting both wasm and non-wasm (i.e. native) architecture and only when the resolver = "1" is used. This outdated dependency resolution performs cross-architecture feature unification, which is not supported. With edition = "2021", the default resolver has been changed to resolver = "2", so this should not affect modern crates. If you are impacted by this, consider upgrading your root packages or specify

resolver = "2"

in your workspace's Cargo.toml.