code icon indicating copy to clipboard operation
code copied to clipboard

ch8/ch8-mget: build fails immediately due to misformed TOML in Cargo.toml

Open ewenmcneill opened this issue 2 years ago • 1 comments

At least with Rust 1.66 / Cargo 1.66, embedded newlines are not permitted in inline tables in TOML. This is also noted in the TOML specification: "No newlines are allowed between the curly braces unless they are valid within a value." So it appears Cargo is simply enforcing the TOML specification.

The pre-book-release version of the Cargo.toml uses multiple TOML (non-inline) tables, which appears to be the recommended TOML formatting if you need to break the table over multiple lines.

For some (not documented in the commit) reason this was changed to a more "JSON-like" multiline inline structure with the release of the book. I'm unclear if there is any rust/cargo version where that multi-line structure of inline TOML tables ever worked, or if this is just another thing that was never tested prior to release.

It apears sufficient to simply join the whole {...} inline table in the TOML onto a single line, in each case.

Ewen

PS: Both the "smoltcp" and "trust-dns" dependency details got reformatted in the book release version of Cargo.toml; both will need fixing for cargo to accept the Cargo.toml file.

ewen@rustdev:~/misc/src/rust/rust-in-action/ch8/ch8-mget$ git status Cargo.toml
On branch 1st-edition
Your branch is up to date with 'origin/1st-edition'.

nothing to commit, working tree clean
ewen@rustdev:~/misc/src/rust/rust-in-action/ch8/ch8-mget$ grep -A 99 dependencies Cargo.toml 
[dependencies]
clap = "2"
rand = "0.7"
smoltcp = {
  version = "0.6",
  features = ["proto-igmp", "proto-ipv4", "verbose", "log"]
}
trust-dns = {
  version = "0.16",
  default-features = false
}
url = "2"
ewen@rustdev:~/misc/src/rust/rust-in-action/ch8/ch8-mget$ cargo build
error: failed to parse manifest at `/home/ewen/misc/src/rust/rust-in-action/ch8/ch8-mget/Cargo.toml`

Caused by:
  could not parse input as TOML

Caused by:
  TOML parse error at line 10, column 12
     |
  10 | smoltcp = {
     |            ^
  Unexpected `
  `
  Expected key
ewen@rustdev:~/misc/src/rust/rust-in-action/ch8/ch8-mget$ 

ewenmcneill avatar Jan 10 '23 05:01 ewenmcneill

It turns out that this is fixed in PR #91, which (a) hasn't been merged, and (b) had too generate a subject line to find it easily (I found it by accident today, looking for something else). PR #91 claims to fix issue #77, but AFAICT it only fixes part of #77; however AFAICT PR #91 would fix this issue.

Ewen

ewenmcneill avatar Jan 10 '23 22:01 ewenmcneill