@@ -594,7 +594,7 @@ impl Pat {
594
594
// In a type expression `_` is an inference variable.
595
595
PatKind :: Wild => TyKind :: Infer ,
596
596
// 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 ) => {
598
598
TyKind :: Path ( None , Path :: from_ident ( * ident) )
599
599
}
600
600
PatKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
@@ -681,10 +681,43 @@ pub struct PatField {
681
681
pub is_placeholder : bool ,
682
682
}
683
683
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
+ }
688
721
}
689
722
690
723
#[ derive( Clone , Encodable , Decodable , Debug ) ]
@@ -713,7 +746,7 @@ pub enum PatKind {
713
746
/// or a unit struct/variant pattern, or a const pattern (in the last two cases the third
714
747
/// field must be `None`). Disambiguation cannot be done with parser alone, so it happens
715
748
/// during name resolution.
716
- Ident ( BindingMode , Ident , Option < P < Pat > > ) ,
749
+ Ident ( BindingAnnotation , Ident , Option < P < Pat > > ) ,
717
750
718
751
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
719
752
/// The `bool` is `true` in the presence of a `..`.
@@ -2228,7 +2261,7 @@ pub type ExplicitSelf = Spanned<SelfKind>;
2228
2261
impl Param {
2229
2262
/// Attempts to cast parameter to `ExplicitSelf`.
2230
2263
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 {
2232
2265
if ident. name == kw:: SelfLower {
2233
2266
return match self . ty . kind {
2234
2267
TyKind :: ImplicitSelf => Some ( respan ( self . pat . span , SelfKind :: Value ( mutbl) ) ) ,
@@ -2258,31 +2291,31 @@ impl Param {
2258
2291
pub fn from_self ( attrs : AttrVec , eself : ExplicitSelf , eself_ident : Ident ) -> Param {
2259
2292
let span = eself. span . to ( eself_ident. span ) ;
2260
2293
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 {
2262
2308
attrs,
2263
2309
pat : P ( Pat {
2264
2310
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 ) ,
2266
2312
span,
2267
2313
tokens : None ,
2268
2314
} ) ,
2269
2315
span,
2270
2316
ty,
2271
2317
id : DUMMY_NODE_ID ,
2272
2318
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
- ) ,
2286
2319
}
2287
2320
}
2288
2321
}
0 commit comments