1
Fork 0

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:
Scott McMurray 2022-03-25 23:43:54 -07:00
parent 2c858a7c3f
commit e094ee5f10
23 changed files with 236 additions and 3 deletions

View file

@ -1275,6 +1275,7 @@ impl Expr {
ExprKind::Paren(..) => ExprPrecedence::Paren,
ExprKind::Try(..) => ExprPrecedence::Try,
ExprKind::Yield(..) => ExprPrecedence::Yield,
ExprKind::Yeet(..) => ExprPrecedence::Yeet,
ExprKind::Err => ExprPrecedence::Err,
}
}
@ -1462,6 +1463,10 @@ pub enum ExprKind {
/// A `yield`, with an optional value to be yielded.
Yield(Option<P<Expr>>),
/// A `do yeet` (aka `throw`/`fail`/`bail`/`raise`/whatever),
/// with an optional value to be returned.
Yeet(Option<P<Expr>>),
/// Placeholder for an expression that wasn't syntactically well formed in some way.
Err,
}

View file

@ -1394,6 +1394,9 @@ pub fn noop_visit_expr<T: MutVisitor>(
ExprKind::Ret(expr) => {
visit_opt(expr, |expr| vis.visit_expr(expr));
}
ExprKind::Yeet(expr) => {
visit_opt(expr, |expr| vis.visit_expr(expr));
}
ExprKind::InlineAsm(asm) => vis.visit_inline_asm(asm),
ExprKind::MacCall(mac) => vis.visit_mac_call(mac),
ExprKind::Struct(se) => {

View file

@ -247,6 +247,7 @@ pub enum ExprPrecedence {
Continue,
Ret,
Yield,
Yeet,
Range,
@ -299,7 +300,8 @@ impl ExprPrecedence {
ExprPrecedence::Break |
ExprPrecedence::Continue |
ExprPrecedence::Ret |
ExprPrecedence::Yield => PREC_JUMP,
ExprPrecedence::Yield |
ExprPrecedence::Yeet => PREC_JUMP,
// `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
// parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence

View file

@ -893,6 +893,9 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
ExprKind::Ret(ref optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression);
}
ExprKind::Yeet(ref optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression);
}
ExprKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
ExprKind::Paren(ref subexpression) => visitor.visit_expr(subexpression),
ExprKind::InlineAsm(ref asm) => walk_inline_asm(visitor, asm),