Repository navigation
feat(ts): translate std::ops operator methods on primitives called by path - #489
Merged
Merged
Conversation
Quest-Claim: d597a5ad6d0afff3
… path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 3, 2026 05:36
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
kixelated
enabled auto-merge
November 3, 2026 06:00
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 3, 2026
|
quest land watch: the merge queue removed this pull request at b6f0c0f because it conflicts with The land fixer works on it in the background, and the watcher re-enqueues it at the back of the queue once it is fixed or judged flaky, or hands it back here with what it needs. (written by quest land watch) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a primitive, rustc lowers an operator to a MIR operation, but a
std::opsmethod called by its path, such as<u8 as AddAssign>::add_assign(&mut n, 1), stays a call to the trait method. The binary operators already mapped there, but every*Assignmethod,Neg::neg, andNot::notof an integer, a float, or aboolwas an "unsupported call", written or as a function value.Approach
Reuse the operators' own lowering, so each call means what its operator does:
call.rs: the*Assignmapping that wrote aWrapping's or aSaturating's result through the&mutalso takes a primitive, computing the result withnum::binary, as+=does. A right side by reference (AddAssign<&u8>) and a shift amount of another type come along.library.rs:NegandNotof a primitive, or a reference to one, lower withnum::unary, as-xand!xdo.A function value of one translates as its call already (#470), so passing it to a generic body or coercing it to a
fnpointer needs nothing more.New fixture
lang/operators, differential against native wasm32: every operator trait's method, its*Assignform, and its by-reference impls, on every integer width,f64,f32, andbool, each written as a call, passed as a function value, and through afnpointer. The caller sweeps each width's edges (MIN / -1, division by zero, shifts at, past, and far past the width, negativei16amounts, 128-bit values past 2^64) and floats' signed zeros, subnormals, infinities, and NaN: 39177 cases, 8298 of them panics. A mutation mappingDivAssignto%fails 1980 of them.Consumer: crates that pass an operator method as a value or call it generically, as
num-traits-style code and folds such asfold(0, Add::add)do; moq reaches them through its dependencies.Impact
Alternatives
*Assigntakes&mut self, whichfrom_mirrefuses for std, and each call would emit a function per impl and instance. The mapping reuses the exact lowering the operator form gets, in about 15 lines.Follow-ups
None.
Review
mechanical fix by quest land watch:
merged main at 7e7af66f6f58c6daebd363a2ec969cac1349ad5e with the quest merge driver(head 0ff7cc7)Codex
gpt-6.1-sol, medium effort, viaquest review, on headceb9eed0477fa6e707b93a0f5ab30559338528e4: no findings.b6f0c0f9136ebcd2989f5fa4a3f2723693931465adds only conflict-free merges oforigin/main.🤖 Generated with Claude Code