Skip to content

Commit

Permalink
Auto merge of #13393 - weihanglo:beta-backport, r=ehuss
Browse files Browse the repository at this point in the history
[beta-1.77.0] Fix panic on empty spans when parsing Cargo.toml

Beta backports:

- <#13375>
- <#13376>

In order to make CI pass, the following PRs are also cherry-picked:

- <#13362>
  • Loading branch information
bors committed Feb 4, 2024
2 parents 7bb7b53 + d1751e0 commit 9075a2c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 12 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions tests/build-std/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/custom_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 32 additions & 0 deletions tests/testsuite/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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:6:3
|
6 | [[bench.foo]]
| ^^^^^
|
",
)
.run();
}
1 change: 1 addition & 0 deletions tests/testsuite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9075a2c

Please sign in to comment.