Skip to content

Commit a8d7c8a

Browse files
committed
fix(lints): Clean up warnings about lints feature
1 parent 5072d9b commit a8d7c8a

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,14 +2928,43 @@ fn parse_unstable_lints<T: Deserialize<'static>>(
29282928
) -> CargoResult<Option<T>> {
29292929
let Some(lints) = lints else { return Ok(None); };
29302930

2931-
if let Err(unstable_err) = features.require(Feature::lints()) {
2932-
let _ = config.shell().warn(unstable_err);
2931+
if !features.is_enabled(Feature::lints()) {
2932+
warn_for_feature("lints", config);
29332933
return Ok(None);
29342934
}
29352935

29362936
lints.try_into().map(Some).map_err(|err| err.into())
29372937
}
29382938

2939+
fn warn_for_feature(name: &str, config: &Config) {
2940+
use std::fmt::Write as _;
2941+
2942+
let mut message = String::new();
2943+
2944+
let _ = write!(
2945+
message,
2946+
"feature `{name}` is not supported on this version of Cargo and will be ignored"
2947+
);
2948+
if config.nightly_features_allowed {
2949+
let _ = write!(
2950+
message,
2951+
"
2952+
2953+
consider adding `cargo-features = [\"{name}\"]` to the manifest"
2954+
);
2955+
} else {
2956+
let _ = write!(
2957+
message,
2958+
"
2959+
2960+
this Cargo does not support nightly features, but if you
2961+
switch to nightly channel you can add
2962+
`cargo-features = [\"{name}\"]` to enable this feature",
2963+
);
2964+
}
2965+
let _ = config.shell().warn(&message);
2966+
}
2967+
29392968
fn verify_lints(lints: Option<TomlLints>) -> CargoResult<Option<TomlLints>> {
29402969
let Some(lints) = lints else { return Ok(None); };
29412970

tests/testsuite/lints.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ fn package_requires_option() {
2222
.build();
2323

2424
foo.cargo("check")
25-
.with_stderr("\
26-
warning: feature `lints` is required
27-
28-
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
29-
Consider trying a newer version of Cargo (this may require the nightly release).
30-
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
25+
.with_stderr(
26+
"\
27+
warning: feature `lints` is not supported on this version of Cargo and will be ignored
3128
29+
this Cargo does not support nightly features, but if you
30+
switch to nightly channel you can add
31+
`cargo-features = [\"lints\"]` to enable this feature
3232
[CHECKING] [..]
3333
[FINISHED] [..]
34-
")
34+
",
35+
)
3536
.run();
3637
}
3738

@@ -54,16 +55,17 @@ fn workspace_requires_option() {
5455
.build();
5556

5657
foo.cargo("check")
57-
.with_stderr("\
58-
warning: feature `lints` is required
59-
60-
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
61-
Consider trying a newer version of Cargo (this may require the nightly release).
62-
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
58+
.with_stderr(
59+
"\
60+
warning: feature `lints` is not supported on this version of Cargo and will be ignored
6361
62+
this Cargo does not support nightly features, but if you
63+
switch to nightly channel you can add
64+
`cargo-features = [\"lints\"]` to enable this feature
6465
[CHECKING] [..]
6566
[FINISHED] [..]
66-
")
67+
",
68+
)
6769
.run();
6870
}
6971

@@ -87,12 +89,11 @@ fn malformed_on_stable() {
8789
foo.cargo("check")
8890
.with_stderr(
8991
"\
90-
warning: feature `lints` is required
91-
92-
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
93-
Consider trying a newer version of Cargo (this may require the nightly release).
94-
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
92+
warning: feature `lints` is not supported on this version of Cargo and will be ignored
9593
94+
this Cargo does not support nightly features, but if you
95+
switch to nightly channel you can add
96+
`cargo-features = [\"lints\"]` to enable this feature
9697
[CHECKING] [..]
9798
[FINISHED] [..]
9899
",

0 commit comments

Comments
 (0)