@@ -3283,16 +3283,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32833283
32843284 /// Checks if we can suggest a derive macro for the unmet trait bound.
32853285 /// Returns Some(list_of_derives) if possible, or None if not.
3286- fn check_derive (
3286+ fn consider_suggesting_derives_for_ty (
32873287 & self ,
32883288 trait_pred : ty:: TraitPredicate < ' tcx > ,
32893289 adt : ty:: AdtDef < ' tcx > ,
32903290 ) -> Option < Vec < ( String , Span , Symbol ) > > {
32913291 let diagnostic_name = self . tcx . get_diagnostic_name ( trait_pred. def_id ( ) ) ?;
32923292
32933293 let can_derive = match diagnostic_name {
3294- sym:: Default => !adt . is_enum ( ) ,
3295- sym:: Eq
3294+ sym:: Default
3295+ | sym:: Eq
32963296 | sym:: PartialEq
32973297 | sym:: Ord
32983298 | sym:: PartialOrd
@@ -3309,16 +3309,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33093309
33103310 let trait_def_id = trait_pred. def_id ( ) ;
33113311 let self_ty = trait_pred. self_ty ( ) ;
3312- let has_impl =
3313- self . tcx . non_blanket_impls_for_ty ( trait_def_id, self_ty) . any ( |impl_def_id| {
3314- self . tcx
3315- . type_of ( impl_def_id)
3316- . instantiate_identity ( )
3317- . ty_adt_def ( )
3318- . is_some_and ( |def| def. did ( ) == adt. did ( ) )
3319- } ) ;
33203312
3321- if has_impl {
3313+ // We need to check if there is already a manual implementation of the trait
3314+ // for this specific ADT to avoid suggesting `#[derive(..)]` that would conflict.
3315+ if self . tcx . non_blanket_impls_for_ty ( trait_def_id, self_ty) . any ( |impl_def_id| {
3316+ self . tcx
3317+ . type_of ( impl_def_id)
3318+ . instantiate_identity ( )
3319+ . ty_adt_def ( )
3320+ . is_some_and ( |def| def. did ( ) == adt. did ( ) )
3321+ } ) {
33223322 return None ;
33233323 }
33243324
@@ -3355,7 +3355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33553355 Some ( adt) if adt. did ( ) . is_local ( ) => adt,
33563356 _ => continue ,
33573357 } ;
3358- if let Some ( new_derives) = self . check_derive ( trait_pred, adt) {
3358+ if let Some ( new_derives) = self . consider_suggesting_derives_for_ty ( trait_pred, adt) {
33593359 derives. extend ( new_derives) ;
33603360 } else {
33613361 traits. push ( trait_pred. def_id ( ) ) ;
0 commit comments