@@ -775,8 +775,9 @@ pub enum PatKind {
775
775
#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , Copy ) ]
776
776
#[ derive( HashStable_Generic , Encodable , Decodable ) ]
777
777
pub enum Mutability {
778
- Mut ,
778
+ // N.B. Order is deliberate, so that Not < Mut
779
779
Not ,
780
+ Mut ,
780
781
}
781
782
782
783
impl Mutability {
@@ -787,12 +788,39 @@ impl Mutability {
787
788
}
788
789
}
789
790
790
- pub fn prefix_str ( & self ) -> & ' static str {
791
+ /// Returns `""` (empty string) or `"mut "` depending on the mutability.
792
+ pub fn prefix_str ( self ) -> & ' static str {
791
793
match self {
792
794
Mutability :: Mut => "mut " ,
793
795
Mutability :: Not => "" ,
794
796
}
795
797
}
798
+
799
+ /// Returns `"&"` or `"&mut "` depending on the mutability.
800
+ pub fn ref_prefix_str ( self ) -> & ' static str {
801
+ match self {
802
+ Mutability :: Not => "&" ,
803
+ Mutability :: Mut => "&mut " ,
804
+ }
805
+ }
806
+
807
+ /// Returns `""` (empty string) or `"mutably "` depending on the mutability.
808
+ pub fn mutably_str ( self ) -> & ' static str {
809
+ match self {
810
+ Mutability :: Not => "" ,
811
+ Mutability :: Mut => "mutably " ,
812
+ }
813
+ }
814
+
815
+ /// Return `true` if self is mutable
816
+ pub fn is_mut ( self ) -> bool {
817
+ matches ! ( self , Self :: Mut )
818
+ }
819
+
820
+ /// Return `true` if self is **not** mutable
821
+ pub fn is_not ( self ) -> bool {
822
+ matches ! ( self , Self :: Not )
823
+ }
796
824
}
797
825
798
826
/// The kind of borrow in an `AddrOf` expression,
0 commit comments