In AssocOp::AssignOp
, use BinOpKind
instead of BinOpToken
`AssocOp::AssignOp` contains a `BinOpToken`. `ExprKind::AssignOp` contains a `BinOpKind`. Given that `AssocOp` is basically a cut-down version of `ExprKind`, it makes sense to make `AssocOp` more like `ExprKind`. Especially given that `AssocOp` and `BinOpKind` use semantic operation names (e.g. `Mul`, `Div`), but `BinOpToken` uses syntactic names (e.g. `Star`, `Slash`). This results in more concise code, and removes the need for various conversions. (Note that the removed functions `hirbinop2assignop` and `astbinop2assignop` are semantically identical, because `hir::BinOp` is just a synonum for `ast::BinOp`!) The only downside to this is that it allows the possibility of some nonsensical combinations, such as `AssocOp::AssignOp(BinOpKind::Lt)`. But `ExprKind::AssignOp` already has that problem. The problem can be fixed for both types in the future with some effort, by introducing an `AssignOpKind` type.
This commit is contained in:
parent
ac91805f31
commit
a8364f3b2a
4 changed files with 23 additions and 77 deletions
|
@ -313,19 +313,7 @@ impl<'a> Parser<'a> {
|
|||
self.mk_expr(span, binary)
|
||||
}
|
||||
AssocOp::Assign => self.mk_expr(span, ExprKind::Assign(lhs, rhs, cur_op_span)),
|
||||
AssocOp::AssignOp(k) => {
|
||||
let aop = match k {
|
||||
token::Plus => BinOpKind::Add,
|
||||
token::Minus => BinOpKind::Sub,
|
||||
token::Star => BinOpKind::Mul,
|
||||
token::Slash => BinOpKind::Div,
|
||||
token::Percent => BinOpKind::Rem,
|
||||
token::Caret => BinOpKind::BitXor,
|
||||
token::And => BinOpKind::BitAnd,
|
||||
token::Or => BinOpKind::BitOr,
|
||||
token::Shl => BinOpKind::Shl,
|
||||
token::Shr => BinOpKind::Shr,
|
||||
};
|
||||
AssocOp::AssignOp(aop) => {
|
||||
let aopexpr = self.mk_assign_op(source_map::respan(cur_op_span, aop), lhs, rhs);
|
||||
self.mk_expr(span, aopexpr)
|
||||
}
|
||||
|
@ -395,7 +383,7 @@ impl<'a> Parser<'a> {
|
|||
AssocOp::ShiftRight
|
||||
| AssocOp::Greater
|
||||
| AssocOp::GreaterEqual
|
||||
| AssocOp::AssignOp(token::BinOpToken::Shr),
|
||||
| AssocOp::AssignOp(BinOpKind::Shr),
|
||||
),
|
||||
_,
|
||||
) if self.restrictions.contains(Restrictions::CONST_EXPR) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue