-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Put impls of primitives near the traits they implement in std #12925
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
Comments
This also lets us delete some modules that are nothing but impls. |
I started working on this |
Turns out I read the description wrong and spend the whole day refactoring primitive impls away from their traits. @brson , I don't suppose this could still be useful: https://github.com/Kimundi/rust/compare/move_impls?expand=1 ? |
@Kimundi That is indeed the opposite of what I wanted :( |
If this is still relevant (it seems to be) and @Kimundi stopped working on this I could work on this. |
@malu Sorry, should've made it clear that I'm not working on it any more. |
I've always found it surprising that implementations for independent types are bundled in the module where the interface is defined. Is refactorability the only reason for this? |
It's very convenient because you can usually reuse a lot of code with a macro. It's not relevant to the user-facing API at all. |
You also avoid ending up with blank modules like this: http://static.rust-lang.org/doc/master/std/unit/index.html |
@kud1ing I guess it's also nice to have impls for standard types near trait def because it like saying "Look, this trait is actually useful and can be fulfilled easily by these standard types." |
@malu Still working on it? |
@tbu- Yes. Sorry, the past day were pretty busy, I hope I can do a pull request this weekend after rebasing. |
Okay, something went horribly wrong during rebasing. I don't think I'm going to be able to fix this anytime soon. :( |
@malu sorry to hear that :( Any chance you can upload your work pre-rebase so that people working on this change can take over based on your changes (or at least use them as reference) ? |
You can use git reflog to "reset" to a previous branch state, restoring you back to how it was before. |
Is this still worth working on? |
I could work on this. I think it's worth it: (well, I started working on this, let me know if someone else is working on this too) |
This is an attempt of fixing #12925. This PR moves almost all trait implementations for primitive types ((), bool, char, i*, u*, f*) near trait definitions. Only Float trait implementations weren't moved because they heavily rely on constants defined in f32.rs and f64.rs. Some trait implementations had cfg(not(test)) attribute. I suspect it's because of issue 2912. Still, someone who knows the problem better should probably check this code. Closes #12925
In
std
there are modules for the primitive types and these modules tend to contain the impls for several of the most 'core' Rust traits. I would rather these live in the module that declares the trait.std
is going to continue to be refactored, and the crates these traits live in may change. Having the primitive impls in one place makes that refactoring easier.The text was updated successfully, but these errors were encountered: