Skip to content

Commit 2e81ce7

Browse files
committed
rustdoc: Hide methods from #[doc(masked)] crates from the search index
1 parent fdc18b3 commit 2e81ce7

File tree

3 files changed

+87
-25
lines changed

3 files changed

+87
-25
lines changed

src/librustdoc/html/render.rs

+27-25
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,16 @@ impl DocFolder for Cache {
11741174
_ => self.stripped_mod,
11751175
};
11761176

1177+
// If the impl is from a masked crate or references something from a
1178+
// masked crate then remove it completely.
1179+
if let clean::ImplItem(ref i) = item.inner {
1180+
if self.masked_crates.contains(&item.def_id.krate) ||
1181+
i.trait_.def_id().map_or(false, |d| self.masked_crates.contains(&d.krate)) ||
1182+
i.for_.def_id().map_or(false, |d| self.masked_crates.contains(&d.krate)) {
1183+
return None;
1184+
}
1185+
}
1186+
11771187
// Register any generics to their corresponding string. This is used
11781188
// when pretty-printing types.
11791189
if let Some(generics) = item.inner.generics() {
@@ -1188,14 +1198,10 @@ impl DocFolder for Cache {
11881198

11891199
// Collect all the implementors of traits.
11901200
if let clean::ImplItem(ref i) = item.inner {
1191-
if !self.masked_crates.contains(&item.def_id.krate) {
1192-
if let Some(did) = i.trait_.def_id() {
1193-
if i.for_.def_id().map_or(true, |d| !self.masked_crates.contains(&d.krate)) {
1194-
self.implementors.entry(did).or_insert(vec![]).push(Impl {
1195-
impl_item: item.clone(),
1196-
});
1197-
}
1198-
}
1201+
if let Some(did) = i.trait_.def_id() {
1202+
self.implementors.entry(did).or_insert(vec![]).push(Impl {
1203+
impl_item: item.clone(),
1204+
});
11991205
}
12001206
}
12011207

@@ -1358,24 +1364,20 @@ impl DocFolder for Cache {
13581364
// Note: matching twice to restrict the lifetime of the `i` borrow.
13591365
let mut dids = FxHashSet();
13601366
if let clean::Item { inner: clean::ImplItem(ref i), .. } = item {
1361-
let masked_trait = i.trait_.def_id().map_or(false,
1362-
|d| self.masked_crates.contains(&d.krate));
1363-
if !masked_trait {
1364-
match i.for_ {
1365-
clean::ResolvedPath { did, .. } |
1366-
clean::BorrowedRef {
1367-
type_: box clean::ResolvedPath { did, .. }, ..
1368-
} => {
1369-
dids.insert(did);
1370-
}
1371-
ref t => {
1372-
let did = t.primitive_type().and_then(|t| {
1373-
self.primitive_locations.get(&t).cloned()
1374-
});
1367+
match i.for_ {
1368+
clean::ResolvedPath { did, .. } |
1369+
clean::BorrowedRef {
1370+
type_: box clean::ResolvedPath { did, .. }, ..
1371+
} => {
1372+
dids.insert(did);
1373+
}
1374+
ref t => {
1375+
let did = t.primitive_type().and_then(|t| {
1376+
self.primitive_locations.get(&t).cloned()
1377+
});
13751378

1376-
if let Some(did) = did {
1377-
dids.insert(did);
1378-
}
1379+
if let Some(did) = did {
1380+
dids.insert(did);
13791381
}
13801382
}
13811383
}

src/test/rustdoc/auxiliary/masked.rs

+20
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

+40
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)