File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -379,6 +379,19 @@ impl<'a> SourceMap<'a> {
379
379
}
380
380
line_count
381
381
}
382
+
383
+ let source_len = self . source . len ( ) ;
384
+ if let Some ( bigger) = patches. iter ( ) . find_map ( |x| {
385
+ // Allow patching one past the last character in the source.
386
+ if source_len + 1 < x. span . end {
387
+ Some ( & x. span )
388
+ } else {
389
+ None
390
+ }
391
+ } ) {
392
+ panic ! ( "Patch span `{bigger:?}` is beyond the end of buffer `{source_len}`" )
393
+ }
394
+
382
395
// Assumption: all spans are in the same file, and all spans
383
396
// are disjoint. Sort in ascending order.
384
397
patches. sort_by_key ( |p| p. span . start ) ;
Original file line number Diff line number Diff line change @@ -2706,6 +2706,7 @@ help: or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicit
2706
2706
}
2707
2707
2708
2708
#[ test]
2709
+ #[ should_panic = "Patch span `47..47` is beyond the end of buffer `45`" ]
2709
2710
fn suggestion_span_bigger_than_source ( ) {
2710
2711
let snippet_source = r#"#![allow(unused)]
2711
2712
fn main() {
You can’t perform that action at this time.
0 commit comments