@@ -74,22 +74,70 @@ crate struct TraitWithExtraInfo {
74
74
crate struct ExternalCrate {
75
75
crate crate_num : CrateNum ,
76
76
crate attrs : Attributes ,
77
- crate keywords : ThinVec < ( DefId , Symbol ) > ,
78
77
}
79
78
80
79
impl ExternalCrate {
80
+ #[ inline]
81
+ fn def_id ( & self ) -> DefId {
82
+ DefId { krate : self . crate_num , index : CRATE_DEF_INDEX }
83
+ }
84
+
81
85
crate fn src ( & self , tcx : TyCtxt < ' _ > ) -> FileName {
82
- let root = DefId { krate : self . crate_num , index : rustc_hir:: def_id:: CRATE_DEF_INDEX } ;
83
- let krate_span = tcx. def_span ( root) ;
86
+ let krate_span = tcx. def_span ( self . def_id ( ) ) ;
84
87
tcx. sess . source_map ( ) . span_to_filename ( krate_span)
85
88
}
86
89
87
90
crate fn name ( & self , tcx : TyCtxt < ' _ > ) -> Symbol {
88
91
tcx. crate_name ( self . crate_num )
89
92
}
90
93
94
+ crate fn keywords ( & self , tcx : TyCtxt < ' _ > ) -> ThinVec < ( DefId , Symbol ) > {
95
+ let root = self . def_id ( ) ;
96
+
97
+ let as_keyword = |res : Res | {
98
+ if let Res :: Def ( DefKind :: Mod , def_id) = res {
99
+ let attrs = tcx. get_attrs ( def_id) ;
100
+ let mut keyword = None ;
101
+ for attr in attrs. lists ( sym:: doc) {
102
+ if attr. has_name ( sym:: keyword) {
103
+ if let Some ( v) = attr. value_str ( ) {
104
+ keyword = Some ( v) ;
105
+ break ;
106
+ }
107
+ }
108
+ }
109
+ return keyword. map ( |p| ( def_id, p) ) ;
110
+ }
111
+ None
112
+ } ;
113
+ if root. is_local ( ) {
114
+ tcx. hir ( )
115
+ . krate ( )
116
+ . item
117
+ . item_ids
118
+ . iter ( )
119
+ . filter_map ( |& id| {
120
+ let item = tcx. hir ( ) . item ( id) ;
121
+ match item. kind {
122
+ hir:: ItemKind :: Mod ( _) => {
123
+ as_keyword ( Res :: Def ( DefKind :: Mod , id. def_id . to_def_id ( ) ) )
124
+ }
125
+ hir:: ItemKind :: Use ( ref path, hir:: UseKind :: Single )
126
+ if item. vis . node . is_pub ( ) =>
127
+ {
128
+ as_keyword ( path. res ) . map ( |( _, prim) | ( id. def_id . to_def_id ( ) , prim) )
129
+ }
130
+ _ => None ,
131
+ }
132
+ } )
133
+ . collect ( )
134
+ } else {
135
+ tcx. item_children ( root) . iter ( ) . map ( |item| item. res ) . filter_map ( as_keyword) . collect ( )
136
+ }
137
+ }
138
+
91
139
crate fn primitives ( & self , tcx : TyCtxt < ' _ > ) -> ThinVec < ( DefId , PrimitiveType ) > {
92
- let root = DefId { krate : self . crate_num , index : CRATE_DEF_INDEX } ;
140
+ let root = self . def_id ( ) ;
93
141
94
142
// Collect all inner modules which are tagged as implementations of
95
143
// primitives.
0 commit comments