From b42c54de4be9a651d2cf13d63ed3d36644768ebb Mon Sep 17 00:00:00 2001 From: bors Date: Wed, 31 Jan 2024 15:57:07 +0000 Subject: [PATCH 1/3] Auto merge of #13375 - epage:panic, r=Muscraft fix(diagnostic): Don't panic on empty spans ### What does this PR try to resolve? There is another level to this bug where we better point to where the error occurs, see toml-rs/toml#669. Fixes #13374 ### How should we test and review this PR? ### Additional information --- src/cargo/util/toml/mod.rs | 2 +- tests/testsuite/diagnostics.rs | 30 ++++++++++++++++++++++++++++++ tests/testsuite/main.rs | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/testsuite/diagnostics.rs diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 0ffeda2ada8..f4c3b9034c7 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -121,7 +121,7 @@ fn read_manifest_from_str( .rfind('\n') .map(|s| s + 1) .unwrap_or(0); - let source_end = contents[span.end - 1..] + let source_end = contents[span.end.saturating_sub(1)..] .find('\n') .map(|s| s + span.end) .unwrap_or(contents.len()); diff --git a/tests/testsuite/diagnostics.rs b/tests/testsuite/diagnostics.rs new file mode 100644 index 00000000000..2de841825f2 --- /dev/null +++ b/tests/testsuite/diagnostics.rs @@ -0,0 +1,30 @@ +use cargo_test_support::project; + +#[cargo_test] +fn dont_panic_on_render() { + let p = project() + .file( + "Cargo.toml", + r#" +[package] +name = "foo" +version = "0.1.0" +edition = "2021" +[[bench.foo]] +"#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr( + "\ +error: invalid type: map, expected a sequence +--> Cargo.toml:1:1 + | + | +", + ) + .run(); +} diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 4643f25f834..1ec140d7618 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -79,6 +79,7 @@ mod cross_publish; mod custom_target; mod death; mod dep_info; +mod diagnostics; mod direct_minimal_versions; mod directory; mod doc; From 74fbf5b7af599b79ab32ed1b458ea2907c922c28 Mon Sep 17 00:00:00 2001 From: bors Date: Wed, 31 Jan 2024 16:55:38 +0000 Subject: [PATCH 2/3] Auto merge of #13376 - epage:error, r=Muscraft fix(toml): Improve map/sequence error message This is a follow up to #13375 --- Cargo.lock | 12 ++++++------ Cargo.toml | 4 ++-- tests/testsuite/diagnostics.rs | 8 +++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0a7cc9b9d3..95ff3ce5fc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3036,9 +3036,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] @@ -3354,9 +3354,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "toml" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" +checksum = "c6a4b9e8023eb94392d3dca65d717c53abc5dad49c07cb65bb8fcd87115fa325" dependencies = [ "serde", "serde_spanned", @@ -3375,9 +3375,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ "indexmap", "serde", diff --git a/Cargo.toml b/Cargo.toml index 0a62314f057..5e216220f97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,8 +96,8 @@ tar = { version = "0.4.40", default-features = false } tempfile = "3.9.0" thiserror = "1.0.56" time = { version = "0.3", features = ["parsing", "formatting", "serde"] } -toml = "0.8.8" -toml_edit = { version = "0.21.0", features = ["serde"] } +toml = "0.8.9" +toml_edit = { version = "0.21.1", features = ["serde"] } tracing = "0.1.37" # be compatible with rustc_log: https://github.com/rust-lang/rust/blob/e51e98dde6a/compiler/rustc_log/Cargo.toml#L9 tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } unicase = "2.7.0" diff --git a/tests/testsuite/diagnostics.rs b/tests/testsuite/diagnostics.rs index 2de841825f2..98a9f421cbb 100644 --- a/tests/testsuite/diagnostics.rs +++ b/tests/testsuite/diagnostics.rs @@ -21,9 +21,11 @@ edition = "2021" .with_stderr( "\ error: invalid type: map, expected a sequence ---> Cargo.toml:1:1 - | - | + --> Cargo.toml:6:3 + | +6 | [[bench.foo]] + | ^^^^^ + | ", ) .run(); From d1751e03a94c75161cdca9d04088516ff72df91c Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sun, 28 Jan 2024 15:52:14 -0500 Subject: [PATCH 3/3] test: data layout fix for `x86_64-unknown-none-gnu` --- tests/build-std/main.rs | 4 ++-- tests/testsuite/custom_target.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/build-std/main.rs b/tests/build-std/main.rs index c905deb4950..c9d5c3d983d 100644 --- a/tests/build-std/main.rs +++ b/tests/build-std/main.rs @@ -155,7 +155,7 @@ fn cross_custom() { r#" { "llvm-target": "x86_64-unknown-none-gnu", - "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", "arch": "x86_64", "target-endian": "little", "target-pointer-width": "64", @@ -196,7 +196,7 @@ fn custom_test_framework() { r#" { "llvm-target": "x86_64-unknown-none-gnu", - "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", "arch": "x86_64", "target-endian": "little", "target-pointer-width": "64", diff --git a/tests/testsuite/custom_target.rs b/tests/testsuite/custom_target.rs index 45cb3ac9fab..69325d0099f 100644 --- a/tests/testsuite/custom_target.rs +++ b/tests/testsuite/custom_target.rs @@ -22,7 +22,7 @@ pub trait Copy { const SIMPLE_SPEC: &str = r#" { "llvm-target": "x86_64-unknown-none-gnu", - "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", "arch": "x86_64", "target-endian": "little", "target-pointer-width": "64",