Skip to content

Resolver did not set to 2 by default in workspaces #9956

Closed
rust-lang/edition-guide
#267
@harrier-lcc

Description

@harrier-lcc

Problem
I have a cargo workspace with 2 packages, all set to edition = "2021". However, this do not set to use the resolver 2 by default, which is misleading.

This can be solved by setting resolver = "2" in workspace Cargo.toml (not in the package Cargo.toml) manually, but this is misleading as one would expect using edition = "2021" will set resolver default to be 2.

setting resolver = "2" directly in the package does generate an warning:
warning: resolver for the non root package will be ignored, specify resolver at the workspace root:.

The rust 2021 edition guide says:
edition = "2021" implies resolver = "2" in Cargo.toml., but this is simply not true in the case of workspace; and edition do not work in workspace Cargo.toml as well.

Steps

  1. Setup an cargo workspace with one package

Cargo.toml:

[workspace]

members = [
   "dev-resolver"
]

dev-resolver/Cargo.toml

[package]
name = "dev-resolver"
version = "0.1.0"
edition = "2021"

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

[dependencies]
p256 = { version = "0.9.0", features = ["ecdsa"], default-features = false }

[dev-dependencies]
rand_core = { version = "0.6.3", features = ["getrandom"] }
  1. cargo build. getrandom is compiled.

  2. Set resolver = "2" in workspace Cargo.toml then cargo build, getrandom is not compiled.

Possible Solution(s)

This have to be add in the documentation.

For rust 2021 (and thus nightly), I suggest to set this automatically (i.e. workspace resolver by default uses resolver 2).

Notes

Output of cargo version:
cargo 1.57.0-nightly (0121d66aa 2021-09-22)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions