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

Fix impl being removed excessively #82496

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 18 additions & 7 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,29 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {

let mut cleaner = BadImplStripper { prims, items: crate_items };

let sized_trait = cx.tcx.lang_items().sized_trait();
let deref_trait = cx.tcx.lang_items().deref_trait();

let mut type_did_to_deref_target: FxHashMap<DefId, &Type> = FxHashMap::default();
// Gather all type to `Deref` target edges.
for it in &new_items {
if let ImplItem(Impl { ref for_, ref trait_, ref items, .. }) = *it.kind {
if trait_.def_id() == cx.tcx.lang_items().deref_trait() {
let target = items.iter().find_map(|item| match *item.kind {
TypedefItem(ref t, true) => Some(&t.type_),
_ => None,
});
if let (Some(for_did), Some(target)) = (for_.def_id(), target) {
type_did_to_deref_target.insert(for_did, target);
match trait_.def_id() {
did if sized_trait == did => {}
Some(did) => {
if Some(did) == deref_trait {
let target = items.iter().find_map(|item| match *item.kind {
TypedefItem(ref t, true) => Some(&t.type_),
_ => None,
});
if let (Some(for_did), Some(target)) = (for_.def_id(), target) {
type_did_to_deref_target.insert(for_did, target);
}
} else {
cleaner.items.insert(did);
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
}
}
_ => {}
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/rustdoc/impl-on-foreign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![crate_name = "foo"]

use std::convert::AsRef;
pub struct Gus;
jyn514 marked this conversation as resolved.
Show resolved Hide resolved

// @has 'foo/struct.Gus.html'
// @has - '//h3[@class="impl"]/code' 'impl AsRef<str> for Gus'
impl AsRef<str> for Gus {
fn as_ref(&self) -> &str {
todo!()
}
}

// @has - '//h3[@class="impl"]/code' 'impl AsRef<Gus> for str'
impl AsRef<Gus> for str {
fn as_ref(&self) -> &Gus {
todo!()
}
}

// @has - '//h3[@class="impl"]/code' 'impl AsRef<Gus> for String'
impl AsRef<Gus> for String {
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
fn as_ref(&self) -> &Gus {
todo!()
}
}