diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-11-19 15:35:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-19 15:35:21 +0100 |
| commit | e86f1845ff6ca556621e2d366a6ad0c2d5aa408f (patch) | |
| tree | a0e0bf5061aff33ed74fa69ef9cf47c554e2d570 /compiler/rustc_span/src | |
| parent | 06707c073dcb29732933dc484877aa57c6dd1f94 (diff) | |
| parent | 867582eb9710b08e88d45ca8d2a452efd3233fea (diff) | |
| download | rust-e86f1845ff6ca556621e2d366a6ad0c2d5aa408f.tar.gz rust-e86f1845ff6ca556621e2d366a6ad0c2d5aa408f.zip | |
Rollup merge of #104497 - lyming2007:issue-104379-fix, r=fee1-dead
detect () to avoid redundant <> suggestion for type fix #104379
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 7ea028b12ef..e8d129d733c 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -753,10 +753,11 @@ 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 { + /// Given a 'Span', tries to tell if it's wrapped by "<>" or "()" + /// the algorithm searches if the next character is '>' or ')' after skipping white space + /// then searches the previous charactoer to match '<' or '(' after skipping white space + /// return true if wrapped by '<>' or '()' + pub fn span_wrapped_by_angle_or_parentheses(&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); @@ -764,11 +765,17 @@ impl SourceMap { // test the right side to match '>' after skipping white space let end_src = &src[end_index..]; let mut i = 0; + let mut found_right_parentheses = false; + let mut found_right_angle = false; while let Some(cc) = end_src.chars().nth(i) { if cc == ' ' { i = i + 1; } else if cc == '>' { // found > in the right; + found_right_angle = true; + break; + } else if cc == ')' { + found_right_parentheses = true; break; } else { // failed to find '>' return false immediately @@ -786,6 +793,16 @@ impl SourceMap { i = i - 1; } else if cc == '<' { // found < in the left + if !found_right_angle { + // skip something like "(< )>" + return Ok(false); + } + break; + } else if cc == '(' { + if !found_right_parentheses { + // skip something like "<(>)" + return Ok(false); + } break; } else { // failed to find '<' return false immediately |
