Rollup merge of #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 #74083.
This commit is contained in:
Manish Goregaokar 2020-07-09 11:50:34 -07:00 committed by GitHub
commit 38541b742a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -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
@ -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();

View file

@ -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
}
}