Skip to content

Commit 51d0d06

Browse files
committed
auto merge of #16767 : SiegeLord/rust/reexported_methods, r=cmr
Previously, this caused methods of re-exported types to not be inserted into the search index. This fix may introduce some false positives, but in my testing they appear as orphaned methods and end up not being inserted into the final search index at a later stage. Fixes issue #11943
2 parents 6025926 + 0db6f4c commit 51d0d06

File tree

4 files changed

+89
-8
lines changed

4 files changed

+89
-8
lines changed

src/librustdoc/html/render.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -819,16 +819,17 @@ impl DocFolder for Cache {
819819
// Index this method for searching later on
820820
match item.name {
821821
Some(ref s) => {
822-
let parent = match item.inner {
822+
let (parent, is_method) = match item.inner {
823823
clean::TyMethodItem(..) |
824824
clean::StructFieldItem(..) |
825825
clean::VariantItem(..) => {
826-
(Some(*self.parent_stack.last().unwrap()),
827-
Some(self.stack.slice_to(self.stack.len() - 1)))
826+
((Some(*self.parent_stack.last().unwrap()),
827+
Some(self.stack.slice_to(self.stack.len() - 1))),
828+
false)
828829
}
829830
clean::MethodItem(..) => {
830831
if self.parent_stack.len() == 0 {
831-
(None, None)
832+
((None, None), false)
832833
} else {
833834
let last = self.parent_stack.last().unwrap();
834835
let did = *last;
@@ -844,17 +845,18 @@ impl DocFolder for Cache {
844845
Some(..) => Some(self.stack.as_slice()),
845846
None => None
846847
};
847-
(Some(*last), path)
848+
((Some(*last), path), true)
848849
}
849850
}
850-
_ => (None, Some(self.stack.as_slice()))
851+
_ => ((None, Some(self.stack.as_slice())), false)
851852
};
852853
let hidden_field = match item.inner {
853854
clean::StructFieldItem(clean::HiddenStructField) => true,
854855
_ => false
855856
};
857+
856858
match parent {
857-
(parent, Some(path)) if !self.privmod && !hidden_field => {
859+
(parent, Some(path)) if is_method || (!self.privmod && !hidden_field) => {
858860
self.search_index.push(IndexItem {
859861
ty: shortty(&item),
860862
name: s.to_string(),
@@ -863,7 +865,7 @@ impl DocFolder for Cache {
863865
parent: parent,
864866
});
865867
}
866-
(Some(parent), None) if !self.privmod => {
868+
(Some(parent), None) if is_method || (!self.privmod && !hidden_field)=> {
867869
if ast_util::is_local(parent) {
868870
// We have a parent, but we don't know where they're
869871
// defined yet. Wait for later to index this item.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-include ../tools.mk
2+
3+
# FIXME ignore windows
4+
ifndef IS_WINDOWS
5+
6+
source=index.rs
7+
8+
all:
9+
$(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc $(source)
10+
cp $(source) $(TMPDIR)
11+
cp verify.sh $(TMPDIR)
12+
$(call RUN,verify.sh) $(TMPDIR)
13+
14+
else
15+
all:
16+
17+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2014 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+
#![crate_name = "rustdoc_test"]
12+
13+
// In: Foo
14+
pub use private::Foo;
15+
16+
mod private {
17+
pub struct Foo;
18+
impl Foo {
19+
// In: test_method
20+
pub fn test_method() {}
21+
// Out: priv_method
22+
fn priv_method() {}
23+
}
24+
25+
pub trait PrivateTrait {
26+
// Out: priv_method
27+
fn trait_method() {}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
source="$1/index.rs"
4+
index="$1/doc/search-index.js"
5+
6+
if ! [ -e $index ]
7+
then
8+
echo "Could not find the search index (looked for $index)"
9+
exit 1
10+
fi
11+
12+
ins=$(grep -o 'In: .*' $source | sed 's/In: \(.*\)/\1/g')
13+
outs=$(grep -o 'Out: .*' $source | sed 's/Out: \(.*\)/\1/g')
14+
15+
for p in $ins
16+
do
17+
if ! grep -q $p $index
18+
then
19+
echo "'$p' was erroneously excluded from search index."
20+
exit 1
21+
fi
22+
done
23+
24+
for p in $outs
25+
do
26+
if grep -q $p $index
27+
then
28+
echo "'$p' was erroneously included in search index."
29+
exit 1
30+
fi
31+
done
32+
33+
exit 0

0 commit comments

Comments
 (0)