@@ -21,7 +21,7 @@ use rustc::middle::ty;
21
21
use rustc:: middle:: subst;
22
22
use rustc:: middle:: stability;
23
23
24
- use core;
24
+ use core:: DocContext ;
25
25
use doctree;
26
26
use clean;
27
27
@@ -39,24 +39,23 @@ use super::Clean;
39
39
///
40
40
/// The returned value is `None` if the `id` could not be inlined, and `Some`
41
41
/// of a vector of items if it was successfully expanded.
42
- pub fn try_inline ( id : ast:: NodeId , into : Option < ast:: Ident > )
42
+ pub fn try_inline ( cx : & DocContext , id : ast:: NodeId , into : Option < ast:: Ident > )
43
43
-> Option < Vec < clean:: Item > > {
44
- let cx = :: ctxtkey. get ( ) . unwrap ( ) ;
45
- let tcx = match cx. maybe_typed {
46
- core:: Typed ( ref tycx) => tycx,
47
- core:: NotTyped ( _) => return None ,
44
+ let tcx = match cx. tcx_opt ( ) {
45
+ Some ( tcx) => tcx,
46
+ None => return None ,
48
47
} ;
49
48
let def = match tcx. def_map . borrow ( ) . find ( & id) {
50
49
Some ( def) => * def,
51
50
None => return None ,
52
51
} ;
53
52
let did = def. def_id ( ) ;
54
53
if ast_util:: is_local ( did) { return None }
55
- try_inline_def ( & * * cx, tcx, def) . map ( |vec| {
54
+ try_inline_def ( cx, tcx, def) . map ( |vec| {
56
55
vec. move_iter ( ) . map ( |mut item| {
57
56
match into {
58
57
Some ( into) if item. name . is_some ( ) => {
59
- item. name = Some ( into. clean ( ) ) ;
58
+ item. name = Some ( into. clean ( cx ) ) ;
60
59
}
61
60
_ => { }
62
61
}
@@ -65,15 +64,14 @@ pub fn try_inline(id: ast::NodeId, into: Option<ast::Ident>)
65
64
} )
66
65
}
67
66
68
- fn try_inline_def ( cx : & core:: DocContext ,
69
- tcx : & ty:: ctxt ,
67
+ fn try_inline_def ( cx : & DocContext , tcx : & ty:: ctxt ,
70
68
def : def:: Def ) -> Option < Vec < clean:: Item > > {
71
69
let mut ret = Vec :: new ( ) ;
72
70
let did = def. def_id ( ) ;
73
71
let inner = match def {
74
72
def:: DefTrait ( did) => {
75
73
record_extern_fqn ( cx, did, clean:: TypeTrait ) ;
76
- clean:: TraitItem ( build_external_trait ( tcx, did) )
74
+ clean:: TraitItem ( build_external_trait ( cx , tcx, did) )
77
75
}
78
76
def:: DefFn ( did, style) => {
79
77
// If this function is a tuple struct constructor, we just skip it
@@ -82,17 +80,17 @@ fn try_inline_def(cx: &core::DocContext,
82
80
return None
83
81
}
84
82
record_extern_fqn ( cx, did, clean:: TypeFunction ) ;
85
- clean:: FunctionItem ( build_external_function ( tcx, did, style) )
83
+ clean:: FunctionItem ( build_external_function ( cx , tcx, did, style) )
86
84
}
87
85
def:: DefStruct ( did) => {
88
86
record_extern_fqn ( cx, did, clean:: TypeStruct ) ;
89
87
ret. extend ( build_impls ( cx, tcx, did) . move_iter ( ) ) ;
90
- clean:: StructItem ( build_struct ( tcx, did) )
88
+ clean:: StructItem ( build_struct ( cx , tcx, did) )
91
89
}
92
90
def:: DefTy ( did) => {
93
91
record_extern_fqn ( cx, did, clean:: TypeEnum ) ;
94
92
ret. extend ( build_impls ( cx, tcx, did) . move_iter ( ) ) ;
95
- build_type ( tcx, did)
93
+ build_type ( cx , tcx, did)
96
94
}
97
95
// Assume that the enum type is reexported next to the variant, and
98
96
// variants don't show up in documentation specially.
@@ -103,7 +101,7 @@ fn try_inline_def(cx: &core::DocContext,
103
101
}
104
102
def:: DefStatic ( did, mtbl) => {
105
103
record_extern_fqn ( cx, did, clean:: TypeStatic ) ;
106
- clean:: StaticItem ( build_static ( tcx, did, mtbl) )
104
+ clean:: StaticItem ( build_static ( cx , tcx, did, mtbl) )
107
105
}
108
106
_ => return None ,
109
107
} ;
@@ -112,20 +110,21 @@ fn try_inline_def(cx: &core::DocContext,
112
110
ret. push ( clean:: Item {
113
111
source : clean:: Span :: empty ( ) ,
114
112
name : Some ( fqn. last ( ) . unwrap ( ) . to_string ( ) ) ,
115
- attrs : load_attrs ( tcx, did) ,
113
+ attrs : load_attrs ( cx , tcx, did) ,
116
114
inner : inner,
117
115
visibility : Some ( ast:: Public ) ,
118
- stability : stability:: lookup ( tcx, did) . clean ( ) ,
116
+ stability : stability:: lookup ( tcx, did) . clean ( cx ) ,
119
117
def_id : did,
120
118
} ) ;
121
119
Some ( ret)
122
120
}
123
121
124
- pub fn load_attrs ( tcx : & ty:: ctxt , did : ast:: DefId ) -> Vec < clean:: Attribute > {
122
+ pub fn load_attrs ( cx : & DocContext , tcx : & ty:: ctxt ,
123
+ did : ast:: DefId ) -> Vec < clean:: Attribute > {
125
124
let mut attrs = Vec :: new ( ) ;
126
125
csearch:: get_item_attrs ( & tcx. sess . cstore , did, |v| {
127
126
attrs. extend ( v. move_iter ( ) . map ( |a| {
128
- a. clean ( )
127
+ a. clean ( cx )
129
128
} ) ) ;
130
129
} ) ;
131
130
attrs
@@ -135,22 +134,21 @@ pub fn load_attrs(tcx: &ty::ctxt, did: ast::DefId) -> Vec<clean::Attribute> {
135
134
///
136
135
/// These names are used later on by HTML rendering to generate things like
137
136
/// source links back to the original item.
138
- pub fn record_extern_fqn ( cx : & core:: DocContext ,
139
- did : ast:: DefId ,
140
- kind : clean:: TypeKind ) {
141
- match cx. maybe_typed {
142
- core:: Typed ( ref tcx) => {
137
+ pub fn record_extern_fqn ( cx : & DocContext , did : ast:: DefId , kind : clean:: TypeKind ) {
138
+ match cx. tcx_opt ( ) {
139
+ Some ( tcx) => {
143
140
let fqn = csearch:: get_item_path ( tcx, did) ;
144
141
let fqn = fqn. move_iter ( ) . map ( |i| i. to_string ( ) ) . collect ( ) ;
145
142
cx. external_paths . borrow_mut ( ) . as_mut ( ) . unwrap ( ) . insert ( did, ( fqn, kind) ) ;
146
143
}
147
- core :: NotTyped ( .. ) => { }
144
+ None => { }
148
145
}
149
146
}
150
147
151
- pub fn build_external_trait ( tcx : & ty:: ctxt , did : ast:: DefId ) -> clean:: Trait {
148
+ pub fn build_external_trait ( cx : & DocContext , tcx : & ty:: ctxt ,
149
+ did : ast:: DefId ) -> clean:: Trait {
152
150
let def = ty:: lookup_trait_def ( tcx, did) ;
153
- let trait_items = ty:: trait_items ( tcx, did) . clean ( ) ;
151
+ let trait_items = ty:: trait_items ( tcx, did) . clean ( cx ) ;
154
152
let provided = ty:: provided_trait_methods ( tcx, did) ;
155
153
let mut items = trait_items. move_iter ( ) . map ( |trait_item| {
156
154
if provided. iter ( ) . any ( |a| a. def_id == trait_item. def_id ) {
@@ -160,29 +158,29 @@ pub fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> clean::Trait {
160
158
}
161
159
} ) ;
162
160
let trait_def = ty:: lookup_trait_def ( tcx, did) ;
163
- let bounds = trait_def. bounds . clean ( ) ;
161
+ let bounds = trait_def. bounds . clean ( cx ) ;
164
162
clean:: Trait {
165
- generics : ( & def. generics , subst:: TypeSpace ) . clean ( ) ,
163
+ generics : ( & def. generics , subst:: TypeSpace ) . clean ( cx ) ,
166
164
items : items. collect ( ) ,
167
165
bounds : bounds,
168
166
}
169
167
}
170
168
171
- fn build_external_function ( tcx : & ty:: ctxt ,
169
+ fn build_external_function ( cx : & DocContext , tcx : & ty:: ctxt ,
172
170
did : ast:: DefId ,
173
171
style : ast:: FnStyle ) -> clean:: Function {
174
172
let t = ty:: lookup_item_type ( tcx, did) ;
175
173
clean:: Function {
176
174
decl : match ty:: get ( t. ty ) . sty {
177
- ty:: ty_bare_fn( ref f) => ( did, & f. sig ) . clean ( ) ,
175
+ ty:: ty_bare_fn( ref f) => ( did, & f. sig ) . clean ( cx ) ,
178
176
_ => fail ! ( "bad function" ) ,
179
177
} ,
180
- generics : ( & t. generics , subst:: FnSpace ) . clean ( ) ,
178
+ generics : ( & t. generics , subst:: FnSpace ) . clean ( cx ) ,
181
179
fn_style : style,
182
180
}
183
181
}
184
182
185
- fn build_struct ( tcx : & ty:: ctxt , did : ast:: DefId ) -> clean:: Struct {
183
+ fn build_struct ( cx : & DocContext , tcx : & ty:: ctxt , did : ast:: DefId ) -> clean:: Struct {
186
184
use syntax:: parse:: token:: special_idents:: unnamed_field;
187
185
188
186
let t = ty:: lookup_item_type ( tcx, did) ;
@@ -195,33 +193,32 @@ fn build_struct(tcx: &ty::ctxt, did: ast::DefId) -> clean::Struct {
195
193
[ ref f, ..] if f. name == unnamed_field. name => doctree:: Tuple ,
196
194
_ => doctree:: Plain ,
197
195
} ,
198
- generics : ( & t. generics , subst:: TypeSpace ) . clean ( ) ,
199
- fields : fields. clean ( ) ,
196
+ generics : ( & t. generics , subst:: TypeSpace ) . clean ( cx ) ,
197
+ fields : fields. clean ( cx ) ,
200
198
fields_stripped : false ,
201
199
}
202
200
}
203
201
204
- fn build_type ( tcx : & ty:: ctxt , did : ast:: DefId ) -> clean:: ItemEnum {
202
+ fn build_type ( cx : & DocContext , tcx : & ty:: ctxt , did : ast:: DefId ) -> clean:: ItemEnum {
205
203
let t = ty:: lookup_item_type ( tcx, did) ;
206
204
match ty:: get ( t. ty ) . sty {
207
205
ty:: ty_enum( edid, _) if !csearch:: is_typedef ( & tcx. sess . cstore , did) => {
208
206
return clean:: EnumItem ( clean:: Enum {
209
- generics : ( & t. generics , subst:: TypeSpace ) . clean ( ) ,
207
+ generics : ( & t. generics , subst:: TypeSpace ) . clean ( cx ) ,
210
208
variants_stripped : false ,
211
- variants : ty:: enum_variants ( tcx, edid) . clean ( ) ,
209
+ variants : ty:: enum_variants ( tcx, edid) . clean ( cx ) ,
212
210
} )
213
211
}
214
212
_ => { }
215
213
}
216
214
217
215
clean:: TypedefItem ( clean:: Typedef {
218
- type_ : t. ty . clean ( ) ,
219
- generics : ( & t. generics , subst:: TypeSpace ) . clean ( ) ,
216
+ type_ : t. ty . clean ( cx ) ,
217
+ generics : ( & t. generics , subst:: TypeSpace ) . clean ( cx ) ,
220
218
} )
221
219
}
222
220
223
- fn build_impls ( cx : & core:: DocContext ,
224
- tcx : & ty:: ctxt ,
221
+ fn build_impls ( cx : & DocContext , tcx : & ty:: ctxt ,
225
222
did : ast:: DefId ) -> Vec < clean:: Item > {
226
223
ty:: populate_implementations_for_type_if_necessary ( tcx, did) ;
227
224
let mut impls = Vec :: new ( ) ;
@@ -248,8 +245,7 @@ fn build_impls(cx: &core::DocContext,
248
245
populate_impls ( cx, tcx, def, & mut impls)
249
246
} ) ;
250
247
251
- fn populate_impls ( cx : & core:: DocContext ,
252
- tcx : & ty:: ctxt ,
248
+ fn populate_impls ( cx : & DocContext , tcx : & ty:: ctxt ,
253
249
def : decoder:: DefLike ,
254
250
impls : & mut Vec < Option < clean:: Item > > ) {
255
251
match def {
@@ -269,8 +265,7 @@ fn build_impls(cx: &core::DocContext,
269
265
impls. move_iter ( ) . filter_map ( |a| a) . collect ( )
270
266
}
271
267
272
- fn build_impl ( cx : & core:: DocContext ,
273
- tcx : & ty:: ctxt ,
268
+ fn build_impl ( cx : & DocContext , tcx : & ty:: ctxt ,
274
269
did : ast:: DefId ) -> Option < clean:: Item > {
275
270
if !cx. inlined . borrow_mut ( ) . as_mut ( ) . unwrap ( ) . insert ( did) {
276
271
return None
@@ -280,15 +275,15 @@ fn build_impl(cx: &core::DocContext,
280
275
// If this is an impl for a #[doc(hidden)] trait, be sure to not inline it.
281
276
match associated_trait {
282
277
Some ( ref t) => {
283
- let trait_attrs = load_attrs ( tcx, t. def_id ) ;
278
+ let trait_attrs = load_attrs ( cx , tcx, t. def_id ) ;
284
279
if trait_attrs. iter ( ) . any ( |a| is_doc_hidden ( a) ) {
285
280
return None
286
281
}
287
282
}
288
283
None => { }
289
284
}
290
285
291
- let attrs = load_attrs ( tcx, did) ;
286
+ let attrs = load_attrs ( cx , tcx, did) ;
292
287
let ty = ty:: lookup_item_type ( tcx, did) ;
293
288
let trait_items = csearch:: get_impl_items ( & tcx. sess . cstore , did)
294
289
. iter ( )
@@ -300,7 +295,7 @@ fn build_impl(cx: &core::DocContext,
300
295
if method. vis != ast:: Public && associated_trait. is_none ( ) {
301
296
return None
302
297
}
303
- let mut item = method. clean ( ) ;
298
+ let mut item = method. clean ( cx ) ;
304
299
item. inner = match item. inner . clone ( ) {
305
300
clean:: TyMethodItem ( clean:: TyMethod {
306
301
fn_style, decl, self_, generics
@@ -321,21 +316,21 @@ fn build_impl(cx: &core::DocContext,
321
316
return Some ( clean:: Item {
322
317
inner : clean:: ImplItem ( clean:: Impl {
323
318
derived : clean:: detect_derived ( attrs. as_slice ( ) ) ,
324
- trait_ : associated_trait. clean ( ) . map ( |bound| {
319
+ trait_ : associated_trait. clean ( cx ) . map ( |bound| {
325
320
match bound {
326
321
clean:: TraitBound ( ty) => ty,
327
322
clean:: RegionBound => unreachable ! ( ) ,
328
323
}
329
324
} ) ,
330
- for_ : ty. ty . clean ( ) ,
331
- generics : ( & ty. generics , subst:: TypeSpace ) . clean ( ) ,
325
+ for_ : ty. ty . clean ( cx ) ,
326
+ generics : ( & ty. generics , subst:: TypeSpace ) . clean ( cx ) ,
332
327
items : trait_items,
333
328
} ) ,
334
329
source : clean:: Span :: empty ( ) ,
335
330
name : None ,
336
331
attrs : attrs,
337
332
visibility : Some ( ast:: Inherited ) ,
338
- stability : stability:: lookup ( tcx, did) . clean ( ) ,
333
+ stability : stability:: lookup ( tcx, did) . clean ( cx ) ,
339
334
def_id : did,
340
335
} ) ;
341
336
@@ -354,7 +349,7 @@ fn build_impl(cx: &core::DocContext,
354
349
}
355
350
}
356
351
357
- fn build_module ( cx : & core :: DocContext , tcx : & ty:: ctxt ,
352
+ fn build_module ( cx : & DocContext , tcx : & ty:: ctxt ,
358
353
did : ast:: DefId ) -> clean:: Module {
359
354
let mut items = Vec :: new ( ) ;
360
355
fill_in ( cx, tcx, did, & mut items) ;
@@ -365,7 +360,7 @@ fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,
365
360
366
361
// FIXME: this doesn't handle reexports inside the module itself.
367
362
// Should they be handled?
368
- fn fill_in ( cx : & core :: DocContext , tcx : & ty:: ctxt , did : ast:: DefId ,
363
+ fn fill_in ( cx : & DocContext , tcx : & ty:: ctxt , did : ast:: DefId ,
369
364
items : & mut Vec < clean:: Item > ) {
370
365
csearch:: each_child_of_item ( & tcx. sess . cstore , did, |def, _, vis| {
371
366
match def {
@@ -387,11 +382,11 @@ fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,
387
382
}
388
383
}
389
384
390
- fn build_static ( tcx : & ty:: ctxt ,
385
+ fn build_static ( cx : & DocContext , tcx : & ty:: ctxt ,
391
386
did : ast:: DefId ,
392
387
mutable : bool ) -> clean:: Static {
393
388
clean:: Static {
394
- type_ : ty:: lookup_item_type ( tcx, did) . ty . clean ( ) ,
389
+ type_ : ty:: lookup_item_type ( tcx, did) . ty . clean ( cx ) ,
395
390
mutability : if mutable { clean:: Mutable } else { clean:: Immutable } ,
396
391
expr : "\n \n \n " . to_string ( ) , // trigger the "[definition]" links
397
392
}
0 commit comments