1
Fork 0

Rollup merge of #112475 - chenyukang:yukang-fix-112278, r=compiler-errors

Fix issue for module name when surround the struct literal with parentheses

Fixes #112278
This commit is contained in:
Matthias Krüger 2023-06-11 01:57:25 +02:00 committed by GitHub
commit e19a509f8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 113 additions and 9 deletions

View file

@ -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) {