Skip to content

Commit

Permalink
process cross-crate glob re-exports
Browse files Browse the repository at this point in the history
  • Loading branch information
QuietMisdreavus committed Jun 15, 2018
1 parent 24edc41 commit 042f1df
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/librustdoc/clean/inline.rs
Expand Up @@ -116,6 +116,23 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa
Some(ret)
}

pub fn try_inline_glob(cx: &DocContext, def: Def, visited: &mut FxHashSet<DefId>)
-> Option<Vec<clean::Item>>
{
if def == Def::Err { return None }
let did = def.def_id();
if did.is_local() { return None }

match def {
Def::Mod(did) => {
let m = build_module(cx, did, visited);
Some(m.items)
}
// glob imports on things like enums aren't inlined even for local exports, so just bail
_ => None,
}
}

pub fn load_attrs(cx: &DocContext, did: DefId) -> clean::Attributes {
cx.tcx.get_attrs(did).clean(cx)
}
Expand Down
7 changes: 7 additions & 0 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -3862,6 +3862,13 @@ impl Clean<Vec<Item>> for doctree::Import {
});
let path = self.path.clean(cx);
let inner = if self.glob {
if !denied {
let mut visited = FxHashSet();
if let Some(items) = inline::try_inline_glob(cx, path.def, &mut visited) {
return items;
}
}

Import::Glob(resolve_use_source(cx, path))
} else {
let name = self.name;
Expand Down
15 changes: 15 additions & 0 deletions src/test/rustdoc/inline_cross/auxiliary/cross-glob.rs
@@ -0,0 +1,15 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![crate_name = "inner"]

pub struct SomeStruct;

pub fn some_fn() {}
21 changes: 21 additions & 0 deletions src/test/rustdoc/inline_cross/cross-glob.rs
@@ -0,0 +1,21 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:cross-glob.rs
// build-aux-docs
// ignore-cross-compile

extern crate inner;

// @has cross_glob/struct.SomeStruct.html
// @has cross_glob/fn.some_fn.html
// @!has cross_glob/index.html '//code' 'pub use inner::*;'
#[doc(inline)]
pub use inner::*;

0 comments on commit 042f1df

Please sign in to comment.