diff --git a/crates/cargo-util-schemas/manifest.schema.json b/crates/cargo-util-schemas/manifest.schema.json index 3b17f3267..ec63f68ee 100644 --- a/crates/cargo-util-schemas/manifest.schema.json +++ b/crates/cargo-util-schemas/manifest.schema.json @@ -1031,9 +1031,13 @@ "type": "object", "properties": { "mostly-unused": { - "type": [ - "boolean", - "null" + "anyOf": [ + { + "$ref": "#/$defs/TomlValue" + }, + { + "type": "null" + } ] } } diff --git a/crates/cargo-util-schemas/src/manifest/mod.rs b/crates/cargo-util-schemas/src/manifest/mod.rs index bf42b3275..2aafcb4bc 100644 --- a/crates/cargo-util-schemas/src/manifest/mod.rs +++ b/crates/cargo-util-schemas/src/manifest/mod.rs @@ -1650,7 +1650,11 @@ pub enum TomlLintLevel { #[serde(rename_all = "kebab-case")] #[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))] pub struct Hints { - pub mostly_unused: Option, + #[cfg_attr( + feature = "unstable-schema", + schemars(with = "Option") + )] + pub mostly_unused: Option, } #[derive(Copy, Clone, Debug)] diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 8ae261f2a..8915f16f8 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -1135,7 +1135,7 @@ fn build_base_args( strip, rustflags: profile_rustflags, trim_paths, - hint_mostly_unused, + hint_mostly_unused: profile_hint_mostly_unused, .. } = unit.profile.clone(); let hints = unit.pkg.hints().cloned().unwrap_or_default(); @@ -1327,15 +1327,29 @@ fn build_base_args( opt(cmd, "-C", "incremental=", Some(dir)); } - if hint_mostly_unused.or(hints.mostly_unused).unwrap_or(false) { + let pkg_hint_mostly_unused = match hints.mostly_unused { + None => None, + Some(toml::Value::Boolean(b)) => Some(b), + Some(v) => { + bcx.gctx.shell().warn(format!( + "ignoring unsupported value type ({}) for 'hints.mostly-unused', which expects a boolean", + v.type_str() + ))?; + None + } + }; + if profile_hint_mostly_unused + .or(pkg_hint_mostly_unused) + .unwrap_or(false) + { if bcx.gctx.cli_unstable().profile_hint_mostly_unused { cmd.arg("-Zhint-mostly-unused"); } else { - if hint_mostly_unused.is_some() { + if profile_hint_mostly_unused.is_some() { bcx.gctx .shell() .warn("ignoring 'hint-mostly-unused' profile option, pass `-Zprofile-hint-mostly-unused` to enable it")?; - } else if hints.mostly_unused.is_some() { + } else if pkg_hint_mostly_unused.is_some() { bcx.gctx .shell() .warn("ignoring 'hints.mostly-unused', pass `-Zprofile-hint-mostly-unused` to enable it")?; diff --git a/tests/testsuite/hints.rs b/tests/testsuite/hints.rs index 319615e13..6cbfedacb 100644 --- a/tests/testsuite/hints.rs +++ b/tests/testsuite/hints.rs @@ -91,19 +91,17 @@ fn hint_unknown_type_warn() { .file("src/main.rs", "fn main() {}") .build(); p.cargo("check -v") - .with_status(101) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 1 package to latest compatible version [DOWNLOADING] crates ... [DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) -[ERROR] invalid type: integer `1`, expected a boolean - --> ../home/.cargo/registry/src/-[HASH]/bar-1.0.0/Cargo.toml:8:29 - | -8 | mostly-unused = 1 - | ^ - | -[ERROR] failed to download replaced source registry `crates-io` +[WARNING] ignoring unsupported value type (integer) for 'hints.mostly-unused', which expects a boolean +[CHECKING] bar v1.0.0 +[RUNNING] `rustc --crate-name bar [..]` +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc --crate-name foo [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]) .with_stderr_does_not_contain("-Zhint-mostly-unused")