From c4077cc2a8c9ade9bd9b61804d756fcfc2cc9931 Mon Sep 17 00:00:00 2001 From: CohenArthur Date: Tue, 3 Aug 2021 16:25:12 +0200 Subject: expand: Merge both implementations for both module types --- gcc/rust/expand/rust-macro-expand.cc | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 28d14ba..0a25471 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -2015,7 +2015,7 @@ public: "cannot strip block expression in this position - outer " "attributes not allowed"); } - void visit (AST::ModuleBodied &module) override + void visit (AST::Module &module) override { // strip test based on outer attrs expander.expand_cfg_attrs (module.get_outer_attrs ()); @@ -2025,27 +2025,21 @@ public: return; } - // strip test based on inner attrs - expander.expand_cfg_attrs (module.get_inner_attrs ()); - if (expander.fails_cfg_with_expand (module.get_inner_attrs ())) + // A loaded module might have inner attributes + if (module.get_kind () == AST::Module::ModuleKind::LOADED) { - module.mark_for_strip (); - return; + // strip test based on inner attrs + expander.expand_cfg_attrs (module.get_inner_attrs ()); + if (expander.fails_cfg_with_expand (module.get_inner_attrs ())) + { + module.mark_for_strip (); + return; + } } // strip items if required expand_pointer_allow_strip (module.get_items ()); } - void visit (AST::ModuleNoBody &module) override - { - // strip test based on outer attrs - expander.expand_cfg_attrs (module.get_outer_attrs ()); - if (expander.fails_cfg_with_expand (module.get_outer_attrs ())) - { - module.mark_for_strip (); - return; - } - } void visit (AST::ExternCrate &crate) override { // strip test based on outer attrs -- cgit v1.1