about summary refs log tree commit diff
path: root/compiler/rustc_span/src/source_map.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-06-11 00:35:36 +0000
committerbors <bors@rust-lang.org>2023-06-11 00:35:36 +0000
commit970058e16b307e1cff01e2ddb084d2e8d14ea8be (patch)
tree8d33cb2cd310d8dcd2bc2ddf27891c2f0c848601 /compiler/rustc_span/src/source_map.rs
parentb8a50010de397df570b38fe67bda435b665e2d86 (diff)
parent46b64aaef097cab420311834eb58b5d05ea408a7 (diff)
downloadrust-970058e16b307e1cff01e2ddb084d2e8d14ea8be.tar.gz
rust-970058e16b307e1cff01e2ddb084d2e8d14ea8be.zip
Auto merge of #112512 - matthiaskrgr:rollup-o2jh1jx, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #112475 (Fix issue for module name when surround the struct literal with parentheses)
 - #112477 (Give more helpful progress messages in `Assemble`)
 - #112484 (Fix ntdll linkage issues on Windows UWP platforms)
 - #112492 (Migrate GUI colors test to original CSS color format)
 - #112493 (iat selection: normalize self ty & completely erase bound vars)
 - #112497 (abs_sub: fix typo 0[-:][+.]0)
 - #112498 (Update links to Rust Reference in diagnostic)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_span/src/source_map.rs')
-rw-r--r--compiler/rustc_span/src/source_map.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs
index 1824510a974..c53fe084c4d 100644
--- a/compiler/rustc_span/src/source_map.rs
+++ b/compiler/rustc_span/src/source_map.rs
@@ -744,6 +744,21 @@ impl SourceMap {
         })
     }
 
+    /// Extends the given `Span` to previous character while the previous character matches the predicate
+    pub fn span_extend_prev_while(
+        &self,
+        span: Span,
+        f: impl Fn(char) -> bool,
+    ) -> Result<Span, SpanSnippetError> {
+        self.span_to_source(span, |s, start, _end| {
+            let n = s[..start]
+                .char_indices()
+                .rfind(|&(_, c)| !f(c))
+                .map_or(start, |(i, _)| start - i - 1);
+            Ok(span.with_lo(span.lo() - BytePos(n as u32)))
+        })
+    }
+
     /// Extends the given `Span` to just before the next occurrence of `c`.
     pub fn span_extend_to_next_char(&self, sp: Span, c: char, accept_newlines: bool) -> Span {
         if let Ok(next_source) = self.span_to_next_source(sp) {