Skip to content

Commit 1dc8576

Browse files
committed
Merge branch 'rustdoc_masked' of https://github.com/ollie27/rust into rollup
2 parents a910109 + 77bc826 commit 1dc8576

File tree

4 files changed

+87
-27
lines changed

4 files changed

+87
-27
lines changed

src/librustdoc/html/render.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,16 @@ impl DocFolder for Cache {
12431243
_ => self.stripped_mod,
12441244
};
12451245

1246+
// If the impl is from a masked crate or references something from a
1247+
// masked crate then remove it completely.
1248+
if let clean::ImplItem(ref i) = item.inner {
1249+
if self.masked_crates.contains(&item.def_id.krate) ||
1250+
i.trait_.def_id().map_or(false, |d| self.masked_crates.contains(&d.krate)) ||
1251+
i.for_.def_id().map_or(false, |d| self.masked_crates.contains(&d.krate)) {
1252+
return None;
1253+
}
1254+
}
1255+
12461256
// Register any generics to their corresponding string. This is used
12471257
// when pretty-printing types.
12481258
if let Some(generics) = item.inner.generics() {
@@ -1257,14 +1267,10 @@ impl DocFolder for Cache {
12571267

12581268
// Collect all the implementors of traits.
12591269
if let clean::ImplItem(ref i) = item.inner {
1260-
if !self.masked_crates.contains(&item.def_id.krate) {
1261-
if let Some(did) = i.trait_.def_id() {
1262-
if i.for_.def_id().map_or(true, |d| !self.masked_crates.contains(&d.krate)) {
1263-
self.implementors.entry(did).or_insert(vec![]).push(Impl {
1264-
impl_item: item.clone(),
1265-
});
1266-
}
1267-
}
1270+
if let Some(did) = i.trait_.def_id() {
1271+
self.implementors.entry(did).or_insert(vec![]).push(Impl {
1272+
impl_item: item.clone(),
1273+
});
12681274
}
12691275
}
12701276

@@ -1427,24 +1433,20 @@ impl DocFolder for Cache {
14271433
// Note: matching twice to restrict the lifetime of the `i` borrow.
14281434
let mut dids = FxHashSet();
14291435
if let clean::Item { inner: clean::ImplItem(ref i), .. } = item {
1430-
let masked_trait = i.trait_.def_id().map_or(false,
1431-
|d| self.masked_crates.contains(&d.krate));
1432-
if !masked_trait {
1433-
match i.for_ {
1434-
clean::ResolvedPath { did, .. } |
1435-
clean::BorrowedRef {
1436-
type_: box clean::ResolvedPath { did, .. }, ..
1437-
} => {
1438-
dids.insert(did);
1439-
}
1440-
ref t => {
1441-
let did = t.primitive_type().and_then(|t| {
1442-
self.primitive_locations.get(&t).cloned()
1443-
});
1436+
match i.for_ {
1437+
clean::ResolvedPath { did, .. } |
1438+
clean::BorrowedRef {
1439+
type_: box clean::ResolvedPath { did, .. }, ..
1440+
} => {
1441+
dids.insert(did);
1442+
}
1443+
ref t => {
1444+
let did = t.primitive_type().and_then(|t| {
1445+
self.primitive_locations.get(&t).cloned()
1446+
});
14441447

1445-
if let Some(did) = did {
1446-
dids.insert(did);
1447-
}
1448+
if let Some(did) = did {
1449+
dids.insert(did);
14481450
}
14491451
}
14501452
}

src/test/rustdoc-js/from_u.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@ const EXPECTED = {
1515
{ 'path': 'std::char', 'name': 'from_u32' },
1616
{ 'path': 'std::str', 'name': 'from_utf8' },
1717
{ 'path': 'std::string::String', 'name': 'from_utf8' },
18-
{ 'path': 'std::i32', 'name': 'from_unsigned' },
19-
{ 'path': 'std::i128', 'name': 'from_unsigned' },
2018
],
2119
};

src/test/rustdoc/auxiliary/masked.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 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+
#[derive(Clone)]
12+
pub struct MaskedStruct;
13+
14+
pub trait MaskedTrait {
15+
fn masked_method();
16+
}
17+
18+
impl MaskedTrait for String {
19+
fn masked_method() {}
20+
}

src/test/rustdoc/masked.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2018 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+
// aux-build:masked.rs
12+
13+
#![feature(doc_masked)]
14+
15+
#![crate_name = "foo"]
16+
17+
#[doc(masked)]
18+
extern crate masked;
19+
20+
// @!has 'search-index.js' 'masked_method'
21+
22+
// @!has 'foo/struct.String.html' 'MaskedTrait'
23+
// @!has 'foo/struct.String.html' 'masked_method'
24+
pub use std::string::String;
25+
26+
// @!has 'foo/trait.Clone.html' 'MaskedStruct'
27+
pub use std::clone::Clone;
28+
29+
// @!has 'foo/struct.MyStruct.html' 'MaskedTrait'
30+
// @!has 'foo/struct.MyStruct.html' 'masked_method'
31+
pub struct MyStruct;
32+
33+
impl masked::MaskedTrait for MyStruct {
34+
fn masked_method() {}
35+
}
36+
37+
// @!has 'foo/trait.MyTrait.html' 'MaskedStruct'
38+
pub trait MyTrait {}
39+
40+
impl MyTrait for masked::MaskedStruct {}

0 commit comments

Comments
 (0)