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:
Ralf Jung 2020-05-17 16:24:27 +02:00 committed by GitHub
commit 65833dcd3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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| {
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()
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");
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