Skip to content

Commit 5c37dea

Browse files
committed
fix: Ignore lints table on stable
1 parent 427d2a4 commit 5c37dea

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ pub struct TomlManifest {
355355
patch: Option<BTreeMap<String, BTreeMap<String, TomlDependency>>>,
356356
workspace: Option<TomlWorkspace>,
357357
badges: Option<MaybeWorkspaceBtreeMap>,
358-
lints: Option<MaybeWorkspaceLints>,
358+
lints: Option<toml::Value>,
359359
}
360360

361361
#[derive(Deserialize, Serialize, Clone, Debug, Default)]
@@ -1440,7 +1440,7 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceLints {
14401440
Err(de::Error::custom("`workspace` cannot be false"))
14411441
};
14421442
}
1443-
BTreeMap::deserialize(serde_value::ValueDeserializer::<D::Error>::new(value))
1443+
TomlLints::deserialize(serde_value::ValueDeserializer::<D::Error>::new(value))
14441444
.map(MaybeWorkspace::Defined)
14451445
}
14461446
}
@@ -1531,7 +1531,7 @@ pub struct TomlWorkspace {
15311531
// Properties that can be inherited by members.
15321532
package: Option<InheritableFields>,
15331533
dependencies: Option<BTreeMap<String, TomlDependency>>,
1534-
lints: Option<TomlLints>,
1534+
lints: Option<toml::Value>,
15351535

15361536
// Note that this field must come last due to the way toml serialization
15371537
// works which requires tables to be emitted after all values.
@@ -2045,7 +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-
let lints = verify_lints(toml_config.lints.clone(), &features, config)?;
2048+
let lints = parse_unstable_lints(toml_config.lints.clone(), &features, config)?;
2049+
let lints = verify_lints(lints)?;
20492050
inheritable.update_lints(lints);
20502051
if let Some(ws_deps) = &inheritable.dependencies {
20512052
for (name, dep) in ws_deps {
@@ -2310,12 +2311,11 @@ impl TomlManifest {
23102311
&inherit_cell,
23112312
)?;
23122313

2313-
let lints = me
2314-
.lints
2315-
.clone()
2316-
.map(|mw| mw.resolve("lints", || inherit()?.lints()))
2317-
.transpose()?;
2318-
let lints = verify_lints(lints.clone(), &features, config)?;
2314+
let lints =
2315+
parse_unstable_lints::<MaybeWorkspaceLints>(me.lints.clone(), &features, config)?
2316+
.map(|mw| mw.resolve("lints", || inherit()?.lints()))
2317+
.transpose()?;
2318+
let lints = verify_lints(lints)?;
23192319
let default = TomlLints::default();
23202320
let mut rustflags = lints
23212321
.as_ref()
@@ -2642,7 +2642,8 @@ impl TomlManifest {
26422642
.badges
26432643
.as_ref()
26442644
.map(|_| MaybeWorkspace::Defined(metadata.badges.clone())),
2645-
lints: lints.map(|lints| MaybeWorkspace::Defined(lints)),
2645+
lints: lints
2646+
.map(|lints| toml::Value::try_from(MaybeWorkspaceLints::Defined(lints)).unwrap()),
26462647
};
26472648
let mut manifest = Manifest::new(
26482649
summary,
@@ -2773,7 +2774,8 @@ impl TomlManifest {
27732774
let mut inheritable = toml_config.package.clone().unwrap_or_default();
27742775
inheritable.update_ws_path(root.to_path_buf());
27752776
inheritable.update_deps(toml_config.dependencies.clone());
2776-
let lints = verify_lints(toml_config.lints.clone(), &features, config)?;
2777+
let lints = parse_unstable_lints(toml_config.lints.clone(), &features, config)?;
2778+
let lints = verify_lints(lints)?;
27772779
inheritable.update_lints(lints);
27782780
let ws_root_config = WorkspaceRootConfig::new(
27792781
root,
@@ -2919,18 +2921,24 @@ impl TomlManifest {
29192921
}
29202922
}
29212923

2922-
fn verify_lints(
2923-
lints: Option<TomlLints>,
2924+
fn parse_unstable_lints<T: Deserialize<'static>>(
2925+
lints: Option<toml::Value>,
29242926
features: &Features,
29252927
config: &Config,
2926-
) -> CargoResult<Option<TomlLints>> {
2928+
) -> CargoResult<Option<T>> {
29272929
let Some(lints) = lints else { return Ok(None); };
29282930

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

2936+
lints.try_into().map(Some).map_err(|err| err.into())
2937+
}
2938+
2939+
fn verify_lints(lints: Option<TomlLints>) -> CargoResult<Option<TomlLints>> {
2940+
let Some(lints) = lints else { return Ok(None); };
2941+
29342942
for (tool, lints) in &lints {
29352943
let supported = ["rust", "clippy", "rustdoc"];
29362944
if !supported.contains(&tool.as_str()) {

tests/testsuite/lints.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,17 @@ fn malformed_on_stable() {
8787
.build();
8888

8989
foo.cargo("check")
90-
.with_status(101)
90+
.with_status(0)
9191
.with_stderr(
9292
"\
93-
error: failed to parse manifest[..]
93+
warning: feature `lints` is required
9494
95-
Caused by:
96-
invalid type: integer `20`, expected a map
97-
in `lints`
95+
The package requires the Cargo feature called `lints`, but that feature is not stabilized in this version of Cargo ([..]).
96+
Consider trying a newer version of Cargo (this may require the nightly release).
97+
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints for more information about the status of this feature.
98+
99+
[CHECKING] [..]
100+
[FINISHED] [..]
98101
",
99102
)
100103
.run();
@@ -127,7 +130,6 @@ error: failed to parse manifest[..]
127130
128131
Caused by:
129132
invalid type: integer `20`, expected a map
130-
in `lints`
131133
",
132134
)
133135
.run();

0 commit comments

Comments
 (0)