about summary refs log tree commit diff
path: root/compiler/rustc_span/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-08-07 05:29:13 +0200
committerGitHub <noreply@github.com>2023-08-07 05:29:13 +0200
commitd804b74c6cd65549c826d2207c4bdaffdd9bf30d (patch)
tree070411e73eb8bee4b4d1e0cefa0af57ea24ba840 /compiler/rustc_span/src
parentcbe25226525ac010295c666c05fef7a81e99984c (diff)
parenteb0fcc5ad1f8e622c942334658ae9d2a9fd2203e (diff)
downloadrust-d804b74c6cd65549c826d2207c4bdaffdd9bf30d.tar.gz
rust-d804b74c6cd65549c826d2207c4bdaffdd9bf30d.zip
Rollup merge of #114549 - chenyukang:yukang-review-resolve-part, r=petrochenkov
Style fix and refactor on resolve diagnostics

- coding style
- refactor api of `span_look_ahead`
Diffstat (limited to 'compiler/rustc_span/src')
-rw-r--r--compiler/rustc_span/src/source_map.rs15
1 files changed, 6 insertions, 9 deletions
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs
index 86716da1712..983b2ab04a4 100644
--- a/compiler/rustc_span/src/source_map.rs
+++ b/compiler/rustc_span/src/source_map.rs
@@ -973,24 +973,21 @@ impl SourceMap {
         Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt(), None)
     }
 
-    /// Returns a new span to check next none-whitespace character or some specified expected character
-    /// If `expect` is none, the first span of non-whitespace character is returned.
-    /// If `expect` presented, the first span of the character `expect` is returned
-    /// Otherwise, the span reached to limit is returned.
-    pub fn span_look_ahead(&self, span: Span, expect: Option<&str>, limit: Option<usize>) -> Span {
+    /// Check whether span is followed by some specified expected string in limit scope
+    pub fn span_look_ahead(&self, span: Span, expect: &str, limit: Option<usize>) -> Option<Span> {
         let mut sp = span;
         for _ in 0..limit.unwrap_or(100_usize) {
             sp = self.next_point(sp);
             if let Ok(ref snippet) = self.span_to_snippet(sp) {
-                if expect.is_some_and(|es| snippet == es) {
-                    break;
+                if snippet == expect {
+                    return Some(sp);
                 }
-                if expect.is_none() && snippet.chars().any(|c| !c.is_whitespace()) {
+                if snippet.chars().any(|c| !c.is_whitespace()) {
                     break;
                 }
             }
         }
-        sp
+        None
     }
 
     /// Finds the width of the character, either before or after the end of provided span,