Cargo: `opt-level = s` and `opt-level = z` don't seem to work

Created on 12 Aug 2019  路  6Comments  路  Source: rust-lang/cargo

Problem

Specifying opt-level = s or opt-level = z for a profile fails with the following error:

$ cargo build
error: failed to parse manifest at `/xoxo/stuff/cargo-opt-level-size-bug/Cargo.toml`

Caused by:
  could not parse input as TOML

Caused by:
  invalid number at line 10

Steps

  1. Create a new project with cargo new repro
  2. Add
    toml [profile.dev] opt-level = s
    to Cargo.toml.
  3. Run cargo build

Possible Solution(s)

Fix the Cargo.toml parser?

Notes

Output of cargo version:

cargo 1.36.0 (c4fcfb725 2019-05-15)
cargo 1.38.0-nightly (26092da33 2019-07-31)
A-errors A-toml C-bug E-help-wanted

Most helpful comment

@aleksator I recently opened https://github.com/alexcrichton/toml-rs/issues/379 regarding the confusing error message here (it has cropped up in a few other places). I left some very rough guidance there, where number_or_date needs to check if the "keylike" value looks like it starts like a number or date, and if not should provide a better error message.

All 6 comments

They need to be specified as a string, like:

[profile.dev]
opt-level = 's'

The TOML language does not allow bare words as values.

Ah, interesting! Considers this a bug report about an unhelpful error message then :)

Looks like the error message is coming from https://github.com/alexcrichton/toml-rs
cc @alexcrichton

@aleksator I recently opened https://github.com/alexcrichton/toml-rs/issues/379 regarding the confusing error message here (it has cropped up in a few other places). I left some very rough guidance there, where number_or_date needs to check if the "keylike" value looks like it starts like a number or date, and if not should provide a better error message.

Fixed in toml-rs 0.5.7 (thank you @ehuss and @alexcrichton!).
We can rename this issue and close it next time we update dependencies.

Yep, just updated via #8772.

Was this page helpful?
0 / 5 - 0 ratings