Skip to content

Commit 2acad9c

Browse files
committed
Rollup merge of rust-lang#32434 - mitaa:rdoc-no-inline, r=alexcrichton
rustdoc: Consider `doc(no_inline)` in crate-local inlining Imports with `doc(no_inline)` will not be inlined, even when `doc(inline)` is present. fixes rust-lang#32343 r? @alexcrichton
2 parents d7bf3d3 + 4c71347 commit 2acad9c

File tree

7 files changed

+48
-11
lines changed

7 files changed

+48
-11
lines changed

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub fn build_impls(cx: &DocContext,
256256
cstore::DlImpl(did) => build_impl(cx, tcx, did, impls),
257257
cstore::DlDef(Def::Mod(did)) => {
258258
// Don't recurse if this is a #[doc(hidden)] module
259-
if load_attrs(cx, tcx, did).list_def("doc").has_word("hidden") {
259+
if load_attrs(cx, tcx, did).list("doc").has_word("hidden") {
260260
return;
261261
}
262262

@@ -299,7 +299,7 @@ pub fn build_impl(cx: &DocContext,
299299
if let Some(ref t) = associated_trait {
300300
// If this is an impl for a #[doc(hidden)] trait, be sure to not inline
301301
let trait_attrs = load_attrs(cx, tcx, t.def_id);
302-
if trait_attrs.list_def("doc").has_word("hidden") {
302+
if trait_attrs.list("doc").has_word("hidden") {
303303
return
304304
}
305305
}

src/librustdoc/clean/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl Clean<Item> for doctree::Module {
418418
pub trait Attributes {
419419
fn has_word(&self, &str) -> bool;
420420
fn value<'a>(&'a self, &str) -> Option<&'a str>;
421-
fn list_def<'a>(&'a self, &str) -> &'a [Attribute];
421+
fn list<'a>(&'a self, &str) -> &'a [Attribute];
422422
}
423423

424424
impl Attributes for [Attribute] {
@@ -447,7 +447,7 @@ impl Attributes for [Attribute] {
447447
}
448448

449449
/// Finds an attribute as List and returns the list of attributes nested inside.
450-
fn list_def<'a>(&'a self, name: &str) -> &'a [Attribute] {
450+
fn list<'a>(&'a self, name: &str) -> &'a [Attribute] {
451451
for attr in self {
452452
if let List(ref x, ref list) = *attr {
453453
if name == *x {
@@ -1535,7 +1535,7 @@ impl PrimitiveType {
15351535
}
15361536

15371537
fn find(attrs: &[Attribute]) -> Option<PrimitiveType> {
1538-
for attr in attrs.list_def("doc") {
1538+
for attr in attrs.list("doc") {
15391539
if let NameValue(ref k, ref v) = *attr {
15401540
if "primitive" == *k {
15411541
if let ret@Some(..) = PrimitiveType::from_str(v) {

src/librustdoc/html/render.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ pub fn run(mut krate: clean::Crate,
432432

433433
// Crawl the crate attributes looking for attributes which control how we're
434434
// going to emit HTML
435-
if let Some(attrs) = krate.module.as_ref().map(|m| m.attrs.list_def("doc")) {
435+
if let Some(attrs) = krate.module.as_ref().map(|m| m.attrs.list("doc")) {
436436
for attr in attrs {
437437
match *attr {
438438
clean::NameValue(ref x, ref s)
@@ -832,7 +832,7 @@ fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation {
832832

833833
// Failing that, see if there's an attribute specifying where to find this
834834
// external crate
835-
e.attrs.list_def("doc").value("html_root_url").map(|url| {
835+
e.attrs.list("doc").value("html_root_url").map(|url| {
836836
let mut url = url.to_owned();
837837
if !url.ends_with("/") {
838838
url.push('/')
@@ -1846,6 +1846,7 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
18461846

18471847
fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
18481848
f: &clean::Function) -> fmt::Result {
1849+
// FIXME(#24111): remove when `const_fn` is stabilized
18491850
let vis_constness = match get_unstable_features_setting() {
18501851
UnstableFeatures::Allow => f.constness,
18511852
_ => hir::Constness::NotConst

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
383383

384384
// Process all of the crate attributes, extracting plugin metadata along
385385
// with the passes which we are supposed to run.
386-
for attr in krate.module.as_ref().unwrap().attrs.list_def("doc") {
386+
for attr in krate.module.as_ref().unwrap().attrs.list("doc") {
387387
match *attr {
388388
clean::Word(ref w) if "no_default_passes" == *w => {
389389
default_passes = false;

src/librustdoc/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
3333
}
3434
impl<'a> fold::DocFolder for Stripper<'a> {
3535
fn fold_item(&mut self, i: Item) -> Option<Item> {
36-
if i.attrs.list_def("doc").has_word("hidden") {
36+
if i.attrs.list("doc").has_word("hidden") {
3737
debug!("found one in strip_hidden; removing");
3838
self.stripped.insert(i.def_id);
3939

src/librustdoc/visit_ast.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
229229
while let Some(id) = cx.map.get_enclosing_scope(node) {
230230
node = id;
231231
let attrs = cx.map.attrs(node).clean(cx);
232-
if attrs.list_def("doc").has_word("hidden") {
232+
if attrs.list("doc").has_word("hidden") {
233233
return true;
234234
}
235235
if node == ast::CRATE_NODE_ID {
@@ -251,11 +251,14 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
251251
Some(analysis) => analysis, None => return false
252252
};
253253

254+
let use_attrs = tcx.map.attrs(id).clean(self.cx);
255+
254256
let is_private = !analysis.access_levels.is_public(def);
255257
let is_hidden = inherits_doc_hidden(self.cx, def_node_id);
258+
let is_no_inline = use_attrs.list("doc").has_word("no_inline");
256259

257260
// Only inline if requested or if the item would otherwise be stripped
258-
if !please_inline && !is_private && !is_hidden {
261+
if (!please_inline && !is_private && !is_hidden) || is_no_inline {
259262
return false
260263
}
261264

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2016 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+
// @!has issue_32343/struct.Foo.html
12+
// @has issue_32343/index.html
13+
// @has - '//code' 'pub use foo::Foo'
14+
// @!has - '//code/a' 'Foo'
15+
#[doc(no_inline)]
16+
pub use foo::Foo;
17+
18+
// @!has issue_32343/struct.Bar.html
19+
// @has issue_32343/index.html
20+
// @has - '//code' 'pub use foo::Bar'
21+
// @has - '//code/a' 'Bar'
22+
#[doc(no_inline)]
23+
pub use foo::Bar;
24+
25+
mod foo {
26+
pub struct Foo;
27+
pub struct Bar;
28+
}
29+
30+
pub mod bar {
31+
// @has issue_32343/bar/struct.Bar.html
32+
pub use ::foo::Bar;
33+
}

0 commit comments

Comments
 (0)