Skip to content

Commit edba503

Browse files
fix: Remove lints from manifests in recipe.json
1 parent 87e1a07 commit edba503

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

src/skeleton/read.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ pub(super) fn manifests<P: AsRef<Path>>(
7373

7474
let mut intermediate = toml::Value::try_from(parsed)?;
7575

76+
// Remove [lints] - they can cause compilation failures on the dummy source files
77+
// generated by `cargo chef cook` (e.g. `missing_docs = "deny"`).
78+
if let Some(table) = intermediate.as_table_mut() {
79+
table.remove("lints");
80+
}
81+
// Remove [workspace.lints] for the same reason.
82+
if let Some(workspace) = intermediate
83+
.get_mut("workspace")
84+
.and_then(|w| w.as_table_mut())
85+
{
86+
workspace.remove("lints");
87+
}
88+
7689
// Specifically, toml gives no guarantees to the ordering of the auto binaries
7790
// in its results. We will manually sort these to ensure that the output
7891
// manifest will match.

tests/skeletons/tests/core.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,63 @@ edition = "2018"
401401
);
402402
}
403403
}
404+
405+
#[test]
406+
pub fn lints_are_removed_from_all_manifests() {
407+
// Arrange - workspace with [workspace.lints] and member with [lints] workspace = true
408+
// See https://github.com/LukeMathWalker/cargo-chef/issues/343
409+
let project = CargoWorkspace::new()
410+
.manifest(
411+
".",
412+
r#"
413+
[workspace]
414+
members = [
415+
"crate_a",
416+
]
417+
418+
[workspace.lints.rust]
419+
missing_docs = "deny"
420+
"#,
421+
)
422+
.lib_package(
423+
"crate_a",
424+
r#"
425+
[package]
426+
name = "crate_a"
427+
version = "0.1.0"
428+
edition = "2021"
429+
430+
[lints]
431+
workspace = true
432+
433+
[dependencies]
434+
"#,
435+
)
436+
.build();
437+
438+
// Act
439+
let skeleton = Skeleton::derive(project.path(), None).unwrap();
440+
441+
// Assert - lints should be stripped from all manifests
442+
for manifest in &skeleton.manifests {
443+
let parsed: toml::Value = toml::from_str(&manifest.contents).unwrap();
444+
445+
// No top-level [lints]
446+
assert!(
447+
parsed.get("lints").is_none(),
448+
"Expected [lints] to be removed from manifest at {:?}, but found: {:?}",
449+
manifest.relative_path,
450+
parsed.get("lints")
451+
);
452+
453+
// No [workspace.lints]
454+
if let Some(workspace) = parsed.get("workspace") {
455+
assert!(
456+
workspace.get("lints").is_none(),
457+
"Expected [workspace.lints] to be removed from manifest at {:?}, but found: {:?}",
458+
manifest.relative_path,
459+
workspace.get("lints")
460+
);
461+
}
462+
}
463+
}

0 commit comments

Comments
 (0)