Skip to content

Commit 268cbfe

Browse files
committed
Auto merge of #79682 - jyn514:no-blanket-impls, r=Manishearth,GuillaumeGomez
Don't look for blanket impls in intra-doc links This never worked and has been causing severe performance problems. Hopefully it will be re-landed at some point in the future when it actually works, but in the meantime it makes no sense to have the code around when it does nothing and actively makes rustdoc harder to use. Closes #78761. Does *not* affect #78800. r? `@Manishearth` cc `@seeplusplus`
2 parents ddbc617 + 6580f11 commit 268cbfe

File tree

2 files changed

+15
-79
lines changed

2 files changed

+15
-79
lines changed

Diff for: src/librustdoc/clean/types.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_hir::def_id::{CrateNum, DefId};
2121
use rustc_hir::lang_items::LangItem;
2222
use rustc_hir::Mutability;
2323
use rustc_index::vec::IndexVec;
24-
use rustc_middle::ty::{AssocKind, TyCtxt};
24+
use rustc_middle::ty::TyCtxt;
2525
use rustc_session::Session;
2626
use rustc_span::hygiene::MacroKind;
2727
use rustc_span::source_map::DUMMY_SP;
@@ -375,15 +375,6 @@ impl ItemKind {
375375
_ => false,
376376
}
377377
}
378-
379-
crate fn as_assoc_kind(&self) -> Option<AssocKind> {
380-
match *self {
381-
ItemKind::AssocConstItem(..) => Some(AssocKind::Const),
382-
ItemKind::AssocTypeItem(..) => Some(AssocKind::Type),
383-
ItemKind::TyMethodItem(..) | ItemKind::MethodItem(..) => Some(AssocKind::Fn),
384-
_ => None,
385-
}
386-
}
387378
}
388379

389380
#[derive(Clone, Debug)]

Diff for: src/librustdoc/passes/collect_intra_doc_links.rs

+14-69
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::cell::Cell;
3131
use std::mem;
3232
use std::ops::Range;
3333

34-
use crate::clean::{self, Crate, GetDefId, Item, ItemLink, PrimitiveType};
34+
use crate::clean::{self, Crate, Item, ItemLink, PrimitiveType};
3535
use crate::core::DocContext;
3636
use crate::fold::DocFolder;
3737
use crate::html::markdown::markdown_links;
@@ -685,78 +685,23 @@ fn resolve_associated_trait_item(
685685
ns: Namespace,
686686
cx: &DocContext<'_>,
687687
) -> Option<(ty::AssocKind, DefId)> {
688-
let ty = cx.tcx.type_of(did);
689-
// First consider blanket impls: `impl From<T> for T`
690-
let implicit_impls = crate::clean::get_auto_trait_and_blanket_impls(cx, ty, did);
691-
let mut candidates: Vec<_> = implicit_impls
692-
.flat_map(|impl_outer| {
693-
match impl_outer.kind {
694-
clean::ImplItem(impl_) => {
695-
debug!("considering auto or blanket impl for trait {:?}", impl_.trait_);
696-
// Give precedence to methods that were overridden
697-
if !impl_.provided_trait_methods.contains(&*item_name.as_str()) {
698-
let mut items = impl_.items.into_iter().filter_map(|assoc| {
699-
if assoc.name != Some(item_name) {
700-
return None;
701-
}
702-
let kind = assoc
703-
.kind
704-
.as_assoc_kind()
705-
.expect("inner items for a trait should be associated items");
706-
if kind.namespace() != ns {
707-
return None;
708-
}
709-
710-
trace!("considering associated item {:?}", assoc.kind);
711-
// We have a slight issue: normal methods come from `clean` types,
712-
// but provided methods come directly from `tcx`.
713-
// Fortunately, we don't need the whole method, we just need to know
714-
// what kind of associated item it is.
715-
Some((kind, assoc.def_id))
716-
});
717-
let assoc = items.next();
718-
debug_assert_eq!(items.count(), 0);
719-
assoc
720-
} else {
721-
// These are provided methods or default types:
722-
// ```
723-
// trait T {
724-
// type A = usize;
725-
// fn has_default() -> A { 0 }
726-
// }
727-
// ```
728-
let trait_ = impl_.trait_.unwrap().def_id().unwrap();
729-
cx.tcx
730-
.associated_items(trait_)
731-
.find_by_name_and_namespace(
732-
cx.tcx,
733-
Ident::with_dummy_span(item_name),
734-
ns,
735-
trait_,
736-
)
737-
.map(|assoc| (assoc.kind, assoc.def_id))
738-
}
739-
}
740-
_ => panic!("get_impls returned something that wasn't an impl"),
741-
}
742-
})
743-
.collect();
688+
// FIXME: this should also consider blanket impls (`impl<T> X for T`). Unfortunately
689+
// `get_auto_trait_and_blanket_impls` is broken because the caching behavior is wrong. In the
690+
// meantime, just don't look for these blanket impls.
744691

745692
// Next consider explicit impls: `impl MyTrait for MyType`
746693
// Give precedence to inherent impls.
747-
if candidates.is_empty() {
748-
let traits = traits_implemented_by(cx, did, module);
749-
debug!("considering traits {:?}", traits);
750-
candidates.extend(traits.iter().filter_map(|&trait_| {
751-
cx.tcx
752-
.associated_items(trait_)
753-
.find_by_name_and_namespace(cx.tcx, Ident::with_dummy_span(item_name), ns, trait_)
754-
.map(|assoc| (assoc.kind, assoc.def_id))
755-
}));
756-
}
694+
let traits = traits_implemented_by(cx, did, module);
695+
debug!("considering traits {:?}", traits);
696+
let mut candidates = traits.iter().filter_map(|&trait_| {
697+
cx.tcx
698+
.associated_items(trait_)
699+
.find_by_name_and_namespace(cx.tcx, Ident::with_dummy_span(item_name), ns, trait_)
700+
.map(|assoc| (assoc.kind, assoc.def_id))
701+
});
757702
// FIXME(#74563): warn about ambiguity
758-
debug!("the candidates were {:?}", candidates);
759-
candidates.pop()
703+
debug!("the candidates were {:?}", candidates.clone().collect::<Vec<_>>());
704+
candidates.next()
760705
}
761706

762707
/// Given a type, return all traits in scope in `module` implemented by that type.

0 commit comments

Comments
 (0)