Skip to content

Commit daeb392

Browse files
committed
rebase
1 parent 17333eb commit daeb392

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use rustc_trait_selection::traits::{
4343
FulfillmentError, Obligation, ObligationCauseCode, supertraits,
4444
};
4545
use tracing::{debug, info, instrument};
46+
4647
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
4748
use super::{CandidateSource, MethodError, NoMatchData};
4849
use crate::errors::{self, CandidateTraitNote, NoAssociatedItem};
@@ -3282,7 +3283,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32823283

32833284
/// Checks if we can suggest a derive macro for the unmet trait bound.
32843285
/// Returns Some(list_of_derives) if possible, or None if not.
3285-
fn consider_suggesting_derives_for_ty(
3286+
fn check_derive(
32863287
&self,
32873288
trait_pred: ty::TraitPredicate<'tcx>,
32883289
adt: ty::AdtDef<'tcx>,
@@ -3308,16 +3309,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33083309

33093310
let trait_def_id = trait_pred.def_id();
33103311
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+
});
33113320

3312-
// We need to check if there is already a manual implementation of the trait
3313-
// for this specific ADT to avoid suggesting `#[derive(..)]` that would conflict.
3314-
if self.tcx.non_blanket_impls_for_ty(trait_def_id, self_ty).any(|impl_def_id| {
3315-
self.tcx
3316-
.type_of(impl_def_id)
3317-
.instantiate_identity()
3318-
.ty_adt_def()
3319-
.is_some_and(|def| def.did() == adt.did())
3320-
}) {
3321+
if has_impl {
33213322
return None;
33223323
}
33233324

@@ -3354,7 +3355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33543355
Some(adt) if adt.did().is_local() => adt,
33553356
_ => continue,
33563357
};
3357-
if let Some(new_derives) = self.consider_suggesting_derives_for_ty(trait_pred, adt) {
3358+
if let Some(new_derives) = self.check_derive(trait_pred, adt) {
33583359
derives.extend(new_derives);
33593360
} else {
33603361
traits.push(trait_pred.def_id());

0 commit comments

Comments
 (0)