Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide &mut self methods from Deref in sidebar if there are no DerefMut impl for the type. #74107

Merged
merged 2 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4095,6 +4095,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 @@ -4115,7 +4119,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
}
}