diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2021-07-06 14:43:03 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2021-07-07 11:30:08 +0200 |
| commit | e948e8de79cdb4a178239a8932b11601a81eca56 (patch) | |
| tree | c9ada6b4e12e7b22545ac7a5d5e7abe6784ef5ad | |
| parent | 84f259e44c97f787fc3dc5f5c596644b75f32e69 (diff) | |
| download | rust-e948e8de79cdb4a178239a8932b11601a81eca56.tar.gz rust-e948e8de79cdb4a178239a8932b11601a81eca56.zip | |
Fix reexports visibility
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 37 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 25 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 1 |
3 files changed, 30 insertions, 33 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index f71720af7ef..b3b89e6e673 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -41,6 +41,7 @@ type Attrs<'hir> = rustc_middle::ty::Attributes<'hir>; crate fn try_inline( cx: &mut DocContext<'_>, parent_module: DefId, + import_def_id: Option<DefId>, res: Res, name: Symbol, attrs: Option<Attrs<'_>>, @@ -108,7 +109,7 @@ crate fn try_inline( clean::ConstantItem(build_const(cx, did)) } Res::Def(DefKind::Macro(kind), did) => { - let mac = build_macro(cx, did, name); + let mac = build_macro(cx, did, name, import_def_id); let type_kind = match kind { MacroKind::Bang => ItemType::Macro, @@ -123,14 +124,13 @@ crate fn try_inline( let (attrs, cfg) = merge_attrs(cx, Some(parent_module), load_attrs(cx, did), attrs_clone); cx.inlined.insert(did.into()); - ret.push(clean::Item::from_def_id_and_attrs_and_parts( - did, - Some(name), - kind, - box attrs, - cx, - cfg, - )); + let mut item = + clean::Item::from_def_id_and_attrs_and_parts(did, Some(name), kind, box attrs, cx, cfg); + if let Some(import_def_id) = import_def_id { + // The visibility needs to reflect the one from the reexport and not from the "source" DefId. + item.visibility = cx.tcx.visibility(import_def_id).clean(cx); + } + ret.push(item); Some(ret) } @@ -509,7 +509,9 @@ fn build_module( )), cfg: None, }); - } else if let Some(i) = try_inline(cx, did, item.res, item.ident.name, None, visited) { + } else if let Some(i) = + try_inline(cx, did, None, item.res, item.ident.name, None, visited) + { items.extend(i) } } @@ -543,13 +545,24 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St } } -fn build_macro(cx: &mut DocContext<'_>, def_id: DefId, name: Symbol) -> clean::ItemKind { +fn build_macro( + cx: &mut DocContext<'_>, + def_id: DefId, + name: Symbol, + import_def_id: Option<DefId>, +) -> clean::ItemKind { let imported_from = cx.tcx.crate_name(def_id.krate); match cx.enter_resolver(|r| r.cstore().load_macro_untracked(def_id, cx.sess())) { LoadedMacro::MacroDef(item_def, _) => { if let ast::ItemKind::MacroDef(ref def) = item_def.kind { clean::MacroItem(clean::Macro { - source: utils::display_macro_source(cx, name, def, def_id, item_def.vis), + source: utils::display_macro_source( + cx, + name, + def, + def_id, + cx.tcx.visibility(import_def_id.unwrap_or(def_id)), + ), imported_from: Some(imported_from), }) } else { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7b359ee42c1..15fe840d65f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -10,7 +10,6 @@ crate mod types; crate mod utils; use rustc_ast as ast; -use rustc_ast_lowering::ResolverAstLowering; use rustc_attr as attr; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; @@ -1697,23 +1696,6 @@ impl Clean<Visibility> for hir::Visibility<'_> { } } -impl Clean<Visibility> for ast::Visibility { - fn clean(&self, cx: &mut DocContext<'_>) -> Visibility { - match self.kind { - ast::VisibilityKind::Public => Visibility::Public, - ast::VisibilityKind::Inherited => Visibility::Inherited, - ast::VisibilityKind::Crate(_) => { - let krate = DefId::local(CRATE_DEF_INDEX); - Visibility::Restricted(krate) - } - ast::VisibilityKind::Restricted { id, .. } => { - let did = cx.enter_resolver(|r| r.local_def_id(id)).to_def_id(); - Visibility::Restricted(did) - } - } - } -} - impl Clean<Visibility> for ty::Visibility { fn clean(&self, _cx: &mut DocContext<'_>) -> Visibility { match *self { @@ -2015,6 +1997,7 @@ fn clean_extern_crate( if let Some(items) = inline::try_inline( cx, cx.tcx.parent_module(krate.hir_id()).to_def_id(), + Some(krate.def_id.to_def_id()), res, name, Some(attrs), @@ -2070,7 +2053,7 @@ fn clean_use_statement( // forcefully don't inline if this is not public or if the // #[doc(no_inline)] attribute is present. // Don't inline doc(hidden) imports so they can be stripped at a later stage. - let mut denied = !import.vis.node.is_pub() + let mut denied = (!import.vis.node.is_pub() && !cx.render_options.document_private) || pub_underscore || attrs.iter().any(|a| { a.has_name(sym::doc) @@ -2106,17 +2089,19 @@ fn clean_use_statement( } if !denied { let mut visited = FxHashSet::default(); + let import_def_id = import.def_id.to_def_id(); if let Some(mut items) = inline::try_inline( cx, cx.tcx.parent_module(import.hir_id()).to_def_id(), + Some(import_def_id), path.res, name, Some(attrs), &mut visited, ) { items.push(Item::from_def_id_and_parts( - import.def_id.to_def_id(), + import_def_id, None, ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)), cx, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 4f51a00f4ff..64a9905b33f 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -31,7 +31,6 @@ extern crate tracing; // Dependencies listed in Cargo.toml do not need `extern crate`. extern crate rustc_ast; -extern crate rustc_ast_lowering; extern crate rustc_ast_pretty; extern crate rustc_attr; extern crate rustc_data_structures; |
