@@ -3494,7 +3494,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34943494 continue ;
34953495 }
34963496 trait_in_other_version_found = self
3497- . detect_and_explain_multiple_crate_versions (
3497+ . detect_and_explain_multiple_crate_versions_of_trait_item (
34983498 err,
34993499 pick. item . def_id ,
35003500 rcvr. hir_id ,
@@ -3701,12 +3701,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37013701 // same crate.
37023702
37033703 let rcvr_ty = self . node_ty_opt ( ty. hir_id ) ;
3704- trait_in_other_version_found = self . detect_and_explain_multiple_crate_versions (
3705- err,
3706- assoc. def_id ,
3707- ty. hir_id ,
3708- rcvr_ty,
3709- ) ;
3704+ trait_in_other_version_found = self
3705+ . detect_and_explain_multiple_crate_versions_of_trait_item (
3706+ err,
3707+ assoc. def_id ,
3708+ ty. hir_id ,
3709+ rcvr_ty,
3710+ ) ;
37103711 }
37113712 if !trait_in_other_version_found
37123713 && self . suggest_valid_traits ( err, item_name, valid_out_of_scope_traits, true )
@@ -4098,7 +4099,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
40984099 }
40994100 }
41004101
4101- fn detect_and_explain_multiple_crate_versions (
4102+ fn detect_and_explain_multiple_crate_versions_of_trait_item (
41024103 & self ,
41034104 err : & mut Diag < ' _ > ,
41044105 item_def_id : DefId ,
@@ -4111,6 +4112,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
41114112 return false ;
41124113 }
41134114 let trait_def_id = self . tcx . parent ( item_def_id) ;
4115+ if !self . tcx . is_trait ( trait_def_id) {
4116+ return false ;
4117+ }
41144118 let krate = self . tcx . crate_name ( trait_def_id. krate ) ;
41154119 let name = self . tcx . item_name ( trait_def_id) ;
41164120 let candidates: Vec < _ > = traits
0 commit comments