Skip to content

Commit

Permalink
Don't unwrap on Span.join.
Browse files Browse the repository at this point in the history
The method `Span.join` will return `None` if the start and end `Span`s
are from different files. This is currently difficult to observe in
practice due to rust-lang/rust#43081, which causes span information
(including file information) to be lost in many cases.

However, PR rust-lang/rust#73084 will cause `Spans` to be properly
preserved in many more cases. This will cause `rocket` to stop
compiling, as this code will end up getting hit with spans from
different files (one from rocket, and one from the `result` ident
defined in the `pear_try!` macro.
  • Loading branch information
Aaron1011 authored and SergioBenitez committed Jun 12, 2020
1 parent a4c5b1d commit 5b6a4ed
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions codegen/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ impl syn::parse::Parse for CallPattern {

impl Spanned for CallPattern {
fn span(&self) -> Span {
match self.name {
Some(ref name) => name.span().unstable().join(self.expr.span()).unwrap(),
None => self.expr.span()
}
self.name.as_ref()
.and_then(|name| name.span().unstable().join(self.expr.span()))
.unwrap_or_else(|| self.expr.span())
}
}

Expand Down Expand Up @@ -207,7 +206,9 @@ impl Parse for Case {
pattern.validate()?;
input.parse::<Token![=>]>()?;
let expr: syn::Expr = input.parse()?;
let span = case_span_start.join(input.cursor().span().unstable()).unwrap();
let span = case_span_start
.join(input.cursor().span().unstable())
.unwrap_or(case_span_start);

Ok(Case { pattern, expr, span })
}
Expand Down

0 comments on commit 5b6a4ed

Please sign in to comment.