@@ -1938,8 +1938,20 @@ fn clean_use_statement(
1938
1938
let inline_attr = attrs. lists ( sym:: doc) . get_word_attr ( sym:: inline) ;
1939
1939
let pub_underscore = visibility. is_public ( ) && name == kw:: Underscore ;
1940
1940
let current_mod = cx. tcx . parent_module_from_def_id ( import. def_id ) ;
1941
+
1942
+ // The parent of the module in which this import resides. This
1943
+ // is the same as `current_mod` if that's already the top
1944
+ // level module.
1941
1945
let parent_mod = cx. tcx . parent_module_from_def_id ( current_mod) ;
1942
1946
1947
+ // This checks if the import can be seen from a higher level module.
1948
+ // In other words, it checks if the visibility is the equivalent of
1949
+ // `pub(super)` or higher. If the current module is the top level
1950
+ // module, there isn't really a parent module, which makes the results
1951
+ // meaningless. In this case, we make sure the answer is `false`.
1952
+ let is_visible_from_parent_mod = visibility. is_accessible_from ( parent_mod. to_def_id ( ) , cx. tcx )
1953
+ && !current_mod. is_top_level_module ( ) ;
1954
+
1943
1955
if pub_underscore {
1944
1956
if let Some ( ref inline) = inline_attr {
1945
1957
rustc_errors:: struct_span_err!(
@@ -1958,8 +1970,7 @@ fn clean_use_statement(
1958
1970
// #[doc(no_inline)] attribute is present.
1959
1971
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
1960
1972
let mut denied = !( visibility. is_public ( )
1961
- || ( cx. render_options . document_private
1962
- && visibility. is_accessible_from ( parent_mod. to_def_id ( ) , cx. tcx ) ) )
1973
+ || ( cx. render_options . document_private && is_visible_from_parent_mod) )
1963
1974
|| pub_underscore
1964
1975
|| attrs. iter ( ) . any ( |a| {
1965
1976
a. has_name ( sym:: doc)
0 commit comments