diff options
| author | Yiming Lei <yiming.lei@futurewei.com> | 2022-10-27 22:38:59 -0700 |
|---|---|---|
| committer | Yiming Lei <yiming.lei@futurewei.com> | 2022-11-09 17:42:17 -0800 |
| commit | 0b6934d6c6fed66e5e783b355de1f33ab3d51efb (patch) | |
| tree | 4ed0ca2d69c7aa800720ceeb8781af6e9a069443 /compiler/rustc_span/src | |
| parent | 73c9eaf21454b718e7c549984d9eb6e1f75e995c (diff) | |
| download | rust-0b6934d6c6fed66e5e783b355de1f33ab3d51efb.tar.gz rust-0b6934d6c6fed66e5e783b355de1f33ab3d51efb.zip | |
remove redundent "<>" for ty::Slice with reference type
this fix #103271
Diffstat (limited to 'compiler/rustc_span/src')
| -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 f9566eeee94..029cd93a52a 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 { |
