Add method support to overload! macro - #11
Merged
Conversation
teor2345
requested changes
Aug 13, 2026
teor2345
left a comment
Collaborator
There was a problem hiding this comment.
The splat attribute has been renamed to avoid clashes with user-provided names on stable. This is caused by a compiler name lookup bug that hasn't been fixed yet.
If you download the latest nightly build, it should have the new name.
Co-authored-by: teor <teor@riseup.net>
teor2345
reviewed
Aug 13, 2026
teor2345
left a comment
Collaborator
There was a problem hiding this comment.
Clippy has style suggestions, I'll apply them now
Co-authored-by: teor <teor@riseup.net>
teor2345
previously approved these changes
Aug 13, 2026
teor2345
left a comment
Collaborator
There was a problem hiding this comment.
Thanks! I think this is good enough to publish as an experiment. I'll get to work on that now.
teor2345
reviewed
Aug 13, 2026
Co-authored-by: teor <teor@riseup.net>
teor2345
reviewed
Aug 13, 2026
Co-authored-by: teor <teor@riseup.net>
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.
Add method support to overload! macro
Extends the overload! macro to support methods (functions taking
&self, &mut self, or owned self), not just free functions.
Usage:
Design problem encountered and resolved
Initially the macro pasted method bodies verbatim into a generated
callmethod on the argument tuple type, the same pattern used for free functions. This breaks for methods, because insidecall,selfrefers to the argument tuple, not the receiver , but the user's original body (e.g.self.value += x) expectsselfto mean the receiver. Rust doesn't allow rebinding the identifierselfto anything other than a function's own receiver, so this couldn't be fixed by rearranging code insidecall.Fix: generate a hidden method directly on the receiver type per overload, with the user's original body pasted in completely
unmodified (so
selfthere genuinely is the receiver), and havecalljust forward to it:This works uniformly across all three receiver kinds (&self, &mut self, self) since the hidden method just uses whatever receiver form the overload declared, and the trait's
callsignature is generated to match, using a genericRin the trait declaration and the concrete type in each impl.All overloads within a single overload! block must use the same receiver kind; mixing e.g. &self and &mut self across overloads of the same name produces a clear panic.
Tested cases
returninside a method bodyIncludes 6 new example binaries with assert_eq! checks, added to the
CI runner list alongside the existing 9.