Skip to content

Commit 1c05d41

Browse files
committed
fix(diagnostic): Don't panic on empty spans
There is another level to this bug where we better point to where the error occurs.
1 parent f2a4a3e commit 1c05d41

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ edition = "2021"
1818

1919
p.cargo("check")
2020
.with_status(101)
21-
.with_stderr_contains("attempt to subtract with overflow")
21+
.with_stderr(
22+
"\
23+
error: invalid type: map, expected a sequence
24+
--> Cargo.toml:1:1
25+
|
26+
|
27+
",
28+
)
2229
.run();
2330
}

0 commit comments

Comments
 (0)