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",
"properties": {
"mostly-unused": {
"type": [
"boolean",
"null"
"anyOf": [
{
"$ref": "#/$defs/TomlValue"
},
{
"type": "null"
}
]
}
}

View File

@ -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<bool>,
#[cfg_attr(
feature = "unstable-schema",
schemars(with = "Option<TomlValueWrapper>")
)]
pub mostly_unused: Option<toml::Value>,
}
#[derive(Copy, Clone, Debug)]

View File

@ -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")?;

View File

@ -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")