@@ -539,7 +539,7 @@ impl SourceMap {
539
539
540
540
pub fn is_line_before_span_empty ( & self , sp : Span ) -> bool {
541
541
match self . span_to_prev_source ( sp) {
542
- Ok ( s) => s. split ( '\n' ) . last ( ) . map_or ( false , |l| l . trim_start ( ) . is_empty ( ) ) ,
542
+ Ok ( s) => s. rsplit_once ( '\n' ) . unwrap_or ( ( "" , & s ) ) . 1 . trim_start ( ) . is_empty ( ) ,
543
543
Err ( _) => false ,
544
544
}
545
545
}
@@ -632,10 +632,11 @@ impl SourceMap {
632
632
pub fn span_to_margin ( & self , sp : Span ) -> Option < usize > {
633
633
match self . span_to_prev_source ( sp) {
634
634
Err ( _) => None ,
635
- Ok ( source) => source
636
- . split ( '\n' )
637
- . last ( )
638
- . map ( |last_line| last_line. len ( ) - last_line. trim_start ( ) . len ( ) ) ,
635
+ Ok ( source) => {
636
+ let last_line = source. rsplit_once ( '\n' ) . unwrap_or ( ( "" , & source) ) . 1 ;
637
+
638
+ Some ( last_line. len ( ) - last_line. trim_start ( ) . len ( ) )
639
+ }
639
640
}
640
641
}
641
642
@@ -651,7 +652,7 @@ impl SourceMap {
651
652
pub fn span_extend_to_prev_char ( & self , sp : Span , c : char , accept_newlines : bool ) -> Span {
652
653
if let Ok ( prev_source) = self . span_to_prev_source ( sp) {
653
654
let prev_source = prev_source. rsplit ( c) . next ( ) . unwrap_or ( "" ) ;
654
- if !prev_source. is_empty ( ) && ( !prev_source. contains ( '\n' ) || accept_newlines ) {
655
+ if !prev_source. is_empty ( ) && ( accept_newlines || !prev_source. contains ( '\n' ) ) {
655
656
return sp. with_lo ( BytePos ( sp. lo ( ) . 0 - prev_source. len ( ) as u32 ) ) ;
656
657
}
657
658
}
@@ -673,7 +674,7 @@ impl SourceMap {
673
674
let prev_source = prev_source. rsplit ( & pat) . next ( ) . unwrap_or ( "" ) . trim_start ( ) ;
674
675
if prev_source. is_empty ( ) && sp. lo ( ) . 0 != 0 {
675
676
return sp. with_lo ( BytePos ( sp. lo ( ) . 0 - 1 ) ) ;
676
- } else if !prev_source. contains ( '\n' ) || accept_newlines {
677
+ } else if accept_newlines || !prev_source. contains ( '\n' ) {
677
678
return sp. with_lo ( BytePos ( sp. lo ( ) . 0 - prev_source. len ( ) as u32 ) ) ;
678
679
}
679
680
}
@@ -693,7 +694,7 @@ impl SourceMap {
693
694
pub fn span_extend_to_next_char ( & self , sp : Span , c : char , accept_newlines : bool ) -> Span {
694
695
if let Ok ( next_source) = self . span_to_next_source ( sp) {
695
696
let next_source = next_source. split ( c) . next ( ) . unwrap_or ( "" ) ;
696
- if !next_source. is_empty ( ) && ( !next_source. contains ( '\n' ) || accept_newlines ) {
697
+ if !next_source. is_empty ( ) && ( accept_newlines || !next_source. contains ( '\n' ) ) {
697
698
return sp. with_hi ( BytePos ( sp. hi ( ) . 0 + next_source. len ( ) as u32 ) ) ;
698
699
}
699
700
}
0 commit comments