Skip to content

Commit 0f37cfb

Browse files
committed
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
2 parents e1ebce1 + 1c05d41 commit 0f37cfb

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn read_manifest_from_str(
121121
.rfind('\n')
122122
.map(|s| s + 1)
123123
.unwrap_or(0);
124-
let source_end = contents[span.end - 1..]
124+
let source_end = contents[span.end.saturating_sub(1)..]
125125
.find('\n')
126126
.map(|s| s + span.end)
127127
.unwrap_or(contents.len());

tests/testsuite/diagnostics.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use cargo_test_support::project;
2+
3+
#[cargo_test]
4+
fn dont_panic_on_render() {
5+
let p = project()
6+
.file(
7+
"Cargo.toml",
8+
r#"
9+
[package]
10+
name = "foo"
11+
version = "0.1.0"
12+
edition = "2021"
13+
[[bench.foo]]
14+
"#,
15+
)
16+
.file("src/lib.rs", "")
17+
.build();
18+
19+
p.cargo("check")
20+
.with_status(101)
21+
.with_stderr(
22+
"\
23+
error: invalid type: map, expected a sequence
24+
--> Cargo.toml:1:1
25+
|
26+
|
27+
",
28+
)
29+
.run();
30+
}

tests/testsuite/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ mod cross_publish;
7979
mod custom_target;
8080
mod death;
8181
mod dep_info;
82+
mod diagnostics;
8283
mod direct_minimal_versions;
8384
mod directory;
8485
mod doc;

0 commit comments

Comments
 (0)