Skip to content

Commit 75bdb92

Browse files
committed
fix: Only warn when seeing lints on stable
This will make it easier for users to test this feature
1 parent d1f7b39 commit 75bdb92

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,8 +2045,8 @@ impl TomlManifest {
20452045
let mut inheritable = toml_config.package.clone().unwrap_or_default();
20462046
inheritable.update_ws_path(package_root.to_path_buf());
20472047
inheritable.update_deps(toml_config.dependencies.clone());
2048-
verify_lints(toml_config.lints.as_ref(), &features)?;
2049-
inheritable.update_lints(toml_config.lints.clone());
2048+
let lints = verify_lints(toml_config.lints.clone(), &features, config)?;
2049+
inheritable.update_lints(lints);
20502050
if let Some(ws_deps) = &inheritable.dependencies {
20512051
for (name, dep) in ws_deps {
20522052
unused_dep_keys(
@@ -2315,7 +2315,7 @@ impl TomlManifest {
23152315
.clone()
23162316
.map(|mw| mw.resolve("lints", || inherit()?.lints()))
23172317
.transpose()?;
2318-
verify_lints(lints.as_ref(), &features)?;
2318+
let lints = verify_lints(lints.clone(), &features, config)?;
23192319
let default = TomlLints::default();
23202320
let mut rustflags = lints
23212321
.as_ref()
@@ -2773,8 +2773,8 @@ impl TomlManifest {
27732773
let mut inheritable = toml_config.package.clone().unwrap_or_default();
27742774
inheritable.update_ws_path(root.to_path_buf());
27752775
inheritable.update_deps(toml_config.dependencies.clone());
2776-
verify_lints(toml_config.lints.as_ref(), &features)?;
2777-
inheritable.update_lints(toml_config.lints.clone());
2776+
let lints = verify_lints(toml_config.lints.clone(), &features, config)?;
2777+
inheritable.update_lints(lints);
27782778
let ws_root_config = WorkspaceRootConfig::new(
27792779
root,
27802780
&toml_config.members,
@@ -2919,12 +2919,19 @@ impl TomlManifest {
29192919
}
29202920
}
29212921

2922-
fn verify_lints(lints: Option<&TomlLints>, features: &Features) -> CargoResult<()> {
2923-
let Some(lints) = lints else { return Ok(()); };
2922+
fn verify_lints(
2923+
lints: Option<TomlLints>,
2924+
features: &Features,
2925+
config: &Config,
2926+
) -> CargoResult<Option<TomlLints>> {
2927+
let Some(lints) = lints else { return Ok(None); };
29242928

2925-
features.require(Feature::lints())?;
2929+
if let Err(err) = features.require(Feature::lints()) {
2930+
let _ = config.shell().warn(err);
2931+
return Ok(None);
2932+
}
29262933

2927-
for (tool, lints) in lints {
2934+
for (tool, lints) in &lints {
29282935
let supported = ["rust", "clippy", "rustdoc"];
29292936
if !supported.contains(&tool.as_str()) {
29302937
let supported = supported.join(", ");
@@ -2947,7 +2954,7 @@ fn verify_lints(lints: Option<&TomlLints>, features: &Features) -> CargoResult<(
29472954
}
29482955
}
29492956

2950-
Ok(())
2957+
Ok(Some(lints))
29512958
}
29522959

29532960
fn unused_dep_keys(

tests/testsuite/lints.rs

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

2424
foo.cargo("check")
25-
.with_status(101)
25+
.with_status(0)
2626
.with_stderr("\
27-
[..]
27+
warning: feature `lints` is required
2828
29-
Caused by:
30-
feature `lints` is required
29+
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
30+
Consider trying a newer version of Cargo (this may require the nightly release).
31+
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
3132
32-
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
33-
Consider trying a newer version of Cargo (this may require the nightly release).
34-
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
33+
[CHECKING] [..]
34+
[FINISHED] [..]
3535
")
3636
.run();
3737
}
@@ -55,16 +55,16 @@ fn workspace_requires_option() {
5555
.build();
5656

5757
foo.cargo("check")
58-
.with_status(101)
58+
.with_status(0)
5959
.with_stderr("\
60-
[..]
60+
warning: feature `lints` is required
6161
62-
Caused by:
63-
feature `lints` is required
62+
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
63+
Consider trying a newer version of Cargo (this may require the nightly release).
64+
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
6465
65-
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
66-
Consider trying a newer version of Cargo (this may require the nightly release).
67-
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
66+
[CHECKING] [..]
67+
[FINISHED] [..]
6868
")
6969
.run();
7070
}

0 commit comments

Comments
 (0)