@@ -583,11 +583,27 @@ pub enum BindingForm<'tcx> {
583
583
/// This is a binding for a non-`self` binding, or a `self` that has an explicit type.
584
584
Var ( VarBindingForm < ' tcx > ) ,
585
585
/// Binding for a `self`/`&self`/`&mut self` binding where the type is implicit.
586
- ImplicitSelf ,
586
+ ImplicitSelf ( ImplicitSelfKind ) ,
587
587
/// Reference used in a guard expression to ensure immutability.
588
588
RefForGuard ,
589
589
}
590
590
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
+
591
607
CloneTypeFoldableAndLiftImpls ! { BindingForm <' tcx>, }
592
608
593
609
impl_stable_hash_for ! ( struct self :: VarBindingForm <' tcx> {
@@ -597,6 +613,14 @@ impl_stable_hash_for!(struct self::VarBindingForm<'tcx> {
597
613
pat_span
598
614
} ) ;
599
615
616
+ impl_stable_hash_for ! ( enum self :: ImplicitSelfKind {
617
+ Imm ,
618
+ Mut ,
619
+ ImmRef ,
620
+ MutRef ,
621
+ None
622
+ } ) ;
623
+
600
624
mod binding_form_impl {
601
625
use ich:: StableHashingContext ;
602
626
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher , StableHasherResult } ;
@@ -612,7 +636,7 @@ mod binding_form_impl {
612
636
613
637
match self {
614
638
Var ( binding) => binding. hash_stable ( hcx, hasher) ,
615
- ImplicitSelf => ( ) ,
639
+ ImplicitSelf ( kind ) => kind . hash_stable ( hcx , hasher ) ,
616
640
RefForGuard => ( ) ,
617
641
}
618
642
}
@@ -775,10 +799,9 @@ impl<'tcx> LocalDecl<'tcx> {
775
799
pat_span : _,
776
800
} ) ) ) => true ,
777
801
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
+
782
805
_ => false ,
783
806
}
784
807
}
@@ -795,7 +818,7 @@ impl<'tcx> LocalDecl<'tcx> {
795
818
pat_span : _,
796
819
} ) ) ) => true ,
797
820
798
- Some ( ClearCrossCrate :: Set ( BindingForm :: ImplicitSelf ) ) => true ,
821
+ Some ( ClearCrossCrate :: Set ( BindingForm :: ImplicitSelf ( _ ) ) ) => true ,
799
822
800
823
_ => false ,
801
824
}
0 commit comments