@@ -20,7 +20,7 @@ pub use self::Visibility::{Public, Inherited};
20
20
21
21
use rustc_target:: spec:: abi:: Abi ;
22
22
use syntax;
23
- use syntax:: ast:: { self , AttrStyle , NodeId , Ident } ;
23
+ use syntax:: ast:: { self , AttrStyle , Name , NodeId , Ident } ;
24
24
use syntax:: attr;
25
25
use syntax:: codemap:: { dummy_spanned, Spanned } ;
26
26
use syntax:: feature_gate:: UnstableFeatures ;
@@ -39,6 +39,7 @@ use rustc::hir::{self, GenericArg, HirVec};
39
39
use rustc:: hir:: def:: { self , Def , CtorKind } ;
40
40
use rustc:: hir:: def_id:: { CrateNum , DefId , DefIndex , CRATE_DEF_INDEX , LOCAL_CRATE } ;
41
41
use rustc:: hir:: def_id:: DefIndexAddressSpace ;
42
+ use rustc:: hir:: map:: Node ;
42
43
use rustc:: ty:: subst:: Substs ;
43
44
use rustc:: ty:: { self , TyCtxt , Region , RegionVid , Ty , AdtKind } ;
44
45
use rustc:: middle:: stability;
@@ -584,10 +585,23 @@ impl Clean<Item> for doctree::Module {
584
585
. next ( )
585
586
. map_or ( true , |a| a. style == AttrStyle :: Inner ) {
586
587
// inner doc comment, use the module's own scope for resolution
588
+ if self . id != NodeId :: new ( 0 ) {
589
+ * cx. current_item_name . borrow_mut ( ) = Some ( cx. tcx . hir . name ( self . id ) ) ;
590
+ } else {
591
+ * cx. current_item_name . borrow_mut ( ) = None ;
592
+ }
587
593
cx. mod_ids . borrow_mut ( ) . push ( self . id ) ;
588
594
self . attrs . clean ( cx)
589
595
} else {
590
596
// outer doc comment, use its parent's scope
597
+ match cx. mod_ids . borrow ( ) . last ( ) {
598
+ Some ( parent) if * parent != NodeId :: new ( 0 ) => {
599
+ * cx. current_item_name . borrow_mut ( ) = Some ( cx. tcx . hir . name ( * parent) ) ;
600
+ }
601
+ _ => {
602
+ * cx. current_item_name . borrow_mut ( ) = None ;
603
+ }
604
+ }
591
605
let attrs = self . attrs . clean ( cx) ;
592
606
cx. mod_ids . borrow_mut ( ) . push ( self . id ) ;
593
607
attrs
@@ -1165,11 +1179,17 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
1165
1179
} ;
1166
1180
1167
1181
let mut path = if let Some ( second) = split. next ( ) {
1168
- second
1182
+ second. to_owned ( )
1169
1183
} else {
1170
1184
return Err ( ( ) )
1171
1185
} ;
1172
1186
1187
+ if path == "self" || path == "Self" {
1188
+ if let Some ( name) = * cx. current_item_name . borrow ( ) {
1189
+ path = name. to_string ( ) ;
1190
+ }
1191
+ }
1192
+
1173
1193
let ty = cx. resolver . borrow_mut ( )
1174
1194
. with_scope ( * id,
1175
1195
|resolver| {
@@ -2143,6 +2163,8 @@ impl Clean<Item> for doctree::Function {
2143
2163
let ( generics, decl) = enter_impl_trait ( cx, || {
2144
2164
( self . generics . clean ( cx) , ( & self . decl , self . body ) . clean ( cx) )
2145
2165
} ) ;
2166
+
2167
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
2146
2168
Item {
2147
2169
name : Some ( self . name . clean ( cx) ) ,
2148
2170
attrs : self . attrs . clean ( cx) ,
@@ -2321,6 +2343,7 @@ pub struct Trait {
2321
2343
2322
2344
impl Clean < Item > for doctree:: Trait {
2323
2345
fn clean ( & self , cx : & DocContext ) -> Item {
2346
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
2324
2347
let attrs = self . attrs . clean ( cx) ;
2325
2348
let is_spotlight = attrs. has_doc_flag ( "spotlight" ) ;
2326
2349
Item {
@@ -2392,6 +2415,7 @@ impl Clean<Item> for hir::TraitItem {
2392
2415
AssociatedTypeItem ( bounds. clean ( cx) , default. clean ( cx) )
2393
2416
}
2394
2417
} ;
2418
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . ident . name ) ;
2395
2419
Item {
2396
2420
name : Some ( self . ident . name . clean ( cx) ) ,
2397
2421
attrs : self . attrs . clean ( cx) ,
@@ -2424,6 +2448,7 @@ impl Clean<Item> for hir::ImplItem {
2424
2448
generics : Generics :: default ( ) ,
2425
2449
} , true ) ,
2426
2450
} ;
2451
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . ident . name ) ;
2427
2452
Item {
2428
2453
name : Some ( self . ident . name . clean ( cx) ) ,
2429
2454
source : self . span . clean ( cx) ,
@@ -3217,6 +3242,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
3217
3242
3218
3243
impl Clean < Item > for hir:: StructField {
3219
3244
fn clean ( & self , cx : & DocContext ) -> Item {
3245
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . ident . name ) ;
3220
3246
Item {
3221
3247
name : Some ( self . ident . name ) . clean ( cx) ,
3222
3248
attrs : self . attrs . clean ( cx) ,
@@ -3295,6 +3321,7 @@ impl Clean<Vec<Item>> for doctree::Struct {
3295
3321
let name = self . name . clean ( cx) ;
3296
3322
let mut ret = get_auto_traits_with_node_id ( cx, self . id , name. clone ( ) ) ;
3297
3323
3324
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3298
3325
ret. push ( Item {
3299
3326
name : Some ( name) ,
3300
3327
attrs : self . attrs . clean ( cx) ,
@@ -3320,6 +3347,7 @@ impl Clean<Vec<Item>> for doctree::Union {
3320
3347
let name = self . name . clean ( cx) ;
3321
3348
let mut ret = get_auto_traits_with_node_id ( cx, self . id , name. clone ( ) ) ;
3322
3349
3350
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3323
3351
ret. push ( Item {
3324
3352
name : Some ( name) ,
3325
3353
attrs : self . attrs . clean ( cx) ,
@@ -3372,6 +3400,7 @@ impl Clean<Vec<Item>> for doctree::Enum {
3372
3400
let name = self . name . clean ( cx) ;
3373
3401
let mut ret = get_auto_traits_with_node_id ( cx, self . id , name. clone ( ) ) ;
3374
3402
3403
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3375
3404
ret. push ( Item {
3376
3405
name : Some ( name) ,
3377
3406
attrs : self . attrs . clean ( cx) ,
@@ -3398,6 +3427,7 @@ pub struct Variant {
3398
3427
3399
3428
impl Clean < Item > for doctree:: Variant {
3400
3429
fn clean ( & self , cx : & DocContext ) -> Item {
3430
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3401
3431
Item {
3402
3432
name : Some ( self . name . clean ( cx) ) ,
3403
3433
attrs : self . attrs . clean ( cx) ,
@@ -3693,6 +3723,7 @@ pub struct Typedef {
3693
3723
3694
3724
impl Clean < Item > for doctree:: Typedef {
3695
3725
fn clean ( & self , cx : & DocContext ) -> Item {
3726
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3696
3727
Item {
3697
3728
name : Some ( self . name . clean ( cx) ) ,
3698
3729
attrs : self . attrs . clean ( cx) ,
@@ -3768,6 +3799,7 @@ pub struct Static {
3768
3799
impl Clean < Item > for doctree:: Static {
3769
3800
fn clean ( & self , cx : & DocContext ) -> Item {
3770
3801
debug ! ( "cleaning static {}: {:?}" , self . name. clean( cx) , self ) ;
3802
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3771
3803
Item {
3772
3804
name : Some ( self . name . clean ( cx) ) ,
3773
3805
attrs : self . attrs . clean ( cx) ,
@@ -3793,6 +3825,7 @@ pub struct Constant {
3793
3825
3794
3826
impl Clean < Item > for doctree:: Constant {
3795
3827
fn clean ( & self , cx : & DocContext ) -> Item {
3828
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3796
3829
Item {
3797
3830
name : Some ( self . name . clean ( cx) ) ,
3798
3831
attrs : self . attrs . clean ( cx) ,
@@ -3862,6 +3895,23 @@ pub fn get_auto_traits_with_def_id(cx: &DocContext, id: DefId) -> Vec<Item> {
3862
3895
finder. get_with_def_id ( id)
3863
3896
}
3864
3897
3898
+ fn get_name_if_possible ( cx : & DocContext , node : NodeId ) -> Option < Name > {
3899
+ match cx. tcx . hir . get ( node) {
3900
+ Node :: NodeItem ( _) |
3901
+ Node :: NodeForeignItem ( _) |
3902
+ Node :: NodeImplItem ( _) |
3903
+ Node :: NodeTraitItem ( _) |
3904
+ Node :: NodeVariant ( _) |
3905
+ Node :: NodeField ( _) |
3906
+ Node :: NodeLifetime ( _) |
3907
+ Node :: NodeGenericParam ( _) |
3908
+ Node :: NodeBinding ( & hir:: Pat { node : hir:: PatKind :: Binding ( _, _, _, _) , .. } ) |
3909
+ Node :: NodeStructCtor ( _) => { }
3910
+ _ => return None ,
3911
+ }
3912
+ Some ( cx. tcx . hir . name ( node) )
3913
+ }
3914
+
3865
3915
impl Clean < Vec < Item > > for doctree:: Impl {
3866
3916
fn clean ( & self , cx : & DocContext ) -> Vec < Item > {
3867
3917
let mut ret = Vec :: new ( ) ;
@@ -3881,6 +3931,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
3881
3931
. collect ( )
3882
3932
} ) . unwrap_or ( FxHashSet ( ) ) ;
3883
3933
3934
+ * cx. current_item_name . borrow_mut ( ) = get_name_if_possible ( cx, self . for_ . id ) ;
3884
3935
ret. push ( Item {
3885
3936
name : None ,
3886
3937
attrs : self . attrs . clean ( cx) ,
@@ -3967,6 +4018,7 @@ fn build_deref_target_impls(cx: &DocContext,
3967
4018
3968
4019
impl Clean < Item > for doctree:: ExternCrate {
3969
4020
fn clean ( & self , cx : & DocContext ) -> Item {
4021
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3970
4022
Item {
3971
4023
name : None ,
3972
4024
attrs : self . attrs . clean ( cx) ,
@@ -4013,6 +4065,8 @@ impl Clean<Vec<Item>> for doctree::Import {
4013
4065
}
4014
4066
Import :: Simple ( name. clean ( cx) , resolve_use_source ( cx, path) )
4015
4067
} ;
4068
+
4069
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
4016
4070
vec ! [ Item {
4017
4071
name: None ,
4018
4072
attrs: self . attrs. clean( cx) ,
@@ -4081,6 +4135,8 @@ impl Clean<Item> for hir::ForeignItem {
4081
4135
ForeignTypeItem
4082
4136
}
4083
4137
} ;
4138
+
4139
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
4084
4140
Item {
4085
4141
name : Some ( self . name . clean ( cx) ) ,
4086
4142
attrs : self . attrs . clean ( cx) ,
@@ -4256,6 +4312,7 @@ pub struct Macro {
4256
4312
impl Clean < Item > for doctree:: Macro {
4257
4313
fn clean ( & self , cx : & DocContext ) -> Item {
4258
4314
let name = self . name . clean ( cx) ;
4315
+ * cx. current_item_name . borrow_mut ( ) = None ;
4259
4316
Item {
4260
4317
name : Some ( name. clone ( ) ) ,
4261
4318
attrs : self . attrs . clean ( cx) ,
0 commit comments