diff options
-rw-r--r-- | gcc/rust/privacy/rust-privacy-reporter.cc | 19 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/macro-issue1233.rs | 6 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/privacy2.rs | 13 |
3 files changed, 28 insertions, 10 deletions
diff --git a/gcc/rust/privacy/rust-privacy-reporter.cc b/gcc/rust/privacy/rust-privacy-reporter.cc index 4c18adb..a974de0 100644 --- a/gcc/rust/privacy/rust-privacy-reporter.cc +++ b/gcc/rust/privacy/rust-privacy-reporter.cc @@ -20,15 +20,22 @@ PrivacyReporter::go (HIR::Crate &crate) } static bool -is_child_module (NodeId current_module, - Optional<std::vector<NodeId> &> children) +is_child_module (Analysis::Mappings &mappings, NodeId parent, + NodeId possible_child) { + auto children = mappings.lookup_module_children (parent); + if (!children) return false; - // FIXME: This checks for one step - we need to go deeper + // Visit all toplevel children for (auto &child : *children) - if (child == current_module) + if (child == possible_child) + return true; + + // Now descend recursively in the child module tree + for (auto &child : *children) + if (is_child_module (mappings, child, possible_child)) return true; return false; @@ -72,11 +79,9 @@ PrivacyReporter::check_for_privacy_violation (const NodeId &use_id, if (mod_node_id == current_module.get ()) break; - auto children = mappings.lookup_module_children (mod_node_id); - // FIXME: This needs a LOT of TLC: hinting about the definition, a // string to say if it's a module, function, type, etc... - if (!is_child_module (current_module.get (), children)) + if (!is_child_module (mappings, mod_node_id, current_module.get ())) valid = false; } break; diff --git a/gcc/testsuite/rust/compile/macro-issue1233.rs b/gcc/testsuite/rust/compile/macro-issue1233.rs index d762bb7..7fab787 100644 --- a/gcc/testsuite/rust/compile/macro-issue1233.rs +++ b/gcc/testsuite/rust/compile/macro-issue1233.rs @@ -1,15 +1,15 @@ -// { dg-additional-options "-w" } +// { dg-additional-options "-frust-cfg=A -w" } macro_rules! impl_uint { ($($ty:ident = $lang:literal),*) => { $( impl $ty { pub fn to_le(self) -> Self { - #[cfg(not(target_endian = "little"))] + #[cfg(not(A))] { self } - #[cfg(target_endian = "little")] + #[cfg(A)] { self } diff --git a/gcc/testsuite/rust/compile/privacy2.rs b/gcc/testsuite/rust/compile/privacy2.rs new file mode 100644 index 0000000..3c07449 --- /dev/null +++ b/gcc/testsuite/rust/compile/privacy2.rs @@ -0,0 +1,13 @@ +// { dg-additional-options "-w" } + +mod orange { + fn tangerine() {} + + mod green { + mod blue { + fn berry() { + tangerine(); + } + } + } +} |