rust/compiler/rustc_parse/src/parser
Nicholas Nethercote ddcb370bc6 Tighten up assignment operator representations.
In the AST, currently we use `BinOpKind` within `ExprKind::AssignOp` and
`AssocOp::AssignOp`, even though this allows some nonsensical
combinations. E.g. there is no `&&=` operator. Likewise for HIR and
THIR.

This commit introduces `AssignOpKind` which only includes the ten
assignable operators, and uses it in `ExprKind::AssignOp` and
`AssocOp::AssignOp`. (And does similar things for `hir::ExprKind` and
`thir::ExprKind`.) This avoids the possibility of nonsensical
combinations, as seen by the removal of the `bug!` case in
`lang_item_for_binop`.

The commit is mostly plumbing, including:
- Adds an `impl From<AssignOpKind> for BinOpKind` (AST) and `impl
  From<AssignOp> for BinOp` (MIR/THIR).
- `BinOpCategory` can now be created from both `BinOpKind` and
  `AssignOpKind`.
- Replaces the `IsAssign` type with `Op`, which has more information and
  a few methods.
- `suggest_swapping_lhs_and_rhs`: moves the condition to the call site,
  it's easier that way.
- `check_expr_inner`: had to factor out some code into a separate
  method.

I'm on the fence about whether avoiding the nonsensical combinations is
worth the extra code.
2025-04-03 10:23:03 +11:00
..
mut_visit Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
tokenstream update cfg(bootstrap) 2025-01-08 21:26:39 +01:00
attr.rs Provide helpful diagnostics for shebang lookalikes 2025-03-13 19:53:53 +05:30
attr_wrapper.rs Rustfmt 2025-02-08 22:12:13 +00:00
diagnostics.rs Remove now unreachable parse recovery code 2025-03-25 15:15:41 +01:00
expr.rs Tighten up assignment operator representations. 2025-04-03 10:23:03 +11:00
generics.rs Implment #[cfg] and #[cfg_attr] in where clauses 2025-03-01 22:02:46 +08:00
item.rs Remove Token::uninterpolated_span. 2025-04-02 06:21:16 +11:00
mod.rs Remove Token::uninterpolated_span. 2025-04-02 06:21:16 +11:00
nonterminal.rs Remove NtExpr and NtLiteral. 2025-04-02 06:20:35 +11:00
pat.rs Remove NtExpr and NtLiteral. 2025-04-02 06:20:35 +11:00
path.rs Replace ast::TokenKind::BinOp{,Eq} and remove BinOpToken. 2025-03-03 09:26:11 +11:00
stmt.rs Remove now unreachable parse recovery code 2025-03-25 15:15:41 +01:00
tests.rs Move ast::Item::ident into ast::ItemKind. 2025-04-01 14:08:57 +11:00
token_type.rs compiler: Use size_of from the prelude instead of imported 2025-03-07 13:37:04 -08:00
ty.rs Remove Token::uninterpolated_span. 2025-04-02 06:21:16 +11:00