Parse hints permissively to allow for future expansion

Make it only a warning, not an error, to have a hint value of the wrong
type.
This commit is contained in:
Josh Triplett 2025-06-17 23:25:20 -07:00
parent 0c5ea24f13
commit fe86023863
4 changed files with 36 additions and 16 deletions

View File

@ -1031,9 +1031,13 @@
"type": "object", "type": "object",
"properties": { "properties": {
"mostly-unused": { "mostly-unused": {
"type": [ "anyOf": [
"boolean", {
"null" "$ref": "#/$defs/TomlValue"
},
{
"type": "null"
}
] ]
} }
} }

View File

@ -1650,7 +1650,11 @@ pub enum TomlLintLevel {
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))] #[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
pub struct Hints { pub struct Hints {
pub mostly_unused: Option<bool>, #[cfg_attr(
feature = "unstable-schema",
schemars(with = "Option<TomlValueWrapper>")
)]
pub mostly_unused: Option<toml::Value>,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]

View File

@ -1135,7 +1135,7 @@ fn build_base_args(
strip, strip,
rustflags: profile_rustflags, rustflags: profile_rustflags,
trim_paths, trim_paths,
hint_mostly_unused, hint_mostly_unused: profile_hint_mostly_unused,
.. ..
} = unit.profile.clone(); } = unit.profile.clone();
let hints = unit.pkg.hints().cloned().unwrap_or_default(); let hints = unit.pkg.hints().cloned().unwrap_or_default();
@ -1327,15 +1327,29 @@ fn build_base_args(
opt(cmd, "-C", "incremental=", Some(dir)); 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 { if bcx.gctx.cli_unstable().profile_hint_mostly_unused {
cmd.arg("-Zhint-mostly-unused"); cmd.arg("-Zhint-mostly-unused");
} else { } else {
if hint_mostly_unused.is_some() { if profile_hint_mostly_unused.is_some() {
bcx.gctx bcx.gctx
.shell() .shell()
.warn("ignoring 'hint-mostly-unused' profile option, pass `-Zprofile-hint-mostly-unused` to enable it")?; .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 bcx.gctx
.shell() .shell()
.warn("ignoring 'hints.mostly-unused', pass `-Zprofile-hint-mostly-unused` to enable it")?; .warn("ignoring 'hints.mostly-unused', pass `-Zprofile-hint-mostly-unused` to enable it")?;

View File

@ -91,19 +91,17 @@ fn hint_unknown_type_warn() {
.file("src/main.rs", "fn main() {}") .file("src/main.rs", "fn main() {}")
.build(); .build();
p.cargo("check -v") p.cargo("check -v")
.with_status(101)
.with_stderr_data(str![[r#" .with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index [UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version [LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ... [DOWNLOADING] crates ...
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) [DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
[ERROR] invalid type: integer `1`, expected a boolean [WARNING] ignoring unsupported value type (integer) for 'hints.mostly-unused', which expects a boolean
--> ../home/.cargo/registry/src/-[HASH]/bar-1.0.0/Cargo.toml:8:29 [CHECKING] bar v1.0.0
| [RUNNING] `rustc --crate-name bar [..]`
8 | mostly-unused = 1 [CHECKING] foo v0.0.1 ([ROOT]/foo)
| ^ [RUNNING] `rustc --crate-name foo [..]`
| [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[ERROR] failed to download replaced source registry `crates-io`
"#]]) "#]])
.with_stderr_does_not_contain("-Zhint-mostly-unused") .with_stderr_does_not_contain("-Zhint-mostly-unused")