Skip to content

Commit 1df13c0

Browse files
committed
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.
1 parent ec337b6 commit 1df13c0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/librustdoc/passes/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ impl<'a> fold::DocFolder for ImplStripper<'a> {
184184
return None;
185185
}
186186
}
187+
if let Some(generics) = imp.trait_.as_ref().and_then(|t| t.generics()) {
188+
for typaram in generics {
189+
if let Some(did) = typaram.def_id() {
190+
if did.is_local() && !self.retained.contains(&did) {
191+
return None;
192+
}
193+
}
194+
}
195+
}
187196
}
188197
self.fold_item_recur(i)
189198
}

src/test/rustdoc/issue-46380-2.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub trait PublicTrait<T> {}
12+
13+
// @has issue_46380_2/struct.Public.html
14+
pub struct PublicStruct;
15+
16+
// @!has - '//*[@class="impl"]' 'impl Add<Private> for Public'
17+
impl PublicTrait<PrivateStruct> for PublicStruct {}
18+
19+
struct PrivateStruct;

0 commit comments

Comments
 (0)