From 1df13c057a7f1937170fe600d24256f0bf943ec2 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 30 Nov 2017 21:18:36 +0100 Subject: [PATCH] Hide trait impl with private trait type parameter 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 | 9 +++++++++ src/test/rustdoc/issue-46380-2.rs | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/test/rustdoc/issue-46380-2.rs diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 77d97c84c99b..3e15d3d3007a 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -184,6 +184,15 @@ impl<'a> fold::DocFolder for ImplStripper<'a> { 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 index 000000000000..93a1ee72013c --- /dev/null +++ b/src/test/rustdoc/issue-46380-2.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub trait PublicTrait {} + +// @has issue_46380_2/struct.Public.html +pub struct PublicStruct; + +// @!has - '//*[@class="impl"]' 'impl Add for Public' +impl PublicTrait for PublicStruct {} + +struct PrivateStruct;