Auto merge of #12393 - J-ZhengLi:issue9413, r=dswij
fix [`derive_partial_eq_without_eq`] FP on trait projection fixes: #9413 #9319 --- changelog: fix [`derive_partial_eq_without_eq`] FP on trait projection Well, this is awkward, it works but I don't understand why, why `clippy_utils::ty::implements_trait` couldn't detects the existance of `Eq` trait, even thought it's obviously present in the derive attribute.
This commit is contained in:
commit
f75d8c7f1b
@ -451,8 +451,8 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r
|
||||
&& let Some(def_id) = trait_ref.trait_def_id()
|
||||
&& cx.tcx.is_diagnostic_item(sym::PartialEq, def_id)
|
||||
&& !has_non_exhaustive_attr(cx.tcx, *adt)
|
||||
&& !ty_implements_eq_trait(cx.tcx, ty, eq_trait_def_id)
|
||||
&& let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id)
|
||||
&& !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[])
|
||||
// If all of our fields implement `Eq`, we can implement `Eq` too
|
||||
&& adt
|
||||
.all_fields()
|
||||
@ -471,6 +471,10 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_implements_eq_trait<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, eq_trait_id: DefId) -> bool {
|
||||
tcx.non_blanket_impls_for_ty(eq_trait_id, ty).next().is_some()
|
||||
}
|
||||
|
||||
/// Creates the `ParamEnv` used for the give type's derived `Eq` impl.
|
||||
fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> ParamEnv<'_> {
|
||||
// Initial map from generic index to param def.
|
||||
|
@ -153,4 +153,30 @@ pub enum MissingEqNonExhaustive3 {
|
||||
Bar,
|
||||
}
|
||||
|
||||
mod struct_gen {
|
||||
// issue 9413
|
||||
pub trait Group {
|
||||
type Element: Eq + PartialEq;
|
||||
}
|
||||
|
||||
pub trait Suite {
|
||||
type Group: Group;
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
//~^ ERROR: you are deriving `PartialEq` and can implement `Eq`
|
||||
pub struct Foo<C: Suite>(<C::Group as Group>::Element);
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct Bar<C: Suite>(i32, <C::Group as Group>::Element);
|
||||
|
||||
// issue 9319
|
||||
#[derive(PartialEq, Eq)]
|
||||
//~^ ERROR: you are deriving `PartialEq` and can implement `Eq`
|
||||
pub struct Oof<T: Fn()>(T);
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct Rab<T: Fn()>(T);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -153,4 +153,30 @@ pub enum MissingEqNonExhaustive3 {
|
||||
Bar,
|
||||
}
|
||||
|
||||
mod struct_gen {
|
||||
// issue 9413
|
||||
pub trait Group {
|
||||
type Element: Eq + PartialEq;
|
||||
}
|
||||
|
||||
pub trait Suite {
|
||||
type Group: Group;
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
//~^ ERROR: you are deriving `PartialEq` and can implement `Eq`
|
||||
pub struct Foo<C: Suite>(<C::Group as Group>::Element);
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct Bar<C: Suite>(i32, <C::Group as Group>::Element);
|
||||
|
||||
// issue 9319
|
||||
#[derive(PartialEq)]
|
||||
//~^ ERROR: you are deriving `PartialEq` and can implement `Eq`
|
||||
pub struct Oof<T: Fn()>(T);
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct Rab<T: Fn()>(T);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -67,5 +67,17 @@ error: you are deriving `PartialEq` and can implement `Eq`
|
||||
LL | #[derive(PartialEq)]
|
||||
| ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq`
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
error: you are deriving `PartialEq` and can implement `Eq`
|
||||
--> tests/ui/derive_partial_eq_without_eq.rs:166:14
|
||||
|
|
||||
LL | #[derive(PartialEq)]
|
||||
| ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq`
|
||||
|
||||
error: you are deriving `PartialEq` and can implement `Eq`
|
||||
--> tests/ui/derive_partial_eq_without_eq.rs:174:14
|
||||
|
|
||||
LL | #[derive(PartialEq)]
|
||||
| ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user