@@ -22,7 +22,7 @@ use super::{
22
22
pub ( super ) fn is_expr_atom_head ( kind : SyntaxKind ) -> bool {
23
23
use SyntaxKind :: * ;
24
24
match kind {
25
- IfKw | MatchKw | LBrace | LParen | LBracket => true ,
25
+ IfKw | MatchKw | LBrace | LParen | LBracket | UnsafeKw => true ,
26
26
kind if lit:: is_lit ( kind) => true ,
27
27
kind if path:: is_path_segment ( kind) => true ,
28
28
_ => false ,
@@ -38,6 +38,7 @@ pub(super) fn parse_expr_atom<S: TokenStream>(
38
38
match parser. current_kind ( ) {
39
39
Some ( IfKw ) => parser. parse_cp ( IfExprScope :: default ( ) , None ) ,
40
40
Some ( MatchKw ) => parser. parse_cp ( MatchExprScope :: default ( ) , None ) ,
41
+ Some ( UnsafeKw ) => parser. parse_cp ( UnsafeExprScope :: default ( ) , None ) ,
41
42
Some ( LBrace ) => parser. parse_cp ( BlockExprScope :: default ( ) , None ) ,
42
43
Some ( LParen ) => parser. parse_cp ( ParenScope :: default ( ) , None ) ,
43
44
Some ( LBracket ) => parser. parse_cp ( ArrayScope :: default ( ) , None ) ,
@@ -83,8 +84,21 @@ impl super::Parse for BlockExprScope {
83
84
. map ( SyntaxKind :: is_item_head)
84
85
. unwrap_or_default ( )
85
86
{
86
- parser. parse ( ItemScope :: default ( ) ) ?;
87
- continue ;
87
+ let is_item = parser. dry_run ( |parser| {
88
+ if parser. bump_if ( SyntaxKind :: UnsafeKw ) {
89
+ parser
90
+ . current_kind ( )
91
+ . map ( SyntaxKind :: is_item_head)
92
+ . unwrap_or_default ( )
93
+ } else {
94
+ true
95
+ }
96
+ } ) ;
97
+
98
+ if is_item {
99
+ parser. parse ( ItemScope :: default ( ) ) ?;
100
+ continue ;
101
+ }
88
102
}
89
103
90
104
parse_stmt ( parser) ?;
@@ -131,6 +145,17 @@ impl super::Parse for IfExprScope {
131
145
}
132
146
}
133
147
148
+ define_scope ! { UnsafeExprScope , UnsafeExpr }
149
+ impl super :: Parse for UnsafeExprScope {
150
+ type Error = Recovery < ErrProof > ;
151
+
152
+ fn parse < S : TokenStream > ( & mut self , parser : & mut Parser < S > ) -> Result < ( ) , Self :: Error > {
153
+ parser. bump_expected ( SyntaxKind :: UnsafeKw ) ;
154
+
155
+ parse_expr ( parser)
156
+ }
157
+ }
158
+
134
159
define_scope ! { MatchExprScope , MatchExpr }
135
160
impl super :: Parse for MatchExprScope {
136
161
type Error = Recovery < ErrProof > ;
0 commit comments