@@ -594,7 +594,7 @@ impl Pat {
594594 // In a type expression `_` is an inference variable.
595595 PatKind :: Wild => TyKind :: Infer ,
596596 // An IDENT pattern with no binding mode would be valid as path to a type. E.g. `u32`.
597- PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Not ) , ident, None ) => {
597+ PatKind :: Ident ( BindingAnnotation :: NONE , ident, None ) => {
598598 TyKind :: Path ( None , Path :: from_ident ( * ident) )
599599 }
600600 PatKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
@@ -681,10 +681,43 @@ pub struct PatField {
681681 pub is_placeholder : bool ,
682682}
683683
684- #[ derive( Clone , PartialEq , Encodable , Decodable , Debug , Copy ) ]
685- pub enum BindingMode {
686- ByRef ( Mutability ) ,
687- ByValue ( Mutability ) ,
684+ #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
685+ #[ derive( Encodable , Decodable , HashStable_Generic ) ]
686+ pub enum ByRef {
687+ Yes ,
688+ No ,
689+ }
690+
691+ impl From < bool > for ByRef {
692+ fn from ( b : bool ) -> ByRef {
693+ match b {
694+ false => ByRef :: No ,
695+ true => ByRef :: Yes ,
696+ }
697+ }
698+ }
699+
700+ /// Explicit binding annotations given in the HIR for a binding. Note
701+ /// that this is not the final binding *mode* that we infer after type
702+ /// inference.
703+ #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
704+ #[ derive( Encodable , Decodable , HashStable_Generic ) ]
705+ pub struct BindingAnnotation ( pub ByRef , pub Mutability ) ;
706+
707+ impl BindingAnnotation {
708+ pub const NONE : Self = Self ( ByRef :: No , Mutability :: Not ) ;
709+ pub const REF : Self = Self ( ByRef :: Yes , Mutability :: Not ) ;
710+ pub const MUT : Self = Self ( ByRef :: No , Mutability :: Mut ) ;
711+ pub const REF_MUT : Self = Self ( ByRef :: Yes , Mutability :: Mut ) ;
712+
713+ pub fn prefix_str ( self ) -> & ' static str {
714+ match self {
715+ Self :: NONE => "" ,
716+ Self :: REF => "ref " ,
717+ Self :: MUT => "mut " ,
718+ Self :: REF_MUT => "ref mut " ,
719+ }
720+ }
688721}
689722
690723#[ derive( Clone , Encodable , Decodable , Debug ) ]
@@ -713,7 +746,7 @@ pub enum PatKind {
713746 /// or a unit struct/variant pattern, or a const pattern (in the last two cases the third
714747 /// field must be `None`). Disambiguation cannot be done with parser alone, so it happens
715748 /// during name resolution.
716- Ident ( BindingMode , Ident , Option < P < Pat > > ) ,
749+ Ident ( BindingAnnotation , Ident , Option < P < Pat > > ) ,
717750
718751 /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
719752 /// The `bool` is `true` in the presence of a `..`.
@@ -2228,7 +2261,7 @@ pub type ExplicitSelf = Spanned<SelfKind>;
22282261impl Param {
22292262 /// Attempts to cast parameter to `ExplicitSelf`.
22302263 pub fn to_self ( & self ) -> Option < ExplicitSelf > {
2231- if let PatKind :: Ident ( BindingMode :: ByValue ( mutbl) , ident, _) = self . pat . kind {
2264+ if let PatKind :: Ident ( BindingAnnotation ( ByRef :: No , mutbl) , ident, _) = self . pat . kind {
22322265 if ident. name == kw:: SelfLower {
22332266 return match self . ty . kind {
22342267 TyKind :: ImplicitSelf => Some ( respan ( self . pat . span , SelfKind :: Value ( mutbl) ) ) ,
@@ -2258,31 +2291,31 @@ impl Param {
22582291 pub fn from_self ( attrs : AttrVec , eself : ExplicitSelf , eself_ident : Ident ) -> Param {
22592292 let span = eself. span . to ( eself_ident. span ) ;
22602293 let infer_ty = P ( Ty { id : DUMMY_NODE_ID , kind : TyKind :: ImplicitSelf , span, tokens : None } ) ;
2261- let param = |mutbl, ty| Param {
2294+ let ( mutbl, ty) = match eself. node {
2295+ SelfKind :: Explicit ( ty, mutbl) => ( mutbl, ty) ,
2296+ SelfKind :: Value ( mutbl) => ( mutbl, infer_ty) ,
2297+ SelfKind :: Region ( lt, mutbl) => (
2298+ Mutability :: Not ,
2299+ P ( Ty {
2300+ id : DUMMY_NODE_ID ,
2301+ kind : TyKind :: Rptr ( lt, MutTy { ty : infer_ty, mutbl } ) ,
2302+ span,
2303+ tokens : None ,
2304+ } ) ,
2305+ ) ,
2306+ } ;
2307+ Param {
22622308 attrs,
22632309 pat : P ( Pat {
22642310 id : DUMMY_NODE_ID ,
2265- kind : PatKind :: Ident ( BindingMode :: ByValue ( mutbl) , eself_ident, None ) ,
2311+ kind : PatKind :: Ident ( BindingAnnotation ( ByRef :: No , mutbl) , eself_ident, None ) ,
22662312 span,
22672313 tokens : None ,
22682314 } ) ,
22692315 span,
22702316 ty,
22712317 id : DUMMY_NODE_ID ,
22722318 is_placeholder : false ,
2273- } ;
2274- match eself. node {
2275- SelfKind :: Explicit ( ty, mutbl) => param ( mutbl, ty) ,
2276- SelfKind :: Value ( mutbl) => param ( mutbl, infer_ty) ,
2277- SelfKind :: Region ( lt, mutbl) => param (
2278- Mutability :: Not ,
2279- P ( Ty {
2280- id : DUMMY_NODE_ID ,
2281- kind : TyKind :: Rptr ( lt, MutTy { ty : infer_ty, mutbl } ) ,
2282- span,
2283- tokens : None ,
2284- } ) ,
2285- ) ,
22862319 }
22872320 }
22882321}
0 commit comments