From 111eaa1cd8b6356a42f0671e16837439f0a9f52f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 18 Mar 2019 07:32:59 -0700 Subject: [PATCH] Handle backcompat hazard with `toml` crate The 0.5.0 release contained a [bugfix](https://github.com/alexcrichton/toml-rs/pull/280) which previously successfully parsed invalid TOML files, so we'll need to manually handle that in Cago to ensure that we don't accidentally regress crates, but rather instead give them an appropriate amount of time to get fixed. --- src/cargo/util/toml/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index eb1354bf251..31099a78e81 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -142,6 +142,24 @@ in the future.", return Ok(ret); } + let mut third_parser = toml::de::Deserializer::new(toml); + third_parser.set_allow_duplicate_after_longer_table(true); + if let Ok(ret) = toml::Value::deserialize(&mut third_parser) { + let msg = format!( + "\ +TOML file found which contains invalid syntax and will soon not parse +at `{}`. + +The TOML spec requires that each table header is defined at most once, but +historical versions of Cargo have erroneously accepted this file. The table +definitions will need to be merged together with one table header to proceed, +and this will become a hard error in the future.", + file.display() + ); + config.shell().warn(&msg)?; + return Ok(ret); + } + let first_error = failure::Error::from(first_error); Err(first_error.context("could not parse input as TOML").into()) }