Unsized tuple coercions by qnighy · Pull Request #42527 · rust-lang/rust (original) (raw)
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.
#[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);
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.