Skip to content

Commit

Permalink
fix(diagnostic): Don't panic on empty spans
Browse files Browse the repository at this point in the history
There is another level to this bug where we better point to where the
error occurs.
  • Loading branch information
epage committed Jan 31, 2024
1 parent f2a4a3e commit 1c05d41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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
9 changes: 8 additions & 1 deletion tests/testsuite/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 18,13 @@ edition = "2021"

p.cargo("check")
.with_status(101)
.with_stderr_contains("attempt to subtract with overflow")
.with_stderr(
"\
error: invalid type: map, expected a sequence
--> Cargo.toml:1:1
|
|
",
)
.run();
}

0 comments on commit 1c05d41

Please sign in to comment.