fix(diagnostic): Don't panic on empty spans

There is another level to this bug where we better point to where the
error occurs.
This commit is contained in:
Ed Page 2024-01-31 09:11:12 -06:00
parent f2a4a3e88b
commit 1c05d412af
2 changed files with 9 additions and 2 deletions

View File

@ -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());

View File

@ -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();
}