aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/rust/hir/rust-ast-lower-item.cc5
-rw-r--r--gcc/testsuite/rust/compile/macro44.rs34
2 files changed, 38 insertions, 1 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc
index fefc938..336be5b 100644
--- a/gcc/rust/hir/rust-ast-lower-item.cc
+++ b/gcc/rust/hir/rust-ast-lower-item.cc
@@ -59,7 +59,10 @@ ASTLoweringItem::visit (AST::Module &module)
for (auto &item : module.get_items ())
{
auto transitem = translate (item.get ());
- items.push_back (std::unique_ptr<Item> (transitem));
+ // The item may be null if it doesn't need to live in the HIR - for
+ // example, macro rules definitions
+ if (transitem)
+ items.push_back (std::unique_ptr<Item> (transitem));
}
// should be lowered/copied from module.get_in/outer_attrs()
diff --git a/gcc/testsuite/rust/compile/macro44.rs b/gcc/testsuite/rust/compile/macro44.rs
new file mode 100644
index 0000000..84b2cdb
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macro44.rs
@@ -0,0 +1,34 @@
+mod foo {
+ mod bar {
+ mod baz {
+ macro_rules! baz {
+ () => {{}};
+ }
+ }
+ }
+
+ macro_rules! foo {
+ () => {{}};
+ }
+
+ fn foo_f() { // { dg-warning "function is never used" }
+ foo!();
+ }
+
+ fn bar_f() { // { dg-warning "function is never used" }
+ baz!();
+ }
+}
+
+mod foo2 {
+ #[macro_export]
+ macro_rules! bar1 {
+ () => {};
+ }
+
+ macro_rules! bar2 {
+ () => {};
+ }
+}
+
+fn main() {}