Prevent ICE when calling parse_attribute without an attribute
Fixes 5729 `parse_attribute` will panic if the first token is not a `#`. To prevent this we return early instead of trying to parse an invalid attribute.
This commit is contained in:
parent
a463f231f5
commit
ac2ebd3a78
3 changed files with 11 additions and 1 deletions
|
|
@ -34,6 +34,11 @@ fn parse_cfg_if_inner<'a>(
|
|||
if !parser.eat_keyword(kw::If) {
|
||||
return Err("Expected `if`");
|
||||
}
|
||||
|
||||
if !matches!(parser.token.kind, TokenKind::Pound) {
|
||||
return Err("Failed to parse attributes");
|
||||
}
|
||||
|
||||
// Inner attributes are not actually syntactically permitted here, but we don't
|
||||
// care about inner vs outer attributes in this position. Our purpose with this
|
||||
// special case parsing of cfg_if macros is to ensure we can correctly resolve
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue