@@ -568,7 +568,7 @@ impl Pat {
568568 // In a type expression `_` is an inference variable.
569569 PatKind :: Wild => TyKind :: Infer ,
570570 // An IDENT pattern with no binding mode would be valid as path to a type. E.g. `u32`.
571- PatKind :: Ident ( BindingAnnotation :: NONE , ident, None ) => {
571+ PatKind :: Ident ( BindingMode :: NONE , ident, None ) => {
572572 TyKind :: Path ( None , Path :: from_ident ( * ident) )
573573 }
574574 PatKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
@@ -675,7 +675,7 @@ impl Pat {
675675 pub fn descr ( & self ) -> Option < String > {
676676 match & self . kind {
677677 PatKind :: Wild => Some ( "_" . to_string ( ) ) ,
678- PatKind :: Ident ( BindingAnnotation :: NONE , ident, None ) => Some ( format ! ( "{ident}" ) ) ,
678+ PatKind :: Ident ( BindingMode :: NONE , ident, None ) => Some ( format ! ( "{ident}" ) ) ,
679679 PatKind :: Ref ( pat, mutbl) => pat. descr ( ) . map ( |d| format ! ( "&{}{d}" , mutbl. prefix_str( ) ) ) ,
680680 _ => None ,
681681 }
@@ -707,14 +707,25 @@ pub enum ByRef {
707707 No ,
708708}
709709
710- /// Explicit binding annotations given in the HIR for a binding. Note
711- /// that this is not the final binding *mode* that we infer after type
712- /// inference.
710+ impl ByRef {
711+ pub fn cap_ref_mutability ( mut self , mutbl : Mutability ) -> Self {
712+ if let ByRef :: Yes ( old_mutbl) = & mut self {
713+ * old_mutbl = cmp:: min ( * old_mutbl, mutbl) ;
714+ }
715+ self
716+ }
717+ }
718+
719+ /// The mode of a binding (`mut`, `ref mut`, etc).
720+ /// Used for both the explicit binding annotations given in the HIR for a binding
721+ /// and the final binding mode that we infer after type inference/match ergonomics.
722+ /// `.0` is the by-reference mode (`ref`, `ref mut`, or by value),
723+ /// `.1` is the mutability of the binding.
713724#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
714725#[ derive( Encodable , Decodable , HashStable_Generic ) ]
715- pub struct BindingAnnotation ( pub ByRef , pub Mutability ) ;
726+ pub struct BindingMode ( pub ByRef , pub Mutability ) ;
716727
717- impl BindingAnnotation {
728+ impl BindingMode {
718729 pub const NONE : Self = Self ( ByRef :: No , Mutability :: Not ) ;
719730 pub const REF : Self = Self ( ByRef :: Yes ( Mutability :: Not ) , Mutability :: Not ) ;
720731 pub const MUT : Self = Self ( ByRef :: No , Mutability :: Mut ) ;
@@ -732,13 +743,6 @@ impl BindingAnnotation {
732743 Self :: MUT_REF_MUT => "mut ref mut " ,
733744 }
734745 }
735-
736- pub fn cap_ref_mutability ( mut self , mutbl : Mutability ) -> Self {
737- if let ByRef :: Yes ( old_mutbl) = & mut self . 0 {
738- * old_mutbl = cmp:: min ( * old_mutbl, mutbl) ;
739- }
740- self
741- }
742746}
743747
744748#[ derive( Clone , Encodable , Decodable , Debug ) ]
@@ -769,7 +773,7 @@ pub enum PatKind {
769773 /// or a unit struct/variant pattern, or a const pattern (in the last two cases the third
770774 /// field must be `None`). Disambiguation cannot be done with parser alone, so it happens
771775 /// during name resolution.
772- Ident ( BindingAnnotation , Ident , Option < P < Pat > > ) ,
776+ Ident ( BindingMode , Ident , Option < P < Pat > > ) ,
773777
774778 /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
775779 Struct ( Option < P < QSelf > > , Path , ThinVec < PatField > , PatFieldsRest ) ,
@@ -2382,7 +2386,7 @@ pub type ExplicitSelf = Spanned<SelfKind>;
23822386impl Param {
23832387 /// Attempts to cast parameter to `ExplicitSelf`.
23842388 pub fn to_self ( & self ) -> Option < ExplicitSelf > {
2385- if let PatKind :: Ident ( BindingAnnotation ( ByRef :: No , mutbl) , ident, _) = self . pat . kind {
2389+ if let PatKind :: Ident ( BindingMode ( ByRef :: No , mutbl) , ident, _) = self . pat . kind {
23862390 if ident. name == kw:: SelfLower {
23872391 return match self . ty . kind {
23882392 TyKind :: ImplicitSelf => Some ( respan ( self . pat . span , SelfKind :: Value ( mutbl) ) ) ,
@@ -2434,7 +2438,7 @@ impl Param {
24342438 attrs,
24352439 pat : P ( Pat {
24362440 id : DUMMY_NODE_ID ,
2437- kind : PatKind :: Ident ( BindingAnnotation ( ByRef :: No , mutbl) , eself_ident, None ) ,
2441+ kind : PatKind :: Ident ( BindingMode ( ByRef :: No , mutbl) , eself_ident, None ) ,
24382442 span,
24392443 tokens : None ,
24402444 } ) ,
0 commit comments