Skip to content

Commit 36b8d58

Browse files
committed
Revert "rustdoc: add impl items from aliased type into sidebar"
This reverts commit d882b21.
1 parent ab125a2 commit 36b8d58

File tree

2 files changed

+5
-45
lines changed

2 files changed

+5
-45
lines changed

src/librustdoc/html/render/sidebar.rs

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ use std::{borrow::Cow, rc::Rc};
33
use askama::Template;
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_hir::{def::CtorKind, def_id::DefIdSet};
6-
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
76
use rustc_middle::ty::{self, TyCtxt};
87

98
use crate::{
109
clean,
11-
clean::types::TypeAliasItem,
1210
formats::{item_type::ItemType, Impl},
1311
html::{format::Buffer, markdown::IdMap},
1412
};
@@ -290,43 +288,10 @@ fn sidebar_assoc_items<'a>(
290288
) {
291289
let did = it.item_id.expect_def_id();
292290
let cache = cx.cache();
293-
let tcx = cx.tcx();
294-
let mut v: Vec<&Impl> =
295-
cache.impls.get(&did).map(Vec::as_slice).unwrap_or(&[]).iter().collect();
296-
if let TypeAliasItem(ait) = &*it.kind &&
297-
let aliased_clean_type = ait.item_type.as_ref().unwrap_or(&ait.type_) &&
298-
let Some(aliased_type_defid) = aliased_clean_type.def_id(cache) &&
299-
let Some(av) = cache.impls.get(&aliased_type_defid) &&
300-
let Some(alias_def_id) = it.item_id.as_def_id()
301-
{
302-
// This branch of the compiler compares types structually, but does
303-
// not check trait bounds. That's probably fine, since type aliases
304-
// don't normally constrain on them anyway.
305-
// https://github.com/rust-lang/rust/issues/21903
306-
//
307-
// FIXME(lazy_type_alias): Once the feature is complete or stable, rewrite this to use type unification.
308-
// Be aware of `tests/rustdoc/issue-112515-impl-ty-alias.rs` which might regress.
309-
let aliased_ty = tcx.type_of(alias_def_id).skip_binder();
310-
let reject_cx = DeepRejectCtxt {
311-
treat_obligation_params: TreatParams::AsCandidateKey,
312-
};
313-
v.extend(av.iter().filter(|impl_| {
314-
if let Some(impl_def_id) = impl_.impl_item.item_id.as_def_id() {
315-
reject_cx.types_may_unify(aliased_ty, tcx.type_of(impl_def_id).skip_binder())
316-
} else {
317-
false
318-
}
319-
}));
320-
}
321-
let v = {
322-
let mut saw_impls = FxHashSet::default();
323-
v.retain(|i| saw_impls.insert(i.def_id()));
324-
v.as_slice()
325-
};
326291

327292
let mut assoc_consts = Vec::new();
328293
let mut methods = Vec::new();
329-
if !v.is_empty() {
294+
if let Some(v) = cache.impls.get(&did) {
330295
let mut used_links = FxHashSet::default();
331296
let mut id_map = IdMap::new();
332297

@@ -362,7 +327,7 @@ fn sidebar_assoc_items<'a>(
362327
cx,
363328
&mut deref_methods,
364329
impl_,
365-
v.iter().copied(),
330+
v,
366331
&mut derefs,
367332
&mut used_links,
368333
);
@@ -392,7 +357,7 @@ fn sidebar_deref_methods<'a>(
392357
cx: &'a Context<'_>,
393358
out: &mut Vec<LinkBlock<'a>>,
394359
impl_: &Impl,
395-
v: impl Iterator<Item = &'a Impl>,
360+
v: &[Impl],
396361
derefs: &mut DefIdSet,
397362
used_links: &mut FxHashSet<String>,
398363
) {
@@ -417,7 +382,7 @@ fn sidebar_deref_methods<'a>(
417382
// Avoid infinite cycles
418383
return;
419384
}
420-
let deref_mut = { v }.any(|i| i.trait_did() == cx.tcx().lang_items().deref_mut_trait());
385+
let deref_mut = v.iter().any(|i| i.trait_did() == cx.tcx().lang_items().deref_mut_trait());
421386
let inner_impl = target
422387
.def_id(c)
423388
.or_else(|| {
@@ -468,7 +433,7 @@ fn sidebar_deref_methods<'a>(
468433
cx,
469434
out,
470435
target_deref_impl,
471-
target_impls.iter(),
436+
target_impls,
472437
derefs,
473438
used_links,
474439
);

tests/rustdoc/type-alias-impls-32077.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ impl Bar for GenericStruct<u32> {}
3232
// @!has - '//h3' 'impl Bar for GenericStruct<u32> {}'
3333
// Same goes for the `Deref` impl.
3434
// @!has - '//h2' 'Methods from Deref<Target = u32>'
35-
// @count - '//nav[@class="sidebar"]//a' 'on_alias' 1
36-
// @count - '//nav[@class="sidebar"]//a' 'on_gen' 1
37-
// @count - '//nav[@class="sidebar"]//a' 'Foo' 1
38-
// @!has - '//nav[@class="sidebar"]//a' 'Bar'
39-
// @!has - '//nav[@class="sidebar"]//a' 'on_u32'
4035
pub type TypedefStruct = GenericStruct<u8>;
4136

4237
impl TypedefStruct {

0 commit comments

Comments
 (0)