X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustdoc%2Fclean%2Finline.rs;h=b3b89e6e673a29f1a438e3ce3d6d9ebaeab5e17b;hb=c7d6bcc788ef6b2293d2d5166a9b0339d5d03b0a;hp=175c7facfdbeb7c89430ba66504c8239fcb6c307;hpb=c630b6b0fc21bf8dfcd49d9e8e675bbde4822a17;p=rust.git diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 175c7facfdb..b3b89e6e673 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -41,6 +41,7 @@ crate fn try_inline( cx: &mut DocContext<'_>, parent_module: DefId, + import_def_id: Option, res: Res, name: Symbol, attrs: Option>, @@ -108,7 +109,7 @@ 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 @@ 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,21 +545,26 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St } } -fn build_macro(cx: &mut DocContext<'_>, did: DefId, name: Symbol) -> clean::ItemKind { - let imported_from = cx.tcx.crate_name(did.krate); - match cx.enter_resolver(|r| r.cstore().load_macro_untracked(did, cx.sess())) { - LoadedMacro::MacroDef(def, _) => { - if let ast::ItemKind::MacroDef(ref def) = def.kind { - let tts: Vec<_> = def.body.inner_tokens().into_trees().collect(); - let matchers = tts.chunks(4).map(|arm| &arm[0]); - - let source = format!( - "macro_rules! {} {{\n{}}}", - name, - utils::render_macro_arms(matchers, ";") - ); - - clean::MacroItem(clean::Macro { source, imported_from: Some(imported_from) }) +fn build_macro( + cx: &mut DocContext<'_>, + def_id: DefId, + name: Symbol, + import_def_id: Option, +) -> 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, + cx.tcx.visibility(import_def_id.unwrap_or(def_id)), + ), + imported_from: Some(imported_from), + }) } else { unreachable!() }