@@ -775,8 +775,9 @@ pub enum PatKind {
775775#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , Copy ) ]
776776#[ derive( HashStable_Generic , Encodable , Decodable ) ]
777777pub enum Mutability {
778- Mut ,
778+ // N.B. Order is deliberate, so that Not < Mut
779779 Not ,
780+ Mut ,
780781}
781782
782783impl Mutability {
@@ -787,12 +788,39 @@ impl Mutability {
787788 }
788789 }
789790
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 {
791793 match self {
792794 Mutability :: Mut => "mut " ,
793795 Mutability :: Not => "" ,
794796 }
795797 }
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+ }
796824}
797825
798826/// The kind of borrow in an `AddrOf` expression,
0 commit comments