@@ -583,11 +583,27 @@ pub enum BindingForm<'tcx> {
583583 /// This is a binding for a non-`self` binding, or a `self` that has an explicit type.
584584 Var ( VarBindingForm < ' tcx > ) ,
585585 /// Binding for a `self`/`&self`/`&mut self` binding where the type is implicit.
586- ImplicitSelf ,
586+ ImplicitSelf ( ImplicitSelfKind ) ,
587587 /// Reference used in a guard expression to ensure immutability.
588588 RefForGuard ,
589589}
590590
591+ /// Represents what type of implicit self a function has, if any.
592+ #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
593+ pub enum ImplicitSelfKind {
594+ /// Represents a `fn x(self);`.
595+ Imm ,
596+ /// Represents a `fn x(mut self);`.
597+ Mut ,
598+ /// Represents a `fn x(&self);`.
599+ ImmRef ,
600+ /// Represents a `fn x(&mut self);`.
601+ MutRef ,
602+ /// Represents when a function does not have a self argument or
603+ /// when a function has a `self: X` argument.
604+ None
605+ }
606+
591607CloneTypeFoldableAndLiftImpls ! { BindingForm <' tcx>, }
592608
593609impl_stable_hash_for ! ( struct self :: VarBindingForm <' tcx> {
@@ -597,6 +613,14 @@ impl_stable_hash_for!(struct self::VarBindingForm<'tcx> {
597613 pat_span
598614} ) ;
599615
616+ impl_stable_hash_for ! ( enum self :: ImplicitSelfKind {
617+ Imm ,
618+ Mut ,
619+ ImmRef ,
620+ MutRef ,
621+ None
622+ } ) ;
623+
600624mod binding_form_impl {
601625 use ich:: StableHashingContext ;
602626 use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher , StableHasherResult } ;
@@ -612,7 +636,7 @@ mod binding_form_impl {
612636
613637 match self {
614638 Var ( binding) => binding. hash_stable ( hcx, hasher) ,
615- ImplicitSelf => ( ) ,
639+ ImplicitSelf ( kind ) => kind . hash_stable ( hcx , hasher ) ,
616640 RefForGuard => ( ) ,
617641 }
618642 }
@@ -775,10 +799,9 @@ impl<'tcx> LocalDecl<'tcx> {
775799 pat_span : _,
776800 } ) ) ) => true ,
777801
778- // FIXME: might be able to thread the distinction between
779- // `self`/`mut self`/`&self`/`&mut self` into the
780- // `BindingForm::ImplicitSelf` variant, (and then return
781- // true here for solely the first case).
802+ Some ( ClearCrossCrate :: Set ( BindingForm :: ImplicitSelf ( ImplicitSelfKind :: Imm ) ) )
803+ => true ,
804+
782805 _ => false ,
783806 }
784807 }
@@ -795,7 +818,7 @@ impl<'tcx> LocalDecl<'tcx> {
795818 pat_span : _,
796819 } ) ) ) => true ,
797820
798- Some ( ClearCrossCrate :: Set ( BindingForm :: ImplicitSelf ) ) => true ,
821+ Some ( ClearCrossCrate :: Set ( BindingForm :: ImplicitSelf ( _ ) ) ) => true ,
799822
800823 _ => false ,
801824 }
0 commit comments