]> git.proxmox.com Git - rustc.git/blame - vendor/rustversion/src/attr.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / vendor / rustversion / src / attr.rs
CommitLineData
f20569fa
XL
1use crate::error::{Error, Result};
2use crate::expr::{self, Expr};
3use crate::{iter, token};
4use proc_macro::{Span, TokenStream};
5
6pub struct Args {
7 pub condition: Expr,
8 pub then: Then,
9}
10
11pub enum Then {
12 Const(Span),
13 Attribute(TokenStream),
14}
15
16pub fn parse(input: TokenStream) -> Result<Args> {
17 let ref mut input = iter::new(input);
18 let condition = expr::parse(input)?;
19
20 token::parse_punct(input, ',')?;
21 if input.peek().is_none() {
22 return Err(Error::new(Span::call_site(), "expected one or more attrs"));
23 }
24
25 let const_span = token::parse_optional_keyword(input, "const");
26 let then = if let Some(const_span) = const_span {
27 token::parse_optional_punct(input, ',');
28 token::parse_end(input)?;
29 Then::Const(const_span)
30 } else {
31 Then::Attribute(input.collect())
32 };
33
34 Ok(Args { condition, then })
35}