-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
clippy fix: non_canonical_clone_impl #150649
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
base: main
Are you sure you want to change the base?
Conversation
| impl const Clone for Infallible { | ||
| fn clone(&self) -> Infallible { | ||
| match *self {} | ||
| *self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, it's not really obvious to me that this is better for all these types.
Like here having the match emphasizes that this is unreachable better than just *self does, to me -- in MIR it's the difference between _0 = copy *_1; Return and Unreachable, for example.
And for phantomdata just being _0 = PhantomData; is more obviously address-uncaring than _0 = copy *_1; is.
Do you disagree, and think these are better? Or were you just doing what clippy said?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, it's not really obvious to me that this is better for all these types.
That is fair (and I don't necessarily disagree), but perhaps the wrong way to view this change.
My goal is to enable a broader set of clippy lints for the compiler, specifically all of clippy::suspicious. This would have prevented bugs like #146940.
But in order to get there, all the positives need to be dealt with in some way. The possibilities for that are:
- a simple code change (like this PR proposes)
- a change to the lint category (like multiple_bound_locations lint should not be in suspicious category rust-clippy#15736)
- a change to the lint behavior (empty_loop triggers on function prototypes in core rust-clippy#15200, crate_in_macro_def lints on a macro use rust-clippy#15620)
- an allow/expect annotation.
Like here having the match emphasizes that this is unreachable better than just
*selfdoes, to me -- in MIR it's the difference between_0 = copy *_1; ReturnandUnreachable, for example.
My thinking was that the argument being Infallible is enough. If it is important to emphasize this, then perhaps unreachable!() would be the better implementation?
I'm intrigued about the MIR implications, but I must confess knowing almost nothing about MIR. If it is important, can you explain why?
And for phantomdata just being
_0 = PhantomData;is more obviously address-uncaring than_0 = copy *_1;is.
Again, I'm intrigued, but I'm not sure what you're getting at here, besides that you think this decreases the quality of the MIR.
Do you disagree, and think these are better?
I think that these changes are largely neutral by themselves, but they are a small step towards an end goal which does have positive value. I'm happy to discuss alternative ways of dealing with these.
Or were you just doing what clippy said?
I hope I have addressed this.
Fixes: