@@ -3498,7 +3498,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34983498 err,
34993499 pick. item . def_id ,
35003500 rcvr. hir_id ,
3501- * rcvr_ty,
3501+ Some ( * rcvr_ty) ,
35023502 ) ;
35033503 if pick. autoderefs == 0 && !trait_in_other_version_found {
35043504 err. span_label (
@@ -3700,7 +3700,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37003700 // See if the `Type::function(val)` where `function` wasn't found corresponds to a
37013701 // `Trait` that is imported directly, but `Type` came from a different version of the
37023702 // same crate.
3703- let rcvr_ty = self . tcx . type_of ( def_id) . instantiate_identity ( ) ;
3703+
3704+ let rcvr_ty = match self . tcx . def_kind ( def_id) {
3705+ DefKind :: Struct | DefKind :: Enum | DefKind :: Union => {
3706+ Some ( self . tcx . type_of ( def_id) . instantiate_identity ( ) )
3707+ }
3708+ _ => None ,
3709+ } ;
37043710 trait_in_other_version_found = self . detect_and_explain_multiple_crate_versions (
37053711 err,
37063712 assoc. def_id ,
@@ -4080,7 +4086,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
40804086 err : & mut Diag < ' _ > ,
40814087 item_def_id : DefId ,
40824088 hir_id : hir:: HirId ,
4083- rcvr_ty : Ty < ' _ > ,
4089+ rcvr_ty : Option < Ty < ' _ > > ,
40844090 ) -> bool {
40854091 let hir_id = self . tcx . parent_hir_id ( hir_id) ;
40864092 let Some ( traits) = self . tcx . in_scope_traits ( hir_id) else { return false } ;
@@ -4110,8 +4116,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
41104116 let mut multi_span: MultiSpan = trait_span. into ( ) ;
41114117 multi_span. push_span_label ( trait_span, format ! ( "this is the trait that is needed" ) ) ;
41124118 let descr = self . tcx . associated_item ( item_def_id) . descr ( ) ;
4119+ let rcvr_ty =
4120+ rcvr_ty. map ( |t| format ! ( "`{t}`" ) ) . unwrap_or_else ( || "the receiver" . to_string ( ) ) ;
41134121 multi_span
4114- . push_span_label ( item_span, format ! ( "the {descr} is available for ` {rcvr_ty}` here" ) ) ;
4122+ . push_span_label ( item_span, format ! ( "the {descr} is available for {rcvr_ty} here" ) ) ;
41154123 for ( def_id, import_def_id) in candidates {
41164124 if let Some ( import_def_id) = import_def_id {
41174125 multi_span. push_span_label (
0 commit comments