aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorThomas Young <wenzhang5800@gmail.com>2021-05-21 14:45:32 +0800
committerThomas Young <wenzhang5800@gmail.com>2021-05-21 17:59:48 +0800
commit41fbeec90c31a0e13e2884b63633919f73e10a08 (patch)
treece5aa93f5be8ed4c92af2cc15b035de4aa174c46 /gcc
parent937352288b3ef8d54ff3edc1ef7153369b564d36 (diff)
downloadgcc-41fbeec90c31a0e13e2884b63633919f73e10a08.zip
gcc-41fbeec90c31a0e13e2884b63633919f73e10a08.tar.gz
gcc-41fbeec90c31a0e13e2884b63633919f73e10a08.tar.bz2
only parse inner_attributes if it start with #! not only #
Fixed #419
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h4
-rw-r--r--gcc/testsuite/rust.test/compile/top_attr.rs5
2 files changed, 8 insertions, 1 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 5dcb458..dc8c773 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -442,7 +442,9 @@ Parser<ManagedTokenSource>::parse_inner_attributes ()
{
std::vector<AST::Attribute> inner_attributes;
- while (lexer.peek_token ()->get_id () == HASH)
+ // only try to parse it if it starts with "#!" not only "#"
+ while (lexer.peek_token ()->get_id () == HASH
+ && lexer.peek_token (1)->get_id () == EXCLAM)
{
AST::Attribute inner_attr = parse_inner_attribute ();
diff --git a/gcc/testsuite/rust.test/compile/top_attr.rs b/gcc/testsuite/rust.test/compile/top_attr.rs
new file mode 100644
index 0000000..0671369
--- /dev/null
+++ b/gcc/testsuite/rust.test/compile/top_attr.rs
@@ -0,0 +1,5 @@
+#![crate_name = "name"]
+
+
+#[allow(dead_code)]
+fn main() {} \ No newline at end of file