Skip to content

Commit ecd2885

Browse files
authored
Rollup merge of rust-lang#100731 - notriddle:notriddle/deref-methods-1, r=jsha
rustdoc: count deref and non-deref as same set of used methods Fixes rust-lang#100679
2 parents 30e65ce + 748c606 commit ecd2885

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

src/librustdoc/html/render/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
19851985
{
19861986
let mut derefs = FxHashSet::default();
19871987
derefs.insert(did);
1988-
sidebar_deref_methods(cx, out, impl_, v, &mut derefs);
1988+
sidebar_deref_methods(cx, out, impl_, v, &mut derefs, &mut used_links);
19891989
}
19901990

19911991
let format_impls = |impls: Vec<&Impl>, id_map: &mut IdMap| {
@@ -2057,6 +2057,7 @@ fn sidebar_deref_methods(
20572057
impl_: &Impl,
20582058
v: &[Impl],
20592059
derefs: &mut FxHashSet<DefId>,
2060+
used_links: &mut FxHashSet<String>,
20602061
) {
20612062
let c = cx.cache();
20622063

@@ -2089,13 +2090,10 @@ fn sidebar_deref_methods(
20892090
.and_then(|did| c.impls.get(&did));
20902091
if let Some(impls) = inner_impl {
20912092
debug!("found inner_impl: {:?}", impls);
2092-
let mut used_links = FxHashSet::default();
20932093
let mut ret = impls
20942094
.iter()
20952095
.filter(|i| i.inner_impl().trait_.is_none())
2096-
.flat_map(|i| {
2097-
get_methods(i.inner_impl(), true, &mut used_links, deref_mut, cx.tcx())
2098-
})
2096+
.flat_map(|i| get_methods(i.inner_impl(), true, used_links, deref_mut, cx.tcx()))
20992097
.collect::<Vec<_>>();
21002098
if !ret.is_empty() {
21012099
let id = if let Some(target_def_id) = real_target.def_id(c) {
@@ -2124,7 +2122,14 @@ fn sidebar_deref_methods(
21242122
.map(|t| Some(t.def_id()) == cx.tcx().lang_items().deref_trait())
21252123
.unwrap_or(false)
21262124
}) {
2127-
sidebar_deref_methods(cx, out, target_deref_impl, target_impls, derefs);
2125+
sidebar_deref_methods(
2126+
cx,
2127+
out,
2128+
target_deref_impl,
2129+
target_impls,
2130+
derefs,
2131+
used_links,
2132+
);
21282133
}
21292134
}
21302135
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![crate_name="foo"]
2+
3+
pub struct Vec;
4+
5+
pub struct Slice;
6+
7+
impl std::ops::Deref for Vec {
8+
type Target = Slice;
9+
fn deref(&self) -> &Slice {
10+
&Slice
11+
}
12+
}
13+
14+
// @has foo/struct.Vec.html '//*[@class="sidebar-elems"]//section//li/a[@href="#method.is_empty"]' \
15+
// "is_empty"
16+
impl Vec {
17+
pub fn is_empty(&self) -> bool {
18+
true
19+
}
20+
}
21+
22+
// @has foo/struct.Vec.html '//*[@class="sidebar-elems"]//section//li/a[@href="#method.is_empty-1"]' \
23+
// "is_empty"
24+
// @has foo/struct.Slice.html '//*[@class="sidebar-elems"]//section//li/a[@href="#method.is_empty"]' \
25+
// "is_empty"
26+
impl Slice {
27+
pub fn is_empty(&self) -> bool {
28+
true
29+
}
30+
}

0 commit comments

Comments
 (0)