fix(lints): Clean up warnings about lints feature

This commit is contained in:
Ed Page 2023-05-17 15:30:58 -05:00
parent 5072d9b789
commit a8d7c8a58f
2 changed files with 51 additions and 21 deletions

View File

@ -2928,14 +2928,43 @@ fn parse_unstable_lints<T: Deserialize<'static>>(
) -> CargoResult<Option<T>> {
let Some(lints) = lints else { return Ok(None); };
if let Err(unstable_err) = features.require(Feature::lints()) {
let _ = config.shell().warn(unstable_err);
if !features.is_enabled(Feature::lints()) {
warn_for_feature("lints", config);
return Ok(None);
}
lints.try_into().map(Some).map_err(|err| err.into())
}
fn warn_for_feature(name: &str, config: &Config) {
use std::fmt::Write as _;
let mut message = String::new();
let _ = write!(
message,
"feature `{name}` is not supported on this version of Cargo and will be ignored"
);
if config.nightly_features_allowed {
let _ = write!(
message,
"
consider adding `cargo-features = [\"{name}\"]` to the manifest"
);
} else {
let _ = write!(
message,
"
this Cargo does not support nightly features, but if you
switch to nightly channel you can add
`cargo-features = [\"{name}\"]` to enable this feature",
);
}
let _ = config.shell().warn(&message);
}
fn verify_lints(lints: Option<TomlLints>) -> CargoResult<Option<TomlLints>> {
let Some(lints) = lints else { return Ok(None); };

View File

@ -22,16 +22,17 @@ fn package_requires_option() {
.build();
foo.cargo("check")
.with_stderr("\
warning: feature `lints` is required
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
Consider trying a newer version of Cargo (this may require the nightly release).
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
.with_stderr(
"\
warning: feature `lints` is not supported on this version of Cargo and will be ignored
this Cargo does not support nightly features, but if you
switch to nightly channel you can add
`cargo-features = [\"lints\"]` to enable this feature
[CHECKING] [..]
[FINISHED] [..]
")
",
)
.run();
}
@ -54,16 +55,17 @@ fn workspace_requires_option() {
.build();
foo.cargo("check")
.with_stderr("\
warning: feature `lints` is required
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
Consider trying a newer version of Cargo (this may require the nightly release).
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
.with_stderr(
"\
warning: feature `lints` is not supported on this version of Cargo and will be ignored
this Cargo does not support nightly features, but if you
switch to nightly channel you can add
`cargo-features = [\"lints\"]` to enable this feature
[CHECKING] [..]
[FINISHED] [..]
")
",
)
.run();
}
@ -87,12 +89,11 @@ fn malformed_on_stable() {
foo.cargo("check")
.with_stderr(
"\
warning: feature `lints` is required
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
Consider trying a newer version of Cargo (this may require the nightly release).
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
warning: feature `lints` is not supported on this version of Cargo and will be ignored
this Cargo does not support nightly features, but if you
switch to nightly channel you can add
`cargo-features = [\"lints\"]` to enable this feature
[CHECKING] [..]
[FINISHED] [..]
",