Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,18 +658,28 @@ impl<'cfg> Workspace<'cfg> {
for pkg in self.members()
.filter(|p| p.manifest_path() != root_manifest)
{
if pkg.manifest().original().has_profiles() {
let message = &format!(
"profiles for the non root package will be ignored, \
specify profiles at the workspace root:\n\
let manifest = pkg.manifest();
let emit_warning = |what| -> CargoResult<()> {
let msg = format!(
"{} for the non root package will be ignored, \
specify {} at the workspace root:\n\
package: {}\n\
workspace: {}",
what,
what,
pkg.manifest_path().display(),
root_manifest.display()
root_manifest.display(),
);

//TODO: remove `Eq` bound from `Profiles` when the warning is removed.
self.config.shell().warn(&message)?;
self.config.shell().warn(&msg)
};
if manifest.original().has_profiles() {
emit_warning("profiles")?;
}
if !manifest.replace().is_empty() {
emit_warning("replace")?;
}
if !manifest.patch().is_empty() {
emit_warning("patch")?;
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,24 @@ impl TomlManifest {
if me.bench.is_some() {
bail!("virtual manifests do not specify [[bench]]");
}
if me.dependencies.is_some() {
bail!("virtual manifests do not specify [dependencies]");
}
if me.dev_dependencies.is_some() || me.dev_dependencies2.is_some() {
bail!("virtual manifests do not specify [dev-dependencies]");
}
if me.build_dependencies.is_some() || me.build_dependencies2.is_some() {
bail!("virtual manifests do not specify [build-dependencies]");
}
if me.features.is_some() {
bail!("virtual manifests do not specify [features]");
}
if me.target.is_some() {
bail!("virtual manifests do not specify [target]");
}
if me.badges.is_some() {
bail!("virtual manifests do not specify [badges]");
}

let mut nested_paths = Vec::new();
let mut warnings = Vec::new();
Expand Down
90 changes: 90 additions & 0 deletions tests/testsuite/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1879,3 +1879,93 @@ fn ws_rustc_err() {
.with_stderr("[ERROR] [..]against an actual package[..]")
.run();
}

#[test]
fn ws_err_unused() {
for key in &[
"[lib]",
"[[bin]]",
"[[example]]",
"[[test]]",
"[[bench]]",
"[dependencies]",
"[dev-dependencies]",
"[build-dependencies]",
"[features]",
"[target]",
"[badges]",
] {
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[workspace]
members = ["a"]

{}
"#,
key
),
)
.file("a/Cargo.toml", &basic_lib_manifest("a"))
.file("a/src/lib.rs", "")
.build();
p.cargo("check")
.with_status(101)
.with_stderr(&format!(
"\
[ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`

Caused by:
virtual manifests do not specify {}
",
key
))
.run();
}
}

#[test]
fn ws_warn_unused() {
for (key, name) in &[
("[profile.dev]\nopt-level = 1", "profiles"),
("[replace]\n\"bar:0.1.0\" = { path = \"bar\" }", "replace"),
("[patch.crates-io]\nbar = { path = \"bar\" }", "patch"),
] {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["a"]
"#,
)
.file(
"a/Cargo.toml",
&format!(
r#"
[package]
name = "a"
version = "0.1.0"

{}
"#,
key
),
)
.file("a/src/lib.rs", "")
.build();
p.cargo("check")
.with_status(0)
.with_stderr_contains(&format!(
"\
[WARNING] {} for the non root package will be ignored, specify {} at the workspace root:
package: [..]/foo/a/Cargo.toml
workspace: [..]/foo/Cargo.toml
",
name, name
))
.run();
}
}