File tree 3 files changed +11
-4
lines changed
3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -1574,7 +1574,7 @@ impl EmitterWriter {
1574
1574
. span_to_lines ( parts[ 0 ] . span )
1575
1575
. expect ( "span_to_lines failed when emitting suggestion" ) ;
1576
1576
1577
- assert ! ( !lines. lines. is_empty( ) ) ;
1577
+ assert ! ( !lines. lines. is_empty( ) || parts [ 0 ] . span . is_dummy ( ) ) ;
1578
1578
1579
1579
let line_start = sm. lookup_char_pos ( parts[ 0 ] . span . lo ( ) ) . line ;
1580
1580
draw_col_separator_no_space ( & mut buffer, 1 , max_line_num_len + 1 ) ;
Original file line number Diff line number Diff line change @@ -194,7 +194,7 @@ impl CodeSuggestion {
194
194
let bounding_span = Span :: with_root_ctxt ( lo, hi) ;
195
195
// The different spans might belong to different contexts, if so ignore suggestion.
196
196
let lines = sm. span_to_lines ( bounding_span) . ok ( ) ?;
197
- assert ! ( !lines. lines. is_empty( ) ) ;
197
+ assert ! ( !lines. lines. is_empty( ) || bounding_span . is_dummy ( ) ) ;
198
198
199
199
// We can't splice anything if the source is unavailable.
200
200
if !sm. ensure_source_file_source_present ( lines. file . clone ( ) ) {
@@ -213,8 +213,8 @@ impl CodeSuggestion {
213
213
let sf = & lines. file ;
214
214
let mut prev_hi = sm. lookup_char_pos ( bounding_span. lo ( ) ) ;
215
215
prev_hi. col = CharPos :: from_usize ( 0 ) ;
216
-
217
- let mut prev_line = sf . get_line ( lines. lines [ 0 ] . line_index ) ;
216
+ let mut prev_line =
217
+ lines. lines . get ( 0 ) . and_then ( |line0| sf . get_line ( line0 . line_index ) ) ;
218
218
let mut buf = String :: new ( ) ;
219
219
220
220
for part in & substitution. parts {
Original file line number Diff line number Diff line change @@ -535,6 +535,10 @@ impl SourceMap {
535
535
let ( lo, hi) = self . is_valid_span ( sp) ?;
536
536
assert ! ( hi. line >= lo. line) ;
537
537
538
+ if sp. is_dummy ( ) {
539
+ return Ok ( FileLines { file : lo. file , lines : Vec :: new ( ) } ) ;
540
+ }
541
+
538
542
let mut lines = Vec :: with_capacity ( hi. line - lo. line + 1 ) ;
539
543
540
544
// The span starts partway through the first line,
@@ -545,6 +549,9 @@ impl SourceMap {
545
549
// and to the end of the line. Be careful because the line
546
550
// numbers in Loc are 1-based, so we subtract 1 to get 0-based
547
551
// lines.
552
+ //
553
+ // FIXME: now that we handle DUMMY_SP up above, we should consider
554
+ // asserting that the line numbers here are all indeed 1-based.
548
555
let hi_line = hi. line . saturating_sub ( 1 ) ;
549
556
for line_index in lo. line . saturating_sub ( 1 ) ..hi_line {
550
557
let line_len = lo. file . get_line ( line_index) . map ( |s| s. chars ( ) . count ( ) ) . unwrap_or ( 0 ) ;
You can’t perform that action at this time.
0 commit comments