Skip to content

Commit a1afadb

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 c1d3b8f commit a1afadb

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
@@ -1130,7 +1130,7 @@ fn build_base_args(
11301130
strip,
11311131
rustflags: profile_rustflags,
11321132
trim_paths,
1133-
hint_mostly_unused,
1133+
hint_mostly_unused: profile_hint_mostly_unused,
11341134
..
11351135
} = unit.profile.clone();
11361136
let hints = unit.pkg.hints().cloned().unwrap_or_default();
@@ -1322,15 +1322,29 @@ fn build_base_args(
13221322
opt(cmd, "-C", "incremental=", Some(dir));
13231323
}
13241324

1325-
if hint_mostly_unused.or(hints.mostly_unused).unwrap_or(false) {
1325+
let pkg_hint_mostly_unused = match hints.mostly_unused {
1326+
None => None,
1327+
Some(toml::Value::Boolean(b)) => Some(b),
1328+
Some(v) => {
1329+
bcx.gctx.shell().warn(format!(
1330+
"ignoring unknown value type ({}) for 'hints.mostly-unused'",
1331+
v.type_str()
1332+
))?;
1333+
None
1334+
}
1335+
};
1336+
if profile_hint_mostly_unused
1337+
.or(pkg_hint_mostly_unused)
1338+
.unwrap_or(false)
1339+
{
13261340
if bcx.gctx.cli_unstable().profile_hint_mostly_unused {
13271341
cmd.arg("-Zhint-mostly-unused");
13281342
} else {
1329-
if hint_mostly_unused.is_some() {
1343+
if profile_hint_mostly_unused.is_some() {
13301344
bcx.gctx
13311345
.shell()
13321346
.warn("ignoring 'hint-mostly-unused' profile option, pass `-Zprofile-hint-mostly-unused` to enable it")?;
1333-
} else if hints.mostly_unused.is_some() {
1347+
} else if pkg_hint_mostly_unused.is_some() {
13341348
bcx.gctx
13351349
.shell()
13361350
.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 unknown value type (integer) for 'hints.mostly-unused'
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)