aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2021-06-27 16:59:57 +0200
committerMark Wielaard <mark@klomp.org>2021-06-27 16:59:57 +0200
commit69ed5eaef43c2997c584347a438b5db8351666d8 (patch)
tree89cf03f5129a254c253b3a052e006bf2df9dd990
parent54e0d0171932b7c43e69f685e5fe41d473ddf5bf (diff)
downloadgcc-69ed5eaef43c2997c584347a438b5db8351666d8.zip
gcc-69ed5eaef43c2997c584347a438b5db8351666d8.tar.gz
gcc-69ed5eaef43c2997c584347a438b5db8351666d8.tar.bz2
Fix inner attribute parsing
parse_inner_attribute tried to skip the right square token twice. This caused odd error messages in case there were multiple inner attributes. This bug masked another bug in parse_attr_input where when the (optional) attr input was an assignment to a literal the parser failed to skip the literal. The existing top_attr.rs testcase relied on the two bugs cancelling each other out. Add a new testcase inner_attributes.rs for the first bug. Resolves: https://github.com/Rust-GCC/gccrs/issues/510
-rw-r--r--gcc/rust/parse/rust-parse-impl.h2
-rw-r--r--gcc/testsuite/rust/compile/torture/inner_attributes.rs3
2 files changed, 4 insertions, 1 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 014beaf..23e6234 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -495,7 +495,6 @@ Parser<ManagedTokenSource>::parse_inner_attribute ()
return AST::Attribute::create_empty ();
AST::Attribute actual_attribute = parse_attribute_body ();
- lexer.skip_token ();
if (!skip_token (RIGHT_SQUARE))
return AST::Attribute::create_empty ();
@@ -785,6 +784,7 @@ Parser<ManagedTokenSource>::parse_attr_input ()
// create actual LiteralExpr
AST::LiteralExpr lit_expr (t->get_str (), lit_type, t->get_type_hint (),
{}, t->get_locus ());
+ lexer.skip_token ();
std::unique_ptr<AST::AttrInput> attr_input_lit (
new AST::AttrInputLiteral (std::move (lit_expr)));
diff --git a/gcc/testsuite/rust/compile/torture/inner_attributes.rs b/gcc/testsuite/rust/compile/torture/inner_attributes.rs
new file mode 100644
index 0000000..3410dd6
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/inner_attributes.rs
@@ -0,0 +1,3 @@
+#![allow(dead_code)]
+#![allow(unused_variables)]
+pub fn main () { }