File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -364,7 +364,10 @@ impl FileInfo {
364364
365365 fn source_text ( & self , span : Span ) -> String {
366366 let lo = ( span. lo - self . span . lo ) as usize ;
367- let trunc_lo = & self . source_text [ lo..] ;
367+ let trunc_lo = match self . source_text . char_indices ( ) . nth ( lo) {
368+ Some ( ( offset, _ch) ) => & self . source_text [ offset..] ,
369+ None => return String :: new ( ) ,
370+ } ;
368371 let char_len = ( span. hi - span. lo ) as usize ;
369372 let source_text = match trunc_lo. char_indices ( ) . nth ( char_len) {
370373 Some ( ( offset, _ch) ) => & trunc_lo[ ..offset] ,
Original file line number Diff line number Diff line change @@ -328,10 +328,17 @@ fn literal_span() {
328328#[ cfg( span_locations) ]
329329#[ test]
330330fn source_text ( ) {
331- let input = " 𓀕 " ;
332- let tokens = input. parse :: < proc_macro2:: TokenStream > ( ) . unwrap ( ) ;
333- let ident = tokens. into_iter ( ) . next ( ) . unwrap ( ) ;
331+ let input = " 𓀕 c " ;
332+ let mut tokens = input
333+ . parse :: < proc_macro2:: TokenStream > ( )
334+ . unwrap ( )
335+ . into_iter ( ) ;
336+
337+ let ident = tokens. next ( ) . unwrap ( ) ;
334338 assert_eq ! ( "𓀕" , ident. span( ) . source_text( ) . unwrap( ) ) ;
339+
340+ let ident = tokens. next ( ) . unwrap ( ) ;
341+ assert_eq ! ( "c" , ident. span( ) . source_text( ) . unwrap( ) ) ;
335342}
336343
337344#[ test]
You can’t perform that action at this time.
0 commit comments