refactor: Make `implicit_features` <= edition 2021

This commit is contained in:
Scott Schafer 2024-04-19 11:02:30 -06:00
parent 495f94e80e
commit 9855e50dcd
No known key found for this signature in database
6 changed files with 17 additions and 101 deletions

View File

@ -147,7 +147,7 @@ const IMPLICIT_FEATURES: Lint = Lint {
desc: "implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition",
groups: &[],
default_level: LintLevel::Allow,
edition_lint_opts: Some((Edition::Edition2024, LintLevel::Deny)),
edition_lint_opts: None,
};
pub fn check_implicit_features(
@ -157,7 +157,14 @@ pub fn check_implicit_features(
error_count: &mut usize,
gctx: &GlobalContext,
) -> CargoResult<()> {
let lint_level = IMPLICIT_FEATURES.level(lints, pkg.manifest().edition());
let edition = pkg.manifest().edition();
// In Edition 2024+, instead of creating optional features, the dependencies are unused.
// See `UNUSED_OPTIONAL_DEPENDENCY`
if edition >= Edition::Edition2024 {
return Ok(());
}
let lint_level = IMPLICIT_FEATURES.level(lints, edition);
if lint_level == LintLevel::Allow {
return Ok(());
}

View File

@ -33,7 +33,7 @@ baz = ["dep:baz"]
.current_dir(p.root())
.arg("check")
.assert()
.code(101)
.success()
.stdout_matches(str![""])
.stderr_matches(file!["stderr.term.svg"]);
}

View File

@ -1,9 +1,8 @@
<svg width="928px" height="146px" xmlns="http://www.w3.org/2000/svg">
<svg width="740px" height="110px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
.fg-bright-blue { fill: #5555FF }
.fg-bright-red { fill: #FF5555 }
.fg-green { fill: #00AA00 }
.container {
padding: 0 10px;
line-height: 18px;
@ -19,19 +18,15 @@
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-bright-red bold">error</tspan><tspan>: </tspan><tspan class="bold">implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition</tspan>
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Updating</tspan><tspan> `dummy-registry` index</tspan>
</tspan>
<tspan x="10px" y="46px"><tspan> </tspan><tspan class="fg-bright-blue bold">--&gt;</tspan><tspan> Cargo.toml:9:1</tspan>
<tspan x="10px" y="46px"><tspan class="fg-green bold"> Locking</tspan><tspan> 3 packages to latest compatible versions</tspan>
</tspan>
<tspan x="10px" y="64px"><tspan class="fg-bright-blue bold"> |</tspan>
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Checking</tspan><tspan> foo v0.1.0 ([ROOT]/foo)</tspan>
</tspan>
<tspan x="10px" y="82px"><tspan class="fg-bright-blue bold">9 |</tspan><tspan> bar = { version = "0.1.0", optional = true }</tspan>
<tspan x="10px" y="82px"><tspan class="fg-green bold"> Finished</tspan><tspan> [..]</tspan>
</tspan>
<tspan x="10px" y="100px"><tspan class="fg-bright-blue bold"> |</tspan><tspan class="fg-bright-red bold"> ^^^</tspan>
</tspan>
<tspan x="10px" y="118px"><tspan class="fg-bright-blue bold"> |</tspan>
</tspan>
<tspan x="10px" y="136px">
<tspan x="10px" y="100px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,4 +1,3 @@
mod edition_2021;
mod edition_2021_warn;
mod edition_2024;
mod warn;

View File

@ -1,38 +0,0 @@
use cargo_test_support::prelude::*;
use cargo_test_support::registry::Package;
use cargo_test_support::str;
use cargo_test_support::{file, project};
#[cargo_test(nightly, reason = "edition2024 is not stable")]
fn case() {
Package::new("bar", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.1.0"
edition = "2024"
[dependencies]
bar = { version = "0.1.0", optional = true }
[lints.cargo]
implicit-features = "warn"
"#,
)
.file("src/lib.rs", "")
.build();
snapbox::cmd::Command::cargo_ui()
.masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"])
.current_dir(p.root())
.arg("check")
.arg("-Zcargo-lints")
.assert()
.success()
.stdout_matches(str![""])
.stderr_matches(file!["stderr.term.svg"]);
}

View File

@ -1,47 +0,0 @@
<svg width="944px" height="218px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
.fg-bright-blue { fill: #5555FF }
.fg-green { fill: #00AA00 }
.fg-yellow { fill: #AA5500 }
.container {
padding: 0 10px;
line-height: 18px;
}
.bold { font-weight: bold; }
tspan {
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
white-space: pre;
line-height: 18px;
}
</style>
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-yellow bold">warning</tspan><tspan>: </tspan><tspan class="bold">implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition</tspan>
</tspan>
<tspan x="10px" y="46px"><tspan> </tspan><tspan class="fg-bright-blue bold">--&gt;</tspan><tspan> Cargo.toml:9:1</tspan>
</tspan>
<tspan x="10px" y="64px"><tspan class="fg-bright-blue bold"> |</tspan>
</tspan>
<tspan x="10px" y="82px"><tspan class="fg-bright-blue bold">9 |</tspan><tspan> bar = { version = "0.1.0", optional = true }</tspan>
</tspan>
<tspan x="10px" y="100px"><tspan class="fg-bright-blue bold"> |</tspan><tspan class="fg-yellow bold"> ---</tspan>
</tspan>
<tspan x="10px" y="118px"><tspan class="fg-bright-blue bold"> |</tspan>
</tspan>
<tspan x="10px" y="136px"><tspan class="fg-green bold"> Updating</tspan><tspan> `dummy-registry` index</tspan>
</tspan>
<tspan x="10px" y="154px"><tspan class="fg-green bold"> Locking</tspan><tspan> 2 packages to latest compatible versions</tspan>
</tspan>
<tspan x="10px" y="172px"><tspan class="fg-green bold"> Checking</tspan><tspan> foo v0.1.0 ([ROOT]/foo)</tspan>
</tspan>
<tspan x="10px" y="190px"><tspan class="fg-green bold"> Finished</tspan><tspan>[..]</tspan>
</tspan>
<tspan x="10px" y="208px">
</tspan>
</text>
</svg>

Before

Width:  |  Height:  |  Size: 1.9 KiB