Skip to content

Commit

Permalink
Auto merge of #13375 - epage:panic, r=Muscraft
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jan 31, 2024
2 parents e1ebce1 + 1c05d41 commit 0f37cfb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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
30 changes: 30 additions & 0 deletions tests/testsuite/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -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();
}
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 0f37cfb

Please sign in to comment.