Skip to content

Commit 16d1fe6

Browse files
committed
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.
1 parent 2b560bd commit 16d1fe6

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

crates/cargo-util-schemas/manifest.schema.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,13 @@
10121012
"type": "object",
10131013
"properties": {
10141014
"mostly-unused": {
1015-
"type": [
1016-
"boolean",
1017-
"null"
1015+
"anyOf": [
1016+
{
1017+
"$ref": "#/$defs/TomlValue"
1018+
},
1019+
{
1020+
"type": "null"
1021+
}
10181022
]
10191023
}
10201024
}

crates/cargo-util-schemas/src/manifest/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,11 @@ pub enum TomlLintLevel {
16471647
#[serde(rename_all = "kebab-case")]
16481648
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
16491649
pub struct Hints {
1650-
pub mostly_unused: Option<bool>,
1650+
#[cfg_attr(
1651+
feature = "unstable-schema",
1652+
schemars(with = "Option<TomlValueWrapper>")
1653+
)]
1654+
pub mostly_unused: Option<toml::Value>,
16511655
}
16521656

16531657
#[derive(Copy, Clone, Debug)]

src/cargo/core/compiler/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ fn build_base_args(
11351135
strip,
11361136
rustflags: profile_rustflags,
11371137
trim_paths,
1138-
hint_mostly_unused,
1138+
hint_mostly_unused: profile_hint_mostly_unused,
11391139
..
11401140
} = unit.profile.clone();
11411141
let hints = unit.pkg.hints().cloned().unwrap_or_default();
@@ -1327,15 +1327,29 @@ fn build_base_args(
13271327
opt(cmd, "-C", "incremental=", Some(dir));
13281328
}
13291329

1330-
if hint_mostly_unused.or(hints.mostly_unused).unwrap_or(false) {
1330+
let pkg_hint_mostly_unused = match hints.mostly_unused {
1331+
None => None,
1332+
Some(toml::Value::Boolean(b)) => Some(b),
1333+
Some(v) => {
1334+
bcx.gctx.shell().warn(format!(
1335+
"ignoring unsupported value type ({}) for 'hints.mostly-unused', which expects a boolean",
1336+
v.type_str()
1337+
))?;
1338+
None
1339+
}
1340+
};
1341+
if profile_hint_mostly_unused
1342+
.or(pkg_hint_mostly_unused)
1343+
.unwrap_or(false)
1344+
{
13311345
if bcx.gctx.cli_unstable().profile_hint_mostly_unused {
13321346
cmd.arg("-Zhint-mostly-unused");
13331347
} else {
1334-
if hint_mostly_unused.is_some() {
1348+
if profile_hint_mostly_unused.is_some() {
13351349
bcx.gctx
13361350
.shell()
13371351
.warn("ignoring 'hint-mostly-unused' profile option, pass `-Zprofile-hint-mostly-unused` to enable it")?;
1338-
} else if hints.mostly_unused.is_some() {
1352+
} else if pkg_hint_mostly_unused.is_some() {
13391353
bcx.gctx
13401354
.shell()
13411355
.warn("ignoring 'hints.mostly-unused', pass `-Zprofile-hint-mostly-unused` to enable it")?;

tests/testsuite/hints.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,17 @@ fn hint_unknown_type_warn() {
9191
.file("src/main.rs", "fn main() {}")
9292
.build();
9393
p.cargo("check -v")
94-
.with_status(101)
9594
.with_stderr_data(str![[r#"
9695
[UPDATING] `dummy-registry` index
9796
[LOCKING] 1 package to latest compatible version
9897
[DOWNLOADING] crates ...
9998
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
100-
[ERROR] invalid type: integer `1`, expected a boolean
101-
--> ../home/.cargo/registry/src/-[HASH]/bar-1.0.0/Cargo.toml:8:29
102-
|
103-
8 | mostly-unused = 1
104-
| ^
105-
|
106-
[ERROR] failed to download replaced source registry `crates-io`
99+
[WARNING] ignoring unsupported value type (integer) for 'hints.mostly-unused', which expects a boolean
100+
[CHECKING] bar v1.0.0
101+
[RUNNING] `rustc --crate-name bar [..]`
102+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
103+
[RUNNING] `rustc --crate-name foo [..]`
104+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
107105
108106
"#]])
109107
.with_stderr_does_not_contain("-Zhint-mostly-unused")

0 commit comments

Comments
 (0)