@@ -20,7 +20,7 @@ pub use self::FunctionRetTy::*;
20
20
pub use self :: Visibility :: * ;
21
21
22
22
use syntax:: abi:: Abi ;
23
- use syntax:: ast;
23
+ use syntax:: ast:: { self , AttrStyle } ;
24
24
use syntax:: attr;
25
25
use syntax:: codemap:: Spanned ;
26
26
use syntax:: feature_gate:: UnstableFeatures ;
@@ -472,11 +472,22 @@ impl Clean<Item> for doctree::Module {
472
472
"" . to_string ( )
473
473
} ;
474
474
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
+ } ;
480
491
481
492
let mut items: Vec < Item > = vec ! [ ] ;
482
493
items. extend ( self . extern_crates . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
0 commit comments