]> git.lizzy.rs Git - rust.git/commitdiff
Only show associated consts from inherent impls in sidebar
authorJules Bertholet <jules.bertholet@gmail.com>
Wed, 30 Mar 2022 14:37:55 +0000 (10:37 -0400)
committerJules Bertholet <jules.bertholet@gmail.com>
Wed, 30 Mar 2022 17:49:50 +0000 (13:49 -0400)
src/librustdoc/html/render/mod.rs
src/test/rustdoc/associated-consts.rs

index 93b33b0d6091262082b3bb7f8147dafcdb0920fb..0cfe12abcd14ac9144ef05881c0a2523fc0d8cae 100644 (file)
@@ -1987,6 +1987,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
             let used_links_bor = &mut used_links;
             let mut assoc_consts = v
                 .iter()
+                .filter(|i| i.inner_impl().trait_.is_none())
                 .flat_map(|i| get_associated_constants(i.inner_impl(), used_links_bor))
                 .collect::<Vec<_>>();
             if !assoc_consts.is_empty() {
index da50fb86cd581a57bf6694df89e97a591677d2ec..9319a073bb7926cf7ffc6169047beff31a0682bb 100644 (file)
@@ -9,8 +9,8 @@ pub trait Trait {
 pub struct Bar;
 
 // @has 'foo/struct.Bar.html'
-// @has - '//h3[@class="sidebar-title"]' 'Associated Constants'
-// @has - '//div[@class="sidebar-elems"]//a' 'FOO'
+// @!has - '//h3[@class="sidebar-title"]' 'Associated Constants'
+// @!has - '//div[@class="sidebar-elems"]//a' 'FOO'
 impl Trait for Bar {
     const FOO: u32 = 1;
 
@@ -22,10 +22,30 @@ pub enum Foo {
 }
 
 // @has 'foo/enum.Foo.html'
-// @has - '//h3[@class="sidebar-title"]' 'Associated Constants'
-// @has - '//div[@class="sidebar-elems"]//a' 'FOO'
+// @!has - '//h3[@class="sidebar-title"]' 'Associated Constants'
+// @!has - '//div[@class="sidebar-elems"]//a' 'FOO'
 impl Trait for Foo {
     const FOO: u32 = 1;
 
     fn foo() {}
 }
+
+pub struct Baz;
+
+// @has 'foo/struct.Baz.html'
+// @has - '//h3[@class="sidebar-title"]' 'Associated Constants'
+// @has - '//div[@class="sidebar-elems"]//a' 'FOO'
+impl Baz {
+    pub const FOO: u32 = 42;
+}
+
+pub enum Quux {
+    B,
+}
+
+// @has 'foo/enum.Quux.html'
+// @has - '//h3[@class="sidebar-title"]' 'Associated Constants'
+// @has - '//div[@class="sidebar-elems"]//a' 'FOO'
+impl Quux {
+    pub const FOO: u32 = 42;
+}