Implied bounds don't work for traits on &Self #47670
Labels
A-trait-system
Area: Trait system
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
If a trait has a bound on &Self, it doesn't seem to work as an implied bound.
For example (also https://gist.github.com/671c7746b96c86f9eb0e39176325157a):
This produces:
It works if the 'where' on
fn compute
is uncommented. Other implicit bounds in the same trait also work (e.g.for<'a> Self: Add<&'a Self>
is fine).This comes up when trying to write generic numeric code. I want to be explicit about using moves/refs to avoid unnecessary clones of things like BigInt, which requires binary operators to have the full set of overloads (i.e.
a+b
,&a+b
,a+&b
,&a+&b
). BigInt and other numeric types support all these, and they work as explicit bounds, but repeating them on every function gets unwieldy quickly.The text was updated successfully, but these errors were encountered: