Skip to content

Rollup of 7 pull requests #72433

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

Merged
merged 20 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a3f30bb
Don't `type_of` on trait assoc ty without default
estebank May 12, 2020
fc4c9a6
Make intra-link resolve links for both trait and impl items
May 19, 2020
cad8fe9
rename `Predicate` to `PredicateKind`, introduce alias
lcnr May 11, 2020
034c25f
make `to_predicate` take a `tcx` argument
nikomatsakis May 7, 2020
f316479
introduce newtype'd `Predicate<'tcx>`
lcnr May 11, 2020
57746f9
intern `PredicateKind`
lcnr May 11, 2020
6544d7b
change `Predicate::kind` to return a reference
lcnr May 11, 2020
3dd830b
ptr eq for `Predicate`
lcnr May 11, 2020
6778c7a
Show default values for debug-assertions & debug-assertions-std
tmiasko May 20, 2020
20b499c
Fix anchor display when hovering impl
GuillaumeGomez May 21, 2020
94aa028
fix discriminant sign extension
RalfJung May 21, 2020
a81e9a7
Improve documentation of `slice::from_raw_parts`
danielhenrymantilla May 19, 2020
67e0755
Typo
RalfJung May 21, 2020
22438fc
Rollup merge of #72055 - lcnr:predicate-kind, r=nikomatsakis
RalfJung May 21, 2020
dc65fd4
Rollup merge of #72149 - estebank:icemation, r=eddyb
RalfJung May 21, 2020
3d5f130
Rollup merge of #72347 - xliiv:72340-impl-for-default, r=GuillaumeGomez
RalfJung May 21, 2020
261505a
Rollup merge of #72350 - danielhenrymantilla:doc_warn_against_adjacen…
RalfJung May 21, 2020
503a2fd
Rollup merge of #72382 - tmiasko:config-toml-debug-assertions, r=niko…
RalfJung May 21, 2020
fc729d0
Rollup merge of #72421 - GuillaumeGomez:fix-impl-hover-anchor, r=kinn…
RalfJung May 21, 2020
74b5c50
Rollup merge of #72425 - RalfJung:discr-sign-ext, r=nikomatsakis
RalfJung May 21, 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
Prev Previous commit
Next Next commit
Make intra-link resolve links for both trait and impl items
  • Loading branch information
Tymoteusz Jankowski committed May 19, 2020
commit fc4c9a6c7f27dc4cc68d8b2afe77e88a29ff8a31
61 changes: 35 additions & 26 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,37 +232,46 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias,
did,
) => {
// We need item's parent to know if it's
// trait impl or struct/enum/etc impl
let item_parent = item_opt
// Checks if item_name belongs to `impl SomeItem`
let impl_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);
let trait_item = item_opt
.and_then(|item| self.cx.as_local_hir_id(item.def_id))
.and_then(|item_hir| {
// Checks if item_name belongs to `impl SomeTrait for SomeItem`
let parent_hir = self.cx.tcx.hir().get_parent_item(item_hir);
self.cx.tcx.hir().find(parent_hir)
let item_parent = self.cx.tcx.hir().find(parent_hir);
match item_parent {
Some(hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl { of_trait: Some(_), self_ty, .. },
..
})) => 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),
_ => None,
}
});
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)
let item = match (impl_item, trait_item) {
(Some(from_impl), Some(_)) => {
// Although it's ambiguous, return impl version for compat. sake.
// To handle that properly resolve() would have to support
// something like
// [`ambi_fn`](<SomeStruct as SomeTrait>::ambi_fn)
Some(from_impl)
}
(None, Some(from_trait)) => Some(from_trait),
(Some(from_impl), None) => Some(from_impl),
_ => None,
};

if let Some(item) = item {
Expand Down
19 changes: 19 additions & 0 deletions src/test/rustdoc/issue-72340.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![crate_name = "foo"]

pub struct Body;

impl Body {
pub fn empty() -> Self {
Body
}

}

impl Default for Body {
// @has foo/struct.Body.html '//a/@href' '../foo/struct.Body.html#method.empty'

/// Returns [`Body::empty()`](Body::empty).
fn default() -> Body {
Body::empty()
}
}