Skip to content

Commit 52955dd

Browse files
committed
rustdoc: Allow forcing inlining of pub use
Rustdoc currently doesn't inline documentation of a `pub use` if the target is publicly reachable. This changes rustdoc to allow a #[doc(inline)] attribute to force inlining the documentation, regardless of whether the targe is public or not. Closes #13045
1 parent eb084b1 commit 52955dd

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/librustdoc/visit_ast.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use syntax::abi;
1515
use syntax::ast;
1616
use syntax::ast_util;
1717
use syntax::ast_map;
18+
use syntax::attr::AttrMetaMethods;
1819
use syntax::codemap::Span;
1920

2021
use core;
@@ -133,9 +134,17 @@ impl<'a> RustdocVisitor<'a> {
133134
if item.vis != ast::Public {
134135
return om.view_items.push(item.clone());
135136
}
137+
let please_inline = item.attrs.iter().any(|item| {
138+
match item.meta_item_list() {
139+
Some(list) => {
140+
list.iter().any(|i| i.name().get() == "inline")
141+
}
142+
None => false,
143+
}
144+
});
136145
let item = match item.node {
137146
ast::ViewItemUse(ref vpath) => {
138-
match self.visit_view_path(*vpath, om) {
147+
match self.visit_view_path(*vpath, om, please_inline) {
139148
None => return,
140149
Some(path) => {
141150
ast::ViewItem {
@@ -151,15 +160,16 @@ impl<'a> RustdocVisitor<'a> {
151160
}
152161

153162
fn visit_view_path(&mut self, path: @ast::ViewPath,
154-
om: &mut Module) -> Option<@ast::ViewPath> {
163+
om: &mut Module,
164+
please_inline: bool) -> Option<@ast::ViewPath> {
155165
match path.node {
156166
ast::ViewPathSimple(_, _, id) => {
157-
if self.resolve_id(id, false, om) { return None }
167+
if self.resolve_id(id, false, om, please_inline) { return None }
158168
}
159169
ast::ViewPathList(ref p, ref paths, ref b) => {
160170
let mut mine = Vec::new();
161171
for path in paths.iter() {
162-
if !self.resolve_id(path.node.id, false, om) {
172+
if !self.resolve_id(path.node.id, false, om, please_inline) {
163173
mine.push(path.clone());
164174
}
165175
}
@@ -173,14 +183,14 @@ impl<'a> RustdocVisitor<'a> {
173183

174184
// these are feature gated anyway
175185
ast::ViewPathGlob(_, id) => {
176-
if self.resolve_id(id, true, om) { return None }
186+
if self.resolve_id(id, true, om, please_inline) { return None }
177187
}
178188
}
179189
return Some(path);
180190
}
181191

182192
fn resolve_id(&mut self, id: ast::NodeId, glob: bool,
183-
om: &mut Module) -> bool {
193+
om: &mut Module, please_inline: bool) -> bool {
184194
let tcx = match self.cx.maybe_typed {
185195
core::Typed(ref tcx) => tcx,
186196
core::NotTyped(_) => return false
@@ -190,7 +200,9 @@ impl<'a> RustdocVisitor<'a> {
190200
let analysis = match self.analysis {
191201
Some(analysis) => analysis, None => return false
192202
};
193-
if analysis.public_items.contains(&def.node) { return false }
203+
if !please_inline && analysis.public_items.contains(&def.node) {
204+
return false
205+
}
194206

195207
match tcx.map.get(def.node) {
196208
ast_map::NodeItem(it) => {

0 commit comments

Comments
 (0)