diff options
| author | inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> | 2021-11-16 21:05:08 -0800 |
|---|---|---|
| committer | inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> | 2021-11-16 21:05:08 -0800 |
| commit | 7b3978ec3e969b50ae794c19093676e101505951 (patch) | |
| tree | a792d0b9194a97af763b091673672367b956414b | |
| parent | d914f17ca71a33a89b2dc3436fca51b1a091559e (diff) | |
| download | rust-7b3978ec3e969b50ae794c19093676e101505951.tar.gz rust-7b3978ec3e969b50ae794c19093676e101505951.zip | |
Avoid documenting top-level private imports
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 70401065689..8679b3dfb7e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1938,8 +1938,20 @@ fn clean_use_statement( let inline_attr = attrs.lists(sym::doc).get_word_attr(sym::inline); let pub_underscore = visibility.is_public() && name == kw::Underscore; let current_mod = cx.tcx.parent_module_from_def_id(import.def_id); + + // The parent of the module in which this import resides. This + // is the same as `current_mod` if that's already the top + // level module. let parent_mod = cx.tcx.parent_module_from_def_id(current_mod); + // This checks if the import can be seen from a higher level module. + // In other words, it checks if the visibility is the equivalent of + // `pub(super)` or higher. If the current module is the top level + // module, there isn't really a parent module, which makes the results + // meaningless. In this case, we make sure the answer is `false`. + let is_visible_from_parent_mod = visibility.is_accessible_from(parent_mod.to_def_id(), cx.tcx) + && !current_mod.is_top_level_module(); + if pub_underscore { if let Some(ref inline) = inline_attr { rustc_errors::struct_span_err!( @@ -1958,8 +1970,7 @@ fn clean_use_statement( // #[doc(no_inline)] attribute is present. // Don't inline doc(hidden) imports so they can be stripped at a later stage. let mut denied = !(visibility.is_public() - || (cx.render_options.document_private - && visibility.is_accessible_from(parent_mod.to_def_id(), cx.tcx))) + || (cx.render_options.document_private && is_visible_from_parent_mod)) || pub_underscore || attrs.iter().any(|a| { a.has_name(sym::doc) |
