Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(diagnostic): Don't panic on empty spans
There is another level to this bug where we better point to where the
error occurs.
  • Loading branch information
epage committed Jan 31, 2024
commit 1c05d412af53d554f1f64470e5939bcfe953dd4f
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();
}