Raise precedence of closure that has explicit return type
This commit is contained in:
parent
4df47a09a4
commit
72ac961616
3 changed files with 18 additions and 6 deletions
|
@ -1316,9 +1316,15 @@ impl Expr {
|
|||
}
|
||||
|
||||
pub fn precedence(&self) -> ExprPrecedence {
|
||||
match self.kind {
|
||||
match &self.kind {
|
||||
ExprKind::Closure(closure) => {
|
||||
match closure.fn_decl.output {
|
||||
FnRetTy::Default(_) => ExprPrecedence::Jump,
|
||||
FnRetTy::Ty(_) => ExprPrecedence::Unambiguous,
|
||||
}
|
||||
}
|
||||
|
||||
ExprKind::Break(..)
|
||||
| ExprKind::Closure(..)
|
||||
| ExprKind::Continue(..)
|
||||
| ExprKind::Ret(..)
|
||||
| ExprKind::Yield(..)
|
||||
|
|
|
@ -1696,9 +1696,15 @@ pub struct Expr<'hir> {
|
|||
|
||||
impl Expr<'_> {
|
||||
pub fn precedence(&self) -> ExprPrecedence {
|
||||
match self.kind {
|
||||
match &self.kind {
|
||||
ExprKind::Closure(closure) => {
|
||||
match closure.fn_decl.output {
|
||||
FnRetTy::DefaultReturn(_) => ExprPrecedence::Jump,
|
||||
FnRetTy::Return(_) => ExprPrecedence::Unambiguous,
|
||||
}
|
||||
}
|
||||
|
||||
ExprKind::Break(..)
|
||||
| ExprKind::Closure { .. }
|
||||
| ExprKind::Continue(..)
|
||||
| ExprKind::Ret(..)
|
||||
| ExprKind::Yield(..)
|
||||
|
@ -1741,7 +1747,7 @@ impl Expr<'_> {
|
|||
| ExprKind::Type(..)
|
||||
| ExprKind::Err(_) => ExprPrecedence::Unambiguous,
|
||||
|
||||
ExprKind::DropTemps(ref expr, ..) => expr.precedence(),
|
||||
ExprKind::DropTemps(expr, ..) => expr.precedence(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ static EXPRS: &[&str] = &[
|
|||
"|| return break 2",
|
||||
"return break || 2",
|
||||
// Closures with a return type have especially high precedence.
|
||||
"(|| -> T { x }) + 1", // FIXME: no parenthesis needed.
|
||||
"|| -> T { x } + 1",
|
||||
"(|| { x }) + 1",
|
||||
// These mean different things.
|
||||
"if let _ = true && false {}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue