@@ -348,6 +348,7 @@ struct Candidate {
348348pub enum RcvrMatchCondition {
349349 RcvrMatchesIfObject ( ast:: DefId ) ,
350350 RcvrMatchesIfSubtype ( ty:: t ) ,
351+ RcvrMatchesIfEqtype ( ty:: t )
351352}
352353
353354impl < ' a , ' tcx > LookupContext < ' a , ' tcx > {
@@ -675,6 +676,14 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
675676 }
676677 _ => { }
677678 }
679+
680+ let condition = match m. explicit_self {
681+ ByReferenceExplicitSelfCategory ( _, mt) if mt == MutMutable =>
682+ RcvrMatchesIfEqtype ( self_ty) ,
683+ _ =>
684+ RcvrMatchesIfSubtype ( self_ty)
685+ } ;
686+
678687 debug ! ( "found match: trait_ref={} substs={} m={}" ,
679688 trait_ref. repr( this. tcx( ) ) ,
680689 trait_ref. substs. repr( this. tcx( ) ) ,
@@ -688,7 +697,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
688697 assert_eq ! ( m. generics. regions. get_slice( subst:: SelfSpace ) . len( ) ,
689698 trait_ref. substs. regions( ) . get_slice( subst:: SelfSpace ) . len( ) ) ;
690699 Some ( Candidate {
691- rcvr_match_condition : RcvrMatchesIfSubtype ( self_ty ) ,
700+ rcvr_match_condition : condition ,
692701 rcvr_substs : trait_ref. substs . clone ( ) ,
693702 method_ty : m,
694703 origin : MethodParam ( MethodParam {
@@ -822,14 +831,21 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
822831 ty : impl_ty
823832 } = impl_self_ty ( & vcx, span, impl_did) ;
824833
834+ let condition = match method. explicit_self {
835+ ByReferenceExplicitSelfCategory ( _, mt) if mt == MutMutable =>
836+ RcvrMatchesIfEqtype ( impl_ty) ,
837+ _ =>
838+ RcvrMatchesIfSubtype ( impl_ty)
839+ } ;
840+
825841 let candidates = if is_extension {
826842 & mut self . extension_candidates
827843 } else {
828844 & mut self . inherent_candidates
829845 } ;
830846
831847 candidates. push ( Candidate {
832- rcvr_match_condition : RcvrMatchesIfSubtype ( impl_ty ) ,
848+ rcvr_match_condition : condition ,
833849 rcvr_substs : impl_substs,
834850 origin : MethodStatic ( method. def_id ) ,
835851 method_ty : method,
@@ -1525,7 +1541,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
15251541 RcvrMatchesIfObject ( desired_did) => {
15261542 self_did == desired_did
15271543 }
1528- RcvrMatchesIfSubtype ( _) => {
1544+ RcvrMatchesIfSubtype ( _) | RcvrMatchesIfEqtype ( _ ) => {
15291545 false
15301546 }
15311547 }
@@ -1541,6 +1557,9 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
15411557 RcvrMatchesIfSubtype ( of_type) => {
15421558 fcx. can_mk_subty ( rcvr_ty, of_type) . is_ok ( )
15431559 }
1560+ RcvrMatchesIfEqtype ( of_type) => {
1561+ fcx. can_mk_eqty ( rcvr_ty, of_type) . is_ok ( )
1562+ }
15441563 }
15451564 }
15461565
@@ -1656,9 +1675,9 @@ impl Repr for RcvrMatchCondition {
16561675 RcvrMatchesIfSubtype ( t) => {
16571676 format ! ( "RcvrMatchesIfSubtype({})" , t. repr( tcx) )
16581677 }
1678+ RcvrMatchesIfEqtype ( t) => {
1679+ format ! ( "RcvrMatchesIfEqtype({})" , t. repr( tcx) )
1680+ }
16591681 }
16601682 }
16611683}
1662-
1663-
1664-
0 commit comments