Skip to content

Commit 67128f1

Browse files
author
Duddino
committed
Improved try_macro_suggestion
1 parent d3f5c27 commit 67128f1

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/librustc_parse/parser/diagnostics.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ impl<'a> Parser<'a> {
10541054
}
10551055
}
10561056

1057-
pub(super) fn try_macro_suggestion(&mut self) -> DiagnosticBuilder<'a> {
1057+
pub(super) fn try_macro_suggestion(&mut self) -> PResult<'a, P<Expr>> {
10581058
let is_try = self.token.is_keyword(kw::Try);
10591059
let is_questionmark = self.look_ahead(1, |t| t == &token::Not); //check for !
10601060
let is_open = self.look_ahead(2, |t| t == &token::OpenDelim(token::Paren)); //check for (
@@ -1082,9 +1082,10 @@ impl<'a> Parser<'a> {
10821082
//if the try! macro is empty, it isn't possible to suggest something using the `?` operator
10831083
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);
10841084
}
1085-
err
1085+
err.emit();
1086+
Ok(self.mk_expr_err(lo.to(hi)))
10861087
} else {
1087-
self.expected_expression_found() // The user isn't trying to invoke the try! macro
1088+
Err(self.expected_expression_found()) // The user isn't trying to invoke the try! macro
10881089
}
10891090
}
10901091

src/librustc_parse/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ impl<'a> Parser<'a> {
10061006
let expr = self.mk_expr(lo.to(self.prev_token.span), ExprKind::Lit(literal), attrs);
10071007
self.maybe_recover_from_bad_qpath(expr, true)
10081008
}
1009-
None => Err(self.try_macro_suggestion()),
1009+
None => self.try_macro_suggestion(),
10101010
}
10111011
}
10121012

0 commit comments

Comments
 (0)