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> {
379379 }
380380 line_count
381381 }
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+
382395 // Assumption: all spans are in the same file, and all spans
383396 // are disjoint. Sort in ascending order.
384397 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
27062706}
27072707
27082708#[ test]
2709+ #[ should_panic = "Patch span `47..47` is beyond the end of buffer `45`" ]
27092710fn suggestion_span_bigger_than_source ( ) {
27102711 let snippet_source = r#"#![allow(unused)]
27112712fn main() {
You can’t perform that action at this time.
0 commit comments