From 41fbeec90c31a0e13e2884b63633919f73e10a08 Mon Sep 17 00:00:00 2001 From: Thomas Young Date: Fri, 21 May 2021 14:45:32 +0800 Subject: only parse inner_attributes if it start with #! not only # Fixed #419 --- gcc/rust/parse/rust-parse-impl.h | 4 +++- gcc/testsuite/rust.test/compile/top_attr.rs | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust.test/compile/top_attr.rs (limited to 'gcc') 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::parse_inner_attributes () { std::vector 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 -- cgit v1.1