Skip to content

Commit

Permalink
Parse builtin# syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 14, 2023
1 parent dad8eba commit 6329fec
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,7 @@ pub(crate) mod parsing {
use std::cmp::Ordering;

mod kw {
crate::custom_keyword!(builtin);
crate::custom_keyword!(raw);
}

Expand Down Expand Up @@ -1594,6 +1595,8 @@ pub(crate) mod parsing {
|| input.peek(Token![async]) && (input.peek2(Token![|]) || input.peek2(Token![move]))
{
expr_closure(input, allow_struct).map(Expr::Closure)
} else if input.peek(kw::builtin) && input.peek2(Token![#]) {
expr_builtin(input)
} else if input.peek(Ident)
|| input.peek(Token![::])
|| input.peek(Token![<])
Expand Down Expand Up @@ -1692,6 +1695,20 @@ pub(crate) mod parsing {
}
}

fn expr_builtin(input: ParseStream) -> Result<Expr> {
let begin = input.fork();

input.parse::<kw::builtin>()?;
input.parse::<Token![#]>()?;
input.parse::<Ident>()?;

let args;
parenthesized!(args in input);
args.parse::<TokenStream>()?;

Ok(Expr::Verbatim(verbatim::between(begin, input)))
}

fn path_or_macro_or_struct(
input: ParseStream,
#[cfg(feature = "full")] allow_struct: AllowStruct,
Expand Down

0 comments on commit 6329fec

Please sign in to comment.