Skip to content

Commit

Permalink
Improved try_macro_suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed Apr 17, 2020
1 parent d3f5c27 commit 67128f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/librustc_parse/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ impl<'a> Parser<'a> {
}
}

pub(super) fn try_macro_suggestion(&mut self) -> DiagnosticBuilder<'a> {
pub(super) fn try_macro_suggestion(&mut self) -> PResult<'a, P<Expr>> {
let is_try = self.token.is_keyword(kw::Try);
let is_questionmark = self.look_ahead(1, |t| t == &token::Not); //check for !
let is_open = self.look_ahead(2, |t| t == &token::OpenDelim(token::Paren)); //check for (
Expand Down Expand Up @@ -1082,9 +1082,10 @@ impl<'a> Parser<'a> {
//if the try! macro is empty, it isn't possible to suggest something using the `?` operator
err.span_suggestion(lo.shrink_to_lo(), "you can still access the deprecated `try!()` macro using the \"raw identifier\" syntax", "r#".to_string(), Applicability::MachineApplicable);
}
err
err.emit();
Ok(self.mk_expr_err(lo.to(hi)))
} else {
self.expected_expression_found() // The user isn't trying to invoke the try! macro
Err(self.expected_expression_found()) // The user isn't trying to invoke the try! macro
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ impl<'a> Parser<'a> {
let expr = self.mk_expr(lo.to(self.prev_token.span), ExprKind::Lit(literal), attrs);
self.maybe_recover_from_bad_qpath(expr, true)
}
None => Err(self.try_macro_suggestion()),
None => self.try_macro_suggestion(),
}
}

Expand Down

0 comments on commit 67128f1

Please sign in to comment.