Uh oh!
There was an error while loading. Please reload this page.
Tighten up assignment operator representations. - #138017
Conversation
rustbot
commented
Mar 4, 2025
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @vakaras Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
nnethercote
commented
Mar 4, 2025
@spastorino: I'm not 100% certain we should do this. It does make the representation better in the sense that it makes it impossible to express some nonsensical combinations, such as I suggest starting with the third commit, which is the most important one. If you are happy with how it looks, then look at the first and second commits, which are just some preliminary refactorings. |
bors
commented
Mar 15, 2025
☔ The latest upstream changes (presumably #138464) made this pull request unmergeable. Please resolve the merge conflicts. |
74227e1 to
7d1e5d0Comparennethercote
commented
Mar 16, 2025
I rebased. |
bors
commented
Mar 19, 2025
☔ The latest upstream changes (presumably #138653) made this pull request unmergeable. Please resolve the merge conflicts. |
7d1e5d0 to
e43b280Comparennethercote
commented
Mar 19, 2025
@spastorino is busy and asked for a different reviewer, so let's try: r? @estebank |
nnethercote
commented
Mar 19, 2025
From above, for the reviewer:
|
bors
commented
Mar 21, 2025
☔ The latest upstream changes (presumably #138747) made this pull request unmergeable. Please resolve the merge conflicts. |
| let by_ref_binop = !op.node.is_by_value(); | ||
| if is_assign == IsAssign::Yes || by_ref_binop { | ||
| let by_ref_binop = !op.is_by_value(); | ||
| if op.is_assign() || by_ref_binop { |
There was a problem hiding this comment.
Not sure if I prefer is_assign or just an explicit matches! checking the type. Whatever you prefer :).
There was a problem hiding this comment.
Ok, I switched to matches!/if let.
spastorino
commented
Apr 2, 2025
@nnethercote r=me after rebasing. I've made a minor comment but do whatever you feel is better :). |
e43b280 to
98b46f5CompareFirst, move the `lang_item_for_op` call from the top of
`lookup_op_method`'s body to its callsites. It makes those callsites a
little more verbose, but also means `lookup_op_method` no longer cares
whether it's handling a binop or unop. This lets us remove `Op` and
split `lang_item_for_op` into `lang_item_for_{bin,un}op`, which is a
little simpler.
This change is a prerequisite for adding the `ast::AssignOpKind` type in
a subsequent commit.Because it's nice to avoid passing in unnecessary data.
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.
98b46f5 to
ddcb370Comparennethercote
commented
Apr 2, 2025
I rebased. @bors r=spastorino |
bors
commented
Apr 2, 2025
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#138017 (Tighten up assignment operator representations.) - rust-lang#138462 (Dedup `&mut *` reborrow suggestion in loops) - rust-lang#138610 (impl !PartialOrd for HirId) - rust-lang#138767 (Allow boolean literals in `check-cfg`) - rust-lang#139068 (io: Avoid marking some bytes as uninit) - rust-lang#139255 (Remove unused variables generated in merged doctests) - rust-lang#139270 (Add a mailmap entry for myself) - rust-lang#139303 (Put Noratrieb on vacation) - rust-lang#139312 (add Marco Ieni to mailmap) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#138017 - nnethercote:tighten-assignment-op, r=spastorino Tighten up assignment operator representations. This is step 3 of [MCP 831](rust-lang/compiler-team#831). r? `@spastorino`
This is step 3 of MCP 831.
r? @spastorino