Mark derived StructuralEq as automatically derived.

This commit is contained in:
Camille GILLOT 2022-10-15 14:33:20 +00:00
parent 9b0a099dfc
commit 16e22e143d
3 changed files with 70 additions and 29 deletions

View File

@ -131,6 +131,8 @@ fn inject_impl_of_structural_trait(
// Create generics param list for where clauses and impl headers
let mut generics = generics.clone();
let ctxt = span.ctxt();
// Create the type of `self`.
//
// in addition, remove defaults from generic params (impls cannot have them).
@ -138,16 +140,18 @@ fn inject_impl_of_structural_trait(
.params
.iter_mut()
.map(|param| match &mut param.kind {
ast::GenericParamKind::Lifetime => {
ast::GenericArg::Lifetime(cx.lifetime(span, param.ident))
}
ast::GenericParamKind::Lifetime => ast::GenericArg::Lifetime(
cx.lifetime(param.ident.span.with_ctxt(ctxt), param.ident),
),
ast::GenericParamKind::Type { default } => {
*default = None;
ast::GenericArg::Type(cx.ty_ident(span, param.ident))
ast::GenericArg::Type(cx.ty_ident(param.ident.span.with_ctxt(ctxt), param.ident))
}
ast::GenericParamKind::Const { ty: _, kw_span: _, default } => {
*default = None;
ast::GenericArg::Const(cx.const_ident(span, param.ident))
ast::GenericArg::Const(
cx.const_ident(param.ident.span.with_ctxt(ctxt), param.ident),
)
}
})
.collect();
@ -174,6 +178,8 @@ fn inject_impl_of_structural_trait(
})
.cloned(),
);
// Mark as `automatically_derived` to avoid some silly lints.
attrs.push(cx.attribute(cx.meta_word(span, sym::automatically_derived)));
let newitem = cx.item(
span,

View File

@ -46,12 +46,14 @@ impl ::core::default::Default for Empty {
impl ::core::hash::Hash for Empty {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Empty { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Empty {
#[inline]
fn eq(&self, other: &Empty) -> bool { true }
}
#[automatically_derived]
impl ::core::marker::StructuralEq for Empty { }
#[automatically_derived]
impl ::core::cmp::Eq for Empty {
@ -115,6 +117,7 @@ impl ::core::hash::Hash for Point {
::core::hash::Hash::hash(&self.y, state)
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Point { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Point {
@ -123,6 +126,7 @@ impl ::core::cmp::PartialEq for Point {
self.x == other.x && self.y == other.y
}
}
#[automatically_derived]
impl ::core::marker::StructuralEq for Point { }
#[automatically_derived]
impl ::core::cmp::Eq for Point {
@ -225,6 +229,7 @@ impl ::core::hash::Hash for Big {
::core::hash::Hash::hash(&self.b8, state)
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Big { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Big {
@ -236,6 +241,7 @@ impl ::core::cmp::PartialEq for Big {
self.b8 == other.b8
}
}
#[automatically_derived]
impl ::core::marker::StructuralEq for Big { }
#[automatically_derived]
impl ::core::cmp::Eq for Big {
@ -345,12 +351,14 @@ impl ::core::hash::Hash for Unsized {
::core::hash::Hash::hash(&self.0, state)
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Unsized { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Unsized {
#[inline]
fn eq(&self, other: &Unsized) -> bool { self.0 == other.0 }
}
#[automatically_derived]
impl ::core::marker::StructuralEq for Unsized { }
#[automatically_derived]
impl ::core::cmp::Eq for Unsized {
@ -410,12 +418,14 @@ impl ::core::hash::Hash for PackedCopy {
::core::hash::Hash::hash(&{ self.0 }, state)
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for PackedCopy { }
#[automatically_derived]
impl ::core::cmp::PartialEq for PackedCopy {
#[inline]
fn eq(&self, other: &PackedCopy) -> bool { { self.0 } == { other.0 } }
}
#[automatically_derived]
impl ::core::marker::StructuralEq for PackedCopy { }
#[automatically_derived]
impl ::core::cmp::Eq for PackedCopy {
@ -479,6 +489,7 @@ impl ::core::hash::Hash for PackedNonCopy {
::core::hash::Hash::hash(__self_0_0, state)
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for PackedNonCopy { }
#[automatically_derived]
impl ::core::cmp::PartialEq for PackedNonCopy {
@ -489,6 +500,7 @@ impl ::core::cmp::PartialEq for PackedNonCopy {
*__self_0_0 == *__self_1_0
}
}
#[automatically_derived]
impl ::core::marker::StructuralEq for PackedNonCopy { }
#[automatically_derived]
impl ::core::cmp::Eq for PackedNonCopy {
@ -540,6 +552,7 @@ impl ::core::hash::Hash for Enum0 {
unsafe { ::core::intrinsics::unreachable() }
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Enum0 { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Enum0 {
@ -548,6 +561,7 @@ impl ::core::cmp::PartialEq for Enum0 {
unsafe { ::core::intrinsics::unreachable() }
}
}
#[automatically_derived]
impl ::core::marker::StructuralEq for Enum0 { }
#[automatically_derived]
impl ::core::cmp::Eq for Enum0 {
@ -607,6 +621,7 @@ impl ::core::hash::Hash for Enum1 {
}
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Enum1 { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Enum1 {
@ -618,6 +633,7 @@ impl ::core::cmp::PartialEq for Enum1 {
}
}
}
#[automatically_derived]
impl ::core::marker::StructuralEq for Enum1 { }
#[automatically_derived]
impl ::core::cmp::Eq for Enum1 {
@ -676,12 +692,14 @@ impl ::core::default::Default for Fieldless1 {
impl ::core::hash::Hash for Fieldless1 {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Fieldless1 { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Fieldless1 {
#[inline]
fn eq(&self, other: &Fieldless1) -> bool { true }
}
#[automatically_derived]
impl ::core::marker::StructuralEq for Fieldless1 { }
#[automatically_derived]
impl ::core::cmp::Eq for Fieldless1 {
@ -743,6 +761,7 @@ impl ::core::hash::Hash for Fieldless {
::core::hash::Hash::hash(&__self_tag, state)
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Fieldless { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Fieldless {
@ -753,6 +772,7 @@ impl ::core::cmp::PartialEq for Fieldless {
__self_tag == __arg1_tag
}
}
#[automatically_derived]
impl ::core::marker::StructuralEq for Fieldless { }
#[automatically_derived]
impl ::core::cmp::Eq for Fieldless {
@ -838,6 +858,7 @@ impl ::core::hash::Hash for Mixed {
}
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Mixed { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Mixed {
@ -856,6 +877,7 @@ impl ::core::cmp::PartialEq for Mixed {
}
}
}
#[automatically_derived]
impl ::core::marker::StructuralEq for Mixed { }
#[automatically_derived]
impl ::core::cmp::Eq for Mixed {
@ -963,6 +985,7 @@ impl ::core::hash::Hash for Fielded {
}
}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Fielded { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Fielded {
@ -982,6 +1005,7 @@ impl ::core::cmp::PartialEq for Fielded {
}
}
}
#[automatically_derived]
impl ::core::marker::StructuralEq for Fielded { }
#[automatically_derived]
impl ::core::cmp::Eq for Fielded {

View File

@ -0,0 +1,11 @@
// check-pass
#![deny(single_use_lifetimes)]
#[derive(PartialEq, Eq)]
struct Foo<'a, T> {
/// a reference to the underlying secret data that will be derefed
pub data: &'a mut T,
}
fn main() {}