From 5b6a4ede42bce2b8faaaa6497959713020e086e2 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 11 Jun 2020 19:36:03 -0400 Subject: [PATCH] Don't `unwrap` on `Span.join`. 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. --- codegen/src/parser.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/codegen/src/parser.rs b/codegen/src/parser.rs index 7f0c7ea..bea69f9 100644 --- a/codegen/src/parser.rs +++ b/codegen/src/parser.rs @@ -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()) } } @@ -207,7 +206,9 @@ impl Parse for Case { pattern.validate()?; input.parse::]>()?; 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 }) }