From e0b69f207b276e0432e45bbe41d26a28bbfbfa2e Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 6 Jul 2020 20:32:26 +0100 Subject: [PATCH 1/2] Hide `&mut self` methods from Deref in sidebar If there are no `DerefMut` impl for the type. --- src/librustdoc/html/render.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 04c4685213b2e..6d3576ed8078c 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -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 @@ -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::>(); // We want links' order to be reproducible so we don't use unstable sort. ret.sort(); From 368aa6f1e292d264bcb74fafa25069fe19c49450 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 6 Jul 2020 21:06:58 +0100 Subject: [PATCH 2/2] Add test for issue 74083 --- src/test/rustdoc/issue-74083.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/rustdoc/issue-74083.rs diff --git a/src/test/rustdoc/issue-74083.rs b/src/test/rustdoc/issue-74083.rs new file mode 100644 index 0000000000000..28585dafa142a --- /dev/null +++ b/src/test/rustdoc/issue-74083.rs @@ -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 + } +}