]> git.lizzy.rs Git - rust.git/commitdiff
Hide trait impl with private trait type parameter
authorChristian Duerr <contact@christianduerr.com>
Thu, 30 Nov 2017 20:18:36 +0000 (21:18 +0100)
committerChristian Duerr <contact@christianduerr.com>
Thu, 30 Nov 2017 20:18:36 +0000 (21:18 +0100)
Trait's implementations with private type parameters were displayed in
the implementing struct's documentation until now.

With this change any trait implementation that uses a private type
parameter is now hidden in the docs.

src/librustdoc/passes/mod.rs
src/test/rustdoc/issue-46380-2.rs [new file with mode: 0644]

index 77d97c84c99bf0e77c125d57ab9575816d60b713..3e15d3d3007ac7ef659792d8321b8321c80b9cbb 100644 (file)
@@ -184,6 +184,15 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
                     return None;
                 }
             }
+            if let Some(generics) = imp.trait_.as_ref().and_then(|t| t.generics()) {
+                for typaram in generics {
+                    if let Some(did) = typaram.def_id() {
+                        if did.is_local() && !self.retained.contains(&did) {
+                            return None;
+                        }
+                    }
+                }
+            }
         }
         self.fold_item_recur(i)
     }
diff --git a/src/test/rustdoc/issue-46380-2.rs b/src/test/rustdoc/issue-46380-2.rs
new file mode 100644 (file)
index 0000000..93a1ee7
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait PublicTrait<T> {}
+
+// @has issue_46380_2/struct.Public.html
+pub struct PublicStruct;
+
+// @!has - '//*[@class="impl"]' 'impl Add<Private> for Public'
+impl PublicTrait<PrivateStruct> for PublicStruct {}
+
+struct PrivateStruct;