Skip to content

Commit e5cd653

Browse files
committed
Auto merge of #22765 - sanxiyn:dedup-rustdoc, r=alexcrichton
rustdoc impl item did not include default methods for local crates, but did include them for external crates. This resulted in duplicate methods. Fix so that impl item does not include default methods for external crates. Fix #22595.
2 parents b47aebe + 6958463 commit e5cd653

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

src/etc/htmldocck.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
highlights for example. If you want to simply check the presence of
9797
given node or attribute, use an empty string (`""`) as a `PATTERN`.
9898
99+
* `@count PATH XPATH COUNT' checks for the occurrence of given XPath
100+
in the given file. The number of occurrences must match the given count.
101+
99102
All conditions can be negated with `!`. `@!has foo/type.NoSuch.html`
100103
checks if the given file does not exist, for example.
101104
@@ -333,6 +336,11 @@ def check_tree_text(tree, path, pat, regexp):
333336
return ret
334337

335338

339+
def check_tree_count(tree, path, count):
340+
path = normalize_xpath(path)
341+
return len(tree.findall(path)) == count
342+
343+
336344
def check(target, commands):
337345
cache = CachedFiles(target)
338346
for c in commands:
@@ -360,6 +368,13 @@ def check(target, commands):
360368
raise RuntimeError('Invalid number of @{} arguments \
361369
at line {}'.format(c.cmd, c.lineno))
362370

371+
elif c.cmd == 'count': # count test
372+
if len(c.args) == 3: # @count <path> <pat> <count> = count test
373+
ret = check_tree_count(cache.get_tree(c.args[0]), c.args[1], int(c.args[2]))
374+
else:
375+
raise RuntimeError('Invalid number of @{} arguments \
376+
at line {}'.format(c.cmd, c.lineno))
377+
363378
elif c.cmd == 'valid-html':
364379
raise RuntimeError('Unimplemented @valid-html at line {}'.format(c.lineno))
365380

src/librustdoc/clean/inline.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
308308
if method.vis != ast::Public && associated_trait.is_none() {
309309
return None
310310
}
311+
if method.provided_source.is_some() {
312+
return None
313+
}
311314
let mut item = method.clean(cx);
312315
item.inner = match item.inner.clone() {
313316
clean::TyMethodItem(clean::TyMethod {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-include ../tools.mk
2+
3+
all: lib.rs ext.rs
4+
$(HOST_RPATH_ENV) $(RUSTC) ext.rs
5+
$(HOST_RPATH_ENV) $(RUSTDOC) -L $(TMPDIR) -w html -o $(TMPDIR)/doc lib.rs
6+
$(HTMLDOCCK) $(TMPDIR)/doc lib.rs
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
#![crate_type="lib"]
12+
13+
pub trait Trait {
14+
fn provided(&self) {}
15+
}
16+
17+
pub struct Struct;
18+
19+
impl Trait for Struct {
20+
fn provided(&self) {}
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
extern crate ext;
12+
13+
// @count lib/struct.Struct.html '//*[@id="method.provided"]' 1
14+
pub use ext::Struct;

0 commit comments

Comments
 (0)