diff options
| author | Michael Goulet <michael@errs.io> | 2022-11-09 21:53:35 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-09 21:53:35 -0800 |
| commit | f9160224cf3cd0986a513415b0377125df7dc249 (patch) | |
| tree | 23dc2046445bd71a105b42314bf4d087f6e9e503 /compiler/rustc_span/src/source_map.rs | |
| parent | 0c4a81c97b6309e7239eb0000bc46a5d348a2230 (diff) | |
| parent | 0b6934d6c6fed66e5e783b355de1f33ab3d51efb (diff) | |
| download | rust-f9160224cf3cd0986a513415b0377125df7dc249.tar.gz rust-f9160224cf3cd0986a513415b0377125df7dc249.zip | |
Rollup merge of #103675 - lyming2007:issue-103271-fix, r=fee1-dead
remove redundent "<>" for ty::Slice with reference type this fix #103271
Diffstat (limited to 'compiler/rustc_span/src/source_map.rs')
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 3baa2e03cba..7ea028b12ef 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -753,6 +753,50 @@ impl SourceMap { } } + /// Given a 'Span', tries to tell if the next character is '>' + /// and the previous charactoer is '<' after skipping white space + /// return true if wrapped by '<>' + pub fn span_wrapped_by_angle_bracket(&self, span: Span) -> bool { + self.span_to_source(span, |src, start_index, end_index| { + if src.get(start_index..end_index).is_none() { + return Ok(false); + } + // test the right side to match '>' after skipping white space + let end_src = &src[end_index..]; + let mut i = 0; + while let Some(cc) = end_src.chars().nth(i) { + if cc == ' ' { + i = i + 1; + } else if cc == '>' { + // found > in the right; + break; + } else { + // failed to find '>' return false immediately + return Ok(false); + } + } + // test the left side to match '<' after skipping white space + i = start_index; + let start_src = &src[0..start_index]; + while let Some(cc) = start_src.chars().nth(i) { + if cc == ' ' { + if i == 0 { + return Ok(false); + } + i = i - 1; + } else if cc == '<' { + // found < in the left + break; + } else { + // failed to find '<' return false immediately + return Ok(false); + } + } + return Ok(true); + }) + .map_or(false, |is_accessible| is_accessible) + } + /// Given a `Span`, tries to get a shorter span ending just after the first occurrence of `char` /// `c`. pub fn span_through_char(&self, sp: Span, c: char) -> Span { |
