Add do yeet expressions to allow experimentation in nightly
Using an obviously-placeholder syntax. An RFC would still be needed before this could have any chance at stabilization, and it might be removed at any point. But I'd really like to have it in nightly at least to ensure it works well with try_trait_v2, especially as we refactor the traits.
This commit is contained in:
@@ -1374,6 +1374,8 @@ impl<'a> Parser<'a> {
|
||||
self.parse_break_expr(attrs)
|
||||
} else if self.eat_keyword(kw::Yield) {
|
||||
self.parse_yield_expr(attrs)
|
||||
} else if self.is_do_yeet() {
|
||||
self.parse_yeet_expr(attrs)
|
||||
} else if self.eat_keyword(kw::Let) {
|
||||
self.parse_let_expr(attrs)
|
||||
} else if self.eat_keyword(kw::Underscore) {
|
||||
@@ -1605,6 +1607,21 @@ impl<'a> Parser<'a> {
|
||||
self.maybe_recover_from_bad_qpath(expr, true)
|
||||
}
|
||||
|
||||
/// Parse `"do" "yeet" expr?`.
|
||||
fn parse_yeet_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
|
||||
let lo = self.token.span;
|
||||
|
||||
self.bump(); // `do`
|
||||
self.bump(); // `yeet`
|
||||
|
||||
let kind = ExprKind::Yeet(self.parse_expr_opt()?);
|
||||
|
||||
let span = lo.to(self.prev_token.span);
|
||||
self.sess.gated_spans.gate(sym::yeet_expr, span);
|
||||
let expr = self.mk_expr(span, kind, attrs);
|
||||
self.maybe_recover_from_bad_qpath(expr, true)
|
||||
}
|
||||
|
||||
/// Parse `"break" (('label (:? expr)?) | expr?)` with `"break"` token already eaten.
|
||||
/// If the label is followed immediately by a `:` token, the label and `:` are
|
||||
/// parsed as part of the expression (i.e. a labeled loop). The language team has
|
||||
@@ -2676,6 +2693,10 @@ impl<'a> Parser<'a> {
|
||||
&& !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL)
|
||||
}
|
||||
|
||||
fn is_do_yeet(&self) -> bool {
|
||||
self.token.is_keyword(kw::Do) && self.is_keyword_ahead(1, &[kw::Yeet])
|
||||
}
|
||||
|
||||
fn is_try_block(&self) -> bool {
|
||||
self.token.is_keyword(kw::Try)
|
||||
&& self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Brace))
|
||||
|
||||
Reference in New Issue
Block a user