@@ -1939,11 +1939,11 @@ impl<'a> Parser<'a> {
1939
1939
/// Parse `builtin # ident(args,*)`.
1940
1940
fn parse_expr_builtin ( & mut self ) -> PResult < ' a , P < Expr > > {
1941
1941
self . parse_builtin ( |this, lo, ident| {
1942
- if ident. name == sym :: offset_of {
1943
- return Ok ( Some ( this. parse_expr_offset_of ( lo) ?) ) ;
1944
- }
1945
-
1946
- Ok ( None )
1942
+ Ok ( match ident. name {
1943
+ sym :: offset_of => Some ( this. parse_expr_offset_of ( lo) ?) ,
1944
+ sym :: type_ascribe => Some ( this . parse_expr_type_ascribe ( lo ) ? ) ,
1945
+ _ => None ,
1946
+ } )
1947
1947
} )
1948
1948
}
1949
1949
@@ -1978,6 +1978,7 @@ impl<'a> Parser<'a> {
1978
1978
ret
1979
1979
}
1980
1980
1981
+ /// Built-in macro for `offset_of!` expressions.
1981
1982
pub ( crate ) fn parse_expr_offset_of ( & mut self , lo : Span ) -> PResult < ' a , P < Expr > > {
1982
1983
let container = self . parse_ty ( ) ?;
1983
1984
self . expect ( & TokenKind :: Comma ) ?;
@@ -2007,6 +2008,15 @@ impl<'a> Parser<'a> {
2007
2008
Ok ( self . mk_expr ( span, ExprKind :: OffsetOf ( container, fields) ) )
2008
2009
}
2009
2010
2011
+ /// Built-in macro for type ascription expressions.
2012
+ pub ( crate ) fn parse_expr_type_ascribe ( & mut self , lo : Span ) -> PResult < ' a , P < Expr > > {
2013
+ let expr = self . parse_expr ( ) ?;
2014
+ self . expect ( & token:: Comma ) ?;
2015
+ let ty = self . parse_ty ( ) ?;
2016
+ let span = lo. to ( self . token . span ) ;
2017
+ Ok ( self . mk_expr ( span, ExprKind :: Type ( expr, ty) ) )
2018
+ }
2019
+
2010
2020
/// Returns a string literal if the next token is a string literal.
2011
2021
/// In case of error returns `Some(lit)` if the next token is a literal with a wrong kind,
2012
2022
/// and returns `None` if the next token is not literal at all.
0 commit comments