Skip to content
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

RFC: Define binary operator traits using associated fns, not methods. #6299

Closed
nikomatsakis opened this issue May 7, 2013 · 2 comments
Closed

Comments

@nikomatsakis
Copy link
Contributor

There has been a constant stream of confusion relating to the interaction between auto-deref and various overloaded operators, particularly Eq (e.g., #6257). I think we ought to define the binary operator traits using an associated fn, not a method. This would side-step any issues around autoderef, and also helps to make the method resolution clearer.

For example, Eq would be define as follows:

trait Eq {
    fn eq(a: &Self, b: &Self);
}

meaning that x==y would be expanded to:

Eq::eq(&x, &y)

The same would apply to other binary operator traits.

@nikomatsakis
Copy link
Contributor Author

nominating for backwards compat milestone

@nikomatsakis
Copy link
Contributor Author

I think I withdraw this idea. We can just add functions if we think that'll be useful for macro authors.

flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 20, 2020
do not trigger map_clone in the case of &mut

fixes rust-lang#6299
changelog: do not trigger map_clone in the case of &mut
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

No branches or pull requests

1 participant