Avoid documenting top-level private imports

This commit is contained in:
inquisitivecrystal 2021-11-16 21:05:08 -08:00
parent d914f17ca7
commit 7b3978ec3e

@ -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)