]> git.lizzy.rs Git - rust.git/commitdiff
Consider `doc(no_inline)` in crate-local inlining
authormitaa <mitaa.ceb@gmail.com>
Tue, 22 Mar 2016 19:26:33 +0000 (20:26 +0100)
committermitaa <mitaa.ceb@gmail.com>
Tue, 22 Mar 2016 20:11:00 +0000 (21:11 +0100)
src/librustdoc/clean/inline.rs
src/librustdoc/clean/mod.rs
src/librustdoc/html/render.rs
src/librustdoc/lib.rs
src/librustdoc/passes.rs
src/librustdoc/visit_ast.rs
src/test/rustdoc/inline_local/issue-32343.rs [new file with mode: 0644]

index 49091a6c2bcfc9ea87d1686a3bcc6bc2791240ef..e9c55c56a9d7226216aef54ade59825e99b1a654 100644 (file)
@@ -256,7 +256,7 @@ fn populate_impls(cx: &DocContext, tcx: &TyCtxt,
                 cstore::DlImpl(did) => build_impl(cx, tcx, did, impls),
                 cstore::DlDef(Def::Mod(did)) => {
                     // Don't recurse if this is a #[doc(hidden)] module
-                    if load_attrs(cx, tcx, did).list_def("doc").has_word("hidden") {
+                    if load_attrs(cx, tcx, did).list("doc").has_word("hidden") {
                         return;
                     }
 
@@ -299,7 +299,7 @@ pub fn build_impl(cx: &DocContext,
     if let Some(ref t) = associated_trait {
         // If this is an impl for a #[doc(hidden)] trait, be sure to not inline
         let trait_attrs = load_attrs(cx, tcx, t.def_id);
-        if trait_attrs.list_def("doc").has_word("hidden") {
+        if trait_attrs.list("doc").has_word("hidden") {
             return
         }
     }
index 54821bd1161ee41648a7c94f0d2e069fb48045bf..651294a8e270d3e08ce7789856ba61fce9b5f49b 100644 (file)
@@ -418,7 +418,7 @@ fn clean(&self, cx: &DocContext) -> Item {
 pub trait Attributes {
     fn has_word(&self, &str) -> bool;
     fn value<'a>(&'a self, &str) -> Option<&'a str>;
-    fn list_def<'a>(&'a self, &str) -> &'a [Attribute];
+    fn list<'a>(&'a self, &str) -> &'a [Attribute];
 }
 
 impl Attributes for [Attribute] {
@@ -447,7 +447,7 @@ fn value<'a>(&'a self, name: &str) -> Option<&'a str> {
     }
 
     /// Finds an attribute as List and returns the list of attributes nested inside.
-    fn list_def<'a>(&'a self, name: &str) -> &'a [Attribute] {
+    fn list<'a>(&'a self, name: &str) -> &'a [Attribute] {
         for attr in self {
             if let List(ref x, ref list) = *attr {
                 if name == *x {
@@ -1535,7 +1535,7 @@ fn from_str(s: &str) -> Option<PrimitiveType> {
     }
 
     fn find(attrs: &[Attribute]) -> Option<PrimitiveType> {
-        for attr in attrs.list_def("doc") {
+        for attr in attrs.list("doc") {
             if let NameValue(ref k, ref v) = *attr {
                 if "primitive" == *k {
                     if let ret@Some(..) = PrimitiveType::from_str(v) {
index eb2d78689451eec6cb1749baa133bee866e0dd70..1e59920d66d15643d9f4e8780dc7630df5141b37 100644 (file)
@@ -432,7 +432,7 @@ pub fn run(mut krate: clean::Crate,
 
     // Crawl the crate attributes looking for attributes which control how we're
     // going to emit HTML
-    if let Some(attrs) = krate.module.as_ref().map(|m| m.attrs.list_def("doc")) {
+    if let Some(attrs) = krate.module.as_ref().map(|m| m.attrs.list("doc")) {
         for attr in attrs {
             match *attr {
                 clean::NameValue(ref x, ref s)
@@ -832,7 +832,7 @@ fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation {
 
     // Failing that, see if there's an attribute specifying where to find this
     // external crate
-    e.attrs.list_def("doc").value("html_root_url").map(|url| {
+    e.attrs.list("doc").value("html_root_url").map(|url| {
         let mut url = url.to_owned();
         if !url.ends_with("/") {
             url.push('/')
@@ -1846,6 +1846,7 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
 
 fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
                  f: &clean::Function) -> fmt::Result {
+    // FIXME(#24111): remove when `const_fn` is stabilized
     let vis_constness = match get_unstable_features_setting() {
         UnstableFeatures::Allow => f.constness,
         _ => hir::Constness::NotConst
index 8a0ad987e2107e695178132eaeaf7e91c609cd74..a68f0a39ca94c0e4149625f8e413049fb023ab0e 100644 (file)
@@ -383,7 +383,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
 
     // Process all of the crate attributes, extracting plugin metadata along
     // with the passes which we are supposed to run.
-    for attr in krate.module.as_ref().unwrap().attrs.list_def("doc") {
+    for attr in krate.module.as_ref().unwrap().attrs.list("doc") {
         match *attr {
             clean::Word(ref w) if "no_default_passes" == *w => {
                 default_passes = false;
index 2eb82dec6daa472e27c74dad4819e0d8d2e5f537..154b812cdff3ed5fe271feccc16cd987c2eab1be 100644 (file)
@@ -33,7 +33,7 @@ struct Stripper<'a> {
         }
         impl<'a> fold::DocFolder for Stripper<'a> {
             fn fold_item(&mut self, i: Item) -> Option<Item> {
-                if i.attrs.list_def("doc").has_word("hidden") {
+                if i.attrs.list("doc").has_word("hidden") {
                     debug!("found one in strip_hidden; removing");
                     self.stripped.insert(i.def_id);
 
index 4c03abac9e867b6f43203975eb10928a8332f558..e4ef0c1a4d6304bc4e167608c030f7a831b24838 100644 (file)
@@ -229,7 +229,7 @@ fn inherits_doc_hidden(cx: &core::DocContext, mut node: ast::NodeId) -> bool {
             while let Some(id) = cx.map.get_enclosing_scope(node) {
                 node = id;
                 let attrs = cx.map.attrs(node).clean(cx);
-                if attrs.list_def("doc").has_word("hidden") {
+                if attrs.list("doc").has_word("hidden") {
                     return true;
                 }
                 if node == ast::CRATE_NODE_ID {
@@ -251,11 +251,14 @@ fn inherits_doc_hidden(cx: &core::DocContext, mut node: ast::NodeId) -> bool {
             Some(analysis) => analysis, None => return false
         };
 
+        let use_attrs = tcx.map.attrs(id).clean(self.cx);
+
         let is_private = !analysis.access_levels.is_public(def);
         let is_hidden = inherits_doc_hidden(self.cx, def_node_id);
+        let is_no_inline = use_attrs.list("doc").has_word("no_inline");
 
         // Only inline if requested or if the item would otherwise be stripped
-        if !please_inline && !is_private && !is_hidden {
+        if (!please_inline && !is_private && !is_hidden) || is_no_inline {
             return false
         }
 
diff --git a/src/test/rustdoc/inline_local/issue-32343.rs b/src/test/rustdoc/inline_local/issue-32343.rs
new file mode 100644 (file)
index 0000000..a045c96
--- /dev/null
@@ -0,0 +1,33 @@
+// 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.
+
+// @!has issue_32343/struct.Foo.html
+// @has issue_32343/index.html
+// @has - '//code' 'pub use foo::Foo'
+// @!has - '//code/a' 'Foo'
+#[doc(no_inline)]
+pub use foo::Foo;
+
+// @!has issue_32343/struct.Bar.html
+// @has issue_32343/index.html
+// @has - '//code' 'pub use foo::Bar'
+// @has - '//code/a' 'Bar'
+#[doc(no_inline)]
+pub use foo::Bar;
+
+mod foo {
+    pub struct Foo;
+    pub struct Bar;
+}
+
+pub mod bar {
+    // @has issue_32343/bar/struct.Bar.html
+    pub use ::foo::Bar;
+}