about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorYacin Tmimi <yacintmimi@gmail.com>2023-03-30 13:18:28 -0400
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2023-06-19 09:58:12 -0500
commitac2ebd3a78246d2dab16aec39d2aaace618a17eb (patch)
tree707ae935bea793131bd3bb22357d1ca22dcef497 /src
parenta463f231f5410ceca88f3eb5dfb8a85b97a63b25 (diff)
downloadrust-ac2ebd3a78246d2dab16aec39d2aaace618a17eb.tar.gz
rust-ac2ebd3a78246d2dab16aec39d2aaace618a17eb.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/parse/macros/cfg_if.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/parse/macros/cfg_if.rs b/src/parse/macros/cfg_if.rs
index ac03409a784..cbc4c90b8f9 100644
--- a/src/parse/macros/cfg_if.rs
+++ b/src/parse/macros/cfg_if.rs
@@ -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