How does a crate make an item in another crate disappear?

Hi,
I have a confusing situation. The crate wasm-logger, depends on crates: log, wasm-bindgen. The function log::set_boxed_logger (from crate log) is not available if wasm-bindgen="0.2.46", but available with 0.2.45.

git clone https://gitlab.com/limira-rs/wasm-logger.git
cd wasm-logger
cargo build --target=wasm32-unknown-unknown

It failed with the error:

error[E0425]: cannot find function `set_boxed_logger` in module `log`
   --> src/lib.rs:167:16
    |
167 |     match log::set_boxed_logger(Box::new(wl)) {
    |                ^^^^^^^^^^^^^^^^ not found in `log`

But if you modify wasm-logger/Cargo.toml like this:

[dependencies]
wasm-bindgen = "=0.2.45"

Then the build will be successful.

It's sure an issue. But what cause this? Where the issue is? (in wasm-logger? or wasm-bindgen? or log? or cargo?)

Can you check whether set_boxed_logger is available in 0.2.46 ? May be the function got removed in the next version ?

set_boxed_logger requires the feature std to be requested on the log crate. Your program was probably relying on that feature being requested by wasm-bindgen, and they may have stopped requesting it in 0.2.46.

The fact that you can accidentally depend on features enabled by your dependencies still strikes me as a Cargo bug, but it's the current state of things.

To fix this, request the feature:

[dependencies]
log = {version = "0.4.6", features = ["std"]}
5 Likes

Thank you very much!

Powered by your answer, I look in wasm-logger dependencies, and found that the issue actually caused by the upgrade of web-sys from 0.3.22 to 0.3.23 (wasm-bindgen - "0.2.45"/"0.2.46" does not depends on log, forcing wasm-bindgen = "=0.2.45" cause cargo to choose web-sys = "0.3.22").

The previous version of web-sys depends env_logger which in turn request feature std from log. The new version of web-sys just optionally depends on env_logger.

Thanks again!

Related issue:

https://github.com/rust-lang/cargo/issues/5730

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.