Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #72222

Merged
merged 20 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e5a1be8
Use `LocalDefId` in `DumpVisitor::nest_tables`
marmeladema May 2, 2020
b6e4581
Add mipsel-sony-psp target
overdrivenpotato May 9, 2020
20a6691
Update stdarch
overdrivenpotato May 9, 2020
8961b08
Formatting
overdrivenpotato May 9, 2020
7e62240
Add lld_link_script to TargetOptions
overdrivenpotato May 10, 2020
7b649c7
Renamed lld_link_script to link_script and support all GNU-like linkers
overdrivenpotato May 10, 2020
7444494
Run rustfmt
overdrivenpotato May 10, 2020
6c41545
Provide separate option for std debug asserts
Mark-Simulacrum May 12, 2020
2b42a2b
Forbid stage arguments to check
Mark-Simulacrum May 13, 2020
617c7cd
Make intra links work inside trait impl block
May 13, 2020
425723f
Rewrite link script from scratch
overdrivenpotato May 14, 2020
c919a6e
Minor fixes to comments
JOE1994 May 14, 2020
00d42bb
Add prioritize_on attribute to triagebot
spastorino May 14, 2020
a264aca
Rollup merge of #71809 - marmeladema:fix-issue-71104, r=eddyb
Dylan-DPC May 14, 2020
d01ee6f
Rollup merge of #72062 - overdrivenpotato:psp, r=jonas-schievink
Dylan-DPC May 14, 2020
24cd427
Rollup merge of #72146 - Mark-Simulacrum:separate-std-asserts, r=alex…
Dylan-DPC May 14, 2020
7709688
Rollup merge of #72172 - Mark-Simulacrum:check-no-stage, r=alexcrichton
Dylan-DPC May 14, 2020
da0745a
Rollup merge of #72173 - xliiv:54172-intra-for-trait-impl, r=Guillaum…
Dylan-DPC May 14, 2020
b96ceba
Rollup merge of #72200 - spastorino:add-prioritize_on-to-triagebot, r…
Dylan-DPC May 14, 2020
49d50e6
Rollup merge of #72214 - JOE1994:nitpicky, r=jonas-schievink
Dylan-DPC May 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 55 additions & 11 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use rustc_hir::def_id::DefId;
use rustc_middle::ty;
use rustc_resolve::ParentScope;
use rustc_session::lint;
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::symbol::Ident;
use rustc_span::symbol::Symbol;
use rustc_span::DUMMY_SP;

use std::ops::Range;
Expand Down Expand Up @@ -130,6 +131,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
current_item: &Option<String>,
parent_id: Option<hir::HirId>,
extra_fragment: &Option<String>,
item_opt: Option<&Item>,
) -> Result<(Res, Option<String>), ErrorKind> {
let cx = self.cx;

Expand Down Expand Up @@ -230,16 +232,44 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias,
did,
) => {
let item = cx
.tcx
.inherent_impls(did)
.iter()
.flat_map(|imp| cx.tcx.associated_items(*imp).in_definition_order())
.find(|item| item.ident.name == item_name);
// We need item's parent to know if it's
// trait impl or struct/enum/etc impl
let item_parent = item_opt
.and_then(|item| self.cx.as_local_hir_id(item.def_id))
.and_then(|item_hir| {
let parent_hir = self.cx.tcx.hir().get_parent_item(item_hir);
self.cx.tcx.hir().find(parent_hir)
});
let item = match item_parent {
Some(hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl { of_trait: Some(_), self_ty, .. },
..
})) => {
// trait impl
cx.tcx
.associated_item_def_ids(self_ty.hir_id.owner)
.iter()
.map(|child| {
let associated_item = cx.tcx.associated_item(*child);
associated_item
})
.find(|child| child.ident.name == item_name)
}
_ => {
// struct/enum/etc. impl
cx.tcx
.inherent_impls(did)
.iter()
.flat_map(|imp| cx.tcx.associated_items(*imp).in_definition_order())
.find(|item| item.ident.name == item_name)
}
};

if let Some(item) = item {
let out = match item.kind {
ty::AssocKind::Fn if ns == ValueNS => "method",
ty::AssocKind::Const if ns == ValueNS => "associatedconstant",
ty::AssocKind::Type if ns == ValueNS => "associatedtype",
_ => return self.variant_field(path_str, current_item, module_id),
};
if extra_fragment.is_some() {
Expand Down Expand Up @@ -484,8 +514,14 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {

match kind {
Some(ns @ ValueNS) => {
match self.resolve(path_str, ns, &current_item, base_node, &extra_fragment)
{
match self.resolve(
path_str,
ns,
&current_item,
base_node,
&extra_fragment,
None,
) {
Ok(res) => res,
Err(ErrorKind::ResolutionFailure) => {
resolution_failure(cx, &item, path_str, &dox, link_range);
Expand All @@ -501,8 +537,14 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
}
}
Some(ns @ TypeNS) => {
match self.resolve(path_str, ns, &current_item, base_node, &extra_fragment)
{
match self.resolve(
path_str,
ns,
&current_item,
base_node,
&extra_fragment,
None,
) {
Ok(res) => res,
Err(ErrorKind::ResolutionFailure) => {
resolution_failure(cx, &item, path_str, &dox, link_range);
Expand All @@ -526,6 +568,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
&current_item,
base_node,
&extra_fragment,
None,
) {
Err(ErrorKind::AnchorFailure(msg)) => {
anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);
Expand All @@ -539,6 +582,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
&current_item,
base_node,
&extra_fragment,
Some(&item),
) {
Err(ErrorKind::AnchorFailure(msg)) => {
anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);
Expand Down
35 changes: 35 additions & 0 deletions src/test/rustdoc/intra-link-trait-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![crate_name = "foo"]

// ignore-tidy-linelength

pub struct MyStruct;

impl MyTrait for MyStruct {

// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#associatedtype.AssoType'

/// [`AssoType`]
///
/// [`AssoType`]: MyStruct::AssoType
type AssoType = u32;

// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#associatedconstant.ASSO_CONST'

/// [`ASSO_CONST`]
///
/// [`ASSO_CONST`]: MyStruct::ASSO_CONST
const ASSO_CONST: i32 = 10;

// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#method.trait_fn'

/// [`trait_fn`]
///
/// [`trait_fn`]: MyStruct::trait_fn
fn trait_fn() { }
}

pub trait MyTrait {
type AssoType;
const ASSO_CONST: i32 = 1;
fn trait_fn();
}