aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-07-18 16:16:12 +0100
committerPhilip Herron <philip.herron@embecosm.com>2022-07-18 16:18:02 +0100
commit3bf3ea88786c43f81064f913d62115a48aac9f44 (patch)
treeb1ab6903f8e9d5bb1d544f40b3b9fca5eee7ba22 /gcc
parent6920d2294b3c6f106478fd3decaa511faf3cac84 (diff)
downloadgcc-3bf3ea88786c43f81064f913d62115a48aac9f44.zip
gcc-3bf3ea88786c43f81064f913d62115a48aac9f44.tar.gz
gcc-3bf3ea88786c43f81064f913d62115a48aac9f44.tar.bz2
Ensure we parse any inner item attributes when expanding a module
When compiling code containing module expansions we must first ensure any possible inner item attributes are parser first and applied to the module, otherwise we end up in a bad state and ignore attributes. Fixes #1089
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast-full-test.cc2
-rw-r--r--gcc/rust/parse/rust-parse.h2
-rw-r--r--gcc/testsuite/rust/compile/issue-1089.rs6
-rw-r--r--gcc/testsuite/rust/compile/test_mod.rs6
4 files changed, 15 insertions, 1 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc
index 25ec6db..cac816d 100644
--- a/gcc/rust/ast/rust-ast-full-test.cc
+++ b/gcc/rust/ast/rust-ast-full-test.cc
@@ -4056,6 +4056,8 @@ Module::load_items ()
Lexer lex (module_file.c_str (), std::move (file_wrap), linemap);
Parser<Lexer> parser (lex);
+ // we need to parse any possible inner attributes for this module
+ inner_attrs = parser.parse_inner_attributes ();
auto parsed_items = parser.parse_items ();
for (const auto &error : parser.get_errors ())
error.emit_error ();
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 4cae6ff..e4c5a2c 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -149,6 +149,7 @@ public:
std::unique_ptr<AST::IdentifierPattern> parse_identifier_pattern ();
std::unique_ptr<AST::TokenTree> parse_token_tree ();
AST::Attribute parse_attribute_body ();
+ AST::AttrVec parse_inner_attributes ();
private:
void skip_after_semicolon ();
@@ -164,7 +165,6 @@ private:
void parse_statement_seq (bool (Parser::*done) ());
// AST-related stuff - maybe move or something?
- AST::AttrVec parse_inner_attributes ();
AST::Attribute parse_inner_attribute ();
AST::AttrVec parse_outer_attributes ();
AST::Attribute parse_outer_attribute ();
diff --git a/gcc/testsuite/rust/compile/issue-1089.rs b/gcc/testsuite/rust/compile/issue-1089.rs
new file mode 100644
index 0000000..635af29
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1089.rs
@@ -0,0 +1,6 @@
+// { dg-additional-options "-w" }
+pub mod test_mod;
+
+fn main() {
+ let a = test_mod::Test(123);
+}
diff --git a/gcc/testsuite/rust/compile/test_mod.rs b/gcc/testsuite/rust/compile/test_mod.rs
new file mode 100644
index 0000000..4b3c000
--- /dev/null
+++ b/gcc/testsuite/rust/compile/test_mod.rs
@@ -0,0 +1,6 @@
+//! test_mod inner doc comment
+//!
+//! foo bar baz cake pizza carbs
+
+pub struct Test(pub i32);
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }