mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-22 20:01:22 -05:00
gccrs: module lowering: Do not append null pointers as items
Some module items do not need to get lowered to HIR such as `macro_rules!` definitions. Hence, module lowering should act the same as crate lowering: Only emplace back the lowered item if it is a valid pointer gcc/rust/ChangeLog: * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Do not lower null items within modules. gcc/testsuite/ChangeLog: * rust/compile/macro44.rs: New test.
This commit is contained in:
@@ -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()
|
||||
|
||||
34
gcc/testsuite/rust/compile/macro44.rs
Normal file
34
gcc/testsuite/rust/compile/macro44.rs
Normal file
@@ -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() {}
|
||||
Reference in New Issue
Block a user