-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
Stable type_eq #2150
Stable type_eq #2150
Conversation
cc @langston-barrett: any immediate soundness concerns come to mind here? |
It's insane, I love it. |
I think all fns should be |
#[allow(clippy::mismatching_type_param_order)] | ||
impl<'a, T: ?Sized> Copy for W<'a, T, T> {} | ||
|
||
let detected = Cell::new(true); | ||
// [].clone() is *specialized* in core. |
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.
Any documentation on this?
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.
Like, anything official/some blog post, forum entry, docstring, ...?
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.
Sanity check here (implied specialization): https://doc.rust-lang.org/stable/std/clone/trait.Clone.html#how-can-i-implement-clone
You can see the specific specialization here: https://doc.rust-lang.org/stable/src/core/slice/mod.rs.html#4656-4686
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.
Can we add those to the code?
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.
Feel free to merge :)
* stable type eq * whoops, wrong section * satiate clippy * remove extraneous comment * explain * bonus inline
* stable type eq * whoops, wrong section * satiate clippy * remove extraneous comment * explain * bonus inline
* stable type eq * whoops, wrong section * satiate clippy * remove extraneous comment * explain * bonus inline
This is right up there with the evilest code I've ever written.
This performs a type equality comparison using Copy/Clone specialisation imported from core. In testing, I found that it is optimized out entirely, i.e.:
Is compiled down to: