diff options
Diffstat (limited to 'src/libsyntax/codemap.rs')
| -rw-r--r-- | src/libsyntax/codemap.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index df5845f6c21..5d36f39b2e4 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -705,17 +705,20 @@ impl CodeMap { }; debug!("find_width_of_character_at_span: snippet=`{:?}`", snippet); - let file_start_pos = local_begin.fm.start_pos.to_usize(); - let file_end_pos = local_begin.fm.end_pos.to_usize(); - debug!("find_width_of_character_at_span: file_start_pos=`{:?}` file_end_pos=`{:?}`", - file_start_pos, file_end_pos); - let mut target = if forwards { end_index + 1 } else { end_index - 1 }; debug!("find_width_of_character_at_span: initial target=`{:?}`", target); - while !snippet.is_char_boundary(target - start_index) - && target >= file_start_pos && target <= file_end_pos { - target = if forwards { target + 1 } else { target - 1 }; + while !snippet.is_char_boundary(target - start_index) && target < source_len { + target = if forwards { + target + 1 + } else { + match target.checked_sub(1) { + Some(target) => target, + None => { + break; + } + } + }; debug!("find_width_of_character_at_span: target=`{:?}`", target); } debug!("find_width_of_character_at_span: final target=`{:?}`", target); |
