fix doc links on extern crate
items
This commit is contained in:
parent
9ebd8095fa
commit
bb98f3ad4d
@ -2643,15 +2643,12 @@ fn clean_extern_crate<'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
|
||||
vec![Item {
|
||||
name: Some(name),
|
||||
attrs: Box::new(Attributes::from_ast(attrs)),
|
||||
item_id: crate_def_id.into(),
|
||||
kind: Box::new(ExternCrateItem { src: orig_name }),
|
||||
cfg: attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),
|
||||
inline_stmt_id: Some(krate_owner_def_id),
|
||||
}]
|
||||
vec![Item::from_def_id_and_parts(
|
||||
krate_owner_def_id,
|
||||
Some(name),
|
||||
ExternCrateItem { src: orig_name },
|
||||
cx,
|
||||
)]
|
||||
}
|
||||
|
||||
fn clean_use_statement<'tcx>(
|
||||
|
@ -38,11 +38,15 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate {
|
||||
for it in &module.items {
|
||||
// `compiler_builtins` should be masked too, but we can't apply
|
||||
// `#[doc(masked)]` to the injected `extern crate` because it's unstable.
|
||||
if it.is_extern_crate()
|
||||
&& (it.attrs.has_doc_flag(sym::masked)
|
||||
|| cx.tcx.is_compiler_builtins(it.item_id.krate()))
|
||||
{
|
||||
if cx.tcx.is_compiler_builtins(it.item_id.krate()) {
|
||||
cx.cache.masked_crates.insert(it.item_id.krate());
|
||||
} else if it.is_extern_crate()
|
||||
&& it.attrs.has_doc_flag(sym::masked)
|
||||
&& let Some(def_id) = it.item_id.as_def_id()
|
||||
&& let Some(local_def_id) = def_id.as_local()
|
||||
&& let Some(cnum) = cx.tcx.extern_mod_stmt_cnum(local_def_id)
|
||||
{
|
||||
cx.cache.masked_crates.insert(cnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc_metadata::creader::{CStore, LoadedMacro};
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
@ -662,6 +662,14 @@ pub(crate) fn href_with_root_path(
|
||||
// documented on their parent's page
|
||||
tcx.parent(did)
|
||||
}
|
||||
DefKind::ExternCrate => {
|
||||
// Link to the crate itself, not the `extern crate` item.
|
||||
if let Some(local_did) = did.as_local() {
|
||||
tcx.extern_mod_stmt_cnum(local_did).unwrap_or(LOCAL_CRATE).as_def_id()
|
||||
} else {
|
||||
did
|
||||
}
|
||||
}
|
||||
_ => did,
|
||||
};
|
||||
let cache = cx.cache();
|
||||
|
@ -4,10 +4,11 @@
|
||||
// ignore-cross-compile
|
||||
|
||||
// @has issue_33178/index.html
|
||||
// @has - //a/@title empty
|
||||
// @has - //a/@href ../empty/index.html
|
||||
// @has - '//a[@title="mod empty"][@href="../empty/index.html"]' empty
|
||||
pub extern crate empty;
|
||||
|
||||
// @has - //a/@title variant_struct
|
||||
// @has - //a/@href ../variant_struct/index.html
|
||||
// @has - '//a[@title="mod variant_struct"][@href="../variant_struct/index.html"]' variant_struct
|
||||
pub extern crate variant_struct as foo;
|
||||
|
||||
// @has - '//a[@title="mod issue_33178"][@href="index.html"]' self
|
||||
pub extern crate self as bar;
|
||||
|
Loading…
Reference in New Issue
Block a user