fix(lints): Tie into manifest warnings

This improves the messaging experience (sometimes showing manifest path)
and hiding the warning when not relevant).
This commit is contained in:
Ed Page 2023-05-19 13:47:08 -05:00
parent a8d7c8a58f
commit 1dfa101cd1
2 changed files with 25 additions and 10 deletions

View File

@ -2045,7 +2045,12 @@ impl TomlManifest {
let mut inheritable = toml_config.package.clone().unwrap_or_default(); let mut inheritable = toml_config.package.clone().unwrap_or_default();
inheritable.update_ws_path(package_root.to_path_buf()); inheritable.update_ws_path(package_root.to_path_buf());
inheritable.update_deps(toml_config.dependencies.clone()); inheritable.update_deps(toml_config.dependencies.clone());
let lints = parse_unstable_lints(toml_config.lints.clone(), &features, config)?; let lints = parse_unstable_lints(
toml_config.lints.clone(),
&features,
config,
&mut warnings,
)?;
let lints = verify_lints(lints)?; let lints = verify_lints(lints)?;
inheritable.update_lints(lints); inheritable.update_lints(lints);
if let Some(ws_deps) = &inheritable.dependencies { if let Some(ws_deps) = &inheritable.dependencies {
@ -2311,10 +2316,14 @@ impl TomlManifest {
&inherit_cell, &inherit_cell,
)?; )?;
let lints = let lints = parse_unstable_lints::<MaybeWorkspaceLints>(
parse_unstable_lints::<MaybeWorkspaceLints>(me.lints.clone(), &features, config)? me.lints.clone(),
.map(|mw| mw.resolve("lints", || inherit()?.lints())) &features,
.transpose()?; config,
cx.warnings,
)?
.map(|mw| mw.resolve("lints", || inherit()?.lints()))
.transpose()?;
let lints = verify_lints(lints)?; let lints = verify_lints(lints)?;
let default = TomlLints::default(); let default = TomlLints::default();
let mut rustflags = lints let mut rustflags = lints
@ -2774,7 +2783,12 @@ impl TomlManifest {
let mut inheritable = toml_config.package.clone().unwrap_or_default(); let mut inheritable = toml_config.package.clone().unwrap_or_default();
inheritable.update_ws_path(root.to_path_buf()); inheritable.update_ws_path(root.to_path_buf());
inheritable.update_deps(toml_config.dependencies.clone()); inheritable.update_deps(toml_config.dependencies.clone());
let lints = parse_unstable_lints(toml_config.lints.clone(), &features, config)?; let lints = parse_unstable_lints(
toml_config.lints.clone(),
&features,
config,
&mut warnings,
)?;
let lints = verify_lints(lints)?; let lints = verify_lints(lints)?;
inheritable.update_lints(lints); inheritable.update_lints(lints);
let ws_root_config = WorkspaceRootConfig::new( let ws_root_config = WorkspaceRootConfig::new(
@ -2925,18 +2939,19 @@ fn parse_unstable_lints<T: Deserialize<'static>>(
lints: Option<toml::Value>, lints: Option<toml::Value>,
features: &Features, features: &Features,
config: &Config, config: &Config,
warnings: &mut Vec<String>,
) -> CargoResult<Option<T>> { ) -> CargoResult<Option<T>> {
let Some(lints) = lints else { return Ok(None); }; let Some(lints) = lints else { return Ok(None); };
if !features.is_enabled(Feature::lints()) { if !features.is_enabled(Feature::lints()) {
warn_for_feature("lints", config); warn_for_feature("lints", config, warnings);
return Ok(None); return Ok(None);
} }
lints.try_into().map(Some).map_err(|err| err.into()) lints.try_into().map(Some).map_err(|err| err.into())
} }
fn warn_for_feature(name: &str, config: &Config) { fn warn_for_feature(name: &str, config: &Config, warnings: &mut Vec<String>) {
use std::fmt::Write as _; use std::fmt::Write as _;
let mut message = String::new(); let mut message = String::new();
@ -2962,7 +2977,7 @@ switch to nightly channel you can add
`cargo-features = [\"{name}\"]` to enable this feature", `cargo-features = [\"{name}\"]` to enable this feature",
); );
} }
let _ = config.shell().warn(&message); warnings.push(message);
} }
fn verify_lints(lints: Option<TomlLints>) -> CargoResult<Option<TomlLints>> { fn verify_lints(lints: Option<TomlLints>) -> CargoResult<Option<TomlLints>> {

View File

@ -57,7 +57,7 @@ fn workspace_requires_option() {
foo.cargo("check") foo.cargo("check")
.with_stderr( .with_stderr(
"\ "\
warning: feature `lints` is not supported on this version of Cargo and will be ignored warning: [CWD]/Cargo.toml: feature `lints` is not supported on this version of Cargo and will be ignored
this Cargo does not support nightly features, but if you this Cargo does not support nightly features, but if you
switch to nightly channel you can add switch to nightly channel you can add