Rollup merge of #72261 - csmoe:issue-72095, r=estebank
Break out early on empty span when generate_fn_span Closes #72095 r? @oli-obk cc @estebank @tmandry
This commit is contained in:
commit
65833dcd3d
1 changed files with 17 additions and 8 deletions
|
@ -910,14 +910,23 @@ impl SourceMap {
|
|||
|
||||
pub fn generate_fn_name_span(&self, span: Span) -> Option<Span> {
|
||||
let prev_span = self.span_extend_to_prev_str(span, "fn", true);
|
||||
self.span_to_snippet(prev_span)
|
||||
.map(|snippet| {
|
||||
if let Ok(snippet) = self.span_to_snippet(prev_span) {
|
||||
debug!(
|
||||
"generate_fn_name_span: span={:?}, prev_span={:?}, snippet={:?}",
|
||||
span, prev_span, snippet
|
||||
);
|
||||
|
||||
if snippet.is_empty() {
|
||||
return None;
|
||||
};
|
||||
|
||||
let len = snippet
|
||||
.find(|c: char| !c.is_alphanumeric() && c != '_')
|
||||
.expect("no label after fn");
|
||||
prev_span.with_hi(BytePos(prev_span.lo().0 + len as u32))
|
||||
})
|
||||
.ok()
|
||||
Some(prev_span.with_hi(BytePos(prev_span.lo().0 + len as u32)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Takes the span of a type parameter in a function signature and try to generate a span for
|
||||
|
|
Loading…
Add table
Reference in a new issue