about summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuietMisdreavus <grey@quietmisdreavus.net>2018-01-08 11:10:50 -0600
committerManish Goregaokar <manishsmail@gmail.com>2018-01-22 15:24:30 +0530
commitb31bb097f519f03a5925da376d4ef2fbc8f30c62 (patch)
tree4b55903785680119cb8d5951e342bddc2bd6498c
parent1a62b17f7d68dfa1ec2f25e02e5cd3dc0095ea94 (diff)
downloadrust-b31bb097f519f03a5925da376d4ef2fbc8f30c62.tar.gz
rust-b31bb097f519f03a5925da376d4ef2fbc8f30c62.zip
resolve module docs based on inner/outer attributes
-rw-r--r--src/librustdoc/clean/mod.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index cd78209df30..e1dbcb27864 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -20,7 +20,7 @@ pub use self::FunctionRetTy::*;
 pub use self::Visibility::*;
 
 use syntax::abi::Abi;
-use syntax::ast;
+use syntax::ast::{self, AttrStyle};
 use syntax::attr;
 use syntax::codemap::Spanned;
 use syntax::feature_gate::UnstableFeatures;
@@ -472,11 +472,22 @@ impl Clean<Item> for doctree::Module {
             "".to_string()
         };
 
-        // maintain a stack of mod ids
-        // we could also pass this down through clean()
-        // but that might complicate things.
-        cx.mod_ids.borrow_mut().push(self.id);
-        let attrs = self.attrs.clean(cx);
+        // maintain a stack of mod ids, for doc comment path resolution
+        // but we also need to resolve the module's own docs based on whether its docs were written
+        // inside or outside the module, so check for that
+        let attrs = if self.attrs.iter()
+                                 .filter(|a| a.check_name("doc"))
+                                 .next()
+                                 .map_or(true, |a| a.style == AttrStyle::Inner) {
+            // inner doc comment, use the module's own scope for resolution
+            cx.mod_ids.borrow_mut().push(self.id);
+            self.attrs.clean(cx)
+        } else {
+            // outer doc comment, use its parent's scope
+            let attrs = self.attrs.clean(cx);
+            cx.mod_ids.borrow_mut().push(self.id);
+            attrs
+        };
 
         let mut items: Vec<Item> = vec![];
         items.extend(self.extern_crates.iter().map(|x| x.clean(cx)));