diff options
| author | yukang <moorekang@gmail.com> | 2023-08-06 22:28:14 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2023-08-06 22:44:11 +0800 |
| commit | eb0fcc5ad1f8e622c942334658ae9d2a9fd2203e (patch) | |
| tree | 6115d2f003ee55ccd83e3e8fba91618424b2334e /compiler/rustc_span/src/source_map.rs | |
| parent | 026c4b6a65891203d25ac403d67a924c9329b962 (diff) | |
| download | rust-eb0fcc5ad1f8e622c942334658ae9d2a9fd2203e.tar.gz rust-eb0fcc5ad1f8e622c942334658ae9d2a9fd2203e.zip | |
refactor on span_look_ahead
Diffstat (limited to 'compiler/rustc_span/src/source_map.rs')
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 15 |
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, |
