@@ -1939,11 +1939,11 @@ impl<'a> Parser<'a> {
19391939 /// Parse `builtin # ident(args,*)`.
19401940 fn parse_expr_builtin ( & mut self ) -> PResult < ' a , P < Expr > > {
19411941 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+ } )
19471947 } )
19481948 }
19491949
@@ -1978,6 +1978,7 @@ impl<'a> Parser<'a> {
19781978 ret
19791979 }
19801980
1981+ /// built-in macro for offset_of!
19811982 pub ( crate ) fn parse_expr_offset_of ( & mut self , lo : Span ) -> PResult < ' a , P < Expr > > {
19821983 let container = self . parse_ty ( ) ?;
19831984 self . expect ( & TokenKind :: Comma ) ?;
@@ -2007,6 +2008,15 @@ impl<'a> Parser<'a> {
20072008 Ok ( self . mk_expr ( span, ExprKind :: OffsetOf ( container, fields) ) )
20082009 }
20092010
2011+ /// built-in macro for type ascription expression
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+
20102020 /// Returns a string literal if the next token is a string literal.
20112021 /// In case of error returns `Some(lit)` if the next token is a literal with a wrong kind,
20122022 /// and returns `None` if the next token is not literal at all.
0 commit comments