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
9 changes: 8 additions & 1 deletion src/workspace/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,14 @@ fn normalize_toml(
normalized_toml.badges = original_toml.badges.clone();
} else {
if let Some(field) = original_toml.requires_package().next() {
bail!("this virtual manifest specifies a `{field}` section, which is not allowed");
let suggestion = if field == "lints" {
"\nhelp: a similar field exists: `[workspace.lints]`"
} else {
""
};
bail!(
"this virtual manifest specifies a `{field}` section, which is not allowed{suggestion}"
);
}
}

Expand Down
50 changes: 49 additions & 1 deletion tests/testsuite/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,6 @@ fn ws_err_unused() {
"[features]",
"[target]",
"[badges]",
"[lints]",
] {
let key = table.trim_start_matches('[').trim_end_matches(']');
let p = project()
Expand Down Expand Up @@ -2377,6 +2376,55 @@ Caused by:
}
}

#[cargo_test]
fn ws_err_unused_similar_suggest() {
let cases: &[(&str, &str)] = &[
(
"[lints]",
"[HELP] a similar field exists: `[workspace.lints]`",
),
(
"[lints.rust]",
"[HELP] a similar field exists: `[workspace.lints]`",
),
(
"[lints.clippy]",
"[HELP] a similar field exists: `[workspace.lints]`",
),
];
for (table, suggestion) in cases {
let key = table.trim_start_matches('[').trim_end_matches(']');
let key = key.split_once('.').map(|p| p.0).unwrap_or(key);
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[workspace]
members = ["a"]

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

Caused by:
this virtual manifest specifies a `{key}` section, which is not allowed
{suggestion}
",
))
.run();
}
}

#[cargo_test]
fn ws_warn_unused() {
for (key, name) in &[
Expand Down