-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Clarify and document operator overloading trait matching rules etc #10337
Comments
Nominating for 1.0. |
Accepted for 1.0, P-backcompat-lang. |
It occurs to me that if we make these changes we could avoid the need to know the type of |
See #8280 for an example where this would help. |
visiting for triage. Nothing to add here |
Given https://github.com/rust-lang/rfcs/blob/master/text/0439-cmp-ops-reform.md and the fact that operators are no longer taking by reference, I believe this issue is resolved, so closing. |
Order auto-imports by relevance Fixes rust-lang#10337. Basically we sort the imports according to how "far away" the imported item is from where we want to import it to. This change makes it so that imports from the current crate are sorted before any third-party crates. Additionally, we make an exception for builtin crates (`std`, `core`, etc.) so that they are sorted before any third-party crates. There are probably other heuristics that should be added to improve the experience (such as preferring imports that are common elsewhere in the same crate, and ranking crates depending on the dependency graph). However, I think this is a first good step. PS. This is my first time contributing here, so please be gentle if I have missed something obvious :-)
Fix: Some suggestions generated by the option_if_let_else lint did not compile This addresses a bug in Clippy where the fix suggestend by the `option_if_let_else` lint would not compile for `Result`s which have an impure expression in the `else` branch. --- changelog: [`option_if_let_else`]: Fixed incorrect suggestion for `Result`s [rust-lang#10337](rust-lang/rust-clippy#10337) <!-- changelog_checked --> Fixes rust-lang#10335.
Our current trait matching rules for operator overloading are somewhat ad-hoc. I've got a branch which implements a more straightforward set of rules, which I think is what we want for 1.0 going forward. Part of completing this bug will be updating the docs.
The rules I've in mind can be summarized as:
Given an expression
l op r
whereop
is a binary operator andl : L
andr : R
:impl Op<R,T> for L
. Note that there is no attempt to autoderefl
and so forth.&l
and&r
to the trait method (as is reflected in the&self
type etc).l op r
isT
.The text was updated successfully, but these errors were encountered: