-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement Eq/Hash/Debug etc. for unsized tuples. #43011
Conversation
r? @sfackler |
No RFC is needed, or a feature - trait implementations can't actually have feature gates applied to them. @rfcbot fcp merge |
Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
ping @brson, you're the last checkbox needed here! |
@bors: r+ rollup |
📌 Commit 728d26c has been approved by |
Implement Eq/Hash/Debug etc. for unsized tuples. As I mentioned in [the comment in rust-lang#18469](rust-lang#18469 (comment)), the implementations of `PartialEq`, `Eq`, `PartialOrd`, `Ord`, `Debug`, `Hash` can be generalized to unsized tuples. This is consistent with the `derive` behavior for unsized structs. ```rust #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)] struct MyTuple<X, Y, Z: ?Sized>(X, Y, Z); fn f(x: &MyTuple<i32, i32, [i32]>) { x == x; x < x; println!("{:?}", x); } ``` Questions: - Need an RFC? - Need a feature gate? I don't think it does because the unsized tuple coercion rust-lang#42527 is feature-gated. - I changed `builder.field($name);` into `builder.field(&$name);` in the `Debug` implementation to pass compilation. This won't affect the behavior because `Debug for &'a T` is a mere redirection to `Debug for T`. However, I don't know if it affects code size / performance.
As I mentioned in the comment in #18469, the implementations of
PartialEq
,Eq
,PartialOrd
,Ord
,Debug
,Hash
can be generalized to unsized tuples.This is consistent with the
derive
behavior for unsized structs.Questions:
builder.field($name);
intobuilder.field(&$name);
in theDebug
implementation to pass compilation. This won't affect the behavior becauseDebug for &'a T
is a mere redirection toDebug for T
. However, I don't know if it affects code size / performance.