Skip to content

Commit 0cb6a1f

Browse files
committed
rustdoc: Fix names of items in cross crate reexported modules
For renamed reexports the new name should be used.
1 parent 14f30da commit 0cb6a1f

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

Diff for: src/librustdoc/clean/inline.rs

+6-22
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,11 @@ use super::Clean;
4141
///
4242
/// The returned value is `None` if the definition could not be inlined,
4343
/// and `Some` of a vector of items if it was successfully expanded.
44-
pub fn try_inline(cx: &DocContext, def: Def, into: Option<ast::Name>)
44+
pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name)
4545
-> Option<Vec<clean::Item>> {
4646
if def == Def::Err { return None }
4747
let did = def.def_id();
4848
if did.is_local() { return None }
49-
try_inline_def(cx, def).map(|vec| {
50-
vec.into_iter().map(|mut item| {
51-
match into {
52-
Some(into) if item.name.is_some() => {
53-
item.name = Some(into.clean(cx));
54-
}
55-
_ => {}
56-
}
57-
item
58-
}).collect()
59-
})
60-
}
61-
62-
fn try_inline_def(cx: &DocContext, def: Def) -> Option<Vec<clean::Item>> {
63-
let tcx = cx.tcx;
6449
let mut ret = Vec::new();
6550
let inner = match def {
6651
Def::Trait(did) => {
@@ -112,16 +97,15 @@ fn try_inline_def(cx: &DocContext, def: Def) -> Option<Vec<clean::Item>> {
11297
}
11398
_ => return None,
11499
};
115-
let did = def.def_id();
116100
cx.renderinfo.borrow_mut().inlined.insert(did);
117101
ret.push(clean::Item {
118-
source: tcx.def_span(did).clean(cx),
119-
name: Some(tcx.item_name(did).to_string()),
102+
source: cx.tcx.def_span(did).clean(cx),
103+
name: Some(name.clean(cx)),
120104
attrs: load_attrs(cx, did),
121105
inner: inner,
122106
visibility: Some(clean::Public),
123-
stability: tcx.lookup_stability(did).clean(cx),
124-
deprecation: tcx.lookup_deprecation(did).clean(cx),
107+
stability: cx.tcx.lookup_stability(did).clean(cx),
108+
deprecation: cx.tcx.lookup_deprecation(did).clean(cx),
125109
def_id: did,
126110
});
127111
Some(ret)
@@ -463,7 +447,7 @@ fn build_module(cx: &DocContext, did: DefId) -> clean::Module {
463447
let def_id = item.def.def_id();
464448
if cx.tcx.sess.cstore.visibility(def_id) == ty::Visibility::Public {
465449
if !visited.insert(def_id) { continue }
466-
if let Some(i) = try_inline_def(cx, item.def) {
450+
if let Some(i) = try_inline(cx, item.def, item.name) {
467451
items.extend(i)
468452
}
469453
}

Diff for: src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,7 @@ impl Clean<Vec<Item>> for doctree::Import {
26182618
} else {
26192619
let name = self.name;
26202620
if !denied {
2621-
if let Some(items) = inline::try_inline(cx, path.def, Some(name)) {
2621+
if let Some(items) = inline::try_inline(cx, path.def, name) {
26222622
return items;
26232623
}
26242624
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 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 = "foo"]
12+
13+
pub mod iter {
14+
mod range {
15+
pub struct StepBy;
16+
}
17+
pub use self::range::StepBy as DeprecatedStepBy;
18+
pub struct StepBy;
19+
}

Diff for: src/test/rustdoc/inline_cross/renamed-via-module.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 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:renamed-via-module.rs
12+
// build-aux-docs
13+
// ignore-cross-compile
14+
15+
#![crate_name = "bar"]
16+
17+
extern crate foo;
18+
19+
// @has foo/iter/index.html
20+
// @has - '//a/[@href="struct.DeprecatedStepBy.html"]' "DeprecatedStepBy"
21+
// @has - '//a/[@href="struct.StepBy.html"]' "StepBy"
22+
// @has foo/iter/struct.DeprecatedStepBy.html
23+
// @has - '//h1' "Struct foo::iter::DeprecatedStepBy"
24+
// @has foo/iter/struct.StepBy.html
25+
// @has - '//h1' "Struct foo::iter::StepBy"
26+
27+
// @has bar/iter/index.html
28+
// @has - '//a/[@href="struct.DeprecatedStepBy.html"]' "DeprecatedStepBy"
29+
// @has - '//a/[@href="struct.StepBy.html"]' "StepBy"
30+
// @has bar/iter/struct.DeprecatedStepBy.html
31+
// @has - '//h1' "Struct bar::iter::DeprecatedStepBy"
32+
// @has bar/iter/struct.StepBy.html
33+
// @has - '//h1' "Struct bar::iter::StepBy"
34+
pub use foo::iter;

0 commit comments

Comments
 (0)