Skip to content

Commit 790b01f

Browse files
committed
Auto merge of #9932 - epage:hacks, r=alexcrichton
Remove TOML incompatibility hacks - `set_require_newline_after_table` was added in #2680 back in 2016 - `set_allow_duplicate_after_longer_table` was added in #6761 in 2019 Several years later, this PR is turning these warnings into errors. The function and documentation was kept so we can add additional hacks in the future, like if we switch TOML parsers.
2 parents e79ba78 + 2fdb710 commit 790b01f

File tree

2 files changed

+7
-58
lines changed

2 files changed

+7
-58
lines changed

src/cargo/util/toml/mod.rs

+4-44
Original file line numberDiff line numberDiff line change
@@ -150,50 +150,10 @@ fn do_read_manifest(
150150
/// The purpose of this wrapper is to detect invalid TOML which was previously
151151
/// accepted and display a warning to the user in that case. The `file` and `config`
152152
/// parameters are only used by this fallback path.
153-
pub fn parse(toml: &str, file: &Path, config: &Config) -> CargoResult<toml::Value> {
154-
let first_error = match toml.parse() {
155-
Ok(ret) => return Ok(ret),
156-
Err(e) => e,
157-
};
158-
159-
let mut second_parser = toml::de::Deserializer::new(toml);
160-
second_parser.set_require_newline_after_table(false);
161-
if let Ok(ret) = toml::Value::deserialize(&mut second_parser) {
162-
let msg = format!(
163-
"\
164-
TOML file found which contains invalid syntax and will soon not parse
165-
at `{}`.
166-
167-
The TOML spec requires newlines after table definitions (e.g., `[a] b = 1` is
168-
invalid), but this file has a table header which does not have a newline after
169-
it. A newline needs to be added and this warning will soon become a hard error
170-
in the future.",
171-
file.display()
172-
);
173-
config.shell().warn(&msg)?;
174-
return Ok(ret);
175-
}
176-
177-
let mut third_parser = toml::de::Deserializer::new(toml);
178-
third_parser.set_allow_duplicate_after_longer_table(true);
179-
if let Ok(ret) = toml::Value::deserialize(&mut third_parser) {
180-
let msg = format!(
181-
"\
182-
TOML file found which contains invalid syntax and will soon not parse
183-
at `{}`.
184-
185-
The TOML spec requires that each table header is defined at most once, but
186-
historical versions of Cargo have erroneously accepted this file. The table
187-
definitions will need to be merged together with one table header to proceed,
188-
and this will become a hard error in the future.",
189-
file.display()
190-
);
191-
config.shell().warn(&msg)?;
192-
return Ok(ret);
193-
}
194-
195-
let first_error = anyhow::Error::from(first_error);
196-
Err(first_error.context("could not parse input as TOML"))
153+
pub fn parse(toml: &str, _file: &Path, _config: &Config) -> CargoResult<toml::Value> {
154+
// At the moment, no compatibility checks are needed.
155+
toml.parse()
156+
.map_err(|e| anyhow::Error::from(e).context("could not parse input as TOML"))
197157
}
198158

199159
type TomlLibTarget = TomlTarget;

tests/testsuite/bad_config.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -773,26 +773,15 @@ to use. This will be considered an error in future versions
773773
}
774774

775775
#[cargo_test]
776-
fn invalid_toml_historically_allowed_is_warned() {
776+
fn invalid_toml_historically_allowed_fails() {
777777
let p = project()
778778
.file(".cargo/config", "[bar] baz = 2")
779779
.file("src/main.rs", "fn main() {}")
780780
.build();
781781

782782
p.cargo("build")
783-
.with_stderr(
784-
"\
785-
warning: TOML file found which contains invalid syntax and will soon not parse
786-
at `[..]config`.
787-
788-
The TOML spec requires newlines after table definitions (e.g., `[a] b = 1` is
789-
invalid), but this file has a table header which does not have a newline after
790-
it. A newline needs to be added and this warning will soon become a hard error
791-
in the future.
792-
[COMPILING] foo v0.0.1 ([..])
793-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
794-
",
795-
)
783+
.with_status(101)
784+
.with_stderr_contains(" expected newline, found an identifier at line 1 column 7")
796785
.run();
797786
}
798787

0 commit comments

Comments
 (0)