@@ -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;
@@ -576,10 +577,23 @@ impl Clean<Item> for doctree::Module {
576
577
. next ( )
577
578
. map_or ( true , |a| a. style == AttrStyle :: Inner ) {
578
579
// inner doc comment, use the module's own scope for resolution
580
+ if self . id != NodeId :: new ( 0 ) {
581
+ * cx. current_item_name . borrow_mut ( ) = Some ( cx. tcx . hir . name ( self . id ) ) ;
582
+ } else {
583
+ * cx. current_item_name . borrow_mut ( ) = None ;
584
+ }
579
585
cx. mod_ids . borrow_mut ( ) . push ( self . id ) ;
580
586
self . attrs . clean ( cx)
581
587
} else {
582
588
// outer doc comment, use its parent's scope
589
+ match cx. mod_ids . borrow ( ) . last ( ) {
590
+ Some ( parent) if * parent != NodeId :: new ( 0 ) => {
591
+ * cx. current_item_name . borrow_mut ( ) = Some ( cx. tcx . hir . name ( * parent) ) ;
592
+ }
593
+ _ => {
594
+ * cx. current_item_name . borrow_mut ( ) = None ;
595
+ }
596
+ }
583
597
let attrs = self . attrs . clean ( cx) ;
584
598
cx. mod_ids . borrow_mut ( ) . push ( self . id ) ;
585
599
attrs
@@ -1132,11 +1146,17 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
1132
1146
} ;
1133
1147
1134
1148
let mut path = if let Some ( second) = split. next ( ) {
1135
- second
1149
+ second. to_owned ( )
1136
1150
} else {
1137
1151
return Err ( ( ) )
1138
1152
} ;
1139
1153
1154
+ if path == "self" || path == "Self" {
1155
+ if let Some ( name) = * cx. current_item_name . borrow ( ) {
1156
+ path = name. to_string ( ) ;
1157
+ }
1158
+ }
1159
+
1140
1160
let ty = cx. resolver . borrow_mut ( )
1141
1161
. with_scope ( * id,
1142
1162
|resolver| {
@@ -2110,6 +2130,8 @@ impl Clean<Item> for doctree::Function {
2110
2130
let ( generics, decl) = enter_impl_trait ( cx, || {
2111
2131
( self . generics . clean ( cx) , ( & self . decl , self . body ) . clean ( cx) )
2112
2132
} ) ;
2133
+
2134
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
2113
2135
Item {
2114
2136
name : Some ( self . name . clean ( cx) ) ,
2115
2137
attrs : self . attrs . clean ( cx) ,
@@ -2288,6 +2310,7 @@ pub struct Trait {
2288
2310
2289
2311
impl Clean < Item > for doctree:: Trait {
2290
2312
fn clean ( & self , cx : & DocContext ) -> Item {
2313
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
2291
2314
let attrs = self . attrs . clean ( cx) ;
2292
2315
let is_spotlight = attrs. has_doc_flag ( "spotlight" ) ;
2293
2316
Item {
@@ -2359,6 +2382,7 @@ impl Clean<Item> for hir::TraitItem {
2359
2382
AssociatedTypeItem ( bounds. clean ( cx) , default. clean ( cx) )
2360
2383
}
2361
2384
} ;
2385
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . ident . name ) ;
2362
2386
Item {
2363
2387
name : Some ( self . ident . name . clean ( cx) ) ,
2364
2388
attrs : self . attrs . clean ( cx) ,
@@ -2387,6 +2411,7 @@ impl Clean<Item> for hir::ImplItem {
2387
2411
generics : Generics :: default ( ) ,
2388
2412
} , true ) ,
2389
2413
} ;
2414
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . ident . name ) ;
2390
2415
Item {
2391
2416
name : Some ( self . ident . name . clean ( cx) ) ,
2392
2417
source : self . span . clean ( cx) ,
@@ -3179,6 +3204,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
3179
3204
3180
3205
impl Clean < Item > for hir:: StructField {
3181
3206
fn clean ( & self , cx : & DocContext ) -> Item {
3207
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . ident . name ) ;
3182
3208
Item {
3183
3209
name : Some ( self . ident . name ) . clean ( cx) ,
3184
3210
attrs : self . attrs . clean ( cx) ,
@@ -3257,6 +3283,7 @@ impl Clean<Vec<Item>> for doctree::Struct {
3257
3283
let name = self . name . clean ( cx) ;
3258
3284
let mut ret = get_auto_traits_with_node_id ( cx, self . id , name. clone ( ) ) ;
3259
3285
3286
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3260
3287
ret. push ( Item {
3261
3288
name : Some ( name) ,
3262
3289
attrs : self . attrs . clean ( cx) ,
@@ -3282,6 +3309,7 @@ impl Clean<Vec<Item>> for doctree::Union {
3282
3309
let name = self . name . clean ( cx) ;
3283
3310
let mut ret = get_auto_traits_with_node_id ( cx, self . id , name. clone ( ) ) ;
3284
3311
3312
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3285
3313
ret. push ( Item {
3286
3314
name : Some ( name) ,
3287
3315
attrs : self . attrs . clean ( cx) ,
@@ -3334,6 +3362,7 @@ impl Clean<Vec<Item>> for doctree::Enum {
3334
3362
let name = self . name . clean ( cx) ;
3335
3363
let mut ret = get_auto_traits_with_node_id ( cx, self . id , name. clone ( ) ) ;
3336
3364
3365
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3337
3366
ret. push ( Item {
3338
3367
name : Some ( name) ,
3339
3368
attrs : self . attrs . clean ( cx) ,
@@ -3360,6 +3389,7 @@ pub struct Variant {
3360
3389
3361
3390
impl Clean < Item > for doctree:: Variant {
3362
3391
fn clean ( & self , cx : & DocContext ) -> Item {
3392
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3363
3393
Item {
3364
3394
name : Some ( self . name . clean ( cx) ) ,
3365
3395
attrs : self . attrs . clean ( cx) ,
@@ -3655,6 +3685,7 @@ pub struct Typedef {
3655
3685
3656
3686
impl Clean < Item > for doctree:: Typedef {
3657
3687
fn clean ( & self , cx : & DocContext ) -> Item {
3688
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3658
3689
Item {
3659
3690
name : Some ( self . name . clean ( cx) ) ,
3660
3691
attrs : self . attrs . clean ( cx) ,
@@ -3706,6 +3737,7 @@ pub struct Static {
3706
3737
impl Clean < Item > for doctree:: Static {
3707
3738
fn clean ( & self , cx : & DocContext ) -> Item {
3708
3739
debug ! ( "cleaning static {}: {:?}" , self . name. clean( cx) , self ) ;
3740
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3709
3741
Item {
3710
3742
name : Some ( self . name . clean ( cx) ) ,
3711
3743
attrs : self . attrs . clean ( cx) ,
@@ -3731,6 +3763,7 @@ pub struct Constant {
3731
3763
3732
3764
impl Clean < Item > for doctree:: Constant {
3733
3765
fn clean ( & self , cx : & DocContext ) -> Item {
3766
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3734
3767
Item {
3735
3768
name : Some ( self . name . clean ( cx) ) ,
3736
3769
attrs : self . attrs . clean ( cx) ,
@@ -3800,6 +3833,23 @@ pub fn get_auto_traits_with_def_id(cx: &DocContext, id: DefId) -> Vec<Item> {
3800
3833
finder. get_with_def_id ( id)
3801
3834
}
3802
3835
3836
+ fn get_name_if_possible ( cx : & DocContext , node : NodeId ) -> Option < Name > {
3837
+ match cx. tcx . hir . get ( node) {
3838
+ Node :: NodeItem ( _) |
3839
+ Node :: NodeForeignItem ( _) |
3840
+ Node :: NodeImplItem ( _) |
3841
+ Node :: NodeTraitItem ( _) |
3842
+ Node :: NodeVariant ( _) |
3843
+ Node :: NodeField ( _) |
3844
+ Node :: NodeLifetime ( _) |
3845
+ Node :: NodeGenericParam ( _) |
3846
+ Node :: NodeBinding ( & hir:: Pat { node : hir:: PatKind :: Binding ( _, _, _, _) , .. } ) |
3847
+ Node :: NodeStructCtor ( _) => { }
3848
+ _ => return None ,
3849
+ }
3850
+ Some ( cx. tcx . hir . name ( node) )
3851
+ }
3852
+
3803
3853
impl Clean < Vec < Item > > for doctree:: Impl {
3804
3854
fn clean ( & self , cx : & DocContext ) -> Vec < Item > {
3805
3855
let mut ret = Vec :: new ( ) ;
@@ -3819,6 +3869,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
3819
3869
. collect ( )
3820
3870
} ) . unwrap_or ( FxHashSet ( ) ) ;
3821
3871
3872
+ * cx. current_item_name . borrow_mut ( ) = get_name_if_possible ( cx, self . for_ . id ) ;
3822
3873
ret. push ( Item {
3823
3874
name : None ,
3824
3875
attrs : self . attrs . clean ( cx) ,
@@ -3905,6 +3956,7 @@ fn build_deref_target_impls(cx: &DocContext,
3905
3956
3906
3957
impl Clean < Item > for doctree:: ExternCrate {
3907
3958
fn clean ( & self , cx : & DocContext ) -> Item {
3959
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3908
3960
Item {
3909
3961
name : None ,
3910
3962
attrs : self . attrs . clean ( cx) ,
@@ -3951,6 +4003,8 @@ impl Clean<Vec<Item>> for doctree::Import {
3951
4003
}
3952
4004
Import :: Simple ( name. clean ( cx) , resolve_use_source ( cx, path) )
3953
4005
} ;
4006
+
4007
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
3954
4008
vec ! [ Item {
3955
4009
name: None ,
3956
4010
attrs: self . attrs. clean( cx) ,
@@ -4019,6 +4073,8 @@ impl Clean<Item> for hir::ForeignItem {
4019
4073
ForeignTypeItem
4020
4074
}
4021
4075
} ;
4076
+
4077
+ * cx. current_item_name . borrow_mut ( ) = Some ( self . name ) ;
4022
4078
Item {
4023
4079
name : Some ( self . name . clean ( cx) ) ,
4024
4080
attrs : self . attrs . clean ( cx) ,
@@ -4194,6 +4250,7 @@ pub struct Macro {
4194
4250
impl Clean < Item > for doctree:: Macro {
4195
4251
fn clean ( & self , cx : & DocContext ) -> Item {
4196
4252
let name = self . name . clean ( cx) ;
4253
+ * cx. current_item_name . borrow_mut ( ) = None ;
4197
4254
Item {
4198
4255
name : Some ( name. clone ( ) ) ,
4199
4256
attrs : self . attrs . clean ( cx) ,
0 commit comments