@@ -15,7 +15,7 @@ use rustc_ast::visit::{Visitor, walk_expr};
15
15
use rustc_ast:: {
16
16
self as ast, AnonConst , Arm , AttrStyle , AttrVec , BinOp , BinOpKind , BlockCheckMode , CaptureBy ,
17
17
ClosureBinder , DUMMY_NODE_ID , Expr , ExprField , ExprKind , FnDecl , FnRetTy , Label , MacCall ,
18
- MetaItemLit , Movability , Param , RangeLimits , StmtKind , Ty , TyKind , UnOp ,
18
+ MetaItemLit , Movability , Param , RangeLimits , StmtKind , Ty , TyKind , UnOp , UnsafeBinderCastKind ,
19
19
} ;
20
20
use rustc_ast_pretty:: pprust;
21
21
use rustc_data_structures:: stack:: ensure_sufficient_stack;
@@ -1931,6 +1931,12 @@ impl<'a> Parser<'a> {
1931
1931
Ok ( match ident. name {
1932
1932
sym:: offset_of => Some ( this. parse_expr_offset_of ( lo) ?) ,
1933
1933
sym:: type_ascribe => Some ( this. parse_expr_type_ascribe ( lo) ?) ,
1934
+ sym:: wrap_binder => {
1935
+ Some ( this. parse_expr_unsafe_binder_cast ( lo, UnsafeBinderCastKind :: Wrap ) ?)
1936
+ }
1937
+ sym:: unwrap_binder => {
1938
+ Some ( this. parse_expr_unsafe_binder_cast ( lo, UnsafeBinderCastKind :: Unwrap ) ?)
1939
+ }
1934
1940
_ => None ,
1935
1941
} )
1936
1942
} )
@@ -2006,6 +2012,17 @@ impl<'a> Parser<'a> {
2006
2012
Ok ( self . mk_expr ( span, ExprKind :: Type ( expr, ty) ) )
2007
2013
}
2008
2014
2015
+ pub ( crate ) fn parse_expr_unsafe_binder_cast (
2016
+ & mut self ,
2017
+ lo : Span ,
2018
+ kind : UnsafeBinderCastKind ,
2019
+ ) -> PResult < ' a , P < Expr > > {
2020
+ let expr = self . parse_expr ( ) ?;
2021
+ let ty = if self . eat ( & TokenKind :: Comma ) { Some ( self . parse_ty ( ) ?) } else { None } ;
2022
+ let span = lo. to ( self . token . span ) ;
2023
+ Ok ( self . mk_expr ( span, ExprKind :: UnsafeBinderCast ( kind, expr, ty) ) )
2024
+ }
2025
+
2009
2026
/// Returns a string literal if the next token is a string literal.
2010
2027
/// In case of error returns `Some(lit)` if the next token is a literal with a wrong kind,
2011
2028
/// and returns `None` if the next token is not literal at all.
@@ -4019,7 +4036,9 @@ impl MutVisitor for CondChecker<'_> {
4019
4036
mut_visit:: walk_expr ( self , e) ;
4020
4037
self . forbid_let_reason = forbid_let_reason;
4021
4038
}
4022
- ExprKind :: Cast ( ref mut op, _) | ExprKind :: Type ( ref mut op, _) => {
4039
+ ExprKind :: Cast ( ref mut op, _)
4040
+ | ExprKind :: Type ( ref mut op, _)
4041
+ | ExprKind :: UnsafeBinderCast ( _, ref mut op, _) => {
4023
4042
let forbid_let_reason = self . forbid_let_reason ;
4024
4043
self . forbid_let_reason = Some ( OtherForbidden ) ;
4025
4044
self . visit_expr ( op) ;
0 commit comments