0xMiden / 0xMiden/miden-diagnostics
SourceFile location and source_slice panic with subtract overflow on empty files
- Vorherrschende Sprache
- Rust
- Sterne
- 0
- Forks
- 4
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
`SourceFile::location()` and `SourceFile::source_slice()` can panic for empty source files while building their `IndexTooLarge` errors.
File evidence:
- `diagnostics/src/source.rs` computes `self.source().len() - 1` in `location()` when `line_start()` fails.
- The same `len() - 1` pattern is used in the `location()` invalid-slice error path.
- `source_slice()` also computes `self.source().len() - 1` when the requested range is invalid.
For an empty file, `self.source().len()` is `0`, so these error paths underflow before returning the expected `Result::Err`. Empty files are reasonable inputs for diagnostics tooling, parsers, and editor integrations.
Expected behavior: out-of-range locations/slices for empty files should return `Error::IndexTooLarge` rather than panicking with subtract overflow.
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.