From b03e84899e8642b3fd50bfbcbbfcf6b3cf47aa5b Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Thu, 25 Apr 2024 14:50:52 -0600 Subject: [PATCH 1/2] test(package): Show [lints.cargo] is not stripped --- tests/testsuite/package.rs | 83 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 5c48f56a534..db219005f93 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -3715,3 +3715,86 @@ 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]) +warning: `im_a_teapot` is specified + --> target/package/foo-0.0.1/Cargo.toml:19:1 + | +19 | im-a-teapot = true + | ------------------ + | + = note: `cargo::im_a_teapot` is set to `warn` in `[lints]` +[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" + +[lints.cargo] +im-a-teapot = "warn" +"#, + )], + ); +} From 3b747f0b37ae9297ab9b4dc4fbb2fe86b5123aea Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Thu, 25 Apr 2024 14:56:12 -0600 Subject: [PATCH 2/2] feat: Strip [lints.cargo] when preparing to publish --- src/cargo/util/toml/mod.rs | 11 +++++++++-- tests/testsuite/package.rs | 10 ---------- 2 files changed, 9 insertions(+), 12 deletions(-) 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 db219005f93..515aba6fb85 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -3748,13 +3748,6 @@ im-a-teapot = "warn" "\ [PACKAGING] foo v0.0.1 ([CWD]) [VERIFYING] foo v0.0.1 ([CWD]) -warning: `im_a_teapot` is specified - --> target/package/foo-0.0.1/Cargo.toml:19:1 - | -19 | im-a-teapot = true - | ------------------ - | - = note: `cargo::im_a_teapot` is set to `warn` in `[lints]` [COMPILING] foo v0.0.1 ([CWD][..]) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] [PACKAGED] 3 files, [..] ([..] compressed) @@ -3791,9 +3784,6 @@ im-a-teapot = true description = "foo" documentation = "docs.rs/foo" license = "MIT" - -[lints.cargo] -im-a-teapot = "warn" "#, )], );