Skip to content

Commit

Permalink
Rollup merge of rust-lang#74107 - nbdd0121:rustdoc, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Hide `&mut self` methods from Deref in sidebar if there are no `DerefMut` impl for the type.

This partially addresses rust-lang#74083.
  • Loading branch information
Manishearth committed Jul 9, 2020
2 parents 2c3c0e6 + 368aa6f commit c5a55ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4054,6 +4054,10 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
_ => None,
})
{
let deref_mut = v
.iter()
.filter(|i| i.inner_impl().trait_.is_some())
.any(|i| i.inner_impl().trait_.def_id() == c.deref_mut_trait_did);
let inner_impl = target
.def_id()
.or(target
Expand All @@ -4074,7 +4078,9 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
let mut ret = impls
.iter()
.filter(|i| i.inner_impl().trait_.is_none())
.flat_map(|i| get_methods(i.inner_impl(), true, &mut used_links, true))
.flat_map(|i| {
get_methods(i.inner_impl(), true, &mut used_links, deref_mut)
})
.collect::<Vec<_>>();
// We want links' order to be reproducible so we don't use unstable sort.
ret.sort();
Expand Down
21 changes: 21 additions & 0 deletions src/test/rustdoc/issue-74083.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::ops::Deref;

pub struct Foo;

impl Foo {
pub fn foo(&mut self) {}
}

// @has issue_74083/struct.Bar.html
// !@has - '//div[@class="sidebar-links"]/a[@href="#method.foo"]' 'foo'
pub struct Bar {
foo: Foo,
}

impl Deref for Bar {
type Target = Foo;

fn deref(&self) -> &Foo {
&self.foo
}
}

0 comments on commit c5a55ac

Please sign in to comment.