Skip to content

Commit d2d76c1

Browse files
authored
Fix workspace manifest loading (#54)
This fixes two things: - first, we looked at the wrong manifest when checking for a `[workspace]` property: we need to look at the workspace manifest, to the child one. - second: there is an "API bug" in `cargo_toml`, that makes it impossible to properly use `from_path_with_metadata` (unless I'm mistaken! see [full analysis](https://gitlab.com/crates.rs/cargo_toml/-/issues/20)), so we need to use other methods to get the content, with a slightly different order. That's fine, it's quite internal and shouldn't change much over time.
1 parent e70030c commit d2d76c1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/search_unused.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,28 @@ fn get_full_manifest(
268268
dir_path: &Path,
269269
manifest_path: &Path,
270270
) -> anyhow::Result<cargo_toml::Manifest<PackageMetadata>> {
271-
let mut manifest = cargo_toml::Manifest::from_path_with_metadata(manifest_path)?;
271+
// HACK: we can't plain use `from_path_with_metadata` here, because it calls
272+
// `complete_from_path` just a bit too early (before we've had a chance to call
273+
// `inherit_workspace`). See https://gitlab.com/crates.rs/cargo_toml/-/issues/20 for details,
274+
// and a possible future fix.
275+
let cargo_toml_content = std::fs::read(manifest_path)?;
276+
let mut manifest =
277+
cargo_toml::Manifest::<PackageMetadata>::from_slice_with_metadata(&cargo_toml_content)?;
272278

273279
let mut dir_path = dir_path.join("../");
274280
while dir_path.exists() {
275281
let workspace_cargo_path = dir_path.join("Cargo.toml");
276282
if let Ok(workspace_manifest) = cargo_toml::Manifest::from_path(&workspace_cargo_path) {
277-
if manifest.workspace.is_some() {
283+
if workspace_manifest.workspace.is_some() {
278284
manifest.inherit_workspace(&workspace_manifest, &workspace_cargo_path)?;
279285
break;
280286
}
281287
}
282288
dir_path = dir_path.join("../");
283289
}
284290

291+
manifest.complete_from_path(manifest_path)?;
292+
285293
Ok(manifest)
286294
}
287295

0 commit comments

Comments
 (0)