diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index ee74c31a4..51e5b44d3 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -690,7 +690,9 @@ impl<'cfg> Workspace<'cfg> { for path in default { let normalized_path = paths::normalize_path(&path); let manifest_path = normalized_path.join("Cargo.toml"); - if !self.members.contains(&manifest_path) { + if !self.members.contains(&manifest_path) + && (self.is_virtual() || manifest_path != root_manifest_path) + { // default-members are allowed to be excluded, but they // still must be referred to by the original (unfiltered) // members list. Note that we aren't testing against the diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index d58b0220a..52f41b118 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -119,6 +119,35 @@ fn non_virtual_default_members_build_other_member() { .run(); } +#[cargo_test] +fn non_virtual_default_members_build_root_project() { + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + authors = [] + + [workspace] + members = ["bar"] + default-members = ["."] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .build(); + + p.cargo("build") + .with_stderr( + "[..] Compiling foo v0.1.0 ([..])\n\ + [..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n", + ) + .run(); +} + #[cargo_test] fn inferred_root() { let p = project()