Skip to content

Commit c5a55ac

Browse files
authored
Rollup merge of rust-lang#74107 - nbdd0121:rustdoc, r=GuillaumeGomez
Hide `&mut self` methods from Deref in sidebar if there are no `DerefMut` impl for the type. This partially addresses rust-lang#74083.
2 parents 2c3c0e6 + 368aa6f commit c5a55ac

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/librustdoc/html/render.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -4054,6 +4054,10 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
40544054
_ => None,
40554055
})
40564056
{
4057+
let deref_mut = v
4058+
.iter()
4059+
.filter(|i| i.inner_impl().trait_.is_some())
4060+
.any(|i| i.inner_impl().trait_.def_id() == c.deref_mut_trait_did);
40574061
let inner_impl = target
40584062
.def_id()
40594063
.or(target
@@ -4074,7 +4078,9 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
40744078
let mut ret = impls
40754079
.iter()
40764080
.filter(|i| i.inner_impl().trait_.is_none())
4077-
.flat_map(|i| get_methods(i.inner_impl(), true, &mut used_links, true))
4081+
.flat_map(|i| {
4082+
get_methods(i.inner_impl(), true, &mut used_links, deref_mut)
4083+
})
40784084
.collect::<Vec<_>>();
40794085
// We want links' order to be reproducible so we don't use unstable sort.
40804086
ret.sort();

src/test/rustdoc/issue-74083.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::ops::Deref;
2+
3+
pub struct Foo;
4+
5+
impl Foo {
6+
pub fn foo(&mut self) {}
7+
}
8+
9+
// @has issue_74083/struct.Bar.html
10+
// !@has - '//div[@class="sidebar-links"]/a[@href="#method.foo"]' 'foo'
11+
pub struct Bar {
12+
foo: Foo,
13+
}
14+
15+
impl Deref for Bar {
16+
type Target = Foo;
17+
18+
fn deref(&self) -> &Foo {
19+
&self.foo
20+
}
21+
}

0 commit comments

Comments
 (0)