]> git.lizzy.rs Git - rust.git/commitdiff
resolve module docs based on inner/outer attributes
authorQuietMisdreavus <grey@quietmisdreavus.net>
Mon, 8 Jan 2018 17:10:50 +0000 (11:10 -0600)
committerManish Goregaokar <manishsmail@gmail.com>
Mon, 22 Jan 2018 09:54:30 +0000 (15:24 +0530)
src/librustdoc/clean/mod.rs

index cd78209df3055e4a8c8879ef529de7b00d5745ec..e1dbcb27864d87cd940f39dd1da1faf01ab35abe 100644 (file)
@@ -20,7 +20,7 @@
 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 @@ fn clean(&self, cx: &DocContext) -> Item {
             "".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)));