Skip to content

Commit

Permalink
Move none-delimited attr behavior only to exprs
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jun 20, 2020
1 parent ef51ded commit 4147689
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl Attribute {
#[cfg(feature = "parsing")]
pub fn parse_outer(input: ParseStream) -> Result<Vec<Self>> {
let mut attrs = Vec::new();
while input.peek(Token![#]) && !input.peek(token::Group) {
while input.peek(Token![#]) {
attrs.push(input.call(parsing::single_parse_outer)?);
}
Ok(attrs)
Expand All @@ -276,7 +276,7 @@ impl Attribute {
#[cfg(feature = "parsing")]
pub fn parse_inner(input: ParseStream) -> Result<Vec<Self>> {
let mut attrs = Vec::new();
while input.peek(Token![#]) && input.peek2(Token![!]) && !input.peek(token::Group) {
while input.peek(Token![#]) && input.peek2(Token![!]) {
attrs.push(input.call(parsing::single_parse_inner)?);
}
Ok(attrs)
Expand Down
26 changes: 25 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,14 +1543,38 @@ pub(crate) mod parsing {
parse_expr(input, lhs, allow_struct, Precedence::Any)
}

#[cfg(feature = "full")]
fn expr_attrs(input: ParseStream) -> Result<Vec<Attribute>> {
let mut attrs = Vec::new();
loop {
if input.peek(token::Group) {
let ahead = input.fork();
let group = crate::group::parse_group(&ahead)?;
if !group.content.peek(Token![#]) || group.content.peek2(Token![!]) {
break;
}
let attr = group.content.call(attr::parsing::single_parse_outer)?;
if !group.content.is_empty() {
break;
}
attrs.push(attr);
} else if input.peek(Token![#]) {
attrs.push(input.call(attr::parsing::single_parse_outer)?);
} else {
break;
}
}
Ok(attrs)
}

// <UnOp> <trailer>
// & <trailer>
// &mut <trailer>
// box <trailer>
#[cfg(feature = "full")]
fn unary_expr(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
let begin = input.fork();
let attrs = input.call(Attribute::parse_outer)?;
let attrs = input.call(expr_attrs)?;
if input.peek(Token![&]) {
let and_token: Token![&] = input.parse()?;
let raw: Option<raw> =
Expand Down

0 comments on commit 4147689

Please sign in to comment.