Skip to content

Commit a7555f9

Browse files
committed
fix(lints): Only warn when seeing lints on stable
This will make it easier for users to test this feature
1 parent 4279d0d commit a7555f9

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
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: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ fn package_requires_option() {
2222
.build();
2323

2424
foo.cargo("check")
25-
.with_status(101)
2625
.with_stderr("\
27-
[..]
26+
warning: feature `lints` is required
2827
29-
Caused by:
30-
feature `lints` is required
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.
3131
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.
32+
[CHECKING] [..]
33+
[FINISHED] [..]
3534
")
3635
.run();
3736
}
@@ -55,16 +54,15 @@ fn workspace_requires_option() {
5554
.build();
5655

5756
foo.cargo("check")
58-
.with_status(101)
5957
.with_stderr("\
60-
[..]
58+
warning: feature `lints` is required
6159
62-
Caused by:
63-
feature `lints` is required
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.
6463
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.
64+
[CHECKING] [..]
65+
[FINISHED] [..]
6866
")
6967
.run();
7068
}
@@ -333,7 +331,6 @@ pub fn foo(num: i32) -> u32 {
333331

334332
foo.cargo("check")
335333
.masquerade_as_nightly_cargo(&["lints"])
336-
.with_status(0)
337334
.run();
338335
}
339336

@@ -368,7 +365,6 @@ pub fn foo(num: i32) -> u32 {
368365
.arg("-v")
369366
.env("RUSTFLAGS", "-Aunsafe_code")
370367
.masquerade_as_nightly_cargo(&["lints"])
371-
.with_status(0)
372368
.run();
373369
}
374370

@@ -457,7 +453,6 @@ pub fn foo() -> u32 {
457453

458454
foo.cargo("check")
459455
.masquerade_as_nightly_cargo(&["lints"])
460-
.with_status(0)
461456
.run();
462457
}
463458

0 commit comments

Comments
 (0)