Skip to content

Commit b31bb09

Browse files
QuietMisdreavusManishearth
authored andcommitted
resolve module docs based on inner/outer attributes
1 parent 1a62b17 commit b31bb09

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use self::FunctionRetTy::*;
2020
pub use self::Visibility::*;
2121

2222
use syntax::abi::Abi;
23-
use syntax::ast;
23+
use syntax::ast::{self, AttrStyle};
2424
use syntax::attr;
2525
use syntax::codemap::Spanned;
2626
use syntax::feature_gate::UnstableFeatures;
@@ -472,11 +472,22 @@ impl Clean<Item> for doctree::Module {
472472
"".to_string()
473473
};
474474

475-
// maintain a stack of mod ids
476-
// we could also pass this down through clean()
477-
// but that might complicate things.
478-
cx.mod_ids.borrow_mut().push(self.id);
479-
let attrs = self.attrs.clean(cx);
475+
// maintain a stack of mod ids, for doc comment path resolution
476+
// but we also need to resolve the module's own docs based on whether its docs were written
477+
// inside or outside the module, so check for that
478+
let attrs = if self.attrs.iter()
479+
.filter(|a| a.check_name("doc"))
480+
.next()
481+
.map_or(true, |a| a.style == AttrStyle::Inner) {
482+
// inner doc comment, use the module's own scope for resolution
483+
cx.mod_ids.borrow_mut().push(self.id);
484+
self.attrs.clean(cx)
485+
} else {
486+
// outer doc comment, use its parent's scope
487+
let attrs = self.attrs.clean(cx);
488+
cx.mod_ids.borrow_mut().push(self.id);
489+
attrs
490+
};
480491

481492
let mut items: Vec<Item> = vec![];
482493
items.extend(self.extern_crates.iter().map(|x| x.clean(cx)));

0 commit comments

Comments
 (0)