Skip to content

Commit 59007a5

Browse files
committed
Remove broken trait_item logic; add back inherent impls
1 parent d22bedf commit 59007a5

File tree

1 file changed

+17
-42
lines changed

1 file changed

+17
-42
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
172172
current_item: &Option<String>,
173173
parent_id: Option<DefId>,
174174
extra_fragment: &Option<String>,
175-
item: &Item,
176175
) -> Result<(Res, Option<String>), ErrorKind> {
177176
let cx = self.cx;
178177

@@ -291,43 +290,23 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
291290
did,
292291
) => {
293292
debug!("looking for associated item named {} for item {:?}", item_name, did);
294-
let impl_kind = resolve_associated_trait_item(did, item_name, &self.cx)?;
295-
// TODO: is this necessary? It doesn't look right, and also only works for local items
296-
let trait_kind = self.cx.as_local_hir_id(item.def_id)
297-
.and_then(|item_hir| {
298-
// Checks if item_name belongs to `impl SomeTrait for SomeItem`
299-
let parent_hir = self.cx.tcx.hir().get_parent_item(item_hir);
300-
let item_parent = self.cx.tcx.hir().find(parent_hir);
301-
match item_parent {
302-
Some(hir::Node::Item(hir::Item {
303-
kind: hir::ItemKind::Impl { of_trait: Some(_), self_ty, .. },
304-
..
305-
})) => cx
306-
.tcx
307-
.associated_item_def_ids(self_ty.hir_id.owner)
308-
.iter()
309-
.map(|child| {
310-
let associated_item = cx.tcx.associated_item(*child);
311-
associated_item
312-
})
313-
.find(|child| child.ident.name == item_name)
314-
.map(|child| child.kind),
315-
_ => None,
316-
}
317-
});
318-
debug!("considering items {:?} and {:?}", impl_kind, trait_kind);
319-
let kind = match (impl_kind, trait_kind) {
320-
(Some(from_kind), Some(_)) => {
321-
// Although it's ambiguous, return impl version for compat. sake.
322-
// To handle that properly resolve() would have to support
323-
// something like
324-
// [`ambi_fn`](<SomeStruct as SomeTrait>::ambi_fn)
325-
Some(from_kind)
326-
}
327-
(None, Some(from_kind)) => Some(from_kind),
328-
(Some(from_kind), None) => Some(from_kind),
329-
_ => None,
330-
};
293+
// Checks if item_name belongs to `impl SomeItem`
294+
let mut kind = cx
295+
.tcx
296+
.inherent_impls(did)
297+
.iter()
298+
.flat_map(|imp| cx.tcx.associated_items(*imp).in_definition_order())
299+
.find(|item| item.ident.name == item_name)
300+
.map(|item| item.kind);
301+
302+
// Check if item_name belogns to `impl SomeTrait for SomeItem`
303+
// This gives precedence to `impl SomeItem`:
304+
// Although having both would be ambiguous, use impl version for compat. sake.
305+
// To handle that properly resolve() would have to support
306+
// something like [`ambi_fn`](<SomeStruct as SomeTrait>::ambi_fn)
307+
if kind.is_none() {
308+
kind = resolve_associated_trait_item(did, item_name, &self.cx)?;
309+
}
331310

332311
if let Some(kind) = kind {
333312
let out = match kind {
@@ -725,7 +704,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
725704
&current_item,
726705
base_node,
727706
&extra_fragment,
728-
&item,
729707
) {
730708
Ok(res) => res,
731709
Err(ErrorKind::ResolutionFailure) => {
@@ -760,7 +738,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
760738
&current_item,
761739
base_node,
762740
&extra_fragment,
763-
&item,
764741
) {
765742
Ok(res) => res,
766743
Err(ErrorKind::ResolutionFailure) => {
@@ -798,7 +775,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
798775
&current_item,
799776
base_node,
800777
&extra_fragment,
801-
&item,
802778
) {
803779
Err(ErrorKind::AnchorFailure(msg)) => {
804780
anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);
@@ -813,7 +789,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
813789
&current_item,
814790
base_node,
815791
&extra_fragment,
816-
&item,
817792
) {
818793
Err(ErrorKind::AnchorFailure(msg)) => {
819794
anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);

0 commit comments

Comments
 (0)