summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_span/src/source_map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_span/src/source_map.rs')
-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 86716da17..983b2ab04 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,