diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2023-05-14 16:24:11 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2023-05-14 16:24:11 +0200 |
| commit | 6289c57dc0ee8ebbe9e20fad808f85aed0afeceb (patch) | |
| tree | 3ab89230f284d14b4089a316f5e74b1054484fee /compiler/rustc_span/src/source_map.rs | |
| parent | 0a0e045e50352d5b8c5c99e965c16aa978a0cbe1 (diff) | |
| download | rust-6289c57dc0ee8ebbe9e20fad808f85aed0afeceb.tar.gz rust-6289c57dc0ee8ebbe9e20fad808f85aed0afeceb.zip | |
Simplify find_width_of_character_at_span.
Diffstat (limited to 'compiler/rustc_span/src/source_map.rs')
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 31 |
1 files changed, 7 insertions, 24 deletions
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 8238a16969d..11ea5fe4ddf 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -1019,36 +1019,19 @@ impl SourceMap { let src = local_begin.sf.external_src.borrow(); - // We need to extend the snippet to the end of the src rather than to end_index so when - // searching forwards for boundaries we've got somewhere to search. - let snippet = if let Some(ref src) = local_begin.sf.src { - &src[start_index..] + let snippet = if let Some(src) = &local_begin.sf.src { + src } else if let Some(src) = src.get_source() { - &src[start_index..] + src } else { return 1; }; - debug!("snippet=`{:?}`", snippet); - let mut target = if forwards { end_index + 1 } else { end_index - 1 }; - debug!("initial target=`{:?}`", target); - - 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!("target=`{:?}`", target); + if forwards { + (snippet.ceil_char_boundary(end_index + 1) - end_index) as u32 + } else { + (end_index - snippet.floor_char_boundary(end_index - 1)) as u32 } - debug!("final target=`{:?}`", target); - - if forwards { (target - end_index) as u32 } else { (end_index - target) as u32 } } pub fn get_source_file(&self, filename: &FileName) -> Option<Lrc<SourceFile>> { |
