@@ -37,10 +37,13 @@ pub(super) fn item_in_module_is_visible(
37
37
38
38
/// Returns true if the given ModuleDefId is visible from the current module, given its visibility.
39
39
/// This will in turn check if the ModuleDefId parent modules are visible from the current module.
40
+ /// If `defining_module` is Some, it will be considered as the parent of the item to check
41
+ /// (this is the case when the item is re-exported with `pub use` or similar).
40
42
pub ( super ) fn module_def_id_is_visible (
41
43
module_def_id : ModuleDefId ,
42
44
current_module_id : ModuleId ,
43
45
mut visibility : ItemVisibility ,
46
+ mut defining_module : Option < ModuleId > ,
44
47
interner : & NodeInterner ,
45
48
def_maps : & BTreeMap < CrateId , CrateDefMap > ,
46
49
) -> bool {
@@ -49,7 +52,7 @@ pub(super) fn module_def_id_is_visible(
49
52
let mut target_module_id = if let ModuleDefId :: ModuleId ( module_id) = module_def_id {
50
53
Some ( module_id)
51
54
} else {
52
- get_parent_module ( interner, module_def_id)
55
+ std :: mem :: take ( & mut defining_module ) . or_else ( || get_parent_module ( interner, module_def_id) )
53
56
} ;
54
57
55
58
// Then check if it's visible, and upwards
@@ -58,10 +61,11 @@ pub(super) fn module_def_id_is_visible(
58
61
return false ;
59
62
}
60
63
61
- let module_data = & def_maps[ & module_id. krate ] . modules ( ) [ module_id. local_id . 0 ] ;
62
- let parent_local_id = module_data. parent ;
63
- target_module_id =
64
- parent_local_id. map ( |local_id| ModuleId { krate : module_id. krate , local_id } ) ;
64
+ target_module_id = std:: mem:: take ( & mut defining_module) . or_else ( || {
65
+ let module_data = & def_maps[ & module_id. krate ] . modules ( ) [ module_id. local_id . 0 ] ;
66
+ let parent_local_id = module_data. parent ;
67
+ parent_local_id. map ( |local_id| ModuleId { krate : module_id. krate , local_id } )
68
+ } ) ;
65
69
66
70
// This is a bit strange, but the visibility is always that of the item inside another module,
67
71
// so the visibility we update here is for the next loop check.
0 commit comments