Skip to content

Commit 6913b9f

Browse files
committed
Rollup merge of rust-lang#33514 - birkenfeld:issue-29503, r=alexcrichton
rustdoc: do not strip blanket impls in crate of origin In `impl<T> Trait for T`, the blanket type parameters `T` were recognized as "local" and "not exported", so these impls were thrown out. Now we check if they are generic, and keep them in that case. Fixes: rust-lang#29503
2 parents 3766313 + 6100b70 commit 6913b9f

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/librustdoc/clean/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,13 @@ impl Type {
15401540
_ => None,
15411541
}
15421542
}
1543+
1544+
pub fn is_generic(&self) -> bool {
1545+
match *self {
1546+
ResolvedPath { is_generic, .. } => is_generic,
1547+
_ => false,
1548+
}
1549+
}
15431550
}
15441551

15451552
impl GetDefId for Type {

src/librustdoc/passes.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ impl<'a> fold::DocFolder for Stripper<'a> {
115115

116116
// trait impls for private items should be stripped
117117
clean::ImplItem(clean::Impl{
118-
for_: clean::ResolvedPath{ did, .. }, ..
118+
for_: clean::ResolvedPath{ did, is_generic, .. }, ..
119119
}) => {
120-
if did.is_local() && !self.access_levels.is_exported(did) {
120+
if did.is_local() && !is_generic && !self.access_levels.is_exported(did) {
121121
return None;
122122
}
123123
}
@@ -183,7 +183,9 @@ impl<'a> fold::DocFolder for ImplStripper<'a> {
183183
fn fold_item(&mut self, i: Item) -> Option<Item> {
184184
if let clean::ImplItem(ref imp) = i.inner {
185185
if let Some(did) = imp.for_.def_id() {
186-
if did.is_local() && !self.retained.contains(&did) {
186+
if did.is_local() && !imp.for_.is_generic() &&
187+
!self.retained.contains(&did)
188+
{
187189
return None;
188190
}
189191
}

src/test/rustdoc/issue-29503.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 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+
use std::fmt;
12+
13+
// @has issue_29503/trait.MyTrait.html
14+
pub trait MyTrait {
15+
fn my_string(&self) -> String;
16+
}
17+
18+
// @has - "//ul[@id='implementors-list']/li" "impl<T> MyTrait for T where T: Debug"
19+
impl<T> MyTrait for T where T: fmt::Debug {
20+
fn my_string(&self) -> String {
21+
format!("{:?}", self)
22+
}
23+
}
24+
25+
pub fn main() {
26+
}

0 commit comments

Comments
 (0)