Skip to content

Warn about unused keys for virtual manifest #4243

@matklad

Description

@matklad

We warn about unused keys in Cargo.toml, unless it is a virtual manifest:

Ok((mut manifest, paths)) => {
for key in unused {
manifest.add_warning(format!("unused manifest key: {}", key));
}
if !manifest.targets().iter().any(|t| !t.is_custom_build()) {
bail!("no targets specified in the manifest\n \
either src/lib.rs, src/main.rs, a [lib] section, or \
[[bin]] section must be present")
}
Ok((EitherManifest::Real(manifest), paths))
}
Err(e) => {
match TomlManifest::to_virtual_manifest(&manifest,
source_id,
&layout,
config) {
Ok((m, paths)) => Ok((EitherManifest::Virtual(m), paths)),
Err(..) => Err(e),
}
}

We probably should warn about unused keys in virtual manifest as well!

The test might look like this:

//tests/build.rs, next to `fn unused_keys()`
#[test]
fn unused_keys_in_virtual_manifest() {
    let p = project("foo")
        .file("Cargo.toml", r#"
            [workspace]
            members = ["bar"]
            bulid = "foo"
        "#)
        .file("bar/Cargo.toml", r#"
            [project]
            version = "0.0.1"
            name = "bar"
            authors = []
        "#)
        .file("bar/src/lib.rs", r"");
    assert_that(p.cargo_process("build").arg("--all"),
                execs().with_status(0)
                       .with_stderr("\
warning: unused manifest key: workspace.bulid
[COMPILING] bar [..]
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
"));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.A-workspacesArea: workspacesC-enhancementCategory: enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions