@@ -1399,6 +1399,7 @@ impl Expr {
1399
1399
// Never need parens
1400
1400
ExprKind :: Array ( _)
1401
1401
| ExprKind :: Await ( ..)
1402
+ | ExprKind :: Use ( ..)
1402
1403
| ExprKind :: Block ( ..)
1403
1404
| ExprKind :: Call ( ..)
1404
1405
| ExprKind :: ConstBlock ( _)
@@ -1588,6 +1589,8 @@ pub enum ExprKind {
1588
1589
Gen ( CaptureBy , P < Block > , GenBlockKind , Span ) ,
1589
1590
/// An await expression (`my_future.await`). Span is of await keyword.
1590
1591
Await ( P < Expr > , Span ) ,
1592
+ /// A use expression (`x.use`). Span is of use keyword.
1593
+ Use ( P < Expr > , Span ) ,
1591
1594
1592
1595
/// A try block (`try { ... }`).
1593
1596
TryBlock ( P < Block > ) ,
@@ -1757,8 +1760,17 @@ pub enum CaptureBy {
1757
1760
/// The span of the `move` keyword.
1758
1761
move_kw : Span ,
1759
1762
} ,
1760
- /// `move` keyword was not specified.
1763
+ /// `move` or `use` keywords were not specified.
1761
1764
Ref ,
1765
+ /// `use |x| y + x`.
1766
+ ///
1767
+ /// Note that if you have a regular closure like `|| x.use`, this will *not* result
1768
+ /// in a `Use` capture. Instead, the `ExprUseVisitor` will look at the type
1769
+ /// of `x` and treat `x.use` as either a copy/clone/move as appropriate.
1770
+ Use {
1771
+ /// The span of the `use` keyword.
1772
+ use_kw : Span ,
1773
+ } ,
1762
1774
}
1763
1775
1764
1776
/// Closure lifetime binder, `for<'a, 'b>` in `for<'a, 'b> |_: &'a (), _: &'b ()|`.
@@ -2641,6 +2653,8 @@ pub enum SelfKind {
2641
2653
Value ( Mutability ) ,
2642
2654
/// `&'lt self`, `&'lt mut self`
2643
2655
Region ( Option < Lifetime > , Mutability ) ,
2656
+ /// `&'lt pin const self`, `&'lt pin mut self`
2657
+ Pinned ( Option < Lifetime > , Mutability ) ,
2644
2658
/// `self: TYPE`, `mut self: TYPE`
2645
2659
Explicit ( P < Ty > , Mutability ) ,
2646
2660
}
@@ -2650,6 +2664,8 @@ impl SelfKind {
2650
2664
match self {
2651
2665
SelfKind :: Region ( None , mutbl) => mutbl. ref_prefix_str ( ) . to_string ( ) ,
2652
2666
SelfKind :: Region ( Some ( lt) , mutbl) => format ! ( "&{lt} {}" , mutbl. prefix_str( ) ) ,
2667
+ SelfKind :: Pinned ( None , mutbl) => format ! ( "&pin {}" , mutbl. ptr_str( ) ) ,
2668
+ SelfKind :: Pinned ( Some ( lt) , mutbl) => format ! ( "&{lt} pin {}" , mutbl. ptr_str( ) ) ,
2653
2669
SelfKind :: Value ( _) | SelfKind :: Explicit ( _, _) => {
2654
2670
unreachable ! ( "if we had an explicit self, we wouldn't be here" )
2655
2671
}
@@ -2666,11 +2682,13 @@ impl Param {
2666
2682
if ident. name == kw:: SelfLower {
2667
2683
return match self . ty . kind {
2668
2684
TyKind :: ImplicitSelf => Some ( respan ( self . pat . span , SelfKind :: Value ( mutbl) ) ) ,
2669
- TyKind :: Ref ( lt, MutTy { ref ty, mutbl } )
2670
- | TyKind :: PinnedRef ( lt, MutTy { ref ty, mutbl } )
2685
+ TyKind :: Ref ( lt, MutTy { ref ty, mutbl } ) if ty. kind . is_implicit_self ( ) => {
2686
+ Some ( respan ( self . pat . span , SelfKind :: Region ( lt, mutbl) ) )
2687
+ }
2688
+ TyKind :: PinnedRef ( lt, MutTy { ref ty, mutbl } )
2671
2689
if ty. kind . is_implicit_self ( ) =>
2672
2690
{
2673
- Some ( respan ( self . pat . span , SelfKind :: Region ( lt, mutbl) ) )
2691
+ Some ( respan ( self . pat . span , SelfKind :: Pinned ( lt, mutbl) ) )
2674
2692
}
2675
2693
_ => Some ( respan (
2676
2694
self . pat . span . to ( self . ty . span ) ,
@@ -2712,6 +2730,15 @@ impl Param {
2712
2730
tokens : None ,
2713
2731
} ) ,
2714
2732
) ,
2733
+ SelfKind :: Pinned ( lt, mutbl) => (
2734
+ mutbl,
2735
+ P ( Ty {
2736
+ id : DUMMY_NODE_ID ,
2737
+ kind : TyKind :: PinnedRef ( lt, MutTy { ty : infer_ty, mutbl } ) ,
2738
+ span,
2739
+ tokens : None ,
2740
+ } ) ,
2741
+ ) ,
2715
2742
} ;
2716
2743
Param {
2717
2744
attrs,
0 commit comments