File tree 2 files changed +8
-24
lines changed
2 files changed +8
-24
lines changed Original file line number Diff line number Diff line change 20
20
#![ feature( min_specialization) ]
21
21
#![ feature( rustc_attrs) ]
22
22
#![ feature( let_chains) ]
23
+ #![ feature( round_char_boundary) ]
23
24
#![ deny( rustc:: untranslatable_diagnostic) ]
24
25
#![ deny( rustc:: diagnostic_outside_of_impl) ]
25
26
Original file line number Diff line number Diff line change @@ -1019,36 +1019,19 @@ impl SourceMap {
1019
1019
1020
1020
let src = local_begin. sf . external_src . borrow ( ) ;
1021
1021
1022
- // We need to extend the snippet to the end of the src rather than to end_index so when
1023
- // searching forwards for boundaries we've got somewhere to search.
1024
- let snippet = if let Some ( ref src) = local_begin. sf . src {
1025
- & src[ start_index..]
1022
+ let snippet = if let Some ( src) = & local_begin. sf . src {
1023
+ src
1026
1024
} else if let Some ( src) = src. get_source ( ) {
1027
- & src[ start_index.. ]
1025
+ src
1028
1026
} else {
1029
1027
return 1 ;
1030
1028
} ;
1031
- debug ! ( "snippet=`{:?}`" , snippet) ;
1032
1029
1033
- let mut target = if forwards { end_index + 1 } else { end_index - 1 } ;
1034
- debug ! ( "initial target=`{:?}`" , target) ;
1035
-
1036
- while !snippet. is_char_boundary ( target - start_index) && target < source_len {
1037
- target = if forwards {
1038
- target + 1
1039
- } else {
1040
- match target. checked_sub ( 1 ) {
1041
- Some ( target) => target,
1042
- None => {
1043
- break ;
1044
- }
1045
- }
1046
- } ;
1047
- debug ! ( "target=`{:?}`" , target) ;
1030
+ if forwards {
1031
+ ( snippet. ceil_char_boundary ( end_index + 1 ) - end_index) as u32
1032
+ } else {
1033
+ ( end_index - snippet. floor_char_boundary ( end_index - 1 ) ) as u32
1048
1034
}
1049
- debug ! ( "final target=`{:?}`" , target) ;
1050
-
1051
- if forwards { ( target - end_index) as u32 } else { ( end_index - target) as u32 }
1052
1035
}
1053
1036
1054
1037
pub fn get_source_file ( & self , filename : & FileName ) -> Option < Lrc < SourceFile > > {
You can’t perform that action at this time.
0 commit comments