Skip to content

Commit 8bfbcdd

Browse files
committed
rustdoc: fix fallout from the addition of a 'tcx lifetime on tcx.
1 parent f7a997b commit 8bfbcdd

File tree

6 files changed

+438
-472
lines changed

6 files changed

+438
-472
lines changed

src/librustdoc/clean/inline.rs

+52-57
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc::middle::ty;
2121
use rustc::middle::subst;
2222
use rustc::middle::stability;
2323

24-
use core;
24+
use core::DocContext;
2525
use doctree;
2626
use clean;
2727

@@ -39,24 +39,23 @@ use super::Clean;
3939
///
4040
/// The returned value is `None` if the `id` could not be inlined, and `Some`
4141
/// 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>)
4343
-> 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,
4847
};
4948
let def = match tcx.def_map.borrow().find(&id) {
5049
Some(def) => *def,
5150
None => return None,
5251
};
5352
let did = def.def_id();
5453
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| {
5655
vec.move_iter().map(|mut item| {
5756
match into {
5857
Some(into) if item.name.is_some() => {
59-
item.name = Some(into.clean());
58+
item.name = Some(into.clean(cx));
6059
}
6160
_ => {}
6261
}
@@ -65,15 +64,14 @@ pub fn try_inline(id: ast::NodeId, into: Option<ast::Ident>)
6564
})
6665
}
6766

68-
fn try_inline_def(cx: &core::DocContext,
69-
tcx: &ty::ctxt,
67+
fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
7068
def: def::Def) -> Option<Vec<clean::Item>> {
7169
let mut ret = Vec::new();
7270
let did = def.def_id();
7371
let inner = match def {
7472
def::DefTrait(did) => {
7573
record_extern_fqn(cx, did, clean::TypeTrait);
76-
clean::TraitItem(build_external_trait(tcx, did))
74+
clean::TraitItem(build_external_trait(cx, tcx, did))
7775
}
7876
def::DefFn(did, style) => {
7977
// If this function is a tuple struct constructor, we just skip it
@@ -82,17 +80,17 @@ fn try_inline_def(cx: &core::DocContext,
8280
return None
8381
}
8482
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))
8684
}
8785
def::DefStruct(did) => {
8886
record_extern_fqn(cx, did, clean::TypeStruct);
8987
ret.extend(build_impls(cx, tcx, did).move_iter());
90-
clean::StructItem(build_struct(tcx, did))
88+
clean::StructItem(build_struct(cx, tcx, did))
9189
}
9290
def::DefTy(did) => {
9391
record_extern_fqn(cx, did, clean::TypeEnum);
9492
ret.extend(build_impls(cx, tcx, did).move_iter());
95-
build_type(tcx, did)
93+
build_type(cx, tcx, did)
9694
}
9795
// Assume that the enum type is reexported next to the variant, and
9896
// variants don't show up in documentation specially.
@@ -103,7 +101,7 @@ fn try_inline_def(cx: &core::DocContext,
103101
}
104102
def::DefStatic(did, mtbl) => {
105103
record_extern_fqn(cx, did, clean::TypeStatic);
106-
clean::StaticItem(build_static(tcx, did, mtbl))
104+
clean::StaticItem(build_static(cx, tcx, did, mtbl))
107105
}
108106
_ => return None,
109107
};
@@ -112,20 +110,21 @@ fn try_inline_def(cx: &core::DocContext,
112110
ret.push(clean::Item {
113111
source: clean::Span::empty(),
114112
name: Some(fqn.last().unwrap().to_string()),
115-
attrs: load_attrs(tcx, did),
113+
attrs: load_attrs(cx, tcx, did),
116114
inner: inner,
117115
visibility: Some(ast::Public),
118-
stability: stability::lookup(tcx, did).clean(),
116+
stability: stability::lookup(tcx, did).clean(cx),
119117
def_id: did,
120118
});
121119
Some(ret)
122120
}
123121

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> {
125124
let mut attrs = Vec::new();
126125
csearch::get_item_attrs(&tcx.sess.cstore, did, |v| {
127126
attrs.extend(v.move_iter().map(|a| {
128-
a.clean()
127+
a.clean(cx)
129128
}));
130129
});
131130
attrs
@@ -135,22 +134,21 @@ pub fn load_attrs(tcx: &ty::ctxt, did: ast::DefId) -> Vec<clean::Attribute> {
135134
///
136135
/// These names are used later on by HTML rendering to generate things like
137136
/// 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) => {
143140
let fqn = csearch::get_item_path(tcx, did);
144141
let fqn = fqn.move_iter().map(|i| i.to_string()).collect();
145142
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind));
146143
}
147-
core::NotTyped(..) => {}
144+
None => {}
148145
}
149146
}
150147

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 {
152150
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);
154152
let provided = ty::provided_trait_methods(tcx, did);
155153
let mut items = trait_items.move_iter().map(|trait_item| {
156154
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 {
160158
}
161159
});
162160
let trait_def = ty::lookup_trait_def(tcx, did);
163-
let bounds = trait_def.bounds.clean();
161+
let bounds = trait_def.bounds.clean(cx);
164162
clean::Trait {
165-
generics: (&def.generics, subst::TypeSpace).clean(),
163+
generics: (&def.generics, subst::TypeSpace).clean(cx),
166164
items: items.collect(),
167165
bounds: bounds,
168166
}
169167
}
170168

171-
fn build_external_function(tcx: &ty::ctxt,
169+
fn build_external_function(cx: &DocContext, tcx: &ty::ctxt,
172170
did: ast::DefId,
173171
style: ast::FnStyle) -> clean::Function {
174172
let t = ty::lookup_item_type(tcx, did);
175173
clean::Function {
176174
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),
178176
_ => fail!("bad function"),
179177
},
180-
generics: (&t.generics, subst::FnSpace).clean(),
178+
generics: (&t.generics, subst::FnSpace).clean(cx),
181179
fn_style: style,
182180
}
183181
}
184182

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 {
186184
use syntax::parse::token::special_idents::unnamed_field;
187185

188186
let t = ty::lookup_item_type(tcx, did);
@@ -195,33 +193,32 @@ fn build_struct(tcx: &ty::ctxt, did: ast::DefId) -> clean::Struct {
195193
[ref f, ..] if f.name == unnamed_field.name => doctree::Tuple,
196194
_ => doctree::Plain,
197195
},
198-
generics: (&t.generics, subst::TypeSpace).clean(),
199-
fields: fields.clean(),
196+
generics: (&t.generics, subst::TypeSpace).clean(cx),
197+
fields: fields.clean(cx),
200198
fields_stripped: false,
201199
}
202200
}
203201

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 {
205203
let t = ty::lookup_item_type(tcx, did);
206204
match ty::get(t.ty).sty {
207205
ty::ty_enum(edid, _) if !csearch::is_typedef(&tcx.sess.cstore, did) => {
208206
return clean::EnumItem(clean::Enum {
209-
generics: (&t.generics, subst::TypeSpace).clean(),
207+
generics: (&t.generics, subst::TypeSpace).clean(cx),
210208
variants_stripped: false,
211-
variants: ty::enum_variants(tcx, edid).clean(),
209+
variants: ty::enum_variants(tcx, edid).clean(cx),
212210
})
213211
}
214212
_ => {}
215213
}
216214

217215
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),
220218
})
221219
}
222220

223-
fn build_impls(cx: &core::DocContext,
224-
tcx: &ty::ctxt,
221+
fn build_impls(cx: &DocContext, tcx: &ty::ctxt,
225222
did: ast::DefId) -> Vec<clean::Item> {
226223
ty::populate_implementations_for_type_if_necessary(tcx, did);
227224
let mut impls = Vec::new();
@@ -248,8 +245,7 @@ fn build_impls(cx: &core::DocContext,
248245
populate_impls(cx, tcx, def, &mut impls)
249246
});
250247

251-
fn populate_impls(cx: &core::DocContext,
252-
tcx: &ty::ctxt,
248+
fn populate_impls(cx: &DocContext, tcx: &ty::ctxt,
253249
def: decoder::DefLike,
254250
impls: &mut Vec<Option<clean::Item>>) {
255251
match def {
@@ -269,8 +265,7 @@ fn build_impls(cx: &core::DocContext,
269265
impls.move_iter().filter_map(|a| a).collect()
270266
}
271267

272-
fn build_impl(cx: &core::DocContext,
273-
tcx: &ty::ctxt,
268+
fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
274269
did: ast::DefId) -> Option<clean::Item> {
275270
if !cx.inlined.borrow_mut().as_mut().unwrap().insert(did) {
276271
return None
@@ -280,15 +275,15 @@ fn build_impl(cx: &core::DocContext,
280275
// If this is an impl for a #[doc(hidden)] trait, be sure to not inline it.
281276
match associated_trait {
282277
Some(ref t) => {
283-
let trait_attrs = load_attrs(tcx, t.def_id);
278+
let trait_attrs = load_attrs(cx, tcx, t.def_id);
284279
if trait_attrs.iter().any(|a| is_doc_hidden(a)) {
285280
return None
286281
}
287282
}
288283
None => {}
289284
}
290285

291-
let attrs = load_attrs(tcx, did);
286+
let attrs = load_attrs(cx, tcx, did);
292287
let ty = ty::lookup_item_type(tcx, did);
293288
let trait_items = csearch::get_impl_items(&tcx.sess.cstore, did)
294289
.iter()
@@ -300,7 +295,7 @@ fn build_impl(cx: &core::DocContext,
300295
if method.vis != ast::Public && associated_trait.is_none() {
301296
return None
302297
}
303-
let mut item = method.clean();
298+
let mut item = method.clean(cx);
304299
item.inner = match item.inner.clone() {
305300
clean::TyMethodItem(clean::TyMethod {
306301
fn_style, decl, self_, generics
@@ -321,21 +316,21 @@ fn build_impl(cx: &core::DocContext,
321316
return Some(clean::Item {
322317
inner: clean::ImplItem(clean::Impl {
323318
derived: clean::detect_derived(attrs.as_slice()),
324-
trait_: associated_trait.clean().map(|bound| {
319+
trait_: associated_trait.clean(cx).map(|bound| {
325320
match bound {
326321
clean::TraitBound(ty) => ty,
327322
clean::RegionBound => unreachable!(),
328323
}
329324
}),
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),
332327
items: trait_items,
333328
}),
334329
source: clean::Span::empty(),
335330
name: None,
336331
attrs: attrs,
337332
visibility: Some(ast::Inherited),
338-
stability: stability::lookup(tcx, did).clean(),
333+
stability: stability::lookup(tcx, did).clean(cx),
339334
def_id: did,
340335
});
341336

@@ -354,7 +349,7 @@ fn build_impl(cx: &core::DocContext,
354349
}
355350
}
356351

357-
fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,
352+
fn build_module(cx: &DocContext, tcx: &ty::ctxt,
358353
did: ast::DefId) -> clean::Module {
359354
let mut items = Vec::new();
360355
fill_in(cx, tcx, did, &mut items);
@@ -365,7 +360,7 @@ fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,
365360

366361
// FIXME: this doesn't handle reexports inside the module itself.
367362
// 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,
369364
items: &mut Vec<clean::Item>) {
370365
csearch::each_child_of_item(&tcx.sess.cstore, did, |def, _, vis| {
371366
match def {
@@ -387,11 +382,11 @@ fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,
387382
}
388383
}
389384

390-
fn build_static(tcx: &ty::ctxt,
385+
fn build_static(cx: &DocContext, tcx: &ty::ctxt,
391386
did: ast::DefId,
392387
mutable: bool) -> clean::Static {
393388
clean::Static {
394-
type_: ty::lookup_item_type(tcx, did).ty.clean(),
389+
type_: ty::lookup_item_type(tcx, did).ty.clean(cx),
395390
mutability: if mutable {clean::Mutable} else {clean::Immutable},
396391
expr: "\n\n\n".to_string(), // trigger the "[definition]" links
397392
}

0 commit comments

Comments
 (0)