rustc: Split 'tcx into 'gcx and 'tcx for InferCtxt and its users.

This commit is contained in:
Eduard Burtescu 2016-05-03 05:23:22 +03:00
parent 166dbc3273
commit 76affa5d6f
160 changed files with 1296 additions and 1189 deletions

View file

@ -68,8 +68,8 @@ pub fn try_inline(cx: &DocContext, id: ast::NodeId, into: Option<ast::Name>)
})
}
fn try_inline_def(cx: &DocContext, tcx: TyCtxt,
def: Def) -> Option<Vec<clean::Item>> {
fn try_inline_def<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
def: Def) -> Option<Vec<clean::Item>> {
let mut ret = Vec::new();
let did = def.def_id();
let inner = match def {
@ -130,8 +130,8 @@ fn try_inline_def(cx: &DocContext, tcx: TyCtxt,
Some(ret)
}
pub fn load_attrs(cx: &DocContext, tcx: TyCtxt,
did: DefId) -> Vec<clean::Attribute> {
pub fn load_attrs<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> Vec<clean::Attribute> {
tcx.get_attrs(did).iter().map(|a| a.clean(cx)).collect()
}
@ -150,8 +150,8 @@ pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) {
}
}
pub fn build_external_trait(cx: &DocContext, tcx: TyCtxt,
did: DefId) -> clean::Trait {
pub fn build_external_trait<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Trait {
let def = tcx.lookup_trait_def(did);
let trait_items = tcx.trait_items(did).clean(cx);
let predicates = tcx.lookup_predicates(did);
@ -166,7 +166,8 @@ pub fn build_external_trait(cx: &DocContext, tcx: TyCtxt,
}
}
fn build_external_function(cx: &DocContext, tcx: TyCtxt, did: DefId) -> clean::Function {
fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Function {
let t = tcx.lookup_item_type(did);
let (decl, style, abi) = match t.ty.sty {
ty::TyFnDef(_, _, ref f) => ((did, &f.sig).clean(cx), f.unsafety, f.abi),
@ -189,7 +190,8 @@ fn build_external_function(cx: &DocContext, tcx: TyCtxt, did: DefId) -> clean::F
}
}
fn build_struct(cx: &DocContext, tcx: TyCtxt, did: DefId) -> clean::Struct {
fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Struct {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
let variant = tcx.lookup_adt_def(did).struct_variant();
@ -207,7 +209,8 @@ fn build_struct(cx: &DocContext, tcx: TyCtxt, did: DefId) -> clean::Struct {
}
}
fn build_type(cx: &DocContext, tcx: TyCtxt, did: DefId) -> clean::ItemEnum {
fn build_type<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::ItemEnum {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
match t.ty.sty {
@ -227,9 +230,9 @@ fn build_type(cx: &DocContext, tcx: TyCtxt, did: DefId) -> clean::ItemEnum {
}, false)
}
pub fn build_impls(cx: &DocContext,
tcx: TyCtxt,
did: DefId) -> Vec<clean::Item> {
pub fn build_impls<'a, 'tcx>(cx: &DocContext,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> Vec<clean::Item> {
tcx.populate_inherent_implementations_for_type_if_necessary(did);
let mut impls = Vec::new();
@ -252,9 +255,9 @@ pub fn build_impls(cx: &DocContext,
populate_impls(cx, tcx, item.def, &mut impls);
}
fn populate_impls(cx: &DocContext, tcx: TyCtxt,
def: cstore::DefLike,
impls: &mut Vec<clean::Item>) {
fn populate_impls<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
def: cstore::DefLike,
impls: &mut Vec<clean::Item>) {
match def {
cstore::DlImpl(did) => build_impl(cx, tcx, did, impls),
cstore::DlDef(Def::Mod(did)) => {
@ -270,10 +273,10 @@ pub fn build_impls(cx: &DocContext,
impls
}
pub fn build_impl(cx: &DocContext,
tcx: TyCtxt,
did: DefId,
ret: &mut Vec<clean::Item>) {
pub fn build_impl<'a, 'tcx>(cx: &DocContext,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId,
ret: &mut Vec<clean::Item>) {
if !cx.renderinfo.borrow_mut().inlined.insert(did) {
return
}
@ -441,8 +444,8 @@ pub fn build_impl(cx: &DocContext,
});
}
fn build_module(cx: &DocContext, tcx: TyCtxt,
did: DefId) -> clean::Module {
fn build_module<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Module {
let mut items = Vec::new();
fill_in(cx, tcx, did, &mut items);
return clean::Module {
@ -450,8 +453,8 @@ fn build_module(cx: &DocContext, tcx: TyCtxt,
is_crate: false,
};
fn fill_in(cx: &DocContext, tcx: TyCtxt, did: DefId,
items: &mut Vec<clean::Item>) {
fn fill_in<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId, items: &mut Vec<clean::Item>) {
// If we're reexporting a reexport it may actually reexport something in
// two namespaces, so the target may be listed twice. Make sure we only
// visit each node at most once.
@ -476,8 +479,8 @@ fn build_module(cx: &DocContext, tcx: TyCtxt,
}
}
fn build_const(cx: &DocContext, tcx: TyCtxt,
did: DefId) -> clean::Constant {
fn build_const<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Constant {
let (expr, ty) = lookup_const_by_id(tcx, did, None).unwrap_or_else(|| {
panic!("expected lookup_const_by_id to succeed for {:?}", did);
});
@ -491,9 +494,9 @@ fn build_const(cx: &DocContext, tcx: TyCtxt,
}
}
fn build_static(cx: &DocContext, tcx: TyCtxt,
did: DefId,
mutable: bool) -> clean::Static {
fn build_static<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId,
mutable: bool) -> clean::Static {
clean::Static {
type_: tcx.lookup_item_type(did).ty.clean(cx),
mutability: if mutable {clean::Mutable} else {clean::Immutable},

View file

@ -42,7 +42,7 @@ pub use rustc::session::search_paths::SearchPaths;
/// Are we generating documentation (`Typed`) or tests (`NotTyped`)?
pub enum MaybeTyped<'a, 'tcx: 'a> {
Typed(TyCtxt<'a, 'tcx>),
Typed(TyCtxt<'a, 'tcx, 'tcx>),
NotTyped(&'a session::Session)
}
@ -74,14 +74,14 @@ impl<'b, 'tcx> DocContext<'b, 'tcx> {
}
}
pub fn tcx_opt<'a>(&'a self) -> Option<TyCtxt<'a, 'tcx>> {
pub fn tcx_opt<'a>(&'a self) -> Option<TyCtxt<'a, 'tcx, 'tcx>> {
match self.maybe_typed {
Typed(tcx) => Some(tcx),
NotTyped(_) => None
}
}
pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx> {
pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
let tcx_opt = self.tcx_opt();
tcx_opt.expect("tcx not present")
}