Skip to content

Commit

Permalink
fix: Tie into manifest warnings
Browse files Browse the repository at this point in the history
This improves the messaging experience (sometimes showing manifest path)
and hiding the warning when not relevant).
  • Loading branch information
epage committed May 19, 2023
1 parent 2980030 commit 59a6899
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
33 changes: 24 additions & 9 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,12 @@ impl TomlManifest {
let mut inheritable = toml_config.package.clone().unwrap_or_default();
inheritable.update_ws_path(package_root.to_path_buf());
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)?;
inheritable.update_lints(lints);
if let Some(ws_deps) = &inheritable.dependencies {
Expand Down Expand Up @@ -2311,10 +2316,14 @@ impl TomlManifest {
&inherit_cell,
)?;

let lints =
parse_unstable_lints::<MaybeWorkspaceLints>(me.lints.clone(), &features, config)?
.map(|mw| mw.resolve("lints", || inherit()?.lints()))
.transpose()?;
let lints = parse_unstable_lints::<MaybeWorkspaceLints>(
me.lints.clone(),
&features,
config,
cx.warnings,
)?
.map(|mw| mw.resolve("lints", || inherit()?.lints()))
.transpose()?;
let lints = verify_lints(lints)?;
let default = TomlLints::default();
let mut rustflags = lints
Expand Down Expand Up @@ -2774,7 +2783,12 @@ impl TomlManifest {
let mut inheritable = toml_config.package.clone().unwrap_or_default();
inheritable.update_ws_path(root.to_path_buf());
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)?;
inheritable.update_lints(lints);
let ws_root_config = WorkspaceRootConfig::new(
Expand Down Expand Up @@ -2925,18 +2939,19 @@ fn parse_unstable_lints<T: Deserialize<'static>>(
lints: Option<toml::Value>,
features: &Features,
config: &Config,
warnings: &mut Vec<String>,
) -> CargoResult<Option<T>> {
let Some(lints) = lints else { return Ok(None); };

if !features.is_enabled(Feature::lints()) {
warn_for_feature("lints", config);
warn_for_feature("lints", config, warnings);
return Ok(None);
}

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 _;

let mut message = String::new();
Expand All @@ -2962,7 +2977,7 @@ switch to nightly channel you can add
`cargo-features = [\"{name}\"]` to enable this feature",
);
}
let _ = config.shell().warn(&message);
warnings.push(message);
}

fn verify_lints(lints: Option<TomlLints>) -> CargoResult<Option<TomlLints>> {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn workspace_requires_option() {
.with_status(0)
.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
switch to nightly channel you can add
Expand Down

0 comments on commit 59a6899

Please sign in to comment.