diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 06887da68d9..5c2ced04e78 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -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), @@ -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); diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 5c48f56a534..515aba6fb85 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -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" +"#, + )], + ); +}