Rust Crate Warning About Workspace Resolver - What is it, how to fix it?

Folks,

I am working on getting an example of Rust BTreeMap working, and so far the docs are very good, and it is working well.

However, I get this unusual error from the compiler which I do not understand, can someone please explains what it means and how to fix it, do I need to fix it?

warning: some crates are on edition 2021 which defaults to resolver = "2", but virtual workspaces default to resolver = "1"
note: to keep the current resolver, specify workspace.resolver = "1" in the workspace root’s manifest
note: to use the edition 2021 resolver, specify workspace.resolver = "2" in the workspace root’s manifest

Below is my Cargo.toml file for the backend in case, and I am using DFX 15.1:

[package]
name = "rust_profile_backend"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib"]

[dependencies]
candid = "0.8.2"
ic-cdk = "0.7"
ic-cdk-timers = "0.1" # Feel free to remove this dependency if you don't need timers
ic-stable-structures = "0.6.0-beta.2"
serde = "1.0"

The code itself comes from the BTreeMap tutorial here:

Thanks for your help!

1 Like

Change the “edition” on line 4 of your “cargo.toml” to “2018”.

Also I recommend using the latest crates for “candid”, “ic-cdk”, “timers” and “stable-structures” which is pulled out of the beta state.

You can search for these packages on https://crates.io/ to check the latest versions

2 Likes

Thanks for that tip, just a follow-up question, why the change to 2018?

And do you know what those workspace mentions mean?

1 Like

Don’t downgrade your Rust edition, just set the resolver to 2 like the error message asks. Like this:

More details here

2 Likes

Thanks Saikatdas! Here is a summary from those who just want to read here.

First what is the resolver:

One of Cargo’s primary tasks is to determine the versions of dependencies to use based on the version requirements specified in each package. This process is called “dependency resolution” and is performed by the “resolver”. The result of the resolution is stored in the Cargo.lock file which “locks” the dependencies to specific versions, and keeps them fixed over time.

The resolver attempts to unify common dependencies while considering possibly conflicting requirements.

Second your link, which now says that the resolver should explicitly default to 2 to avoid warnings:

Since Rust 1.51.0, Cargo has opt-in support for a new feature resolver which can be activated with resolver = “2” in Cargo.toml.

Starting in Rust 2021, this will be the default. That is, writing edition = “2021” in Cargo.toml will imply resolver = “2”.