提交 82b3b070 编写于 作者: J Joshua Nelson

Support intra-doc links on trait and module re-exports

Trait implementations are treated the same as modules for the purposes
of intra-doc links.
上级 e63e5cda
......@@ -50,7 +50,8 @@ enum ErrorKind {
struct LinkCollector<'a, 'tcx> {
cx: &'a DocContext<'tcx>,
mod_ids: Vec<hir::HirId>,
// NOTE: this may not necessarily be a module in the current crate
mod_ids: Vec<DefId>,
}
impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
......@@ -445,17 +446,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
fn fold_item(&mut self, mut item: Item) -> Option<Item> {
use rustc_middle::ty::DefIdTree;
let item_hir_id = if item.is_mod() {
if let Some(def_id) = item.def_id.as_local() {
Some(self.cx.tcx.hir().as_local_hir_id(def_id))
} else {
debug!("attempting to fold on a non-local item: {:?}", item);
return self.fold_item_recur(item);
}
} else {
None
};
let parent_node = if item.is_fake() {
// FIXME: is this correct?
None
......@@ -482,13 +472,9 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
let current_item = match item.inner {
ModuleItem(..) => {
if item.attrs.inner_docs {
if item_hir_id.unwrap() != hir::CRATE_HIR_ID { item.name.clone() } else { None }
if item.def_id.is_top_level_module() { item.name.clone() } else { None }
} else {
match parent_node.or(self
.mod_ids
.last()
.map(|&local| self.cx.tcx.hir().local_def_id(local).to_def_id()))
{
match parent_node.or(self.mod_ids.last().copied()) {
Some(parent) if !parent.is_top_level_module() => {
// FIXME: can we pull the parent module's name from elsewhere?
Some(self.cx.tcx.item_name(parent).to_string())
......@@ -508,7 +494,7 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
};
if item.is_mod() && item.attrs.inner_docs {
self.mod_ids.push(item_hir_id.unwrap());
self.mod_ids.push(item.def_id);
}
let cx = self.cx;
......@@ -655,7 +641,7 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
// for outer comments we explicitly try and resolve against the
// parent_node first.
let base_node = if item.is_mod() && item.attrs.inner_docs {
self.mod_ids.last().map(|&id| self.cx.tcx.hir().local_def_id(id).to_def_id())
self.mod_ids.last().copied()
} else {
parent_node
};
......@@ -842,7 +828,7 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
}
if item.is_mod() && !item.attrs.inner_docs {
self.mod_ids.push(item_hir_id.unwrap());
self.mod_ids.push(item.def_id);
}
if item.is_mod() {
......
#![crate_name = "module_inner"]
#![deny(intra_doc_link_resolution_failure)]
/// [SomeType] links to [bar]
pub struct SomeType;
pub trait SomeTrait {}
/// [bar] links to [SomeTrait] and also [SomeType]
pub mod bar {}
#![crate_name = "inner"]
/// this is a trait
pub trait SomeTrait {
/// this is a method for [SomeTrait]
fn foo();
}
pub mod bar {
use super::SomeTrait;
pub struct BarStruct;
impl SomeTrait for BarStruct {
fn foo() {}
}
}
// outer.rs
// aux-build: module.rs
// build-aux-docs
#![deny(intra_doc_link_resolution_failure)]
extern crate module_inner;
// @has 'module/bar/index.html' '//a[@href="../../module_inner/trait.SomeTrait.html"]' 'SomeTrait'
// @has 'module/bar/index.html' '//a[@href="../../module_inner/struct.SomeType.html"]' 'SomeType'
pub use module_inner::bar;
// aux-build:traits.rs
// build-aux-docs
// ignore-tidy-line-length
#![deny(intra_doc_link_resolution_failure)]
extern crate inner;
use inner::SomeTrait;
pub struct SomeStruct;
// @has 'traits/struct.SomeStruct.html' '//a[@href="../inner/trait.SomeTrait.html"]' 'SomeTrait'
impl SomeTrait for SomeStruct {
// @has 'traits/struct.SomeStruct.html' '//a[@href="../inner/trait.SomeTrait.html"]' 'SomeTrait'
fn foo() {}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册