Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip cargo lints table #13806

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 9 additions & 2 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,14 @@ fn prepare_toml_for_publish(
let example = prepare_targets_for_publish(me.example.as_ref(), "example")?;
let test = prepare_targets_for_publish(me.test.as_ref(), "test")?;
let bench = prepare_targets_for_publish(me.bench.as_ref(), "benchmark")?;

let lints = me.lints.clone().and_then(|mut lints| {
lints.lints.remove("cargo");
if lints.lints.is_empty() {
None
} else {
Some(lints)
}
});
let all = |_d: &manifest::TomlDependency| true;
let mut manifest = manifest::TomlManifest {
package: Some(package),
Expand Down Expand Up @@ -2561,7 +2568,7 @@ fn prepare_toml_for_publish(
workspace: None,
badges: me.badges.clone(),
cargo_features: me.cargo_features.clone(),
lints: me.lints.clone(),
lints,
_unused_keys: Default::default(),
};
strip_features(&mut manifest);
Expand Down
73 changes: 73 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3715,3 +3715,76 @@ path = "benches/bench_foo.rs"
)],
);
}

#[cargo_test]
fn strip_cargo_lints() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["test-dummy-unstable"]

[package]
name = "foo"
version = "0.0.1"
edition = "2015"
license = "MIT"
description = "foo"
documentation = "docs.rs/foo"
authors = []
im-a-teapot = true

[lints.cargo]
im-a-teapot = "warn"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("package -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"])
.with_stdout("")
.with_stderr(
"\
[PACKAGING] foo v0.0.1 ([CWD])
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 3 files, [..] ([..] compressed)
",
)
.run();

let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
validate_crate_contents(
f,
"foo-0.0.1.crate",
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
&[(
"Cargo.toml",
r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.

cargo-features = ["test-dummy-unstable"]

[package]
edition = "2015"
name = "foo"
version = "0.0.1"
authors = []
im-a-teapot = true
description = "foo"
documentation = "docs.rs/foo"
license = "MIT"
"#,
)],
);
}