Skip to content

Operator overloading only considers the method name, not which trait is implemented #12402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SiegeLord opened this issue Feb 19, 2014 · 2 comments · Fixed by #12493
Closed

Comments

@SiegeLord
Copy link
Contributor

Currently this code compiles, but it shouldn't:

trait MyMul<RHS, Res>
{
    fn mul(&self, rhs: &RHS) -> Res;
}

fn foo<T: MyMul<f64, f64>>(a: &T, b: f64) -> f64
{
    a * b
}

fn main()
{

}
@alexcrichton
Copy link
Member

Oh dear that's bad, nominating.

@eddyb
Copy link
Member

eddyb commented Feb 23, 2014

Even though we only use the lang item as a potential trait for overloadable expressions, push_bound_candidates in typeck::check::method will also consider traits in generic bounds.

It doesn't seem hard to duplicate the functionality of typeck::check::method::lookup to only consider the relevant operator overload trait - also see push_extension_candidates.

@bors bors closed this as completed in c24946e Feb 25, 2014
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022

Unverified

The signature in this commit could not be verified. Someone may be trying to trick you.
minor: Freshen up goto feature docs

Fixes rust-lang/rust-analyzer#2541
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 7, 2024
Pointers cannot be converted to integers at compile time

Fix rust-lang#12402

changelog: [`transmutes_expressible_as_ptr_casts`]: do not suggest invalid const casts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants