Revert "rustdoc: list matching impls on type aliases"

This reverts commit 19edb3ce80.
This commit is contained in:
Michael Howell 2023-10-05 18:44:48 -07:00
parent 77da7c655e
commit e701e64d59
2 changed files with 4 additions and 104 deletions

View File

@ -63,7 +63,6 @@ use rustc_span::{
use serde::ser::{SerializeMap, SerializeSeq};
use serde::{Serialize, Serializer};
use crate::clean::types::TypeAliasItem;
use crate::clean::{self, ItemId, RenderedLink, SelfTy};
use crate::error::Error;
use crate::formats::cache::Cache;
@ -1156,40 +1155,8 @@ fn render_assoc_items_inner(
info!("Documenting associated items of {:?}", containing_item.name);
let shared = Rc::clone(&cx.shared);
let cache = &shared.cache;
let tcx = cx.tcx();
let av = if let TypeAliasItem(ait) = &*containing_item.kind &&
let aliased_clean_type = ait.item_type.as_ref().unwrap_or(&ait.type_) &&
let Some(aliased_type_defid) = aliased_clean_type.def_id(cache) &&
let Some(mut av) = cache.impls.get(&aliased_type_defid).cloned() &&
let Some(alias_def_id) = containing_item.item_id.as_def_id()
{
// This branch of the compiler compares types structually, but does
// not check trait bounds. That's probably fine, since type aliases
// don't normally constrain on them anyway.
// https://github.com/rust-lang/rust/issues/21903
//
// If that changes, then this will need to check them with type
// unification.
let aliased_ty = tcx.type_of(alias_def_id).skip_binder();
let reject_cx = DeepRejectCtxt {
treat_obligation_params: TreatParams::AsCandidateKey,
};
av.retain(|impl_| {
if let Some(impl_def_id) = impl_.impl_item.item_id.as_def_id() {
reject_cx.types_may_unify(aliased_ty, tcx.type_of(impl_def_id).skip_binder())
} else {
false
}
});
av
} else {
Vec::new()
};
let blank = Vec::new();
let v = cache.impls.get(&it).unwrap_or(&blank);
let (non_trait, traits): (Vec<_>, _) =
v.iter().chain(&av[..]).partition(|i| i.inner_impl().trait_.is_none());
let mut saw_impls = FxHashSet::default();
let Some(v) = cache.impls.get(&it) else { return };
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
if !non_trait.is_empty() {
let mut tmp_buf = Buffer::html();
let (render_mode, id, class_html) = match what {
@ -1218,9 +1185,6 @@ fn render_assoc_items_inner(
};
let mut impls_buf = Buffer::html();
for i in &non_trait {
if !saw_impls.insert(i.def_id()) {
continue;
}
render_impl(
&mut impls_buf,
cx,
@ -1266,10 +1230,8 @@ fn render_assoc_items_inner(
let (synthetic, concrete): (Vec<&Impl>, Vec<&Impl>) =
traits.into_iter().partition(|t| t.inner_impl().kind.is_auto());
let (blanket_impl, concrete): (Vec<&Impl>, _) = concrete
.into_iter()
.filter(|t| saw_impls.insert(t.def_id()))
.partition(|t| t.inner_impl().kind.is_blanket());
let (blanket_impl, concrete): (Vec<&Impl>, _) =
concrete.into_iter().partition(|t| t.inner_impl().kind.is_blanket());
render_all_impls(w, cx, containing_item, &concrete, &synthetic, &blanket_impl);
}

View File

@ -1,62 +0,0 @@
// Regression test for <https://github.com/rust-lang/rust/issues/32077>.
// https://github.com/rust-lang/rust/issues/32077
#![crate_name = "foo"]
pub struct GenericStruct<T>(T);
impl<T> GenericStruct<T> {
pub fn on_gen(arg: T) {}
}
impl GenericStruct<u32> {
pub fn on_u32(arg: u32) {}
}
pub trait Foo {}
pub trait Bar {}
impl<T> Foo for GenericStruct<T> {}
impl Bar for GenericStruct<u32> {}
// @has 'foo/type.TypedefStruct.html'
// We check that "Aliased type" is also present as a title in the sidebar.
// @has - '//*[@class="sidebar-elems"]//h3/a[@href="#aliased-type"]' 'Aliased type'
// We check that we have the implementation of the type alias itself.
// @has - '//*[@id="impl-GenericStruct%3Cu8%3E"]/h3' 'impl TypedefStruct'
// @has - '//*[@id="method.on_alias"]/h4' 'pub fn on_alias()'
// @has - '//*[@id="impl-GenericStruct%3CT%3E"]/h3' 'impl<T> GenericStruct<T>'
// @has - '//*[@id="method.on_gen"]/h4' 'pub fn on_gen(arg: T)'
// @has - '//*[@id="impl-Foo-for-GenericStruct%3CT%3E"]/h3' 'impl<T> Foo for GenericStruct<T>'
// This trait implementation doesn't match the type alias parameters so shouldn't appear in docs.
// @!has - '//h3' 'impl Bar for GenericStruct<u32> {}'
// Same goes for the `Deref` impl.
// @!has - '//h2' 'Methods from Deref<Target = u32>'
pub type TypedefStruct = GenericStruct<u8>;
impl TypedefStruct {
pub fn on_alias() {}
}
impl std::ops::Deref for GenericStruct<u32> {
type Target = u32;
fn deref(&self) -> &Self::Target {
&self.0
}
}
pub struct Wrap<T>(GenericStruct<T>);
// @has 'foo/type.Alias.html'
// @has - '//h2' 'Methods from Deref<Target = u32>'
// @has - '//*[@id="impl-Deref-for-Wrap%3CT%3E"]/h3' 'impl<T> Deref for Wrap<T>'
pub type Alias = Wrap<u32>;
impl<T> std::ops::Deref for Wrap<T> {
type Target = GenericStruct<T>;
fn deref(&self) -> &Self::Target {
&self.0
}
}