From b777d46ae61fce3c3a891eeda5b5d7c91fda3871 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 19 Apr 2021 01:06:04 +0200 Subject: Fix visibility of items in block modules --- crates/hir_def/src/visibility.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'crates/hir_def/src/visibility.rs') diff --git a/crates/hir_def/src/visibility.rs b/crates/hir_def/src/visibility.rs index 9908cd926..d4b7c9970 100644 --- a/crates/hir_def/src/visibility.rs +++ b/crates/hir_def/src/visibility.rs @@ -123,11 +123,19 @@ impl Visibility { def_map: &DefMap, mut from_module: crate::LocalModuleId, ) -> bool { - let to_module = match self { + let mut to_module = match self { Visibility::Module(m) => m, Visibility::Public => return true, }; + // `to_module` might be the root module of a block expression. Those have the same + // visibility as the containing module (even though no items are directly nameable from + // there, getting this right is important for method resolution). + // In that case, we adjust the visibility of `to_module` to point to the containing module. + if to_module.is_block_root(db) { + to_module = to_module.containing_module(db).unwrap(); + } + // from_module needs to be a descendant of to_module let mut def_map = def_map; let mut parent_arc; -- cgit v1.2.3