diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index df014eb1206aa..fce8627e22673 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -28,9 +28,10 @@ use self::MethodContext::*; use metadata::csearch; use middle::def::*; +use middle::ty::{mod, Ty}; use middle::typeck::astconv::ast_ty_to_ty; -use middle::typeck::infer; -use middle::{typeck, ty, def, pat_util, stability}; +use middle::typeck::{mod, infer}; +use middle::{def, pat_util, stability}; use middle::const_eval::{eval_const_expr_partial, const_int, const_uint}; use util::ppaux::{ty_to_string}; use util::nodemap::{FnvHashMap, NodeSet}; @@ -99,7 +100,7 @@ impl LintPass for UnusedCasts { match e.node { ast::ExprCast(ref expr, ref ty) => { let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), &**ty); - if ty::get(ty::expr_ty(cx.tcx, &**expr)).sty == ty::get(t_t).sty { + if ty::expr_ty(cx.tcx, &**expr) == t_t { cx.span_lint(UNUSED_TYPECASTS, ty.span, "unnecessary type cast"); } } @@ -155,7 +156,7 @@ impl LintPass for TypeLimits { }, _ => { let t = ty::expr_ty(cx.tcx, &**expr); - match ty::get(t).sty { + match t.sty { ty::ty_uint(_) => { cx.span_lint(UNSIGNED_NEGATION, e.span, "negation of unsigned int variable may \ @@ -180,7 +181,7 @@ impl LintPass for TypeLimits { } if is_shift_binop(binop) { - let opt_ty_bits = match ty::get(ty::expr_ty(cx.tcx, &**l)).sty { + let opt_ty_bits = match ty::expr_ty(cx.tcx, &**l).sty { ty::ty_int(t) => Some(int_ty_bits(t, cx.sess().target.int_type)), ty::ty_uint(t) => Some(uint_ty_bits(t, cx.sess().target.uint_type)), _ => None @@ -205,7 +206,7 @@ impl LintPass for TypeLimits { } }, ast::ExprLit(ref lit) => { - match ty::get(ty::expr_ty(cx.tcx, e)).sty { + match ty::expr_ty(cx.tcx, e).sty { ty::ty_int(t) => { match lit.node { ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) | @@ -343,7 +344,7 @@ impl LintPass for TypeLimits { // Normalize the binop so that the literal is always on the RHS in // the comparison let norm_binop = if swap { rev_binop(binop) } else { binop }; - match ty::get(ty::expr_ty(tcx, expr)).sty { + match ty::expr_ty(tcx, expr).sty { ty::ty_int(int_ty) => { let (min, max) = int_ty_range(int_ty); let lit_val: i64 = match lit.node { @@ -473,10 +474,11 @@ declare_lint!(BOX_POINTERS, Allow, pub struct BoxPointers; impl BoxPointers { - fn check_heap_type(&self, cx: &Context, span: Span, ty: ty::t) { + fn check_heap_type<'a, 'tcx>(&self, cx: &Context<'a, 'tcx>, + span: Span, ty: Ty<'tcx>) { let mut n_uniq = 0i; ty::fold_ty(cx.tcx, ty, |t| { - match ty::get(t).sty { + match t.sty { ty::ty_uniq(_) | ty::ty_closure(box ty::ClosureTy { store: ty::UniqTraitStore, @@ -576,7 +578,7 @@ impl LintPass for RawPointerDeriving { } let did = match item.node { ast::ItemImpl(..) => { - match ty::get(ty::node_id_to_type(cx.tcx, item.id)).sty { + match ty::node_id_to_type(cx.tcx, item.id).sty { ty::ty_enum(did, _) => did, ty::ty_struct(did, _) => did, _ => return, @@ -738,7 +740,7 @@ impl LintPass for UnusedResults { let t = ty::expr_ty(cx.tcx, expr); let mut warned = false; - match ty::get(t).sty { + match t.sty { ty::ty_tup(ref tys) if tys.is_empty() => return, ty::ty_bool => return, ty::ty_struct(did, _) | diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index e9b235a2fe34b..83f14d3a0db54 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -27,7 +27,7 @@ use self::TargetLint::*; use middle::privacy::ExportedItems; use middle::subst; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::astconv::AstConv; use middle::typeck::infer; use session::{early_error, Session}; @@ -546,19 +546,19 @@ impl<'a, 'tcx> Context<'a, 'tcx> { impl<'a, 'tcx> AstConv<'tcx> for Context<'a, 'tcx>{ fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { + fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { ty::lookup_item_type(self.tcx, id) } - fn get_trait_def(&self, id: ast::DefId) -> Rc { + fn get_trait_def(&self, id: ast::DefId) -> Rc> { ty::lookup_trait_def(self.tcx, id) } - fn ty_infer(&self, _span: Span) -> ty::t { + fn ty_infer(&self, _span: Span) -> Ty<'tcx> { infer::new_infer_ctxt(self.tcx).next_ty_var() } - fn associated_types_of_trait_are_valid(&self, _: ty::t, _: ast::DefId) + fn associated_types_of_trait_are_valid(&self, _: Ty<'tcx>, _: ast::DefId) -> bool { // FIXME(pcwalton): This is wrong. true @@ -566,10 +566,10 @@ impl<'a, 'tcx> AstConv<'tcx> for Context<'a, 'tcx>{ fn associated_type_binding(&self, _: Span, - _: Option, + _: Option>, trait_id: ast::DefId, associated_type_id: ast::DefId) - -> ty::t { + -> Ty<'tcx> { // FIXME(pcwalton): This is wrong. let trait_def = self.get_trait_def(trait_id); let index = ty::associated_type_parameter_index(self.tcx, diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 50c4178601f2f..20e3f27f2ae18 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -123,8 +123,8 @@ pub fn get_enum_variant_defs(cstore: &cstore::CStore, enum_id: ast::DefId) decoder::get_enum_variant_defs(&*cstore.intr, &*cdata, enum_id.node) } -pub fn get_enum_variants(tcx: &ty::ctxt, def: ast::DefId) - -> Vec> { +pub fn get_enum_variants<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId) + -> Vec>> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(def.krate); decoder::get_enum_variants(cstore.intr.clone(), &*cdata, def.node, tcx) @@ -137,8 +137,8 @@ pub fn get_impl_items(cstore: &cstore::CStore, impl_def_id: ast::DefId) decoder::get_impl_items(&*cdata, impl_def_id.node) } -pub fn get_impl_or_trait_item(tcx: &ty::ctxt, def: ast::DefId) - -> ty::ImplOrTraitItem { +pub fn get_impl_or_trait_item<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId) + -> ty::ImplOrTraitItem<'tcx> { let cdata = tcx.sess.cstore.get_crate_data(def.krate); decoder::get_impl_or_trait_item(tcx.sess.cstore.intr.clone(), &*cdata, @@ -166,15 +166,17 @@ pub fn get_item_variances(cstore: &cstore::CStore, decoder::get_item_variances(&*cdata, def.node) } -pub fn get_provided_trait_methods(tcx: &ty::ctxt, - def: ast::DefId) - -> Vec> { +pub fn get_provided_trait_methods<'tcx>(tcx: &ty::ctxt<'tcx>, + def: ast::DefId) + -> Vec>> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(def.krate); decoder::get_provided_trait_methods(cstore.intr.clone(), &*cdata, def.node, tcx) } -pub fn get_supertraits(tcx: &ty::ctxt, def: ast::DefId) -> Vec> { +pub fn get_supertraits<'tcx>(tcx: &ty::ctxt<'tcx>, + def: ast::DefId) + -> Vec>> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(def.krate); decoder::get_supertraits(&*cdata, def.node, tcx) @@ -213,22 +215,22 @@ pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: ast::DefId) -> HashM decoder::get_struct_field_attrs(&*cdata) } -pub fn get_type(tcx: &ty::ctxt, - def: ast::DefId) - -> ty::Polytype { +pub fn get_type<'tcx>(tcx: &ty::ctxt<'tcx>, + def: ast::DefId) + -> ty::Polytype<'tcx> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(def.krate); decoder::get_type(&*cdata, def.node, tcx) } -pub fn get_trait_def(tcx: &ty::ctxt, def: ast::DefId) -> ty::TraitDef { +pub fn get_trait_def<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId) -> ty::TraitDef<'tcx> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(def.krate); decoder::get_trait_def(&*cdata, def.node, tcx) } -pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId, - def: ast::DefId) -> ty::Polytype { +pub fn get_field_type<'tcx>(tcx: &ty::ctxt<'tcx>, class_id: ast::DefId, + def: ast::DefId) -> ty::Polytype<'tcx> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(class_id.krate); let all_items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items); @@ -255,17 +257,18 @@ pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId, // Given a def_id for an impl, return the trait it implements, // if there is one. -pub fn get_impl_trait(tcx: &ty::ctxt, - def: ast::DefId) -> Option> { +pub fn get_impl_trait<'tcx>(tcx: &ty::ctxt<'tcx>, + def: ast::DefId) + -> Option>> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(def.krate); decoder::get_impl_trait(&*cdata, def.node, tcx) } // Given a def_id for an impl, return information about its vtables -pub fn get_impl_vtables(tcx: &ty::ctxt, - def: ast::DefId) - -> typeck::vtable_res { +pub fn get_impl_vtables<'tcx>(tcx: &ty::ctxt<'tcx>, + def: ast::DefId) + -> typeck::vtable_res<'tcx> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(def.krate); decoder::get_impl_vtables(&*cdata, def.node, tcx) diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index e0110a81c179f..209e78682b418 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -29,7 +29,7 @@ use middle::lang_items; use middle::resolve::{TraitItemKind, TypeTraitItemKind}; use middle::subst; use middle::ty::{ImplContainer, TraitContainer}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck; use middle::astencode::vtable_decoder_helpers; @@ -224,39 +224,44 @@ fn variant_disr_val(d: rbml::Doc) -> Option { }) } -fn doc_type(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::t { +fn doc_type<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) -> Ty<'tcx> { let tp = reader::get_doc(doc, tag_items_data_item_type); parse_ty_data(tp.data, cdata.cnum, tp.start, tcx, |_, did| translate_def_id(cdata, did)) } -fn doc_method_fty(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::BareFnTy { +fn doc_method_fty<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, + cdata: Cmd) -> ty::BareFnTy<'tcx> { let tp = reader::get_doc(doc, tag_item_method_fty); parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx, |_, did| translate_def_id(cdata, did)) } -pub fn item_type(_item_id: ast::DefId, item: rbml::Doc, - tcx: &ty::ctxt, cdata: Cmd) -> ty::t { +pub fn item_type<'tcx>(_item_id: ast::DefId, item: rbml::Doc, + tcx: &ty::ctxt<'tcx>, cdata: Cmd) -> Ty<'tcx> { doc_type(item, tcx, cdata) } -fn doc_trait_ref(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef { +fn doc_trait_ref<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) + -> ty::TraitRef<'tcx> { parse_trait_ref_data(doc.data, cdata.cnum, doc.start, tcx, |_, did| translate_def_id(cdata, did)) } -fn item_trait_ref(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef { +fn item_trait_ref<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) + -> ty::TraitRef<'tcx> { let tp = reader::get_doc(doc, tag_item_trait_ref); doc_trait_ref(tp, tcx, cdata) } -fn doc_bounds(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::ParamBounds { +fn doc_bounds<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) + -> ty::ParamBounds<'tcx> { parse_bounds_data(doc.data, cdata.cnum, doc.start, tcx, |_, did| translate_def_id(cdata, did)) } -fn trait_def_bounds(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::ParamBounds { +fn trait_def_bounds<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) + -> ty::ParamBounds<'tcx> { let d = reader::get_doc(doc, tag_trait_def_bounds); doc_bounds(d, tcx, cdata) } @@ -353,9 +358,9 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum) } } -pub fn get_trait_def(cdata: Cmd, - item_id: ast::NodeId, - tcx: &ty::ctxt) -> ty::TraitDef +pub fn get_trait_def<'tcx>(cdata: Cmd, + item_id: ast::NodeId, + tcx: &ty::ctxt<'tcx>) -> ty::TraitDef<'tcx> { let item_doc = lookup_item(item_id, cdata.data()); let generics = doc_generics(item_doc, tcx, cdata, tag_item_generics); @@ -368,8 +373,8 @@ pub fn get_trait_def(cdata: Cmd, } } -pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt) - -> ty::Polytype { +pub fn get_type<'tcx>(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt<'tcx>) + -> ty::Polytype<'tcx> { let item = lookup_item(id, cdata.data()); @@ -403,9 +408,10 @@ pub fn get_repr_attrs(cdata: Cmd, id: ast::NodeId) -> Vec { } } -pub fn get_impl_trait(cdata: Cmd, - id: ast::NodeId, - tcx: &ty::ctxt) -> Option> +pub fn get_impl_trait<'tcx>(cdata: Cmd, + id: ast::NodeId, + tcx: &ty::ctxt<'tcx>) + -> Option>> { let item_doc = lookup_item(id, cdata.data()); reader::maybe_get_doc(item_doc, tag_item_trait_ref).map(|tp| { @@ -413,10 +419,10 @@ pub fn get_impl_trait(cdata: Cmd, }) } -pub fn get_impl_vtables(cdata: Cmd, - id: ast::NodeId, - tcx: &ty::ctxt) - -> typeck::vtable_res +pub fn get_impl_vtables<'tcx>(cdata: Cmd, + id: ast::NodeId, + tcx: &ty::ctxt<'tcx>) + -> typeck::vtable_res<'tcx> { let item_doc = lookup_item(id, cdata.data()); let vtables_doc = reader::get_doc(item_doc, tag_item_impl_vtables); @@ -682,8 +688,8 @@ pub fn get_enum_variant_defs(intr: &IdentInterner, }).collect() } -pub fn get_enum_variants(intr: Rc, cdata: Cmd, id: ast::NodeId, - tcx: &ty::ctxt) -> Vec> { +pub fn get_enum_variants<'tcx>(intr: Rc, cdata: Cmd, id: ast::NodeId, + tcx: &ty::ctxt<'tcx>) -> Vec>> { let data = cdata.data(); let items = reader::get_doc(rbml::Doc::new(data), tag_items); let item = find_item(id, items); @@ -693,7 +699,7 @@ pub fn get_enum_variants(intr: Rc, cdata: Cmd, id: ast::NodeId, let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id}, item, tcx, cdata); let name = item_name(&*intr, item); - let (ctor_ty, arg_tys) = match ty::get(ctor_ty).sty { + let (ctor_ty, arg_tys) = match ctor_ty.sty { ty::ty_bare_fn(ref f) => (Some(ctor_ty), f.sig.inputs.clone()), _ => // Nullary or struct enum variant. @@ -786,11 +792,11 @@ pub fn get_trait_item_name_and_kind(intr: Rc, } } -pub fn get_impl_or_trait_item(intr: Rc, - cdata: Cmd, - id: ast::NodeId, - tcx: &ty::ctxt) - -> ty::ImplOrTraitItem { +pub fn get_impl_or_trait_item<'tcx>(intr: Rc, + cdata: Cmd, + id: ast::NodeId, + tcx: &ty::ctxt<'tcx>) + -> ty::ImplOrTraitItem<'tcx> { let method_doc = lookup_item(id, cdata.data()); let def_id = item_def_id(method_doc, cdata); @@ -860,11 +866,11 @@ pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances { Decodable::decode(&mut decoder).unwrap() } -pub fn get_provided_trait_methods(intr: Rc, - cdata: Cmd, - id: ast::NodeId, - tcx: &ty::ctxt) - -> Vec> { +pub fn get_provided_trait_methods<'tcx>(intr: Rc, + cdata: Cmd, + id: ast::NodeId, + tcx: &ty::ctxt<'tcx>) + -> Vec>> { let data = cdata.data(); let item = lookup_item(id, data); let mut result = Vec::new(); @@ -892,8 +898,8 @@ pub fn get_provided_trait_methods(intr: Rc, } /// Returns the supertraits of the given trait. -pub fn get_supertraits(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt) - -> Vec> { +pub fn get_supertraits<'tcx>(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt<'tcx>) + -> Vec>> { let mut results = Vec::new(); let item_doc = lookup_item(id, cdata.data()); reader::tagged_docs(item_doc, tag_item_super_trait_ref, |trait_doc| { @@ -1388,11 +1394,11 @@ pub fn is_typedef(cdata: Cmd, id: ast::NodeId) -> bool { } } -fn doc_generics(base_doc: rbml::Doc, - tcx: &ty::ctxt, - cdata: Cmd, - tag: uint) - -> ty::Generics +fn doc_generics<'tcx>(base_doc: rbml::Doc, + tcx: &ty::ctxt<'tcx>, + cdata: Cmd, + tag: uint) + -> ty::Generics<'tcx> { let doc = reader::get_doc(base_doc, tag); diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index e90bf1e2b3314..7e4d2621f1837 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -22,7 +22,7 @@ use metadata::cstore; use metadata::decoder; use metadata::tyencode; use middle::ty::{lookup_item_type}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::stability; use middle; use util::nodemap::{FnvHashMap, NodeMap, NodeSet}; @@ -32,8 +32,7 @@ use std::cell::RefCell; use std::hash::Hash; use std::hash; use syntax::abi; -use syntax::ast::*; -use syntax::ast; +use syntax::ast::{mod, DefId, NodeId}; use syntax::ast_map::{PathElem, PathElems}; use syntax::ast_map; use syntax::ast_util::*; @@ -53,8 +52,8 @@ use rbml::io::SeekableMemWriter; /// A borrowed version of `ast::InlinedItem`. pub enum InlinedItemRef<'a> { IIItemRef(&'a ast::Item), - IITraitItemRef(ast::DefId, &'a ast::TraitItem), - IIImplItemRef(ast::DefId, &'a ast::ImplItem), + IITraitItemRef(DefId, &'a ast::TraitItem), + IIImplItemRef(DefId, &'a ast::ImplItem), IIForeignRef(&'a ast::ForeignItem) } @@ -83,15 +82,15 @@ pub struct EncodeContext<'a, 'tcx: 'a> { pub link_meta: &'a LinkMeta, pub cstore: &'a cstore::CStore, pub encode_inlined_item: RefCell>, - pub type_abbrevs: tyencode::abbrev_map, + pub type_abbrevs: tyencode::abbrev_map<'tcx>, pub reachable: &'a NodeSet, } -fn encode_name(rbml_w: &mut Encoder, name: Name) { +fn encode_name(rbml_w: &mut Encoder, name: ast::Name) { rbml_w.wr_tagged_str(tag_paths_data_name, token::get_name(name).get()); } -fn encode_impl_type_basename(rbml_w: &mut Encoder, name: Ident) { +fn encode_impl_type_basename(rbml_w: &mut Encoder, name: ast::Ident) { rbml_w.wr_tagged_str(tag_item_impl_type_basename, token::get_ident(name).get()); } @@ -105,10 +104,10 @@ struct entry { pos: u64 } -fn encode_trait_ref(rbml_w: &mut Encoder, - ecx: &EncodeContext, - trait_ref: &ty::TraitRef, - tag: uint) { +fn encode_trait_ref<'a, 'tcx>(rbml_w: &mut Encoder, + ecx: &EncodeContext<'a, 'tcx>, + trait_ref: &ty::TraitRef<'tcx>, + tag: uint) { let ty_str_ctxt = &tyencode::ctxt { diag: ecx.diag, ds: def_to_string, @@ -134,16 +133,16 @@ pub fn def_to_string(did: DefId) -> String { fn encode_item_variances(rbml_w: &mut Encoder, ecx: &EncodeContext, - id: ast::NodeId) { + id: NodeId) { let v = ty::item_variances(ecx.tcx, ast_util::local_def(id)); rbml_w.start_tag(tag_item_variances); v.encode(rbml_w); rbml_w.end_tag(); } -fn encode_bounds_and_type(rbml_w: &mut Encoder, - ecx: &EncodeContext, - pty: &ty::Polytype) { +fn encode_bounds_and_type<'a, 'tcx>(rbml_w: &mut Encoder, + ecx: &EncodeContext<'a, 'tcx>, + pty: &ty::Polytype<'tcx>) { encode_generics(rbml_w, ecx, &pty.generics, tag_item_generics); encode_type(ecx, rbml_w, pty.ty); } @@ -159,9 +158,9 @@ fn encode_variant_id(rbml_w: &mut Encoder, vid: DefId) { rbml_w.end_tag(); } -pub fn write_closure_type(ecx: &EncodeContext, - rbml_w: &mut Encoder, - closure_type: &ty::ClosureTy) { +pub fn write_closure_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, + rbml_w: &mut Encoder, + closure_type: &ty::ClosureTy<'tcx>) { let ty_str_ctxt = &tyencode::ctxt { diag: ecx.diag, ds: def_to_string, @@ -171,9 +170,9 @@ pub fn write_closure_type(ecx: &EncodeContext, tyencode::enc_closure_ty(rbml_w.writer, ty_str_ctxt, closure_type); } -pub fn write_type(ecx: &EncodeContext, - rbml_w: &mut Encoder, - typ: ty::t) { +pub fn write_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, + rbml_w: &mut Encoder, + typ: Ty<'tcx>) { let ty_str_ctxt = &tyencode::ctxt { diag: ecx.diag, ds: def_to_string, @@ -183,9 +182,9 @@ pub fn write_type(ecx: &EncodeContext, tyencode::enc_ty(rbml_w.writer, ty_str_ctxt, typ); } -pub fn write_trait_ref(ecx: &EncodeContext, - rbml_w: &mut Encoder, - trait_ref: &ty::TraitRef) { +pub fn write_trait_ref<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, + rbml_w: &mut Encoder, + trait_ref: &ty::TraitRef<'tcx>) { let ty_str_ctxt = &tyencode::ctxt { diag: ecx.diag, ds: def_to_string, @@ -207,10 +206,10 @@ pub fn write_region(ecx: &EncodeContext, tyencode::enc_region(rbml_w.writer, ty_str_ctxt, r); } -fn encode_bounds(rbml_w: &mut Encoder, - ecx: &EncodeContext, - bounds: &ty::ParamBounds, - tag: uint) { +fn encode_bounds<'a, 'tcx>(rbml_w: &mut Encoder, + ecx: &EncodeContext<'a, 'tcx>, + bounds: &ty::ParamBounds<'tcx>, + tag: uint) { rbml_w.start_tag(tag); let ty_str_ctxt = &tyencode::ctxt { diag: ecx.diag, @@ -222,9 +221,9 @@ fn encode_bounds(rbml_w: &mut Encoder, rbml_w.end_tag(); } -fn encode_type(ecx: &EncodeContext, - rbml_w: &mut Encoder, - typ: ty::t) { +fn encode_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, + rbml_w: &mut Encoder, + typ: Ty<'tcx>) { rbml_w.start_tag(tag_items_data_item_type); write_type(ecx, rbml_w, typ); rbml_w.end_tag(); @@ -238,9 +237,9 @@ fn encode_region(ecx: &EncodeContext, rbml_w.end_tag(); } -fn encode_method_fty(ecx: &EncodeContext, - rbml_w: &mut Encoder, - typ: &ty::BareFnTy) { +fn encode_method_fty<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, + rbml_w: &mut Encoder, + typ: &ty::BareFnTy<'tcx>) { rbml_w.start_tag(tag_item_method_fty); let ty_str_ctxt = &tyencode::ctxt { @@ -310,14 +309,14 @@ fn encode_struct_fields(rbml_w: &mut Encoder, fn encode_enum_variant_info(ecx: &EncodeContext, rbml_w: &mut Encoder, id: NodeId, - variants: &[P], + variants: &[P], index: &mut Vec>) { debug!("encode_enum_variant_info(id={})", id); let mut disr_val = 0; let mut i = 0; let vi = ty::enum_variants(ecx.tcx, - ast::DefId { krate: LOCAL_CRATE, node: id }); + DefId { krate: ast::LOCAL_CRATE, node: id }); for variant in variants.iter() { let def_id = local_def(variant.node.id); index.push(entry { @@ -382,7 +381,7 @@ fn encode_path + Clone>(rbml_w: &mut Encoder, fn encode_reexported_static_method(rbml_w: &mut Encoder, exp: &middle::resolve::Export2, method_def_id: DefId, - method_name: Name) { + method_name: ast::Name) { debug!("(encode reexported static method) {}::{}", exp.name, token::get_name(method_name)); rbml_w.start_tag(tag_items_data_item_reexport); @@ -504,10 +503,10 @@ fn encode_reexported_static_methods(ecx: &EncodeContext, /// * For enums, iterates through the node IDs of the variants. /// /// * For newtype structs, iterates through the node ID of the constructor. -fn each_auxiliary_node_id(item: &Item, callback: |NodeId| -> bool) -> bool { +fn each_auxiliary_node_id(item: &ast::Item, callback: |NodeId| -> bool) -> bool { let mut continue_ = true; match item.node { - ItemEnum(ref enum_def, _) => { + ast::ItemEnum(ref enum_def, _) => { for variant in enum_def.variants.iter() { continue_ = callback(variant.node.id); if !continue_ { @@ -515,7 +514,7 @@ fn each_auxiliary_node_id(item: &Item, callback: |NodeId| -> bool) -> bool { } } } - ItemStruct(ref struct_def, _) => { + ast::ItemStruct(ref struct_def, _) => { // If this is a newtype struct, return the constructor. match struct_def.ctor_id { Some(ctor_id) if struct_def.fields.len() > 0 && @@ -566,12 +565,12 @@ fn encode_reexports(ecx: &EncodeContext, fn encode_info_for_mod(ecx: &EncodeContext, rbml_w: &mut Encoder, - md: &Mod, - attrs: &[Attribute], + md: &ast::Mod, + attrs: &[ast::Attribute], id: NodeId, path: PathElems, - name: Ident, - vis: Visibility) { + name: ast::Ident, + vis: ast::Visibility) { rbml_w.start_tag(tag_items_data_item); encode_def_id(rbml_w, local_def(id)); encode_family(rbml_w, 'm'); @@ -593,7 +592,7 @@ fn encode_info_for_mod(ecx: &EncodeContext, }); match item.node { - ItemImpl(..) => { + ast::ItemImpl(..) => { let (ident, did) = (item.ident, item.id); debug!("(encoding info for module) ... encoding impl {} \ ({}/{})", @@ -615,7 +614,7 @@ fn encode_info_for_mod(ecx: &EncodeContext, encode_stability(rbml_w, stab); // Encode the reexports of this module, if this module is public. - if vis == Public { + if vis == ast::Public { debug!("(encoding info for module) encoding reexports for {}", id); encode_reexports(ecx, rbml_w, id, path); } @@ -625,18 +624,18 @@ fn encode_info_for_mod(ecx: &EncodeContext, } fn encode_struct_field_family(rbml_w: &mut Encoder, - visibility: Visibility) { + visibility: ast::Visibility) { encode_family(rbml_w, match visibility { - Public => 'g', - Inherited => 'N' + ast::Public => 'g', + ast::Inherited => 'N' }); } -fn encode_visibility(rbml_w: &mut Encoder, visibility: Visibility) { +fn encode_visibility(rbml_w: &mut Encoder, visibility: ast::Visibility) { rbml_w.start_tag(tag_items_data_item_visibility); let ch = match visibility { - Public => 'y', - Inherited => 'i', + ast::Public => 'y', + ast::Inherited => 'i', }; rbml_w.wr_str(ch.to_string().as_slice()); rbml_w.end_tag(); @@ -681,8 +680,8 @@ fn encode_explicit_self(rbml_w: &mut Encoder, fn encode_mutability(rbml_w: &mut Encoder, m: ast::Mutability) { match m { - MutImmutable => { rbml_w.writer.write(&[ 'i' as u8 ]); } - MutMutable => { rbml_w.writer.write(&[ 'm' as u8 ]); } + ast::MutImmutable => { rbml_w.writer.write(&[ 'i' as u8 ]); } + ast::MutMutable => { rbml_w.writer.write(&[ 'm' as u8 ]); } } } } @@ -782,10 +781,10 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext, rbml_w.end_tag(); } -fn encode_generics(rbml_w: &mut Encoder, - ecx: &EncodeContext, - generics: &ty::Generics, - tag: uint) +fn encode_generics<'a, 'tcx>(rbml_w: &mut Encoder, + ecx: &EncodeContext<'a, 'tcx>, + generics: &ty::Generics<'tcx>, + tag: uint) { rbml_w.start_tag(tag); @@ -829,9 +828,9 @@ fn encode_generics(rbml_w: &mut Encoder, rbml_w.end_tag(); } -fn encode_method_ty_fields(ecx: &EncodeContext, - rbml_w: &mut Encoder, - method_ty: &ty::Method) { +fn encode_method_ty_fields<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, + rbml_w: &mut Encoder, + method_ty: &ty::Method<'tcx>) { encode_def_id(rbml_w, method_ty.def_id); encode_name(rbml_w, method_ty.name); encode_generics(rbml_w, ecx, &method_ty.generics, @@ -848,13 +847,13 @@ fn encode_method_ty_fields(ecx: &EncodeContext, encode_provided_source(rbml_w, method_ty.provided_source); } -fn encode_info_for_method(ecx: &EncodeContext, - rbml_w: &mut Encoder, - m: &ty::Method, - impl_path: PathElems, - is_default_impl: bool, - parent_id: NodeId, - ast_item_opt: Option<&ImplItem>) { +fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, + rbml_w: &mut Encoder, + m: &ty::Method<'tcx>, + impl_path: PathElems, + is_default_impl: bool, + parent_id: NodeId, + ast_item_opt: Option<&ast::ImplItem>) { debug!("encode_info_for_method: {} {}", m.def_id, token::get_name(m.name)); @@ -948,7 +947,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder, fn encode_repr_attrs(rbml_w: &mut Encoder, ecx: &EncodeContext, - attrs: &[Attribute]) { + attrs: &[ast::Attribute]) { let mut repr_attrs = Vec::new(); for attr in attrs.iter() { repr_attrs.extend(attr::find_repr_attrs(ecx.tcx.sess.diagnostic(), @@ -971,7 +970,7 @@ const FN_FAMILY: char = 'f'; const STATIC_METHOD_FAMILY: char = 'F'; const METHOD_FAMILY: char = 'h'; -fn should_inline(attrs: &[Attribute]) -> bool { +fn should_inline(attrs: &[ast::Attribute]) -> bool { use syntax::attr::*; match find_inline_attr(attrs) { InlineNone | InlineNever => false, @@ -1021,13 +1020,13 @@ fn encode_stability(rbml_w: &mut Encoder, stab_opt: Option) { fn encode_info_for_item(ecx: &EncodeContext, rbml_w: &mut Encoder, - item: &Item, + item: &ast::Item, index: &mut Vec>, path: PathElems, vis: ast::Visibility) { let tcx = ecx.tcx; - fn add_to_index(item: &Item, rbml_w: &Encoder, + fn add_to_index(item: &ast::Item, rbml_w: &Encoder, index: &mut Vec>) { index.push(entry { val: item.id as i64, @@ -1042,7 +1041,7 @@ fn encode_info_for_item(ecx: &EncodeContext, let stab = stability::lookup(tcx, ast_util::local_def(item.id)); match item.node { - ItemStatic(_, m, _) => { + ast::ItemStatic(_, m, _) => { add_to_index(item, rbml_w, index); rbml_w.start_tag(tag_items_data_item); encode_def_id(rbml_w, def_id); @@ -1060,7 +1059,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_attributes(rbml_w, item.attrs.as_slice()); rbml_w.end_tag(); } - ItemConst(_, _) => { + ast::ItemConst(_, _) => { add_to_index(item, rbml_w, index); rbml_w.start_tag(tag_items_data_item); encode_def_id(rbml_w, def_id); @@ -1073,7 +1072,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_stability(rbml_w, stab); rbml_w.end_tag(); } - ItemFn(ref decl, _, _, ref generics, _) => { + ast::ItemFn(ref decl, _, _, ref generics, _) => { add_to_index(item, rbml_w, index); rbml_w.start_tag(tag_items_data_item); encode_def_id(rbml_w, def_id); @@ -1094,7 +1093,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_method_argument_names(rbml_w, &**decl); rbml_w.end_tag(); } - ItemMod(ref m) => { + ast::ItemMod(ref m) => { add_to_index(item, rbml_w, index); encode_info_for_mod(ecx, rbml_w, @@ -1105,7 +1104,7 @@ fn encode_info_for_item(ecx: &EncodeContext, item.ident, item.vis); } - ItemForeignMod(ref fm) => { + ast::ItemForeignMod(ref fm) => { add_to_index(item, rbml_w, index); rbml_w.start_tag(tag_items_data_item); encode_def_id(rbml_w, def_id); @@ -1123,7 +1122,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_stability(rbml_w, stab); rbml_w.end_tag(); } - ItemTy(..) => { + ast::ItemTy(..) => { add_to_index(item, rbml_w, index); rbml_w.start_tag(tag_items_data_item); encode_def_id(rbml_w, def_id); @@ -1135,7 +1134,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_stability(rbml_w, stab); rbml_w.end_tag(); } - ItemEnum(ref enum_definition, _) => { + ast::ItemEnum(ref enum_definition, _) => { add_to_index(item, rbml_w, index); rbml_w.start_tag(tag_items_data_item); @@ -1165,7 +1164,7 @@ fn encode_info_for_item(ecx: &EncodeContext, (*enum_definition).variants.as_slice(), index); } - ItemStruct(ref struct_def, _) => { + ast::ItemStruct(ref struct_def, _) => { let fields = ty::lookup_struct_fields(tcx, def_id); /* First, encode the fields @@ -1217,7 +1216,7 @@ fn encode_info_for_item(ecx: &EncodeContext, None => {} } } - ItemImpl(_, ref opt_trait, ref ty, ref ast_items) => { + ast::ItemImpl(_, ref opt_trait, ref ty, ref ast_items) => { // We need to encode information about the default methods we // have inherited, so we drive this based on the impl structure. let impl_items = tcx.impl_items.borrow(); @@ -1321,7 +1320,7 @@ fn encode_info_for_item(ecx: &EncodeContext, } } } - ItemTrait(_, _, _, ref ms) => { + ast::ItemTrait(_, _, _, ref ms) => { add_to_index(item, rbml_w, index); rbml_w.start_tag(tag_items_data_item); encode_def_id(rbml_w, def_id); @@ -1433,14 +1432,14 @@ fn encode_info_for_item(ecx: &EncodeContext, } }; match trait_item { - &RequiredMethod(ref m) => { + &ast::RequiredMethod(ref m) => { encode_attributes(rbml_w, m.attrs.as_slice()); encode_trait_item(rbml_w); encode_item_sort(rbml_w, 'r'); encode_method_argument_names(rbml_w, &*m.decl); } - &ProvidedMethod(ref m) => { + &ast::ProvidedMethod(ref m) => { encode_attributes(rbml_w, m.attrs.as_slice()); encode_trait_item(rbml_w); encode_item_sort(rbml_w, 'p'); @@ -1448,7 +1447,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_method_argument_names(rbml_w, &*m.pe_fn_decl()); } - &TypeTraitItem(ref associated_type) => { + &ast::TypeTraitItem(ref associated_type) => { encode_attributes(rbml_w, associated_type.attrs.as_slice()); encode_item_sort(rbml_w, 't'); @@ -1461,7 +1460,7 @@ fn encode_info_for_item(ecx: &EncodeContext, // Encode inherent implementations for this trait. encode_inherent_implementations(ecx, rbml_w, def_id); } - ItemMac(..) => { + ast::ItemMac(..) => { // macros are encoded separately } } @@ -1469,7 +1468,7 @@ fn encode_info_for_item(ecx: &EncodeContext, fn encode_info_for_foreign_item(ecx: &EncodeContext, rbml_w: &mut Encoder, - nitem: &ForeignItem, + nitem: &ast::ForeignItem, index: &mut Vec>, path: PathElems, abi: abi::Abi) { @@ -1482,7 +1481,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, encode_def_id(rbml_w, local_def(nitem.id)); encode_visibility(rbml_w, nitem.vis); match nitem.node { - ForeignItemFn(..) => { + ast::ForeignItemFn(..) => { encode_family(rbml_w, FN_FAMILY); encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(ecx.tcx,local_def(nitem.id))); @@ -1492,7 +1491,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, } encode_symbol(ecx, rbml_w, nitem.id); } - ForeignItemStatic(_, mutbl) => { + ast::ForeignItemStatic(_, mutbl) => { if mutbl { encode_family(rbml_w, 'b'); } else { @@ -1508,9 +1507,9 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, rbml_w.end_tag(); } -fn my_visit_expr(_e: &Expr) { } +fn my_visit_expr(_e: &ast::Expr) { } -fn my_visit_item(i: &Item, +fn my_visit_item(i: &ast::Item, rbml_w: &mut Encoder, ecx: &EncodeContext, index: &mut Vec>) { @@ -1519,7 +1518,7 @@ fn my_visit_item(i: &Item, }); } -fn my_visit_foreign_item(ni: &ForeignItem, +fn my_visit_foreign_item(ni: &ast::ForeignItem, rbml_w: &mut Encoder, ecx: &EncodeContext, index: &mut Vec>) { @@ -1542,18 +1541,18 @@ struct EncodeVisitor<'a, 'b:'a, 'c:'a, 'tcx:'c> { } impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for EncodeVisitor<'a, 'b, 'c, 'tcx> { - fn visit_expr(&mut self, ex: &Expr) { + fn visit_expr(&mut self, ex: &ast::Expr) { visit::walk_expr(self, ex); my_visit_expr(ex); } - fn visit_item(&mut self, i: &Item) { + fn visit_item(&mut self, i: &ast::Item) { visit::walk_item(self, i); my_visit_item(i, self.rbml_w_for_visit_item, self.ecx, self.index); } - fn visit_foreign_item(&mut self, ni: &ForeignItem) { + fn visit_foreign_item(&mut self, ni: &ast::ForeignItem) { visit::walk_foreign_item(self, ni); my_visit_foreign_item(ni, self.rbml_w_for_visit_item, @@ -1564,22 +1563,22 @@ impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for EncodeVisitor<'a, 'b, 'c, 'tcx> { fn encode_info_for_items(ecx: &EncodeContext, rbml_w: &mut Encoder, - krate: &Crate) + krate: &ast::Crate) -> Vec> { let mut index = Vec::new(); rbml_w.start_tag(tag_items_data); index.push(entry { - val: CRATE_NODE_ID as i64, + val: ast::CRATE_NODE_ID as i64, pos: rbml_w.writer.tell().unwrap(), }); encode_info_for_mod(ecx, rbml_w, &krate.module, &[], - CRATE_NODE_ID, + ast::CRATE_NODE_ID, ast_map::Values([].iter()).chain(None), syntax::parse::token::special_idents::invalid, - Public); + ast::Public); visit::walk_crate(&mut EncodeVisitor { index: &mut index, @@ -1637,18 +1636,18 @@ fn write_i64(writer: &mut SeekableMemWriter, &n: &i64) { wr.write_be_u32(n as u32); } -fn encode_meta_item(rbml_w: &mut Encoder, mi: &MetaItem) { +fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) { match mi.node { - MetaWord(ref name) => { + ast::MetaWord(ref name) => { rbml_w.start_tag(tag_meta_item_word); rbml_w.start_tag(tag_meta_item_name); rbml_w.writer.write(name.get().as_bytes()); rbml_w.end_tag(); rbml_w.end_tag(); } - MetaNameValue(ref name, ref value) => { + ast::MetaNameValue(ref name, ref value) => { match value.node { - LitStr(ref value, _) => { + ast::LitStr(ref value, _) => { rbml_w.start_tag(tag_meta_item_name_value); rbml_w.start_tag(tag_meta_item_name); rbml_w.writer.write(name.get().as_bytes()); @@ -1661,7 +1660,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &MetaItem) { _ => {/* FIXME (#623): encode other variants */ } } } - MetaList(ref name, ref items) => { + ast::MetaList(ref name, ref items) => { rbml_w.start_tag(tag_meta_item_list); rbml_w.start_tag(tag_meta_item_name); rbml_w.writer.write(name.get().as_bytes()); @@ -1674,7 +1673,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &MetaItem) { } } -fn encode_attributes(rbml_w: &mut Encoder, attrs: &[Attribute]) { +fn encode_attributes(rbml_w: &mut Encoder, attrs: &[ast::Attribute]) { rbml_w.start_tag(tag_attributes); for attr in attrs.iter() { rbml_w.start_tag(tag_attribute); @@ -1728,7 +1727,7 @@ fn encode_lang_items(ecx: &EncodeContext, rbml_w: &mut Encoder) { for (i, def_id) in ecx.tcx.lang_items.items() { for id in def_id.iter() { - if id.krate == LOCAL_CRATE { + if id.krate == ast::LOCAL_CRATE { rbml_w.start_tag(tag_lang_items_item); rbml_w.start_tag(tag_lang_items_item_id); @@ -1804,7 +1803,7 @@ fn encode_macro_def(ecx: &EncodeContext, /// Serialize the text of the exported macros fn encode_macro_defs(ecx: &EncodeContext, - krate: &Crate, + krate: &ast::Crate, rbml_w: &mut Encoder) { rbml_w.start_tag(tag_exported_macros); for item in krate.exported_macros.iter() { @@ -1821,7 +1820,7 @@ fn encode_unboxed_closures<'a>( .unboxed_closures .borrow() .iter() { - if unboxed_closure_id.krate != LOCAL_CRATE { + if unboxed_closure_id.krate != ast::LOCAL_CRATE { continue } @@ -1836,7 +1835,7 @@ fn encode_unboxed_closures<'a>( rbml_w.end_tag(); } -fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &Crate) { +fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &ast::Crate) { struct StructFieldVisitor<'a, 'b:'a> { rbml_w: &'a mut Encoder<'b>, } @@ -1865,9 +1864,9 @@ struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> { } impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> { - fn visit_item(&mut self, item: &Item) { + fn visit_item(&mut self, item: &ast::Item) { match item.node { - ItemImpl(_, Some(ref trait_ref), _, _) => { + ast::ItemImpl(_, Some(ref trait_ref), _, _) => { let def_map = &self.ecx.tcx.def_map; let trait_def = def_map.borrow()[trait_ref.ref_id].clone(); let def_id = trait_def.def_id(); @@ -1875,7 +1874,7 @@ impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> { // Load eagerly if this is an implementation of the Drop trait // or if the trait is not defined in this crate. if Some(def_id) == self.ecx.tcx.lang_items.drop_trait() || - def_id.krate != LOCAL_CRATE { + def_id.krate != ast::LOCAL_CRATE { self.rbml_w.start_tag(tag_impls_impl); encode_def_id(self.rbml_w, local_def(item.id)); self.rbml_w.end_tag(); @@ -1898,7 +1897,7 @@ impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> { /// /// * Implementations of traits not defined in this crate. fn encode_impls<'a>(ecx: &'a EncodeContext, - krate: &Crate, + krate: &ast::Crate, rbml_w: &'a mut Encoder) { rbml_w.start_tag(tag_impls); @@ -1914,7 +1913,7 @@ fn encode_impls<'a>(ecx: &'a EncodeContext, } fn encode_misc_info(ecx: &EncodeContext, - krate: &Crate, + krate: &ast::Crate, rbml_w: &mut Encoder) { rbml_w.start_tag(tag_misc_info); rbml_w.start_tag(tag_misc_info_crate_items); @@ -2011,13 +2010,15 @@ fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) { #[allow(non_upper_case_globals)] pub const metadata_encoding_version : &'static [u8] = &[b'r', b'u', b's', b't', 0, 0, 0, 1 ]; -pub fn encode_metadata(parms: EncodeParams, krate: &Crate) -> Vec { +pub fn encode_metadata(parms: EncodeParams, krate: &ast::Crate) -> Vec { let mut wr = SeekableMemWriter::new(); encode_metadata_inner(&mut wr, parms, krate); wr.unwrap().into_iter().collect() } -fn encode_metadata_inner(wr: &mut SeekableMemWriter, parms: EncodeParams, krate: &Crate) { +fn encode_metadata_inner(wr: &mut SeekableMemWriter, + parms: EncodeParams, + krate: &ast::Crate) { struct Stats { attr_bytes: u64, dep_bytes: u64, @@ -2166,7 +2167,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter, parms: EncodeParams, krate: } // Get the encoded string for a type -pub fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> String { +pub fn encoded_ty<'tcx>(tcx: &ty::ctxt<'tcx>, t: Ty<'tcx>) -> String { let mut wr = SeekableMemWriter::new(); tyencode::enc_ty(&mut wr, &tyencode::ctxt { diag: tcx.sess.diagnostic(), diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 69be2e3491526..34b57c5b437ed 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -20,17 +20,16 @@ pub use self::DefIdSource::*; use middle::subst; use middle::subst::VecPerParamSpace; -use middle::ty; +use middle::ty::{mod, Ty}; use std::rc::Rc; use std::str; use std::string::String; use syntax::abi; use syntax::ast; -use syntax::ast::*; use syntax::parse::token; -// Compact string representation for ty::t values. API ty_str & +// Compact string representation for Ty values. API ty_str & // parse_from_str. Extra parameters are for converting to/from def_ids in the // data buffer. Whatever format you choose should not contain pipe characters. @@ -140,18 +139,18 @@ fn data_log_string(data: &[u8], pos: uint) -> String { buf } -pub fn parse_ty_closure_data(data: &[u8], - crate_num: ast::CrateNum, - pos: uint, - tcx: &ty::ctxt, - conv: conv_did) - -> ty::ClosureTy { +pub fn parse_ty_closure_data<'tcx>(data: &[u8], + crate_num: ast::CrateNum, + pos: uint, + tcx: &ty::ctxt<'tcx>, + conv: conv_did) + -> ty::ClosureTy<'tcx> { let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_closure_ty(&mut st, conv) } -pub fn parse_ty_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt, - conv: conv_did) -> ty::t { +pub fn parse_ty_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint, + tcx: &ty::ctxt<'tcx>, conv: conv_did) -> Ty<'tcx> { debug!("parse_ty_data {}", data_log_string(data, pos)); let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_ty(&mut st, conv) @@ -164,30 +163,32 @@ pub fn parse_region_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: parse_region(&mut st, conv) } -pub fn parse_bare_fn_ty_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt, - conv: conv_did) -> ty::BareFnTy { +pub fn parse_bare_fn_ty_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint, + tcx: &ty::ctxt<'tcx>, conv: conv_did) + -> ty::BareFnTy<'tcx> { debug!("parse_bare_fn_ty_data {}", data_log_string(data, pos)); let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_bare_fn_ty(&mut st, conv) } -pub fn parse_trait_ref_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt, - conv: conv_did) -> ty::TraitRef { +pub fn parse_trait_ref_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint, + tcx: &ty::ctxt<'tcx>, conv: conv_did) + -> ty::TraitRef<'tcx> { debug!("parse_trait_ref_data {}", data_log_string(data, pos)); let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_trait_ref(&mut st, conv) } -pub fn parse_substs_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt, - conv: conv_did) -> subst::Substs { +pub fn parse_substs_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint, + tcx: &ty::ctxt<'tcx>, conv: conv_did) -> subst::Substs<'tcx> { debug!("parse_substs_data {}", data_log_string(data, pos)); let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_substs(&mut st, conv) } -pub fn parse_bounds_data(data: &[u8], crate_num: ast::CrateNum, - pos: uint, tcx: &ty::ctxt, conv: conv_did) - -> ty::ParamBounds { +pub fn parse_bounds_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, + pos: uint, tcx: &ty::ctxt<'tcx>, conv: conv_did) + -> ty::ParamBounds<'tcx> { let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_bounds(&mut st, conv) } @@ -230,9 +231,9 @@ fn parse_trait_store(st: &mut PState, conv: conv_did) -> ty::TraitStore { } } -fn parse_vec_per_param_space(st: &mut PState, - f: |&mut PState| -> T) - -> VecPerParamSpace +fn parse_vec_per_param_space<'a, 'tcx, T>(st: &mut PState<'a, 'tcx>, + f: |&mut PState<'a, 'tcx>| -> T) + -> VecPerParamSpace { let mut r = VecPerParamSpace::empty(); for &space in subst::ParamSpace::all().iter() { @@ -245,7 +246,8 @@ fn parse_vec_per_param_space(st: &mut PState, r } -fn parse_substs(st: &mut PState, conv: conv_did) -> subst::Substs { +fn parse_substs<'a, 'tcx>(st: &mut PState<'a, 'tcx>, + conv: conv_did) -> subst::Substs<'tcx> { let regions = parse_region_substs(st, |x,y| conv(x,y)); @@ -335,7 +337,8 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region { } } -fn parse_opt(st: &mut PState, f: |&mut PState| -> T) -> Option { +fn parse_opt<'a, 'tcx, T>(st: &mut PState<'a, 'tcx>, f: |&mut PState<'a, 'tcx>| -> T) + -> Option { match next(st) { 'n' => None, 's' => Some(f(st)), @@ -354,13 +357,14 @@ fn parse_str(st: &mut PState, term: char) -> String { result } -fn parse_trait_ref(st: &mut PState, conv: conv_did) -> ty::TraitRef { +fn parse_trait_ref<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) + -> ty::TraitRef<'tcx> { let def = parse_def(st, NominalType, |x,y| conv(x,y)); let substs = parse_substs(st, |x,y| conv(x,y)); ty::TraitRef {def_id: def, substs: substs} } -fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t { +fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> { match next(st) { 'b' => return ty::mk_bool(), 'i' => return ty::mk_int(), @@ -487,7 +491,7 @@ fn parse_mutability(st: &mut PState) -> ast::Mutability { } } -fn parse_mt(st: &mut PState, conv: conv_did) -> ty::mt { +fn parse_mt<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> ty::mt<'tcx> { let m = parse_mutability(st); ty::mt { ty: parse_ty(st, |x,y| conv(x,y)), mutbl: m } } @@ -525,10 +529,10 @@ fn parse_hex(st: &mut PState) -> uint { }; } -fn parse_fn_style(c: char) -> FnStyle { +fn parse_fn_style(c: char) -> ast::FnStyle { match c { - 'u' => UnsafeFn, - 'n' => NormalFn, + 'u' => ast::UnsafeFn, + 'n' => ast::NormalFn, _ => panic!("parse_fn_style: bad fn_style {}", c) } } @@ -549,7 +553,8 @@ fn parse_onceness(c: char) -> ast::Onceness { } } -fn parse_closure_ty(st: &mut PState, conv: conv_did) -> ty::ClosureTy { +fn parse_closure_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, + conv: conv_did) -> ty::ClosureTy<'tcx> { let fn_style = parse_fn_style(next(st)); let onceness = parse_onceness(next(st)); let store = parse_trait_store(st, |x,y| conv(x,y)); @@ -566,7 +571,8 @@ fn parse_closure_ty(st: &mut PState, conv: conv_did) -> ty::ClosureTy { } } -fn parse_bare_fn_ty(st: &mut PState, conv: conv_did) -> ty::BareFnTy { +fn parse_bare_fn_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, + conv: conv_did) -> ty::BareFnTy<'tcx> { let fn_style = parse_fn_style(next(st)); let abi = parse_abi_set(st); let sig = parse_sig(st, |x,y| conv(x,y)); @@ -577,7 +583,7 @@ fn parse_bare_fn_ty(st: &mut PState, conv: conv_did) -> ty::BareFnTy { } } -fn parse_sig(st: &mut PState, conv: conv_did) -> ty::FnSig { +fn parse_sig<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> ty::FnSig<'tcx> { assert_eq!(next(st), '['); let mut inputs = Vec::new(); while peek(st) != ']' { @@ -627,15 +633,16 @@ pub fn parse_def_id(buf: &[u8]) -> ast::DefId { ast::DefId { krate: crate_num, node: def_num } } -pub fn parse_type_param_def_data(data: &[u8], start: uint, - crate_num: ast::CrateNum, tcx: &ty::ctxt, - conv: conv_did) -> ty::TypeParameterDef +pub fn parse_type_param_def_data<'tcx>(data: &[u8], start: uint, + crate_num: ast::CrateNum, tcx: &ty::ctxt<'tcx>, + conv: conv_did) -> ty::TypeParameterDef<'tcx> { let mut st = parse_state_from_data(data, crate_num, start, tcx); parse_type_param_def(&mut st, conv) } -fn parse_type_param_def(st: &mut PState, conv: conv_did) -> ty::TypeParameterDef { +fn parse_type_param_def<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) + -> ty::TypeParameterDef<'tcx> { let name = parse_name(st, ':'); let def_id = parse_def(st, NominalType, |x,y| conv(x,y)); let space = parse_param_space(st); @@ -693,7 +700,8 @@ fn parse_builtin_bounds(st: &mut PState, _conv: conv_did) -> ty::BuiltinBounds { } } -fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds { +fn parse_bounds<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) + -> ty::ParamBounds<'tcx> { let builtin_bounds = parse_builtin_bounds(st, |x,y| conv(x,y)); let mut param_bounds = ty::ParamBounds { diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index a53f5fa187df2..ea778d07e1c9d 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -18,12 +18,11 @@ use std::cell::RefCell; use middle::subst; use middle::subst::VecPerParamSpace; use middle::ty::ParamTy; -use middle::ty; +use middle::ty::{mod, Ty}; use util::nodemap::FnvHashMap; use syntax::abi::Abi; use syntax::ast; -use syntax::ast::*; use syntax::diagnostic::SpanHandler; use syntax::parse::token; @@ -34,28 +33,28 @@ macro_rules! mywrite( ($($arg:tt)*) => ({ write!($($arg)*); }) ) pub struct ctxt<'a, 'tcx: 'a> { pub diag: &'a SpanHandler, // Def -> str Callback: - pub ds: fn(DefId) -> String, + pub ds: fn(ast::DefId) -> String, // The type context. pub tcx: &'a ty::ctxt<'tcx>, - pub abbrevs: &'a abbrev_map + pub abbrevs: &'a abbrev_map<'tcx> } -// Compact string representation for ty.t values. API ty_str & parse_from_str. +// Compact string representation for Ty values. API ty_str & parse_from_str. // Extra parameters are for converting to/from def_ids in the string rep. // Whatever format you choose should not contain pipe characters. pub struct ty_abbrev { s: String } -pub type abbrev_map = RefCell>; +pub type abbrev_map<'tcx> = RefCell, ty_abbrev>>; -pub fn enc_ty(w: &mut SeekableMemWriter, cx: &ctxt, t: ty::t) { +pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) { match cx.abbrevs.borrow_mut().get(&t) { Some(a) => { w.write(a.s.as_bytes()); return; } None => {} } let pos = w.tell().unwrap(); - enc_sty(w, cx, &ty::get(t).sty); + enc_sty(w, cx, &t.sty); let end = w.tell().unwrap(); let len = end - pos; fn estimate_sz(u: u64) -> u64 { @@ -75,12 +74,13 @@ pub fn enc_ty(w: &mut SeekableMemWriter, cx: &ctxt, t: ty::t) { fn enc_mutability(w: &mut SeekableMemWriter, mt: ast::Mutability) { match mt { - MutImmutable => (), - MutMutable => mywrite!(w, "m"), + ast::MutImmutable => (), + ast::MutMutable => mywrite!(w, "m"), } } -fn enc_mt(w: &mut SeekableMemWriter, cx: &ctxt, mt: ty::mt) { +fn enc_mt<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, + mt: ty::mt<'tcx>) { enc_mutability(w, mt.mutbl); enc_ty(w, cx, mt.ty); } @@ -95,10 +95,10 @@ fn enc_opt(w: &mut SeekableMemWriter, t: Option, enc_f: |&mut SeekableMemW } } -fn enc_vec_per_param_space(w: &mut SeekableMemWriter, - cx: &ctxt, - v: &VecPerParamSpace, - op: |&mut SeekableMemWriter, &ctxt, &T|) { +fn enc_vec_per_param_space<'a, 'tcx, T>(w: &mut SeekableMemWriter, + cx: &ctxt<'a, 'tcx>, + v: &VecPerParamSpace, + op: |&mut SeekableMemWriter, &ctxt<'a, 'tcx>, &T|) { for &space in subst::ParamSpace::all().iter() { mywrite!(w, "["); for t in v.get_slice(space).iter() { @@ -108,7 +108,8 @@ fn enc_vec_per_param_space(w: &mut SeekableMemWriter, } } -pub fn enc_substs(w: &mut SeekableMemWriter, cx: &ctxt, substs: &subst::Substs) { +pub fn enc_substs<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, + substs: &subst::Substs<'tcx>) { enc_region_substs(w, cx, &substs.regions); enc_vec_per_param_space(w, cx, &substs.types, |w, cx, &ty| enc_ty(w, cx, ty)); @@ -181,7 +182,8 @@ fn enc_bound_region(w: &mut SeekableMemWriter, cx: &ctxt, br: ty::BoundRegion) { } } -pub fn enc_trait_ref(w: &mut SeekableMemWriter, cx: &ctxt, s: &ty::TraitRef) { +pub fn enc_trait_ref<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, + s: &ty::TraitRef<'tcx>) { mywrite!(w, "{}|", (cx.ds)(s.def_id)); enc_substs(w, cx, &s.substs); } @@ -197,32 +199,33 @@ pub fn enc_trait_store(w: &mut SeekableMemWriter, cx: &ctxt, s: ty::TraitStore) } } -fn enc_sty(w: &mut SeekableMemWriter, cx: &ctxt, st: &ty::sty) { +fn enc_sty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, + st: &ty::sty<'tcx>) { match *st { ty::ty_bool => mywrite!(w, "b"), ty::ty_char => mywrite!(w, "c"), ty::ty_int(t) => { match t { - TyI => mywrite!(w, "i"), - TyI8 => mywrite!(w, "MB"), - TyI16 => mywrite!(w, "MW"), - TyI32 => mywrite!(w, "ML"), - TyI64 => mywrite!(w, "MD") + ast::TyI => mywrite!(w, "i"), + ast::TyI8 => mywrite!(w, "MB"), + ast::TyI16 => mywrite!(w, "MW"), + ast::TyI32 => mywrite!(w, "ML"), + ast::TyI64 => mywrite!(w, "MD") } } ty::ty_uint(t) => { match t { - TyU => mywrite!(w, "u"), - TyU8 => mywrite!(w, "Mb"), - TyU16 => mywrite!(w, "Mw"), - TyU32 => mywrite!(w, "Ml"), - TyU64 => mywrite!(w, "Md") + ast::TyU => mywrite!(w, "u"), + ast::TyU8 => mywrite!(w, "Mb"), + ast::TyU16 => mywrite!(w, "Mw"), + ast::TyU32 => mywrite!(w, "Ml"), + ast::TyU64 => mywrite!(w, "Md") } } ty::ty_float(t) => { match t { - TyF32 => mywrite!(w, "Mf"), - TyF64 => mywrite!(w, "MF"), + ast::TyF32 => mywrite!(w, "Mf"), + ast::TyF64 => mywrite!(w, "MF"), } } ty::ty_enum(def, ref substs) => { @@ -295,10 +298,10 @@ fn enc_sty(w: &mut SeekableMemWriter, cx: &ctxt, st: &ty::sty) { } } -fn enc_fn_style(w: &mut SeekableMemWriter, p: FnStyle) { +fn enc_fn_style(w: &mut SeekableMemWriter, p: ast::FnStyle) { match p { - NormalFn => mywrite!(w, "n"), - UnsafeFn => mywrite!(w, "u"), + ast::NormalFn => mywrite!(w, "n"), + ast::UnsafeFn => mywrite!(w, "u"), } } @@ -308,20 +311,22 @@ fn enc_abi(w: &mut SeekableMemWriter, abi: Abi) { mywrite!(w, "]") } -fn enc_onceness(w: &mut SeekableMemWriter, o: Onceness) { +fn enc_onceness(w: &mut SeekableMemWriter, o: ast::Onceness) { match o { - Once => mywrite!(w, "o"), - Many => mywrite!(w, "m") + ast::Once => mywrite!(w, "o"), + ast::Many => mywrite!(w, "m") } } -pub fn enc_bare_fn_ty(w: &mut SeekableMemWriter, cx: &ctxt, ft: &ty::BareFnTy) { +pub fn enc_bare_fn_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, + ft: &ty::BareFnTy<'tcx>) { enc_fn_style(w, ft.fn_style); enc_abi(w, ft.abi); enc_fn_sig(w, cx, &ft.sig); } -pub fn enc_closure_ty(w: &mut SeekableMemWriter, cx: &ctxt, ft: &ty::ClosureTy) { +pub fn enc_closure_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, + ft: &ty::ClosureTy<'tcx>) { enc_fn_style(w, ft.fn_style); enc_onceness(w, ft.onceness); enc_trait_store(w, cx, ft.store); @@ -330,7 +335,8 @@ pub fn enc_closure_ty(w: &mut SeekableMemWriter, cx: &ctxt, ft: &ty::ClosureTy) enc_abi(w, ft.abi); } -fn enc_fn_sig(w: &mut SeekableMemWriter, cx: &ctxt, fsig: &ty::FnSig) { +fn enc_fn_sig<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, + fsig: &ty::FnSig<'tcx>) { mywrite!(w, "["); for ty in fsig.inputs.iter() { enc_ty(w, cx, *ty); @@ -369,7 +375,8 @@ pub fn enc_existential_bounds(w: &mut SeekableMemWriter, cx: &ctxt, bs: &ty::Exi enc_builtin_bounds(w, cx, &bs.builtin_bounds); } -pub fn enc_bounds(w: &mut SeekableMemWriter, cx: &ctxt, bs: &ty::ParamBounds) { +pub fn enc_bounds<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, + bs: &ty::ParamBounds<'tcx>) { enc_builtin_bounds(w, cx, &bs.builtin_bounds); for &r in bs.region_bounds.iter() { @@ -385,7 +392,8 @@ pub fn enc_bounds(w: &mut SeekableMemWriter, cx: &ctxt, bs: &ty::ParamBounds) { mywrite!(w, "."); } -pub fn enc_type_param_def(w: &mut SeekableMemWriter, cx: &ctxt, v: &ty::TypeParameterDef) { +pub fn enc_type_param_def<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, + v: &ty::TypeParameterDef<'tcx>) { mywrite!(w, "{}:{}|{}|{}|", token::get_name(v.name), (cx.ds)(v.def_id), v.space.to_uint(), v.index); diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index ff6965574be92..3cebb7236b640 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -26,8 +26,8 @@ use metadata::tyencode; use middle::mem_categorization::Typer; use middle::subst; use middle::subst::VecPerParamSpace; -use middle::typeck::{MethodCall, MethodCallee, MethodOrigin}; -use middle::{ty, typeck}; +use middle::typeck::{mod, MethodCall, MethodCallee, MethodOrigin}; +use middle::ty::{mod, Ty}; use util::ppaux::ty_to_string; use syntax::{ast, ast_map, ast_util, codemap, fold}; @@ -577,15 +577,15 @@ impl tr for ty::UpvarBorrow { // ______________________________________________________________________ // Encoding and decoding of MethodCallee -trait read_method_callee_helper { - fn read_method_callee(&mut self, dcx: &DecodeContext) - -> (typeck::ExprAdjustment, MethodCallee); +trait read_method_callee_helper<'tcx> { + fn read_method_callee<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> (typeck::ExprAdjustment, MethodCallee<'tcx>); } -fn encode_method_callee(ecx: &e::EncodeContext, - rbml_w: &mut Encoder, - adjustment: typeck::ExprAdjustment, - method: &MethodCallee) { +fn encode_method_callee<'a, 'tcx>(ecx: &e::EncodeContext<'a, 'tcx>, + rbml_w: &mut Encoder, + adjustment: typeck::ExprAdjustment, + method: &MethodCallee<'tcx>) { use serialize::Encoder; rbml_w.emit_struct("MethodCallee", 4, |rbml_w| { @@ -604,9 +604,9 @@ fn encode_method_callee(ecx: &e::EncodeContext, }).unwrap(); } -impl<'a> read_method_callee_helper for reader::Decoder<'a> { - fn read_method_callee(&mut self, dcx: &DecodeContext) - -> (typeck::ExprAdjustment, MethodCallee) { +impl<'a, 'tcx> read_method_callee_helper<'tcx> for reader::Decoder<'a> { + fn read_method_callee<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> (typeck::ExprAdjustment, MethodCallee<'tcx>) { self.read_struct("MethodCallee", 4, |this| { let adjustment = this.read_struct_field("adjustment", 0, |this| { @@ -627,8 +627,8 @@ impl<'a> read_method_callee_helper for reader::Decoder<'a> { } } -impl tr for MethodOrigin { - fn tr(&self, dcx: &DecodeContext) -> MethodOrigin { +impl<'tcx> tr for MethodOrigin<'tcx> { + fn tr(&self, dcx: &DecodeContext) -> MethodOrigin<'tcx> { match *self { typeck::MethodStatic(did) => typeck::MethodStatic(did.tr(dcx)), typeck::MethodStaticUnboxedClosure(did) => { @@ -683,26 +683,26 @@ pub fn encode_unboxed_closure_kind(ebml_w: &mut Encoder, }).unwrap() } -pub trait vtable_decoder_helpers { +pub trait vtable_decoder_helpers<'tcx> { fn read_vec_per_param_space(&mut self, f: |&mut Self| -> T) -> VecPerParamSpace; fn read_vtable_res_with_key(&mut self, - tcx: &ty::ctxt, + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> (typeck::ExprAdjustment, typeck::vtable_res); + -> (typeck::ExprAdjustment, typeck::vtable_res<'tcx>); fn read_vtable_res(&mut self, - tcx: &ty::ctxt, cdata: &cstore::crate_metadata) - -> typeck::vtable_res; + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) + -> typeck::vtable_res<'tcx>; fn read_vtable_param_res(&mut self, - tcx: &ty::ctxt, cdata: &cstore::crate_metadata) - -> typeck::vtable_param_res; + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) + -> typeck::vtable_param_res<'tcx>; fn read_vtable_origin(&mut self, - tcx: &ty::ctxt, cdata: &cstore::crate_metadata) - -> typeck::vtable_origin; + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) + -> typeck::vtable_origin<'tcx>; } -impl<'a> vtable_decoder_helpers for reader::Decoder<'a> { +impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> { fn read_vec_per_param_space(&mut self, f: |&mut reader::Decoder<'a>| -> T) -> VecPerParamSpace @@ -715,9 +715,9 @@ impl<'a> vtable_decoder_helpers for reader::Decoder<'a> { } fn read_vtable_res_with_key(&mut self, - tcx: &ty::ctxt, + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> (typeck::ExprAdjustment, typeck::vtable_res) { + -> (typeck::ExprAdjustment, typeck::vtable_res<'tcx>) { self.read_struct("VtableWithKey", 2, |this| { let adjustment = this.read_struct_field("adjustment", 0, |this| { Decodable::decode(this) @@ -729,24 +729,24 @@ impl<'a> vtable_decoder_helpers for reader::Decoder<'a> { } fn read_vtable_res(&mut self, - tcx: &ty::ctxt, + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> typeck::vtable_res + -> typeck::vtable_res<'tcx> { self.read_vec_per_param_space( |this| this.read_vtable_param_res(tcx, cdata)) } fn read_vtable_param_res(&mut self, - tcx: &ty::ctxt, cdata: &cstore::crate_metadata) - -> typeck::vtable_param_res { + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) + -> typeck::vtable_param_res<'tcx> { self.read_to_vec(|this| Ok(this.read_vtable_origin(tcx, cdata))) .unwrap().into_iter().collect() } fn read_vtable_origin(&mut self, - tcx: &ty::ctxt, cdata: &cstore::crate_metadata) - -> typeck::vtable_origin { + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) + -> typeck::vtable_origin<'tcx> { self.read_enum("vtable_origin", |this| { this.read_enum_variant(&["vtable_static", "vtable_param", @@ -824,43 +824,46 @@ impl<'a, 'tcx> get_ty_str_ctxt<'tcx> for e::EncodeContext<'a, 'tcx> { } } -trait rbml_writer_helpers { - fn emit_closure_type(&mut self, - ecx: &e::EncodeContext, - closure_type: &ty::ClosureTy); - fn emit_method_origin(&mut self, - ecx: &e::EncodeContext, - method_origin: &typeck::MethodOrigin); - fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t); - fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]); - fn emit_type_param_def(&mut self, - ecx: &e::EncodeContext, - type_param_def: &ty::TypeParameterDef); - fn emit_trait_ref(&mut self, ecx: &e::EncodeContext, ty: &ty::TraitRef); - fn emit_polytype(&mut self, - ecx: &e::EncodeContext, - pty: ty::Polytype); - fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &subst::Substs); +trait rbml_writer_helpers<'tcx> { + fn emit_closure_type<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + closure_type: &ty::ClosureTy<'tcx>); + fn emit_method_origin<'a>(&mut self, + ecx: &e::EncodeContext<'a, 'tcx>, + method_origin: &typeck::MethodOrigin<'tcx>); + fn emit_ty<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, ty: Ty<'tcx>); + fn emit_tys<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, tys: &[Ty<'tcx>]); + fn emit_type_param_def<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + type_param_def: &ty::TypeParameterDef<'tcx>); + fn emit_trait_ref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + ty: &ty::TraitRef<'tcx>); + fn emit_polytype<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + pty: ty::Polytype<'tcx>); + fn emit_substs<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + substs: &subst::Substs<'tcx>); fn emit_existential_bounds(&mut self, ecx: &e::EncodeContext, bounds: &ty::ExistentialBounds); fn emit_builtin_bounds(&mut self, ecx: &e::EncodeContext, bounds: &ty::BuiltinBounds); - fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment); - fn emit_autoref(&mut self, ecx: &e::EncodeContext, autoref: &ty::AutoRef); - fn emit_auto_deref_ref(&mut self, ecx: &e::EncodeContext, auto_deref_ref: &ty::AutoDerefRef); - fn emit_unsize_kind(&mut self, ecx: &e::EncodeContext, uk: &ty::UnsizeKind); -} - -impl<'a> rbml_writer_helpers for Encoder<'a> { - fn emit_closure_type(&mut self, - ecx: &e::EncodeContext, - closure_type: &ty::ClosureTy) { + fn emit_auto_adjustment<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + adj: &ty::AutoAdjustment<'tcx>); + fn emit_autoref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + autoref: &ty::AutoRef<'tcx>); + fn emit_auto_deref_ref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + auto_deref_ref: &ty::AutoDerefRef<'tcx>); + fn emit_unsize_kind<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + uk: &ty::UnsizeKind<'tcx>); +} + +impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> { + fn emit_closure_type<'a>(&mut self, + ecx: &e::EncodeContext<'a, 'tcx>, + closure_type: &ty::ClosureTy<'tcx>) { self.emit_opaque(|this| { Ok(e::write_closure_type(ecx, this, closure_type)) }); } - fn emit_method_origin(&mut self, - ecx: &e::EncodeContext, - method_origin: &typeck::MethodOrigin) + fn emit_method_origin<'a>(&mut self, + ecx: &e::EncodeContext<'a, 'tcx>, + method_origin: &typeck::MethodOrigin<'tcx>) { use serialize::Encoder; @@ -915,23 +918,21 @@ impl<'a> rbml_writer_helpers for Encoder<'a> { }); } - fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t) { + fn emit_ty<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, ty: Ty<'tcx>) { self.emit_opaque(|this| Ok(e::write_type(ecx, this, ty))); } - fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]) { + fn emit_tys<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, tys: &[Ty<'tcx>]) { self.emit_from_vec(tys, |this, ty| Ok(this.emit_ty(ecx, *ty))); } - fn emit_trait_ref(&mut self, - ecx: &e::EncodeContext, - trait_ref: &ty::TraitRef) { + fn emit_trait_ref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + trait_ref: &ty::TraitRef<'tcx>) { self.emit_opaque(|this| Ok(e::write_trait_ref(ecx, this, trait_ref))); } - fn emit_type_param_def(&mut self, - ecx: &e::EncodeContext, - type_param_def: &ty::TypeParameterDef) { + fn emit_type_param_def<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + type_param_def: &ty::TypeParameterDef<'tcx>) { self.emit_opaque(|this| { Ok(tyencode::enc_type_param_def(this.writer, &ecx.ty_str_ctxt(), @@ -939,9 +940,9 @@ impl<'a> rbml_writer_helpers for Encoder<'a> { }); } - fn emit_polytype(&mut self, - ecx: &e::EncodeContext, - pty: ty::Polytype) { + fn emit_polytype<'a>(&mut self, + ecx: &e::EncodeContext<'a, 'tcx>, + pty: ty::Polytype<'tcx>) { use serialize::Encoder; self.emit_struct("Polytype", 2, |this| { @@ -977,13 +978,15 @@ impl<'a> rbml_writer_helpers for Encoder<'a> { bounds))); } - fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &subst::Substs) { + fn emit_substs<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + substs: &subst::Substs<'tcx>) { self.emit_opaque(|this| Ok(tyencode::enc_substs(this.writer, &ecx.ty_str_ctxt(), substs))); } - fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment) { + fn emit_auto_adjustment<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + adj: &ty::AutoAdjustment<'tcx>) { use serialize::Encoder; self.emit_enum("AutoAdjustment", |this| { @@ -1004,7 +1007,8 @@ impl<'a> rbml_writer_helpers for Encoder<'a> { }); } - fn emit_autoref(&mut self, ecx: &e::EncodeContext, autoref: &ty::AutoRef) { + fn emit_autoref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + autoref: &ty::AutoRef<'tcx>) { use serialize::Encoder; self.emit_enum("AutoRef", |this| { @@ -1053,7 +1057,8 @@ impl<'a> rbml_writer_helpers for Encoder<'a> { }); } - fn emit_auto_deref_ref(&mut self, ecx: &e::EncodeContext, auto_deref_ref: &ty::AutoDerefRef) { + fn emit_auto_deref_ref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + auto_deref_ref: &ty::AutoDerefRef<'tcx>) { use serialize::Encoder; self.emit_struct("AutoDerefRef", 2, |this| { @@ -1069,7 +1074,8 @@ impl<'a> rbml_writer_helpers for Encoder<'a> { }); } - fn emit_unsize_kind(&mut self, ecx: &e::EncodeContext, uk: &ty::UnsizeKind) { + fn emit_unsize_kind<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + uk: &ty::UnsizeKind<'tcx>) { use serialize::Encoder; self.emit_enum("UnsizeKind", |this| { @@ -1325,23 +1331,31 @@ impl<'a> doc_decoder_helpers for rbml::Doc<'a> { } } -trait rbml_decoder_decoder_helpers { - fn read_method_origin(&mut self, dcx: &DecodeContext) -> typeck::MethodOrigin; - fn read_ty(&mut self, dcx: &DecodeContext) -> ty::t; - fn read_tys(&mut self, dcx: &DecodeContext) -> Vec; - fn read_trait_ref(&mut self, dcx: &DecodeContext) -> Rc; - fn read_type_param_def(&mut self, dcx: &DecodeContext) - -> ty::TypeParameterDef; - fn read_polytype(&mut self, dcx: &DecodeContext) - -> ty::Polytype; - fn read_existential_bounds(&mut self, dcx: &DecodeContext) -> ty::ExistentialBounds; - fn read_substs(&mut self, dcx: &DecodeContext) -> subst::Substs; - fn read_auto_adjustment(&mut self, dcx: &DecodeContext) -> ty::AutoAdjustment; - fn read_unboxed_closure(&mut self, dcx: &DecodeContext) - -> ty::UnboxedClosure; - fn read_auto_deref_ref(&mut self, dcx: &DecodeContext) -> ty::AutoDerefRef; - fn read_autoref(&mut self, dcx: &DecodeContext) -> ty::AutoRef; - fn read_unsize_kind(&mut self, dcx: &DecodeContext) -> ty::UnsizeKind; +trait rbml_decoder_decoder_helpers<'tcx> { + fn read_method_origin<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> typeck::MethodOrigin<'tcx>; + fn read_ty<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> Ty<'tcx>; + fn read_tys<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> Vec>; + fn read_trait_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> Rc>; + fn read_type_param_def<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::TypeParameterDef<'tcx>; + fn read_polytype<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::Polytype<'tcx>; + fn read_existential_bounds<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::ExistentialBounds; + fn read_substs<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> subst::Substs<'tcx>; + fn read_auto_adjustment<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::AutoAdjustment<'tcx>; + fn read_unboxed_closure<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::UnboxedClosure<'tcx>; + fn read_auto_deref_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::AutoDerefRef<'tcx>; + fn read_autoref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::AutoRef<'tcx>; + fn read_unsize_kind<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::UnsizeKind<'tcx>; fn convert_def_id(&mut self, dcx: &DecodeContext, source: DefIdSource, @@ -1351,18 +1365,18 @@ trait rbml_decoder_decoder_helpers { // Versions of the type reading functions that don't need the full // DecodeContext. fn read_ty_nodcx(&mut self, - tcx: &ty::ctxt, cdata: &cstore::crate_metadata) -> ty::t; + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) -> Ty<'tcx>; fn read_tys_nodcx(&mut self, - tcx: &ty::ctxt, - cdata: &cstore::crate_metadata) -> Vec; - fn read_substs_nodcx(&mut self, tcx: &ty::ctxt, + tcx: &ty::ctxt<'tcx>, + cdata: &cstore::crate_metadata) -> Vec>; + fn read_substs_nodcx(&mut self, tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> subst::Substs; + -> subst::Substs<'tcx>; } -impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { +impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> { fn read_ty_nodcx(&mut self, - tcx: &ty::ctxt, cdata: &cstore::crate_metadata) -> ty::t { + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) -> Ty<'tcx> { self.read_opaque(|_, doc| { Ok(tydecode::parse_ty_data( doc.data, @@ -1374,8 +1388,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { } fn read_tys_nodcx(&mut self, - tcx: &ty::ctxt, - cdata: &cstore::crate_metadata) -> Vec { + tcx: &ty::ctxt<'tcx>, + cdata: &cstore::crate_metadata) -> Vec> { self.read_to_vec(|this| Ok(this.read_ty_nodcx(tcx, cdata)) ) .unwrap() .into_iter() @@ -1383,9 +1397,9 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { } fn read_substs_nodcx(&mut self, - tcx: &ty::ctxt, + tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> subst::Substs + -> subst::Substs<'tcx> { self.read_opaque(|_, doc| { Ok(tydecode::parse_substs_data( @@ -1397,8 +1411,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { }).unwrap() } - fn read_method_origin(&mut self, dcx: &DecodeContext) - -> typeck::MethodOrigin + fn read_method_origin<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> typeck::MethodOrigin<'tcx> { self.read_enum("MethodOrigin", |this| { let variants = &["MethodStatic", "MethodStaticUnboxedClosure", @@ -1468,7 +1482,7 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { } - fn read_ty(&mut self, dcx: &DecodeContext) -> ty::t { + fn read_ty<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> Ty<'tcx> { // Note: regions types embed local node ids. In principle, we // should translate these node ids into the new decode // context. However, we do not bother, because region types @@ -1496,11 +1510,13 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { } } - fn read_tys(&mut self, dcx: &DecodeContext) -> Vec { + fn read_tys<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> Vec> { self.read_to_vec(|this| Ok(this.read_ty(dcx))).unwrap().into_iter().collect() } - fn read_trait_ref(&mut self, dcx: &DecodeContext) -> Rc { + fn read_trait_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> Rc> { Rc::new(self.read_opaque(|this, doc| { let ty = tydecode::parse_trait_ref_data( doc.data, @@ -1512,8 +1528,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { }).unwrap()) } - fn read_type_param_def(&mut self, dcx: &DecodeContext) - -> ty::TypeParameterDef { + fn read_type_param_def<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::TypeParameterDef<'tcx> { self.read_opaque(|this, doc| { Ok(tydecode::parse_type_param_def_data( doc.data, @@ -1524,8 +1540,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { }).unwrap() } - fn read_polytype(&mut self, dcx: &DecodeContext) - -> ty::Polytype { + fn read_polytype<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::Polytype<'tcx> { self.read_struct("Polytype", 2, |this| { Ok(ty::Polytype { generics: this.read_struct_field("generics", 0, |this| { @@ -1552,7 +1568,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { }).unwrap() } - fn read_existential_bounds(&mut self, dcx: &DecodeContext) -> ty::ExistentialBounds + fn read_existential_bounds<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::ExistentialBounds { self.read_opaque(|this, doc| { Ok(tydecode::parse_existential_bounds_data(doc.data, @@ -1563,7 +1580,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { }).unwrap() } - fn read_substs(&mut self, dcx: &DecodeContext) -> subst::Substs { + fn read_substs<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> subst::Substs<'tcx> { self.read_opaque(|this, doc| { Ok(tydecode::parse_substs_data(doc.data, dcx.cdata.cnum, @@ -1573,7 +1591,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { }).unwrap() } - fn read_auto_adjustment(&mut self, dcx: &DecodeContext) -> ty::AutoAdjustment { + fn read_auto_adjustment<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::AutoAdjustment<'tcx> { self.read_enum("AutoAdjustment", |this| { let variants = ["AutoAddEnv", "AutoDerefRef"]; this.read_enum_variant(&variants, |this, i| { @@ -1597,7 +1616,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { }).unwrap() } - fn read_auto_deref_ref(&mut self, dcx: &DecodeContext) -> ty::AutoDerefRef { + fn read_auto_deref_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::AutoDerefRef<'tcx> { self.read_struct("AutoDerefRef", 2, |this| { Ok(ty::AutoDerefRef { autoderefs: this.read_struct_field("autoderefs", 0, |this| { @@ -1616,7 +1636,7 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { }).unwrap() } - fn read_autoref(&mut self, dcx: &DecodeContext) -> ty::AutoRef { + fn read_autoref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> ty::AutoRef<'tcx> { self.read_enum("AutoRef", |this| { let variants = ["AutoPtr", "AutoUnsize", @@ -1674,7 +1694,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { }).unwrap() } - fn read_unsize_kind(&mut self, dcx: &DecodeContext) -> ty::UnsizeKind { + fn read_unsize_kind<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::UnsizeKind<'tcx> { self.read_enum("UnsizeKind", |this| { let variants = &["UnsizeLength", "UnsizeStruct", "UnsizeVtable"]; this.read_enum_variant(variants, |this, i| { @@ -1716,8 +1737,8 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { }).unwrap() } - fn read_unboxed_closure(&mut self, dcx: &DecodeContext) - -> ty::UnboxedClosure { + fn read_unboxed_closure<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::UnboxedClosure<'tcx> { let closure_type = self.read_opaque(|this, doc| { Ok(tydecode::parse_ty_closure_data( doc.data, diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index c7fe1ce731946..d91d666511dd5 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -86,11 +86,11 @@ struct CheckLoanCtxt<'a, 'tcx: 'a> { all_loans: &'a [Loan], } -impl<'a, 'tcx> euv::Delegate for CheckLoanCtxt<'a, 'tcx> { +impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> { fn consume(&mut self, consume_id: ast::NodeId, consume_span: Span, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, mode: euv::ConsumeMode) { debug!("consume(consume_id={}, cmt={}, mode={})", consume_id, cmt.repr(self.tcx()), mode); @@ -100,7 +100,7 @@ impl<'a, 'tcx> euv::Delegate for CheckLoanCtxt<'a, 'tcx> { fn consume_pat(&mut self, consume_pat: &ast::Pat, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, mode: euv::ConsumeMode) { debug!("consume_pat(consume_pat={}, cmt={}, mode={})", consume_pat.repr(self.tcx()), @@ -113,7 +113,7 @@ impl<'a, 'tcx> euv::Delegate for CheckLoanCtxt<'a, 'tcx> { fn borrow(&mut self, borrow_id: ast::NodeId, borrow_span: Span, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, loan_region: ty::Region, bk: ty::BorrowKind, loan_cause: euv::LoanCause) @@ -140,7 +140,7 @@ impl<'a, 'tcx> euv::Delegate for CheckLoanCtxt<'a, 'tcx> { fn mutate(&mut self, assignment_id: ast::NodeId, assignment_span: Span, - assignee_cmt: mc::cmt, + assignee_cmt: mc::cmt<'tcx>, mode: euv::MutateMode) { debug!("mutate(assignment_id={}, assignee_cmt={})", @@ -737,7 +737,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { fn check_assignment(&self, assignment_id: ast::NodeId, assignment_span: Span, - assignee_cmt: mc::cmt, + assignee_cmt: mc::cmt<'tcx>, mode: euv::MutateMode) { debug!("check_assignment(assignee_cmt={})", assignee_cmt.repr(self.tcx())); @@ -820,8 +820,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { } return; - fn mark_variable_as_used_mut(this: &CheckLoanCtxt, - mut cmt: mc::cmt) { + fn mark_variable_as_used_mut<'a, 'tcx>(this: &CheckLoanCtxt<'a, 'tcx>, + mut cmt: mc::cmt<'tcx>) { //! If the mutability of the `cmt` being written is inherited //! from a local variable, liveness will //! not have been able to detect that this variable's mutability @@ -868,9 +868,9 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { } } - fn check_for_aliasable_mutable_writes(this: &CheckLoanCtxt, - span: Span, - cmt: mc::cmt) -> bool { + fn check_for_aliasable_mutable_writes<'a, 'tcx>(this: &CheckLoanCtxt<'a, 'tcx>, + span: Span, + cmt: mc::cmt<'tcx>) -> bool { //! Safety checks related to writes to aliasable, mutable locations let guarantor = cmt.guarantor(); @@ -889,10 +889,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { return true; // no errors reported } - fn check_for_aliasability_violation(this: &CheckLoanCtxt, - span: Span, - cmt: mc::cmt) - -> bool { + fn check_for_aliasability_violation<'a, 'tcx>(this: &CheckLoanCtxt<'a, 'tcx>, + span: Span, + cmt: mc::cmt<'tcx>) + -> bool { match cmt.freely_aliasable(this.tcx()) { None => { return true; diff --git a/src/librustc/middle/borrowck/gather_loans/gather_moves.rs b/src/librustc/middle/borrowck/gather_loans/gather_moves.rs index a1c02b85e8f51..4caea5ae423bd 100644 --- a/src/librustc/middle/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc/middle/borrowck/gather_loans/gather_moves.rs @@ -25,10 +25,10 @@ use util::ppaux::Repr; use std::rc::Rc; -struct GatherMoveInfo { +struct GatherMoveInfo<'tcx> { id: ast::NodeId, kind: MoveKind, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, span_path_opt: Option } @@ -41,12 +41,12 @@ pub fn gather_decl(bccx: &BorrowckCtxt, move_data.add_move(bccx.tcx, loan_path, decl_id, Declared); } -pub fn gather_move_from_expr(bccx: &BorrowckCtxt, - move_data: &MoveData, - move_error_collector: &MoveErrorCollector, - move_expr_id: ast::NodeId, - cmt: mc::cmt, - move_reason: euv::MoveReason) { +pub fn gather_move_from_expr<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + move_data: &MoveData, + move_error_collector: &MoveErrorCollector<'tcx>, + move_expr_id: ast::NodeId, + cmt: mc::cmt<'tcx>, + move_reason: euv::MoveReason) { let kind = match move_reason { euv::DirectRefMove | euv::PatBindingMove => MoveExpr, euv::CaptureMove => Captured @@ -60,11 +60,11 @@ pub fn gather_move_from_expr(bccx: &BorrowckCtxt, gather_move(bccx, move_data, move_error_collector, move_info); } -pub fn gather_move_from_pat(bccx: &BorrowckCtxt, - move_data: &MoveData, - move_error_collector: &MoveErrorCollector, - move_pat: &ast::Pat, - cmt: mc::cmt) { +pub fn gather_move_from_pat<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + move_data: &MoveData, + move_error_collector: &MoveErrorCollector<'tcx>, + move_pat: &ast::Pat, + cmt: mc::cmt<'tcx>) { let pat_span_path_opt = match move_pat.node { ast::PatIdent(_, ref path1, _) => { Some(MoveSpanAndPath{span: move_pat.span, @@ -81,10 +81,10 @@ pub fn gather_move_from_pat(bccx: &BorrowckCtxt, gather_move(bccx, move_data, move_error_collector, move_info); } -fn gather_move(bccx: &BorrowckCtxt, - move_data: &MoveData, - move_error_collector: &MoveErrorCollector, - move_info: GatherMoveInfo) { +fn gather_move<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + move_data: &MoveData, + move_error_collector: &MoveErrorCollector<'tcx>, + move_info: GatherMoveInfo<'tcx>) { debug!("gather_move(move_id={}, cmt={})", move_info.id, move_info.cmt.repr(bccx.tcx)); @@ -127,8 +127,9 @@ pub fn gather_assignment(bccx: &BorrowckCtxt, mode); } -fn check_and_get_illegal_move_origin(bccx: &BorrowckCtxt, - cmt: &mc::cmt) -> Option { +fn check_and_get_illegal_move_origin<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + cmt: &mc::cmt<'tcx>) + -> Option> { match cmt.cat { mc::cat_deref(_, _, mc::BorrowedPtr(..)) | mc::cat_deref(_, _, mc::Implicit(..)) | @@ -145,7 +146,7 @@ fn check_and_get_illegal_move_origin(bccx: &BorrowckCtxt, mc::cat_downcast(ref b) | mc::cat_interior(ref b, _) => { - match ty::get(b.ty).sty { + match b.ty.sty { ty::ty_struct(did, _) | ty::ty_enum(did, _) => { if ty::has_dtor(bccx.tcx, did) { Some(cmt.clone()) diff --git a/src/librustc/middle/borrowck/gather_loans/lifetime.rs b/src/librustc/middle/borrowck/gather_loans/lifetime.rs index 41fe77d5197fd..99795fb300902 100644 --- a/src/librustc/middle/borrowck/gather_loans/lifetime.rs +++ b/src/librustc/middle/borrowck/gather_loans/lifetime.rs @@ -23,14 +23,14 @@ use syntax::codemap::Span; type R = Result<(),()>; -pub fn guarantee_lifetime(bccx: &BorrowckCtxt, - item_scope_id: ast::NodeId, - span: Span, - cause: euv::LoanCause, - cmt: mc::cmt, - loan_region: ty::Region, - _: ty::BorrowKind) - -> Result<(),()> { +pub fn guarantee_lifetime<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + item_scope_id: ast::NodeId, + span: Span, + cause: euv::LoanCause, + cmt: mc::cmt<'tcx>, + loan_region: ty::Region, + _: ty::BorrowKind) + -> Result<(),()> { debug!("guarantee_lifetime(cmt={}, loan_region={})", cmt.repr(bccx.tcx), loan_region.repr(bccx.tcx)); let ctxt = GuaranteeLifetimeContext {bccx: bccx, @@ -54,12 +54,12 @@ struct GuaranteeLifetimeContext<'a, 'tcx: 'a> { span: Span, cause: euv::LoanCause, loan_region: ty::Region, - cmt_original: mc::cmt + cmt_original: mc::cmt<'tcx> } impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> { - fn check(&self, cmt: &mc::cmt, discr_scope: Option) -> R { + fn check(&self, cmt: &mc::cmt<'tcx>, discr_scope: Option) -> R { //! Main routine. Walks down `cmt` until we find the "guarantor". debug!("guarantee_lifetime.check(cmt={}, loan_region={})", cmt.repr(self.bccx.tcx), diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index 7d893a0533a37..6bb511b2077c9 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -60,16 +60,16 @@ pub fn gather_loans_in_fn(bccx: &BorrowckCtxt, struct GatherLoanCtxt<'a, 'tcx: 'a> { bccx: &'a BorrowckCtxt<'a, 'tcx>, move_data: move_data::MoveData, - move_error_collector: move_error::MoveErrorCollector, + move_error_collector: move_error::MoveErrorCollector<'tcx>, all_loans: Vec, item_ub: ast::NodeId, } -impl<'a, 'tcx> euv::Delegate for GatherLoanCtxt<'a, 'tcx> { +impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { fn consume(&mut self, consume_id: ast::NodeId, _consume_span: Span, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, mode: euv::ConsumeMode) { debug!("consume(consume_id={}, cmt={}, mode={})", consume_id, cmt.repr(self.tcx()), mode); @@ -86,7 +86,7 @@ impl<'a, 'tcx> euv::Delegate for GatherLoanCtxt<'a, 'tcx> { fn consume_pat(&mut self, consume_pat: &ast::Pat, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, mode: euv::ConsumeMode) { debug!("consume_pat(consume_pat={}, cmt={}, mode={})", consume_pat.repr(self.tcx()), @@ -106,7 +106,7 @@ impl<'a, 'tcx> euv::Delegate for GatherLoanCtxt<'a, 'tcx> { fn borrow(&mut self, borrow_id: ast::NodeId, borrow_span: Span, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, loan_region: ty::Region, bk: ty::BorrowKind, loan_cause: euv::LoanCause) @@ -127,7 +127,7 @@ impl<'a, 'tcx> euv::Delegate for GatherLoanCtxt<'a, 'tcx> { fn mutate(&mut self, assignment_id: ast::NodeId, assignment_span: Span, - assignee_cmt: mc::cmt, + assignee_cmt: mc::cmt<'tcx>, mode: euv::MutateMode) { debug!("mutate(assignment_id={}, assignee_cmt={})", @@ -153,12 +153,12 @@ impl<'a, 'tcx> euv::Delegate for GatherLoanCtxt<'a, 'tcx> { } /// Implements the A-* rules in doc.rs. -fn check_aliasability(bccx: &BorrowckCtxt, - borrow_span: Span, - loan_cause: euv::LoanCause, - cmt: mc::cmt, - req_kind: ty::BorrowKind) - -> Result<(),()> { +fn check_aliasability<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + borrow_span: Span, + loan_cause: euv::LoanCause, + cmt: mc::cmt<'tcx>, + req_kind: ty::BorrowKind) + -> Result<(),()> { match (cmt.freely_aliasable(bccx.tcx), req_kind) { (None, _) => { @@ -206,7 +206,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { fn guarantee_valid(&mut self, borrow_id: ast::NodeId, borrow_span: Span, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, req_kind: ty::BorrowKind, loan_region: ty::Region, cause: euv::LoanCause) { @@ -349,12 +349,12 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { // } // } - fn check_mutability(bccx: &BorrowckCtxt, - borrow_span: Span, - cause: euv::LoanCause, - cmt: mc::cmt, - req_kind: ty::BorrowKind) - -> Result<(),()> { + fn check_mutability<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + borrow_span: Span, + cause: euv::LoanCause, + cmt: mc::cmt<'tcx>, + req_kind: ty::BorrowKind) + -> Result<(),()> { //! Implements the M-* rules in doc.rs. match req_kind { diff --git a/src/librustc/middle/borrowck/gather_loans/move_error.rs b/src/librustc/middle/borrowck/gather_loans/move_error.rs index ab6ff08c9d4e8..c7ffcc3ac1d15 100644 --- a/src/librustc/middle/borrowck/gather_loans/move_error.rs +++ b/src/librustc/middle/borrowck/gather_loans/move_error.rs @@ -18,35 +18,35 @@ use syntax::codemap; use syntax::print::pprust; use util::ppaux::UserString; -pub struct MoveErrorCollector { - errors: RefCell> +pub struct MoveErrorCollector<'tcx> { + errors: RefCell>> } -impl MoveErrorCollector { - pub fn new() -> MoveErrorCollector { +impl<'tcx> MoveErrorCollector<'tcx> { + pub fn new() -> MoveErrorCollector<'tcx> { MoveErrorCollector { errors: RefCell::new(Vec::new()) } } - pub fn add_error(&self, error: MoveError) { + pub fn add_error(&self, error: MoveError<'tcx>) { self.errors.borrow_mut().push(error); } - pub fn report_potential_errors(&self, bccx: &BorrowckCtxt) { + pub fn report_potential_errors<'a>(&self, bccx: &BorrowckCtxt<'a, 'tcx>) { report_move_errors(bccx, self.errors.borrow().deref()) } } -pub struct MoveError { - move_from: mc::cmt, +pub struct MoveError<'tcx> { + move_from: mc::cmt<'tcx>, move_to: Option } -impl MoveError { - pub fn with_move_info(move_from: mc::cmt, +impl<'tcx> MoveError<'tcx> { + pub fn with_move_info(move_from: mc::cmt<'tcx>, move_to: Option) - -> MoveError { + -> MoveError<'tcx> { MoveError { move_from: move_from, move_to: move_to, @@ -60,12 +60,13 @@ pub struct MoveSpanAndPath { pub ident: ast::Ident } -pub struct GroupedMoveErrors { - move_from: mc::cmt, +pub struct GroupedMoveErrors<'tcx> { + move_from: mc::cmt<'tcx>, move_to_places: Vec } -fn report_move_errors(bccx: &BorrowckCtxt, errors: &Vec) { +fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + errors: &Vec>) { let grouped_errors = group_errors_with_same_origin(errors); for error in grouped_errors.iter() { report_cannot_move_out_of(bccx, error.move_from.clone()); @@ -78,16 +79,16 @@ fn report_move_errors(bccx: &BorrowckCtxt, errors: &Vec) { } } -fn group_errors_with_same_origin(errors: &Vec) - -> Vec { +fn group_errors_with_same_origin<'tcx>(errors: &Vec>) + -> Vec> { let mut grouped_errors = Vec::new(); for error in errors.iter() { append_to_grouped_errors(&mut grouped_errors, error) } return grouped_errors; - fn append_to_grouped_errors(grouped_errors: &mut Vec, - error: &MoveError) { + fn append_to_grouped_errors<'tcx>(grouped_errors: &mut Vec>, + error: &MoveError<'tcx>) { let move_from_id = error.move_from.id; debug!("append_to_grouped_errors(move_from_id={})", move_from_id); let move_to = if error.move_to.is_some() { @@ -110,7 +111,8 @@ fn group_errors_with_same_origin(errors: &Vec) } } -fn report_cannot_move_out_of(bccx: &BorrowckCtxt, move_from: mc::cmt) { +fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + move_from: mc::cmt<'tcx>) { match move_from.cat { mc::cat_deref(_, _, mc::BorrowedPtr(..)) | mc::cat_deref(_, _, mc::Implicit(..)) | @@ -124,7 +126,7 @@ fn report_cannot_move_out_of(bccx: &BorrowckCtxt, move_from: mc::cmt) { mc::cat_downcast(ref b) | mc::cat_interior(ref b, _) => { - match ty::get(b.ty).sty { + match b.ty.sty { ty::ty_struct(did, _) | ty::ty_enum(did, _) if ty::has_dtor(bccx.tcx, did) => { bccx.span_err( diff --git a/src/librustc/middle/borrowck/gather_loans/restrictions.rs b/src/librustc/middle/borrowck/gather_loans/restrictions.rs index 1c8f1effcf6d4..9b9a5e61393f8 100644 --- a/src/librustc/middle/borrowck/gather_loans/restrictions.rs +++ b/src/librustc/middle/borrowck/gather_loans/restrictions.rs @@ -29,11 +29,12 @@ pub enum RestrictionResult { SafeIf(Rc, Vec>) } -pub fn compute_restrictions(bccx: &BorrowckCtxt, - span: Span, - cause: euv::LoanCause, - cmt: mc::cmt, - loan_region: ty::Region) -> RestrictionResult { +pub fn compute_restrictions<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + span: Span, + cause: euv::LoanCause, + cmt: mc::cmt<'tcx>, + loan_region: ty::Region) + -> RestrictionResult { let ctxt = RestrictionsContext { bccx: bccx, span: span, @@ -56,7 +57,7 @@ struct RestrictionsContext<'a, 'tcx: 'a> { impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> { fn restrict(&self, - cmt: mc::cmt) -> RestrictionResult { + cmt: mc::cmt<'tcx>) -> RestrictionResult { debug!("restrict(cmt={})", cmt.repr(self.bccx.tcx)); match cmt.cat.clone() { diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index d7925177c29db..fbb0a87cf3f87 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -24,7 +24,7 @@ use middle::dataflow::BitwiseOperator; use middle::dataflow::DataFlowOperator; use middle::expr_use_visitor as euv; use middle::mem_categorization as mc; -use middle::ty; +use middle::ty::{mod, Ty}; use util::ppaux::{note_and_explain_region, Repr, UserString}; use std::rc::Rc; @@ -247,7 +247,7 @@ struct BorrowStats { guaranteed_paths: uint } -pub type BckResult = Result; +pub type BckResult<'tcx, T> = Result>; /////////////////////////////////////////////////////////////////////////// // Loans and loan paths @@ -405,10 +405,10 @@ pub enum bckerr_code { // Combination of an error code and the categorization of the expression // that caused it #[deriving(PartialEq)] -pub struct BckError { +pub struct BckError<'tcx> { span: Span, cause: euv::LoanCause, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, code: bckerr_code } @@ -436,7 +436,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { mc::MemCategorizationContext::new(self.tcx) } - pub fn cat_expr(&self, expr: &ast::Expr) -> mc::cmt { + pub fn cat_expr(&self, expr: &ast::Expr) -> mc::cmt<'tcx> { match self.mc().cat_expr(expr) { Ok(c) => c, Err(()) => { @@ -445,7 +445,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } } - pub fn report(&self, err: BckError) { + pub fn report(&self, err: BckError<'tcx>) { self.span_err( err.span, self.bckerr_to_string(&err).as_slice()); @@ -586,9 +586,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } } - fn move_suggestion(tcx: &ty::ctxt, ty: ty::t, default_msgs: (&'static str, &'static str)) - -> (&'static str, &'static str) { - match ty::get(ty).sty { + fn move_suggestion<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>, + default_msgs: (&'static str, &'static str)) + -> (&'static str, &'static str) { + match ty.sty { ty::ty_closure(box ty::ClosureTy { store: ty::RegionTraitStore(..), .. @@ -631,7 +632,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { self.tcx.sess.span_help(s, m); } - pub fn bckerr_to_string(&self, err: &BckError) -> String { + pub fn bckerr_to_string(&self, err: &BckError<'tcx>) -> String { match err.code { err_mutbl => { let descr = match err.cmt.note { @@ -766,7 +767,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } } - pub fn note_and_explain_bckerr(&self, err: BckError) { + pub fn note_and_explain_bckerr(&self, err: BckError<'tcx>) { let code = err.code; match code { err_mutbl(..) => { @@ -893,7 +894,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { result } - pub fn cmt_to_string(&self, cmt: &mc::cmt_) -> String { + pub fn cmt_to_string(&self, cmt: &mc::cmt_<'tcx>) -> String { self.mc().cmt_to_string(cmt) } } @@ -924,7 +925,7 @@ impl DataFlowOperator for LoanDataFlowOperator { } } -impl Repr for Loan { +impl<'tcx> Repr<'tcx> for Loan { fn repr(&self, tcx: &ty::ctxt) -> String { format!("Loan_{}({}, {}, {}-{}, {})", self.index, @@ -936,7 +937,7 @@ impl Repr for Loan { } } -impl Repr for LoanPath { +impl<'tcx> Repr<'tcx> for LoanPath { fn repr(&self, tcx: &ty::ctxt) -> String { match self { &LpVar(id) => { diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 7a97589b9facb..8cb63fcd82741 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -14,7 +14,7 @@ use middle::ty; use middle::typeck; use util::ppaux; -use syntax::ast::*; +use syntax::ast; use syntax::ast_util; use syntax::visit::Visitor; use syntax::visit; @@ -40,13 +40,13 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { } impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { - fn visit_item(&mut self, i: &Item) { + fn visit_item(&mut self, i: &ast::Item) { check_item(self, i); } - fn visit_pat(&mut self, p: &Pat) { + fn visit_pat(&mut self, p: &ast::Pat) { check_pat(self, p); } - fn visit_expr(&mut self, ex: &Expr) { + fn visit_expr(&mut self, ex: &ast::Expr) { if check_expr(self, ex) { visit::walk_expr(self, ex); } @@ -59,13 +59,13 @@ pub fn check_crate(tcx: &ty::ctxt) { tcx.sess.abort_if_errors(); } -fn check_item(v: &mut CheckCrateVisitor, it: &Item) { +fn check_item(v: &mut CheckCrateVisitor, it: &ast::Item) { match it.node { - ItemStatic(_, _, ref ex) | - ItemConst(_, ref ex) => { + ast::ItemStatic(_, _, ref ex) | + ast::ItemConst(_, ref ex) => { v.inside_const(|v| v.visit_expr(&**ex)); } - ItemEnum(ref enum_definition, _) => { + ast::ItemEnum(ref enum_definition, _) => { for var in (*enum_definition).variants.iter() { for ex in var.node.disr_expr.iter() { v.inside_const(|v| v.visit_expr(&**ex)); @@ -76,12 +76,12 @@ fn check_item(v: &mut CheckCrateVisitor, it: &Item) { } } -fn check_pat(v: &mut CheckCrateVisitor, p: &Pat) { - fn is_str(e: &Expr) -> bool { +fn check_pat(v: &mut CheckCrateVisitor, p: &ast::Pat) { + fn is_str(e: &ast::Expr) -> bool { match e.node { - ExprBox(_, ref expr) => { + ast::ExprBox(_, ref expr) => { match expr.node { - ExprLit(ref lit) => ast_util::lit_is_str(&**lit), + ast::ExprLit(ref lit) => ast_util::lit_is_str(&**lit), _ => false, } } @@ -90,8 +90,8 @@ fn check_pat(v: &mut CheckCrateVisitor, p: &Pat) { } match p.node { // Let through plain ~-string literals here - PatLit(ref a) => if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); }, - PatRange(ref a, ref b) => { + ast::PatLit(ref a) => if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); }, + ast::PatRange(ref a, ref b) => { if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); } if !is_str(&**b) { v.inside_const(|v| v.visit_expr(&**b)); } } @@ -99,18 +99,18 @@ fn check_pat(v: &mut CheckCrateVisitor, p: &Pat) { } } -fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { +fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool { if !v.in_const { return true } match e.node { - ExprUnary(UnDeref, _) => {} - ExprUnary(UnUniq, _) => { + ast::ExprUnary(ast::UnDeref, _) => {} + ast::ExprUnary(ast::UnUniq, _) => { span_err!(v.tcx.sess, e.span, E0010, "cannot do allocations in constant expressions"); return false; } - ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {} - ExprBinary(..) | ExprUnary(..) => { + ast::ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {} + ast::ExprBinary(..) | ast::ExprUnary(..) => { let method_call = typeck::MethodCall::expr(e.id); if v.tcx.method_map.borrow().contains_key(&method_call) { span_err!(v.tcx.sess, e.span, E0011, @@ -118,8 +118,8 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { expressions"); } } - ExprLit(_) => (), - ExprCast(ref from, _) => { + ast::ExprLit(_) => (), + ast::ExprCast(ref from, _) => { let toty = ty::expr_ty(v.tcx, e); let fromty = ty::expr_ty(v.tcx, &**from); if !ty::type_is_numeric(toty) && !ty::type_is_unsafe_ptr(toty) { @@ -133,7 +133,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { expression"); } } - ExprPath(ref pth) => { + ast::ExprPath(ref pth) => { // NB: In the future you might wish to relax this slightly // to handle on-demand instantiation of functions via // foo:: in a const. Currently that is only done on @@ -161,7 +161,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { } } } - ExprCall(ref callee, _) => { + ast::ExprCall(ref callee, _) => { match v.tcx.def_map.borrow().get(&callee.id) { Some(&DefStruct(..)) | Some(&DefVariant(..)) => {} // OK. @@ -173,7 +173,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { } } } - ExprBlock(ref block) => { + ast::ExprBlock(ref block) => { // Check all statements in the block for stmt in block.stmts.iter() { let block_span_err = |span| @@ -181,17 +181,17 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { "blocks in constants are limited to items and \ tail expressions"); match stmt.node { - StmtDecl(ref span, _) => { + ast::StmtDecl(ref span, _) => { match span.node { - DeclLocal(_) => block_span_err(span.span), + ast::DeclLocal(_) => block_span_err(span.span), // Item statements are allowed - DeclItem(_) => {} + ast::DeclItem(_) => {} } } - StmtExpr(ref expr, _) => block_span_err(expr.span), - StmtSemi(ref semi, _) => block_span_err(semi.span), - StmtMac(..) => { + ast::StmtExpr(ref expr, _) => block_span_err(expr.span), + ast::StmtSemi(ref semi, _) => block_span_err(semi.span), + ast::StmtMac(..) => { v.tcx.sess.span_bug(e.span, "unexpanded statement \ macro in const?!") } @@ -202,20 +202,20 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { None => {} } } - ExprVec(_) | - ExprAddrOf(MutImmutable, _) | - ExprParen(..) | - ExprField(..) | - ExprTupField(..) | - ExprIndex(..) | - ExprTup(..) | - ExprRepeat(..) | - ExprStruct(..) => {} - - ExprAddrOf(_, ref inner) => { + ast::ExprVec(_) | + ast::ExprAddrOf(ast::MutImmutable, _) | + ast::ExprParen(..) | + ast::ExprField(..) | + ast::ExprTupField(..) | + ast::ExprIndex(..) | + ast::ExprTup(..) | + ast::ExprRepeat(..) | + ast::ExprStruct(..) => {} + + ast::ExprAddrOf(_, ref inner) => { match inner.node { // Mutable slices are allowed. - ExprVec(_) => {} + ast::ExprVec(_) => {} _ => span_err!(v.tcx.sess, e.span, E0017, "references in constants may only refer \ to immutable values") diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index c733084e9818a..edc4e4ac7758b 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -21,13 +21,13 @@ use middle::expr_use_visitor::{WriteAndRead}; use middle::mem_categorization::cmt; use middle::pat_util::*; use middle::ty::*; -use middle::ty; +use middle::ty::{mod, Ty}; use std::fmt; use std::iter::AdditiveIterator; use std::iter::range_inclusive; use std::num::Float; use std::slice; -use syntax::ast::*; +use syntax::ast::{mod, DUMMY_NODE_ID, NodeId, Pat}; use syntax::ast_util::walk_pat; use syntax::codemap::{Span, Spanned, DUMMY_SP}; use syntax::fold::{Folder, noop_fold_pat}; @@ -39,7 +39,7 @@ use util::ppaux::ty_to_string; pub const DUMMY_WILD_PAT: &'static Pat = &Pat { id: DUMMY_NODE_ID, - node: PatWild(PatWildSingle), + node: ast::PatWild(ast::PatWildSingle), span: DUMMY_SP }; @@ -108,7 +108,7 @@ pub enum Constructor { /// e.g. struct patterns and fixed-length arrays. Single, /// Enum variants. - Variant(DefId), + Variant(ast::DefId), /// Literal values. ConstantValue(const_val), /// Ranges of literal values (2..5). @@ -132,14 +132,14 @@ enum WitnessPreference { } impl<'a, 'tcx, 'v> Visitor<'v> for MatchCheckCtxt<'a, 'tcx> { - fn visit_expr(&mut self, ex: &Expr) { + fn visit_expr(&mut self, ex: &ast::Expr) { check_expr(self, ex); } - fn visit_local(&mut self, l: &Local) { + fn visit_local(&mut self, l: &ast::Local) { check_local(self, l); } - fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, - b: &'v Block, s: Span, n: NodeId) { + fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v ast::FnDecl, + b: &'v ast::Block, s: Span, n: NodeId) { check_fn(self, fk, fd, b, s, n); } } @@ -149,10 +149,10 @@ pub fn check_crate(tcx: &ty::ctxt) { tcx.sess.abort_if_errors(); } -fn check_expr(cx: &mut MatchCheckCtxt, ex: &Expr) { +fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) { visit::walk_expr(cx, ex); match ex.node { - ExprMatch(ref scrut, ref arms, source) => { + ast::ExprMatch(ref scrut, ref arms, source) => { // First, check legality of move bindings. for arm in arms.iter() { check_legality_of_move_bindings(cx, @@ -177,7 +177,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &Expr) { (arm.pats.iter().map(|pat| { static_inliner.fold_pat((*pat).clone()) }).collect(), arm.guard.as_ref().map(|e| &**e)) - }).collect::>, Option<&Expr>)>>(); + }).collect::>, Option<&ast::Expr>)>>(); if static_inliner.failed { return; @@ -214,7 +214,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &Expr) { .collect(); check_exhaustive(cx, ex.span, &matrix); }, - ExprForLoop(ref pat, _, _, _) => { + ast::ExprForLoop(ref pat, _, _, _) => { let mut static_inliner = StaticInliner::new(cx.tcx); is_refutable(cx, &*static_inliner.fold_pat((*pat).clone()), |uncovered_pat| { cx.tcx.sess.span_err( @@ -232,7 +232,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &Expr) { } } -fn is_expr_const_nan(tcx: &ty::ctxt, expr: &Expr) -> bool { +fn is_expr_const_nan(tcx: &ty::ctxt, expr: &ast::Expr) -> bool { match eval_const_expr(tcx, expr) { const_float(f) => f.is_nan(), _ => false @@ -244,7 +244,7 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pats: &[P]) { for pat in pats.iter() { walk_pat(&**pat, |p| { match p.node { - PatLit(ref expr) if is_expr_const_nan(cx.tcx, &**expr) => { + ast::PatLit(ref expr) if is_expr_const_nan(cx.tcx, &**expr) => { span_warn!(cx.tcx.sess, p.span, E0003, "unmatchable NaN in pattern, \ use the is_nan method in a guard instead"); @@ -257,7 +257,9 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pats: &[P]) { } // Check for unreachable patterns -fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec>, Option<&Expr>)], source: MatchSource) { +fn check_arms(cx: &MatchCheckCtxt, + arms: &[(Vec>, Option<&ast::Expr>)], + source: ast::MatchSource) { let mut seen = Matrix(vec![]); let mut printed_if_let_err = false; for &(ref pats, guard) in arms.iter() { @@ -267,7 +269,7 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec>, Option<&Expr>)], source match is_useful(cx, &seen, v.as_slice(), LeaveOutWitness) { NotUseful => { match source { - MatchIfLetDesugar => { + ast::MatchIfLetDesugar => { if printed_if_let_err { // we already printed an irrefutable if-let pattern error. // We don't want two, that's just confusing. @@ -281,7 +283,7 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec>, Option<&Expr>)], source } }, - MatchWhileLetDesugar => { + ast::MatchWhileLetDesugar => { // find the first arm pattern so we can use its span let &(ref first_arm_pats, _) = &arms[0]; let first_pat = &first_arm_pats[0]; @@ -289,7 +291,7 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec>, Option<&Expr>)], source span_err!(cx.tcx.sess, span, E0165, "irrefutable while-let pattern"); }, - MatchNormal => { + ast::MatchNormal => { span_err!(cx.tcx.sess, pat.span, E0001, "unreachable pattern") }, } @@ -308,7 +310,7 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec>, Option<&Expr>)], source fn raw_pat<'a>(p: &'a Pat) -> &'a Pat { match p.node { - PatIdent(_, _, Some(ref s)) => raw_pat(&**s), + ast::PatIdent(_, _, Some(ref s)) => raw_pat(&**s), _ => p } } @@ -333,14 +335,14 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) { } } -fn const_val_to_expr(value: &const_val) -> P { +fn const_val_to_expr(value: &const_val) -> P { let node = match value { - &const_bool(b) => LitBool(b), + &const_bool(b) => ast::LitBool(b), _ => unreachable!() }; - P(Expr { + P(ast::Expr { id: 0, - node: ExprLit(P(Spanned { node: node, span: DUMMY_SP })), + node: ast::ExprLit(P(Spanned { node: node, span: DUMMY_SP })), span: DUMMY_SP }) } @@ -362,7 +364,7 @@ impl<'a, 'tcx> StaticInliner<'a, 'tcx> { impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> { fn fold_pat(&mut self, pat: P) -> P { match pat.node { - PatIdent(..) | PatEnum(..) => { + ast::PatIdent(..) | ast::PatEnum(..) => { let def = self.tcx.def_map.borrow().get(&pat.id).cloned(); match def { Some(DefConst(did)) => match lookup_const_by_id(self.tcx, did) { @@ -401,11 +403,11 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> { /// left_ty: struct X { a: (bool, &'static str), b: uint} /// pats: [(false, "foo"), 42] => X { a: (false, "foo"), b: 42 } fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor, - pats: Vec<&Pat>, left_ty: ty::t) -> P { + pats: Vec<&Pat>, left_ty: Ty) -> P { let pats_len = pats.len(); let mut pats = pats.into_iter().map(|p| P((*p).clone())); - let pat = match ty::get(left_ty).sty { - ty::ty_tup(_) => PatTup(pats.collect()), + let pat = match left_ty.sty { + ty::ty_tup(_) => ast::PatTup(pats.collect()), ty::ty_enum(cid, _) | ty::ty_struct(cid, _) => { let (vid, is_structure) = match ctor { @@ -417,63 +419,63 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor, }; if is_structure { let fields = ty::lookup_struct_fields(cx.tcx, vid); - let field_pats: Vec> = fields.into_iter() + let field_pats: Vec<_> = fields.into_iter() .zip(pats) - .filter(|&(_, ref pat)| pat.node != PatWild(PatWildSingle)) + .filter(|&(_, ref pat)| pat.node != ast::PatWild(ast::PatWildSingle)) .map(|(field, pat)| Spanned { span: DUMMY_SP, - node: FieldPat { - ident: Ident::new(field.name), + node: ast::FieldPat { + ident: ast::Ident::new(field.name), pat: pat, is_shorthand: false, } }).collect(); let has_more_fields = field_pats.len() < pats_len; - PatStruct(def_to_path(cx.tcx, vid), field_pats, has_more_fields) + ast::PatStruct(def_to_path(cx.tcx, vid), field_pats, has_more_fields) } else { - PatEnum(def_to_path(cx.tcx, vid), Some(pats.collect())) + ast::PatEnum(def_to_path(cx.tcx, vid), Some(pats.collect())) } } ty::ty_rptr(_, ty::mt { ty, .. }) => { - match ty::get(ty).sty { + match ty.sty { ty::ty_vec(_, Some(n)) => match ctor { &Single => { assert_eq!(pats_len, n); - PatVec(pats.collect(), None, vec!()) + ast::PatVec(pats.collect(), None, vec!()) }, _ => unreachable!() }, ty::ty_vec(_, None) => match ctor { &Slice(n) => { assert_eq!(pats_len, n); - PatVec(pats.collect(), None, vec!()) + ast::PatVec(pats.collect(), None, vec!()) }, _ => unreachable!() }, - ty::ty_str => PatWild(PatWildSingle), + ty::ty_str => ast::PatWild(ast::PatWildSingle), _ => { assert_eq!(pats_len, 1); - PatRegion(pats.nth(0).unwrap()) + ast::PatRegion(pats.nth(0).unwrap()) } } } ty::ty_vec(_, Some(len)) => { assert_eq!(pats_len, len); - PatVec(pats.collect(), None, vec![]) + ast::PatVec(pats.collect(), None, vec![]) } _ => { match *ctor { - ConstantValue(ref v) => PatLit(const_val_to_expr(v)), - _ => PatWild(PatWildSingle), + ConstantValue(ref v) => ast::PatLit(const_val_to_expr(v)), + _ => ast::PatWild(ast::PatWildSingle), } } }; - P(Pat { + P(ast::Pat { id: 0, node: pat, span: DUMMY_SP @@ -481,7 +483,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor, } fn missing_constructor(cx: &MatchCheckCtxt, &Matrix(ref rows): &Matrix, - left_ty: ty::t, max_slice_length: uint) -> Option { + left_ty: Ty, max_slice_length: uint) -> Option { let used_constructors: Vec = rows.iter() .flat_map(|row| pat_constructors(cx, row[0], left_ty, max_slice_length).into_iter()) .collect(); @@ -494,13 +496,13 @@ fn missing_constructor(cx: &MatchCheckCtxt, &Matrix(ref rows): &Matrix, /// values of type `left_ty`. For vectors, this would normally be an infinite set /// but is instead bounded by the maximum fixed length of slice patterns in /// the column of patterns being analyzed. -fn all_constructors(cx: &MatchCheckCtxt, left_ty: ty::t, +fn all_constructors(cx: &MatchCheckCtxt, left_ty: Ty, max_slice_length: uint) -> Vec { - match ty::get(left_ty).sty { + match left_ty.sty { ty::ty_bool => [true, false].iter().map(|b| ConstantValue(const_bool(*b))).collect(), - ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty { + ty::ty_rptr(_, ty::mt { ty, .. }) => match ty.sty { ty::ty_vec(_, None) => range_inclusive(0, max_slice_length).map(|length| Slice(length)).collect(), _ => vec!(Single) @@ -558,7 +560,7 @@ fn is_useful(cx: &MatchCheckCtxt, }; let max_slice_length = rows.iter().filter_map(|row| match row[0].node { - PatVec(ref before, _, ref after) => Some(before.len() + after.len()), + ast::PatVec(ref before, _, ref after) => Some(before.len() + after.len()), _ => None }).max().map_or(0, |v| v + 1); @@ -614,7 +616,7 @@ fn is_useful(cx: &MatchCheckCtxt, } fn is_useful_specialized(cx: &MatchCheckCtxt, &Matrix(ref m): &Matrix, - v: &[&Pat], ctor: Constructor, lty: ty::t, + v: &[&Pat], ctor: Constructor, lty: Ty, witness: WitnessPreference) -> Usefulness { let arity = constructor_arity(cx, &ctor, lty); let matrix = Matrix(m.iter().filter_map(|r| { @@ -636,10 +638,10 @@ fn is_useful_specialized(cx: &MatchCheckCtxt, &Matrix(ref m): &Matrix, /// On the other hand, a wild pattern and an identifier pattern cannot be /// specialized in any way. fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, - left_ty: ty::t, max_slice_length: uint) -> Vec { + left_ty: Ty, max_slice_length: uint) -> Vec { let pat = raw_pat(p); match pat.node { - PatIdent(..) => + ast::PatIdent(..) => match cx.tcx.def_map.borrow().get(&pat.id) { Some(&DefConst(..)) => cx.tcx.sess.span_bug(pat.span, "const pattern should've \ @@ -648,7 +650,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, Some(&DefVariant(_, id, _)) => vec!(Variant(id)), _ => vec!() }, - PatEnum(..) => + ast::PatEnum(..) => match cx.tcx.def_map.borrow().get(&pat.id) { Some(&DefConst(..)) => cx.tcx.sess.span_bug(pat.span, "const pattern should've \ @@ -656,7 +658,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, Some(&DefVariant(_, id, _)) => vec!(Variant(id)), _ => vec!(Single) }, - PatStruct(..) => + ast::PatStruct(..) => match cx.tcx.def_map.borrow().get(&pat.id) { Some(&DefConst(..)) => cx.tcx.sess.span_bug(pat.span, "const pattern should've \ @@ -664,12 +666,12 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, Some(&DefVariant(_, id, _)) => vec!(Variant(id)), _ => vec!(Single) }, - PatLit(ref expr) => + ast::PatLit(ref expr) => vec!(ConstantValue(eval_const_expr(cx.tcx, &**expr))), - PatRange(ref lo, ref hi) => + ast::PatRange(ref lo, ref hi) => vec!(ConstantRange(eval_const_expr(cx.tcx, &**lo), eval_const_expr(cx.tcx, &**hi))), - PatVec(ref before, ref slice, ref after) => - match ty::get(left_ty).sty { + ast::PatVec(ref before, ref slice, ref after) => + match left_ty.sty { ty::ty_vec(_, Some(_)) => vec!(Single), _ => if slice.is_some() { range_inclusive(before.len() + after.len(), max_slice_length) @@ -679,11 +681,11 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, vec!(Slice(before.len() + after.len())) } }, - PatBox(_) | PatTup(_) | PatRegion(..) => + ast::PatBox(_) | ast::PatTup(_) | ast::PatRegion(..) => vec!(Single), - PatWild(_) => + ast::PatWild(_) => vec!(), - PatMac(_) => + ast::PatMac(_) => cx.tcx.sess.bug("unexpanded macro") } } @@ -693,11 +695,11 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, /// /// For instance, a tuple pattern (_, 42u, Some([])) has the arity of 3. /// A struct pattern's arity is the number of fields it contains, etc. -pub fn constructor_arity(cx: &MatchCheckCtxt, ctor: &Constructor, ty: ty::t) -> uint { - match ty::get(ty).sty { +pub fn constructor_arity(cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> uint { + match ty.sty { ty::ty_tup(ref fs) => fs.len(), ty::ty_uniq(_) => 1u, - ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty { + ty::ty_rptr(_, ty::mt { ty, .. }) => match ty.sty { ty::ty_vec(_, None) => match *ctor { Slice(length) => length, ConstantValue(_) => 0u, @@ -747,12 +749,11 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], let &Pat { id: pat_id, ref node, span: pat_span } = raw_pat(r[col]); - let head: Option> = match node { - - &PatWild(_) => + let head: Option> = match *node { + ast::PatWild(_) => Some(Vec::from_elem(arity, DUMMY_WILD_PAT)), - &PatIdent(_, _, _) => { + ast::PatIdent(_, _, _) => { let opt_def = cx.tcx.def_map.borrow().get(&pat_id).cloned(); match opt_def { Some(DefConst(..)) => @@ -767,7 +768,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], } } - &PatEnum(_, ref args) => { + ast::PatEnum(_, ref args) => { let def = cx.tcx.def_map.borrow()[pat_id].clone(); match def { DefConst(..) => @@ -784,7 +785,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], } } - &PatStruct(_, ref pattern_fields, _) => { + ast::PatStruct(_, ref pattern_fields, _) => { // Is this a struct or an enum variant? let def = cx.tcx.def_map.borrow()[pat_id].clone(); let class_id = match def { @@ -820,13 +821,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], }) } - &PatTup(ref args) => + ast::PatTup(ref args) => Some(args.iter().map(|p| &**p).collect()), - &PatBox(ref inner) | &PatRegion(ref inner) => + ast::PatBox(ref inner) | ast::PatRegion(ref inner) => Some(vec![&**inner]), - &PatLit(ref expr) => { + ast::PatLit(ref expr) => { let expr_value = eval_const_expr(cx.tcx, &**expr); match range_covered_by_constructor(constructor, &expr_value, &expr_value) { Some(true) => Some(vec![]), @@ -838,7 +839,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], } } - &PatRange(ref from, ref to) => { + ast::PatRange(ref from, ref to) => { let from_value = eval_const_expr(cx.tcx, &**from); let to_value = eval_const_expr(cx.tcx, &**to); match range_covered_by_constructor(constructor, &from_value, &to_value) { @@ -851,7 +852,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], } } - &PatVec(ref before, ref slice, ref after) => { + ast::PatVec(ref before, ref slice, ref after) => { match *constructor { // Fixed-length vectors. Single => { @@ -883,7 +884,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], } } - &PatMac(_) => { + ast::PatMac(_) => { cx.tcx.sess.span_err(pat_span, "unexpanded macro"); None } @@ -895,12 +896,12 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], }) } -fn check_local(cx: &mut MatchCheckCtxt, loc: &Local) { +fn check_local(cx: &mut MatchCheckCtxt, loc: &ast::Local) { visit::walk_local(cx, loc); let name = match loc.source { - LocalLet => "local", - LocalFor => "`for` loop" + ast::LocalLet => "local", + ast::LocalFor => "`for` loop" }; let mut static_inliner = StaticInliner::new(cx.tcx); @@ -918,8 +919,8 @@ fn check_local(cx: &mut MatchCheckCtxt, loc: &Local) { fn check_fn(cx: &mut MatchCheckCtxt, kind: FnKind, - decl: &FnDecl, - body: &Block, + decl: &ast::FnDecl, + body: &ast::Block, sp: Span, _: NodeId) { visit::walk_fn(cx, kind, decl, body, sp); @@ -957,10 +958,10 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, for pat in pats.iter() { pat_bindings(def_map, &**pat, |bm, _, span, _path| { match bm { - BindByRef(_) => { + ast::BindByRef(_) => { by_ref_span = Some(span); } - BindByValue(_) => { + ast::BindByValue(_) => { } } }) @@ -985,13 +986,13 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, walk_pat(&**pat, |p| { if pat_is_binding(def_map, &*p) { match p.node { - PatIdent(BindByValue(_), _, ref sub) => { + ast::PatIdent(ast::BindByValue(_), _, ref sub) => { let pat_ty = ty::node_id_to_type(tcx, p.id); if ty::type_moves_by_default(tcx, pat_ty) { check_move(p, sub.as_ref().map(|p| &**p)); } } - PatIdent(BindByRef(_), _, _) => { + ast::PatIdent(ast::BindByRef(_), _, _) => { } _ => { cx.tcx.sess.span_bug( @@ -1010,7 +1011,8 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, /// Ensures that a pattern guard doesn't borrow by mutable reference or /// assign. -fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>, guard: &Expr) { +fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>, + guard: &ast::Expr) { let mut checker = MutationChecker { cx: cx, }; @@ -1022,7 +1024,7 @@ struct MutationChecker<'a, 'tcx: 'a> { cx: &'a MatchCheckCtxt<'a, 'tcx>, } -impl<'a, 'tcx> Delegate for MutationChecker<'a, 'tcx> { +impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> { fn consume(&mut self, _: NodeId, _: Span, _: cmt, _: ConsumeMode) {} fn consume_pat(&mut self, _: &Pat, _: cmt, _: ConsumeMode) {} fn borrow(&mut self, @@ -1078,7 +1080,7 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> { } match pat.node { - PatIdent(_, _, Some(_)) => { + ast::PatIdent(_, _, Some(_)) => { let bindings_were_allowed = self.bindings_allowed; self.bindings_allowed = false; visit::walk_pat(self, pat); diff --git a/src/librustc/middle/check_rvalues.rs b/src/librustc/middle/check_rvalues.rs index cd7c4b15494a9..dbba9288cbbc4 100644 --- a/src/librustc/middle/check_rvalues.rs +++ b/src/librustc/middle/check_rvalues.rs @@ -45,11 +45,11 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> { } } -impl<'a, 'tcx> euv::Delegate for RvalueContext<'a, 'tcx> { +impl<'a, 'tcx> euv::Delegate<'tcx> for RvalueContext<'a, 'tcx> { fn consume(&mut self, _: ast::NodeId, span: Span, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, _: euv::ConsumeMode) { debug!("consume; cmt: {}; type: {}", *cmt, ty_to_string(self.tcx, cmt.ty)); if !ty::type_is_sized(self.tcx, cmt.ty) { diff --git a/src/librustc/middle/check_static.rs b/src/librustc/middle/check_static.rs index 636898187e49e..afba72cea99a2 100644 --- a/src/librustc/middle/check_static.rs +++ b/src/librustc/middle/check_static.rs @@ -53,7 +53,7 @@ struct CheckStaticVisitor<'a, 'tcx: 'a> { checker: &'a mut GlobalChecker, } -struct GlobalVisitor<'a, 'b, 't: 'b>(euv::ExprUseVisitor<'a, 'b, ty::ctxt<'t>>); +struct GlobalVisitor<'a, 'b, 'tcx: 'b>(euv::ExprUseVisitor<'a, 'b, 'tcx, ty::ctxt<'tcx>>); struct GlobalChecker { static_consumptions: NodeSet, const_borrows: NodeSet, @@ -162,7 +162,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckStaticVisitor<'a, 'tcx> { let node_ty = ty::node_id_to_type(self.tcx, e.id); - match ty::get(node_ty).sty { + match node_ty.sty { ty::ty_struct(did, _) | ty::ty_enum(did, _) if ty::has_dtor(self.tcx, did) => { self.tcx.sess.span_err(e.span, @@ -256,7 +256,7 @@ impl<'a, 'b, 't, 'v> Visitor<'v> for GlobalVisitor<'a, 'b, 't> { } } -impl euv::Delegate for GlobalChecker { +impl<'tcx> euv::Delegate<'tcx> for GlobalChecker { fn consume(&mut self, consume_id: ast::NodeId, _consume_span: Span, diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index a892744262bbe..c7c67e8a67b61 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -18,17 +18,17 @@ use metadata::csearch; use middle::astencode; use middle::def; use middle::pat_util::def_to_path; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::astconv; use middle::typeck::check; use util::nodemap::{DefIdMap}; -use syntax::ast::*; +use syntax::ast::{mod, Expr}; use syntax::parse::token::InternedString; use syntax::ptr::P; use syntax::visit::Visitor; use syntax::visit; -use syntax::{ast, ast_map, ast_util, codemap}; +use syntax::{ast_map, ast_util, codemap}; use std::rc::Rc; use std::collections::hash_map::Vacant; @@ -118,7 +118,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt, match tcx.map.find(enum_def.node) { None => None, Some(ast_map::NodeItem(it)) => match it.node { - ItemEnum(ast::EnumDef { ref variants }, _) => { + ast::ItemEnum(ast::EnumDef { ref variants }, _) => { variant_expr(variants.as_slice(), variant_def.node) } _ => None @@ -136,7 +136,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt, let expr_id = match csearch::maybe_get_item_ast(tcx, enum_def, |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) { csearch::found(&ast::IIItem(ref item)) => match item.node { - ItemEnum(ast::EnumDef { ref variants }, _) => { + ast::ItemEnum(ast::EnumDef { ref variants }, _) => { // NOTE this doesn't do the right thing, it compares inlined // NodeId's to the original variant_def's NodeId, but they // come from different crates, so they will likely never match. @@ -158,7 +158,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId) match tcx.map.find(def_id.node) { None => None, Some(ast_map::NodeItem(it)) => match it.node { - ItemConst(_, ref const_expr) => { + ast::ItemConst(_, ref const_expr) => { Some(&**const_expr) } _ => None @@ -176,7 +176,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId) let expr_id = match csearch::maybe_get_item_ast(tcx, def_id, |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) { csearch::found(&ast::IIItem(ref item)) => match item.node { - ItemConst(_, ref const_expr) => Some(const_expr.id), + ast::ItemConst(_, ref const_expr) => Some(const_expr.id), _ => None }, _ => None @@ -280,9 +280,9 @@ impl<'a, 'tcx> ConstEvalVisitor<'a, 'tcx> { } impl<'a, 'tcx, 'v> Visitor<'v> for ConstEvalVisitor<'a, 'tcx> { - fn visit_ty(&mut self, t: &Ty) { + fn visit_ty(&mut self, t: &ast::Ty) { match t.node { - TyFixedLengthVec(_, ref expr) => { + ast::TyFixedLengthVec(_, ref expr) => { check::check_const_in_type(self.tcx, &**expr, ty::mk_uint()); } _ => {} @@ -317,12 +317,12 @@ pub enum const_val { const_bool(bool) } -pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P { +pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P { let pat = match expr.node { - ExprTup(ref exprs) => - PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr)).collect()), + ast::ExprTup(ref exprs) => + ast::PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr)).collect()), - ExprCall(ref callee, ref args) => { + ast::ExprCall(ref callee, ref args) => { let def = tcx.def_map.borrow()[callee.id].clone(); match tcx.def_map.borrow_mut().entry(expr.id) { Vacant(entry) => { entry.set(def); } @@ -334,33 +334,33 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P { _ => unreachable!() }; let pats = args.iter().map(|expr| const_expr_to_pat(tcx, &**expr)).collect(); - PatEnum(path, Some(pats)) + ast::PatEnum(path, Some(pats)) } - ExprStruct(ref path, ref fields, None) => { + ast::ExprStruct(ref path, ref fields, None) => { let field_pats = fields.iter().map(|field| codemap::Spanned { span: codemap::DUMMY_SP, - node: FieldPat { + node: ast::FieldPat { ident: field.ident.node, pat: const_expr_to_pat(tcx, &*field.expr), is_shorthand: false, }, }).collect(); - PatStruct(path.clone(), field_pats, false) + ast::PatStruct(path.clone(), field_pats, false) } - ExprVec(ref exprs) => { + ast::ExprVec(ref exprs) => { let pats = exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr)).collect(); - PatVec(pats, None, vec![]) + ast::PatVec(pats, None, vec![]) } - ExprPath(ref path) => { + ast::ExprPath(ref path) => { let opt_def = tcx.def_map.borrow().get(&expr.id).cloned(); match opt_def { Some(def::DefStruct(..)) => - PatStruct(path.clone(), vec![], false), + ast::PatStruct(path.clone(), vec![], false), Some(def::DefVariant(..)) => - PatEnum(path.clone(), None), + ast::PatEnum(path.clone(), None), _ => { match lookup_const(tcx, expr) { Some(actual) => return const_expr_to_pat(tcx, actual), @@ -370,9 +370,9 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P { } } - _ => PatLit(P(expr.clone())) + _ => ast::PatLit(P(expr.clone())) }; - P(Pat { id: expr.id, node: pat, span: expr.span }) + P(ast::Pat { id: expr.id, node: pat, span: expr.span }) } pub fn eval_const_expr(tcx: &ty::ctxt, e: &Expr) -> const_val { @@ -385,7 +385,7 @@ pub fn eval_const_expr(tcx: &ty::ctxt, e: &Expr) -> const_val { pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result { fn fromb(b: bool) -> Result { Ok(const_int(b as i64)) } match e.node { - ExprUnary(UnNeg, ref inner) => { + ast::ExprUnary(ast::UnNeg, ref inner) => { match eval_const_expr_partial(tcx, &**inner) { Ok(const_float(f)) => Ok(const_float(-f)), Ok(const_int(i)) => Ok(const_int(-i)), @@ -395,7 +395,7 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result ((*err).clone()) } } - ExprUnary(UnNot, ref inner) => { + ast::ExprUnary(ast::UnNot, ref inner) => { match eval_const_expr_partial(tcx, &**inner) { Ok(const_int(i)) => Ok(const_int(!i)), Ok(const_uint(i)) => Ok(const_uint(!i)), @@ -403,110 +403,110 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result Err("not on float or string".to_string()) } } - ExprBinary(op, ref a, ref b) => { + ast::ExprBinary(op, ref a, ref b) => { match (eval_const_expr_partial(tcx, &**a), eval_const_expr_partial(tcx, &**b)) { (Ok(const_float(a)), Ok(const_float(b))) => { match op { - BiAdd => Ok(const_float(a + b)), - BiSub => Ok(const_float(a - b)), - BiMul => Ok(const_float(a * b)), - BiDiv => Ok(const_float(a / b)), - BiRem => Ok(const_float(a % b)), - BiEq => fromb(a == b), - BiLt => fromb(a < b), - BiLe => fromb(a <= b), - BiNe => fromb(a != b), - BiGe => fromb(a >= b), - BiGt => fromb(a > b), + ast::BiAdd => Ok(const_float(a + b)), + ast::BiSub => Ok(const_float(a - b)), + ast::BiMul => Ok(const_float(a * b)), + ast::BiDiv => Ok(const_float(a / b)), + ast::BiRem => Ok(const_float(a % b)), + ast::BiEq => fromb(a == b), + ast::BiLt => fromb(a < b), + ast::BiLe => fromb(a <= b), + ast::BiNe => fromb(a != b), + ast::BiGe => fromb(a >= b), + ast::BiGt => fromb(a > b), _ => Err("can't do this op on floats".to_string()) } } (Ok(const_int(a)), Ok(const_int(b))) => { match op { - BiAdd => Ok(const_int(a + b)), - BiSub => Ok(const_int(a - b)), - BiMul => Ok(const_int(a * b)), - BiDiv if b == 0 => { + ast::BiAdd => Ok(const_int(a + b)), + ast::BiSub => Ok(const_int(a - b)), + ast::BiMul => Ok(const_int(a * b)), + ast::BiDiv if b == 0 => { Err("attempted to divide by zero".to_string()) } - BiDiv => Ok(const_int(a / b)), - BiRem if b == 0 => { + ast::BiDiv => Ok(const_int(a / b)), + ast::BiRem if b == 0 => { Err("attempted remainder with a divisor of \ zero".to_string()) } - BiRem => Ok(const_int(a % b)), - BiAnd | BiBitAnd => Ok(const_int(a & b)), - BiOr | BiBitOr => Ok(const_int(a | b)), - BiBitXor => Ok(const_int(a ^ b)), - BiShl => Ok(const_int(a << b as uint)), - BiShr => Ok(const_int(a >> b as uint)), - BiEq => fromb(a == b), - BiLt => fromb(a < b), - BiLe => fromb(a <= b), - BiNe => fromb(a != b), - BiGe => fromb(a >= b), - BiGt => fromb(a > b) + ast::BiRem => Ok(const_int(a % b)), + ast::BiAnd | ast::BiBitAnd => Ok(const_int(a & b)), + ast::BiOr | ast::BiBitOr => Ok(const_int(a | b)), + ast::BiBitXor => Ok(const_int(a ^ b)), + ast::BiShl => Ok(const_int(a << b as uint)), + ast::BiShr => Ok(const_int(a >> b as uint)), + ast::BiEq => fromb(a == b), + ast::BiLt => fromb(a < b), + ast::BiLe => fromb(a <= b), + ast::BiNe => fromb(a != b), + ast::BiGe => fromb(a >= b), + ast::BiGt => fromb(a > b) } } (Ok(const_uint(a)), Ok(const_uint(b))) => { match op { - BiAdd => Ok(const_uint(a + b)), - BiSub => Ok(const_uint(a - b)), - BiMul => Ok(const_uint(a * b)), - BiDiv if b == 0 => { + ast::BiAdd => Ok(const_uint(a + b)), + ast::BiSub => Ok(const_uint(a - b)), + ast::BiMul => Ok(const_uint(a * b)), + ast::BiDiv if b == 0 => { Err("attempted to divide by zero".to_string()) } - BiDiv => Ok(const_uint(a / b)), - BiRem if b == 0 => { + ast::BiDiv => Ok(const_uint(a / b)), + ast::BiRem if b == 0 => { Err("attempted remainder with a divisor of \ zero".to_string()) } - BiRem => Ok(const_uint(a % b)), - BiAnd | BiBitAnd => Ok(const_uint(a & b)), - BiOr | BiBitOr => Ok(const_uint(a | b)), - BiBitXor => Ok(const_uint(a ^ b)), - BiShl => Ok(const_uint(a << b as uint)), - BiShr => Ok(const_uint(a >> b as uint)), - BiEq => fromb(a == b), - BiLt => fromb(a < b), - BiLe => fromb(a <= b), - BiNe => fromb(a != b), - BiGe => fromb(a >= b), - BiGt => fromb(a > b), + ast::BiRem => Ok(const_uint(a % b)), + ast::BiAnd | ast::BiBitAnd => Ok(const_uint(a & b)), + ast::BiOr | ast::BiBitOr => Ok(const_uint(a | b)), + ast::BiBitXor => Ok(const_uint(a ^ b)), + ast::BiShl => Ok(const_uint(a << b as uint)), + ast::BiShr => Ok(const_uint(a >> b as uint)), + ast::BiEq => fromb(a == b), + ast::BiLt => fromb(a < b), + ast::BiLe => fromb(a <= b), + ast::BiNe => fromb(a != b), + ast::BiGe => fromb(a >= b), + ast::BiGt => fromb(a > b), } } // shifts can have any integral type as their rhs (Ok(const_int(a)), Ok(const_uint(b))) => { match op { - BiShl => Ok(const_int(a << b as uint)), - BiShr => Ok(const_int(a >> b as uint)), + ast::BiShl => Ok(const_int(a << b as uint)), + ast::BiShr => Ok(const_int(a >> b as uint)), _ => Err("can't do this op on an int and uint".to_string()) } } (Ok(const_uint(a)), Ok(const_int(b))) => { match op { - BiShl => Ok(const_uint(a << b as uint)), - BiShr => Ok(const_uint(a >> b as uint)), + ast::BiShl => Ok(const_uint(a << b as uint)), + ast::BiShr => Ok(const_uint(a >> b as uint)), _ => Err("can't do this op on a uint and int".to_string()) } } (Ok(const_bool(a)), Ok(const_bool(b))) => { Ok(const_bool(match op { - BiAnd => a && b, - BiOr => a || b, - BiBitXor => a ^ b, - BiBitAnd => a & b, - BiBitOr => a | b, - BiEq => a == b, - BiNe => a != b, + ast::BiAnd => a && b, + ast::BiOr => a || b, + ast::BiBitXor => a ^ b, + ast::BiBitAnd => a & b, + ast::BiBitOr => a | b, + ast::BiEq => a == b, + ast::BiNe => a != b, _ => return Err("can't do this op on bools".to_string()) })) } _ => Err("bad operands for binary".to_string()) } } - ExprCast(ref base, ref target_ty) => { + ast::ExprCast(ref base, ref target_ty) => { // This tends to get called w/o the type actually having been // populated in the ctxt, which was causing things to blow up // (#5900). Fall back to doing a limited lookup to get past it. @@ -524,7 +524,7 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result (match ty::get(ety).sty { + }) => (match ety.sty { $($ty_pat => { match $val { const_bool(b) => Ok($const_type(b as $intermediate_ty as $target_ty)), @@ -556,15 +556,15 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result (f64, const_float, f64) })) } - ExprPath(_) => { + ast::ExprPath(_) => { match lookup_const(tcx, e) { Some(actual_e) => eval_const_expr_partial(tcx, &*actual_e), None => Err("non-constant path in constant expr".to_string()) } } - ExprLit(ref lit) => Ok(lit_to_const(&**lit)), - ExprParen(ref e) => eval_const_expr_partial(tcx, &**e), - ExprBlock(ref block) => { + ast::ExprLit(ref lit) => Ok(lit_to_const(&**lit)), + ast::ExprParen(ref e) => eval_const_expr_partial(tcx, &**e), + ast::ExprBlock(ref block) => { match block.expr { Some(ref expr) => eval_const_expr_partial(tcx, &**expr), None => Ok(const_int(0i64)) @@ -574,24 +574,24 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result const_val { +pub fn lit_to_const(lit: &ast::Lit) -> const_val { match lit.node { - LitStr(ref s, _) => const_str((*s).clone()), - LitBinary(ref data) => { + ast::LitStr(ref s, _) => const_str((*s).clone()), + ast::LitBinary(ref data) => { const_binary(Rc::new(data.iter().map(|x| *x).collect())) } - LitByte(n) => const_uint(n as u64), - LitChar(n) => const_uint(n as u64), - LitInt(n, ast::SignedIntLit(_, ast::Plus)) | - LitInt(n, ast::UnsuffixedIntLit(ast::Plus)) => const_int(n as i64), - LitInt(n, ast::SignedIntLit(_, ast::Minus)) | - LitInt(n, ast::UnsuffixedIntLit(ast::Minus)) => const_int(-(n as i64)), - LitInt(n, ast::UnsignedIntLit(_)) => const_uint(n), - LitFloat(ref n, _) | - LitFloatUnsuffixed(ref n) => { + ast::LitByte(n) => const_uint(n as u64), + ast::LitChar(n) => const_uint(n as u64), + ast::LitInt(n, ast::SignedIntLit(_, ast::Plus)) | + ast::LitInt(n, ast::UnsuffixedIntLit(ast::Plus)) => const_int(n as i64), + ast::LitInt(n, ast::SignedIntLit(_, ast::Minus)) | + ast::LitInt(n, ast::UnsuffixedIntLit(ast::Minus)) => const_int(-(n as i64)), + ast::LitInt(n, ast::UnsignedIntLit(_)) => const_uint(n), + ast::LitFloat(ref n, _) | + ast::LitFloatUnsuffixed(ref n) => { const_float(from_str::(n.get()).unwrap() as f64) } - LitBool(b) => const_bool(b) + ast::LitBool(b) => const_bool(b) } } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 8186ebccdad41..62a5d23e3332c 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -140,7 +140,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { } fn handle_field_access(&mut self, lhs: &ast::Expr, name: &ast::Ident) { - match ty::get(ty::expr_ty_adjusted(self.tcx, lhs)).sty { + match ty::expr_ty_adjusted(self.tcx, lhs).sty { ty::ty_struct(id, _) => { let fields = ty::lookup_struct_fields(self.tcx, id); let field_id = fields.iter() @@ -152,7 +152,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { } fn handle_tup_field_access(&mut self, lhs: &ast::Expr, idx: uint) { - match ty::get(ty::expr_ty_adjusted(self.tcx, lhs)).sty { + match ty::expr_ty_adjusted(self.tcx, lhs).sty { ty::ty_struct(id, _) => { let fields = ty::lookup_struct_fields(self.tcx, id); let field_id = fields[idx].id; diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index 41d35969f38be..71885a769f580 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -13,7 +13,7 @@ use self::UnsafeContext::*; use middle::def; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::MethodCall; use util::ppaux; @@ -30,8 +30,8 @@ enum UnsafeContext { UnsafeBlock(ast::NodeId), } -fn type_is_unsafe_function(ty: ty::t) -> bool { - match ty::get(ty).sty { +fn type_is_unsafe_function(ty: Ty) -> bool { + match ty.sty { ty::ty_bare_fn(ref f) => f.fn_style == ast::UnsafeFn, ty::ty_closure(ref f) => f.fn_style == ast::UnsafeFn, _ => false, @@ -70,8 +70,8 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> { }; debug!("effect: checking index with base type {}", ppaux::ty_to_string(self.tcx, base_type)); - match ty::get(base_type).sty { - ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty { + match base_type.sty { + ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty.sty { ty::ty_str => { span_err!(self.tcx.sess, e.span, E0134, "modification of string types is not allowed"); @@ -166,7 +166,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> { let base_type = ty::node_id_to_type(self.tcx, base.id); debug!("effect: unary case, base type is {}", ppaux::ty_to_string(self.tcx, base_type)); - match ty::get(base_type).sty { + match base_type.sty { ty::ty_ptr(_) => { self.require_unsafe(expr.span, "dereference of unsafe pointer") diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index a8ab4425f1dba..f4c22c5716390 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -24,7 +24,7 @@ use middle::mem_categorization as mc; use middle::def; use middle::mem_categorization::Typer; use middle::pat_util; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::{MethodCall, MethodObject, MethodTraitObject}; use middle::typeck::{MethodOrigin, MethodParam, MethodTypeParam}; use middle::typeck::{MethodStatic, MethodStaticUnboxedClosure}; @@ -40,20 +40,20 @@ use syntax::codemap::Span; /// This trait defines the callbacks you can expect to receive when /// employing the ExprUseVisitor. -pub trait Delegate { +pub trait Delegate<'tcx> { // The value found at `cmt` is either copied or moved, depending // on mode. fn consume(&mut self, consume_id: ast::NodeId, consume_span: Span, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, mode: ConsumeMode); // The value found at `cmt` is either copied or moved via the // pattern binding `consume_pat`, depending on mode. fn consume_pat(&mut self, consume_pat: &ast::Pat, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, mode: ConsumeMode); // The value found at `borrow` is being borrowed at the point @@ -61,7 +61,7 @@ pub trait Delegate { fn borrow(&mut self, borrow_id: ast::NodeId, borrow_span: Span, - cmt: mc::cmt, + cmt: mc::cmt<'tcx>, loan_region: ty::Region, bk: ty::BorrowKind, loan_cause: LoanCause); @@ -75,7 +75,7 @@ pub trait Delegate { fn mutate(&mut self, assignment_id: ast::NodeId, assignment_span: Span, - assignee_cmt: mc::cmt, + assignee_cmt: mc::cmt<'tcx>, mode: MutateMode); } @@ -201,10 +201,10 @@ impl OverloadedCallType { // supplies types from the tree. After type checking is complete, you // can just use the tcx as the typer. -pub struct ExprUseVisitor<'d,'t,TYPER:'t> { +pub struct ExprUseVisitor<'d,'t,'tcx,TYPER:'t> { typer: &'t TYPER, mc: mc::MemCategorizationContext<'t,TYPER>, - delegate: &'d mut Delegate+'d, + delegate: &'d mut Delegate<'tcx>+'d, } // If the TYPER results in an error, it's because the type check @@ -223,10 +223,10 @@ macro_rules! return_if_err( ) ) -impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { - pub fn new(delegate: &'d mut Delegate, +impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { + pub fn new(delegate: &'d mut Delegate<'tcx>, typer: &'t TYPER) - -> ExprUseVisitor<'d,'t,TYPER> { + -> ExprUseVisitor<'d,'t,'tcx,TYPER> { ExprUseVisitor { typer: typer, mc: mc::MemCategorizationContext::new(typer), delegate: delegate } @@ -262,7 +262,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { fn delegate_consume(&mut self, consume_id: ast::NodeId, consume_span: Span, - cmt: mc::cmt) { + cmt: mc::cmt<'tcx>) { let mode = copy_or_move(self.tcx(), cmt.ty, DirectRefMove); self.delegate.consume(consume_id, consume_span, cmt, mode); } @@ -519,7 +519,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { let callee_ty = ty::expr_ty_adjusted(self.tcx(), callee); debug!("walk_callee: callee={} callee_ty={}", callee.repr(self.tcx()), callee_ty.repr(self.tcx())); - match ty::get(callee_ty).sty { + match callee_ty.sty { ty::ty_bare_fn(..) => { self.consume_expr(callee); } @@ -656,7 +656,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { // Select just those fields of the `with` // expression that will actually be used - let with_fields = match ty::get(with_cmt.ty).sty { + let with_fields = match with_cmt.ty.sty { ty::ty_struct(did, ref substs) => { ty::struct_fields(self.tcx(), did, substs) } @@ -745,7 +745,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { Some(method_ty) => { let cmt = return_if_err!(self.mc.cat_expr_autoderefd(expr, i)); let self_ty = ty::ty_fn_args(method_ty)[0]; - let (m, r) = match ty::get(self_ty).sty { + let (m, r) = match self_ty.sty { ty::ty_rptr(r, ref m) => (m.mutbl, r), _ => self.tcx().sess.span_bug(expr.span, format!("bad overloaded deref type {}", @@ -823,7 +823,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { return true; } - fn walk_arm(&mut self, discr_cmt: mc::cmt, arm: &ast::Arm) { + fn walk_arm(&mut self, discr_cmt: mc::cmt<'tcx>, arm: &ast::Arm) { for pat in arm.pats.iter() { self.walk_pat(discr_cmt.clone(), &**pat); } @@ -835,7 +835,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { self.consume_expr(&*arm.body); } - fn walk_pat(&mut self, cmt_discr: mc::cmt, pat: &ast::Pat) { + fn walk_pat(&mut self, cmt_discr: mc::cmt<'tcx>, pat: &ast::Pat) { debug!("walk_pat cmt_discr={} pat={}", cmt_discr.repr(self.tcx()), pat.repr(self.tcx())); let mc = &self.mc; @@ -990,7 +990,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { closure_id: ast::NodeId, closure_span: Span, upvar_def: def::Def) - -> mc::McResult { + -> mc::McResult> { // Create the cmt for the variable being borrowed, from the // caller's perspective let var_id = upvar_def.def_id().node; @@ -999,7 +999,8 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { } } -fn copy_or_move(tcx: &ty::ctxt, ty: ty::t, move_reason: MoveReason) -> ConsumeMode { +fn copy_or_move<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>, + move_reason: MoveReason) -> ConsumeMode { if ty::type_moves_by_default(tcx, ty) { Move(move_reason) } else { Copy } } diff --git a/src/librustc/middle/fast_reject.rs b/src/librustc/middle/fast_reject.rs index d2c58b2ceee2a..7514a63c7fa58 100644 --- a/src/librustc/middle/fast_reject.rs +++ b/src/librustc/middle/fast_reject.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::ty; +use middle::ty::{mod, Ty}; use syntax::ast; use self::SimplifiedType::*; @@ -34,7 +34,7 @@ pub enum SimplifiedType { } pub fn simplify_type(tcx: &ty::ctxt, - ty: ty::t, + ty: Ty, can_simplify_params: bool) -> Option { @@ -53,7 +53,7 @@ pub fn simplify_type(tcx: &ty::ctxt, * are to be considered bound. */ - match ty::get(ty).sty { + match ty.sty { ty::ty_bool => Some(BoolSimplifiedType), ty::ty_char => Some(CharSimplifiedType), ty::ty_int(int_type) => Some(IntSimplifiedType(int_type)), diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index 2c7c360bb1df6..68d0ac932164a 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -12,7 +12,7 @@ use metadata::csearch; use middle::def::DefFn; use middle::subst::Subst; use middle::ty::{TransmuteRestriction, ctxt, ty_bare_fn}; -use middle::ty; +use middle::ty::{mod, Ty}; use syntax::abi::RustIntrinsic; use syntax::ast::DefId; @@ -23,11 +23,11 @@ use syntax::parse::token; use syntax::visit::Visitor; use syntax::visit; -fn type_size_is_affected_by_type_parameters(tcx: &ty::ctxt, typ: ty::t) - -> bool { +fn type_size_is_affected_by_type_parameters<'tcx>(tcx: &ty::ctxt<'tcx>, typ: Ty<'tcx>) + -> bool { let mut result = false; ty::maybe_walk_ty(typ, |typ| { - match ty::get(typ).sty { + match typ.sty { ty::ty_uniq(_) | ty::ty_ptr(_) | ty::ty_rptr(..) | ty::ty_bare_fn(..) | ty::ty_closure(..) => { false @@ -73,7 +73,7 @@ struct IntrinsicCheckingVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> { fn def_id_is_transmute(&self, def_id: DefId) -> bool { - let intrinsic = match ty::get(ty::lookup_item_type(self.tcx, def_id).ty).sty { + let intrinsic = match ty::lookup_item_type(self.tcx, def_id).ty.sty { ty::ty_bare_fn(ref bfty) => bfty.abi == RustIntrinsic, _ => return false }; @@ -96,7 +96,7 @@ impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> { } } - fn check_transmute(&self, span: Span, from: ty::t, to: ty::t, id: ast::NodeId) { + fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>, id: ast::NodeId) { if type_size_is_affected_by_type_parameters(self.tcx, from) { span_err!(self.tcx.sess, span, E0139, "cannot transmute from a type that contains type parameters"); @@ -123,7 +123,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> { match ty::resolve_expr(self.tcx, expr) { DefFn(did, _) if self.def_id_is_transmute(did) => { let typ = ty::node_id_to_type(self.tcx, expr.id); - match ty::get(typ).sty { + match typ.sty { ty_bare_fn(ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => { if let ty::FnConverging(to) = bare_fn_ty.sig.output { diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 8604c3967a926..82edfdf146eae 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -123,8 +123,7 @@ use std::fmt; use std::io; use std::rc::Rc; use std::uint; -use syntax::ast; -use syntax::ast::*; +use syntax::ast::{mod, NodeId, Expr}; use syntax::codemap::{BytePos, original_sp, Span}; use syntax::parse::token::special_idents; use syntax::parse::token; @@ -140,7 +139,7 @@ enum LoopKind<'a> { /// A `while` loop, with the given expression as condition. WhileLoop(&'a Expr), /// A `for` loop, with the given pattern to bind. - ForLoop(&'a Pat), + ForLoop(&'a ast::Pat), } #[deriving(PartialEq)] @@ -187,12 +186,13 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, cx: &ty::ctxt) -> String { } impl<'a, 'tcx, 'v> Visitor<'v> for IrMaps<'a, 'tcx> { - fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, id: ast::NodeId) { + fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v ast::FnDecl, + b: &'v ast::Block, s: Span, id: NodeId) { visit_fn(self, fk, fd, b, s, id); } fn visit_local(&mut self, l: &ast::Local) { visit_local(self, l); } fn visit_expr(&mut self, ex: &Expr) { visit_expr(self, ex); } - fn visit_arm(&mut self, a: &Arm) { visit_arm(self, a); } + fn visit_arm(&mut self, a: &ast::Arm) { visit_arm(self, a); } } pub fn check_crate(tcx: &ty::ctxt) { @@ -250,12 +250,12 @@ struct CaptureInfo { #[deriving(Show)] struct LocalInfo { id: NodeId, - ident: Ident + ident: ast::Ident } #[deriving(Show)] enum VarKind { - Arg(NodeId, Ident), + Arg(NodeId, ast::Ident), Local(LocalInfo), ImplicitRet, CleanExit @@ -354,7 +354,8 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> { } impl<'a, 'tcx, 'v> Visitor<'v> for Liveness<'a, 'tcx> { - fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, n: NodeId) { + fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v ast::FnDecl, + b: &'v ast::Block, s: Span, n: NodeId) { check_fn(self, fk, fd, b, s, n); } fn visit_local(&mut self, l: &ast::Local) { @@ -363,15 +364,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Liveness<'a, 'tcx> { fn visit_expr(&mut self, ex: &Expr) { check_expr(self, ex); } - fn visit_arm(&mut self, a: &Arm) { + fn visit_arm(&mut self, a: &ast::Arm) { check_arm(self, a); } } fn visit_fn(ir: &mut IrMaps, fk: FnKind, - decl: &FnDecl, - body: &Block, + decl: &ast::FnDecl, + body: &ast::Block, sp: Span, id: ast::NodeId) { debug!("visit_fn"); @@ -429,7 +430,7 @@ fn visit_local(ir: &mut IrMaps, local: &ast::Local) { visit::walk_local(ir, local); } -fn visit_arm(ir: &mut IrMaps, arm: &Arm) { +fn visit_arm(ir: &mut IrMaps, arm: &ast::Arm) { for pat in arm.pats.iter() { pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| { debug!("adding local variable {} from match with bm {}", @@ -448,7 +449,7 @@ fn visit_arm(ir: &mut IrMaps, arm: &Arm) { fn visit_expr(ir: &mut IrMaps, expr: &Expr) { match expr.node { // live nodes required for uses or definitions of variables: - ExprPath(_) => { + ast::ExprPath(_) => { let def = ir.tcx.def_map.borrow()[expr.id].clone(); debug!("expr {}: path that leads to {}", expr.id, def); match def { @@ -457,7 +458,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) { } visit::walk_expr(ir, expr); } - ExprFnBlock(..) | ExprProc(..) | ExprUnboxedFn(..) => { + ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprUnboxedFn(..) => { // Interesting control flow (for loops can contain labeled // breaks or continues) ir.add_live_node_for_node(expr.id, ExprNode(expr.span)); @@ -485,17 +486,17 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) { } // live nodes required for interesting control flow: - ExprIf(..) | ExprMatch(..) | ExprWhile(..) | ExprLoop(..) => { + ast::ExprIf(..) | ast::ExprMatch(..) | ast::ExprWhile(..) | ast::ExprLoop(..) => { ir.add_live_node_for_node(expr.id, ExprNode(expr.span)); visit::walk_expr(ir, expr); } - ExprIfLet(..) => { + ast::ExprIfLet(..) => { ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet"); } - ExprWhileLet(..) => { + ast::ExprWhileLet(..) => { ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ExprForLoop(ref pat, _, _, _) => { + ast::ExprForLoop(ref pat, _, _, _) => { pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| { debug!("adding local variable {} from for loop with bm {}", p_id, bm); @@ -509,20 +510,21 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) { ir.add_live_node_for_node(expr.id, ExprNode(expr.span)); visit::walk_expr(ir, expr); } - ExprBinary(op, _, _) if ast_util::lazy_binop(op) => { + ast::ExprBinary(op, _, _) if ast_util::lazy_binop(op) => { ir.add_live_node_for_node(expr.id, ExprNode(expr.span)); visit::walk_expr(ir, expr); } // otherwise, live nodes are not required: - ExprIndex(..) | ExprField(..) | ExprTupField(..) | ExprVec(..) | - ExprCall(..) | ExprMethodCall(..) | ExprTup(..) | ExprSlice(..) | - ExprBinary(..) | ExprAddrOf(..) | - ExprCast(..) | ExprUnary(..) | ExprBreak(_) | - ExprAgain(_) | ExprLit(_) | ExprRet(..) | ExprBlock(..) | - ExprAssign(..) | ExprAssignOp(..) | ExprMac(..) | - ExprStruct(..) | ExprRepeat(..) | ExprParen(..) | - ExprInlineAsm(..) | ExprBox(..) => { + ast::ExprIndex(..) | ast::ExprField(..) | ast::ExprTupField(..) | + ast::ExprVec(..) | ast::ExprCall(..) | ast::ExprMethodCall(..) | + ast::ExprTup(..) | ast::ExprBinary(..) | ast::ExprAddrOf(..) | + ast::ExprCast(..) | ast::ExprUnary(..) | ast::ExprBreak(_) | + ast::ExprAgain(_) | ast::ExprLit(_) | ast::ExprRet(..) | + ast::ExprBlock(..) | ast::ExprAssign(..) | ast::ExprAssignOp(..) | + ast::ExprMac(..) | ast::ExprStruct(..) | ast::ExprRepeat(..) | + ast::ExprParen(..) | ast::ExprInlineAsm(..) | ast::ExprBox(..) | + ast::ExprSlice(..) => { visit::walk_expr(ir, expr); } } @@ -611,7 +613,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } fn pat_bindings(&mut self, - pat: &Pat, + pat: &ast::Pat, f: |&mut Liveness<'a, 'tcx>, LiveNode, Variable, Span, NodeId|) { pat_util::pat_bindings(&self.ir.tcx.def_map, pat, |_bm, p_id, sp, _n| { let ln = self.live_node(p_id, sp); @@ -621,7 +623,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } fn arm_pats_bindings(&mut self, - pat: Option<&Pat>, + pat: Option<&ast::Pat>, f: |&mut Liveness<'a, 'tcx>, LiveNode, Variable, Span, NodeId|) { match pat { Some(pat) => { @@ -631,12 +633,12 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } } - fn define_bindings_in_pat(&mut self, pat: &Pat, succ: LiveNode) + fn define_bindings_in_pat(&mut self, pat: &ast::Pat, succ: LiveNode) -> LiveNode { self.define_bindings_in_arm_pats(Some(pat), succ) } - fn define_bindings_in_arm_pats(&mut self, pat: Option<&Pat>, succ: LiveNode) + fn define_bindings_in_arm_pats(&mut self, pat: Option<&ast::Pat>, succ: LiveNode) -> LiveNode { let mut succ = succ; self.arm_pats_bindings(pat, |this, ln, var, _sp, _id| { @@ -711,7 +713,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } fn find_loop_scope(&self, - opt_label: Option, + opt_label: Option, id: NodeId, sp: Span) -> NodeId { @@ -846,7 +848,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // _______________________________________________________________________ - fn compute(&mut self, decl: &FnDecl, body: &Block) -> LiveNode { + fn compute(&mut self, decl: &ast::FnDecl, body: &ast::Block) -> LiveNode { // if there is a `break` or `again` at the top level, then it's // effectively a return---this only occurs in `for` loops, // where the body is really a closure. @@ -871,7 +873,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { entry_ln } - fn propagate_through_fn_block(&mut self, _: &FnDecl, blk: &Block) + fn propagate_through_fn_block(&mut self, _: &ast::FnDecl, blk: &ast::Block) -> LiveNode { // the fallthrough exit is only for those cases where we do not // explicitly return: @@ -885,7 +887,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.propagate_through_block(blk, s.fallthrough_ln) } - fn propagate_through_block(&mut self, blk: &Block, succ: LiveNode) + fn propagate_through_block(&mut self, blk: &ast::Block, succ: LiveNode) -> LiveNode { let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ); blk.stmts.iter().rev().fold(succ, |succ, stmt| { @@ -893,30 +895,30 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { }) } - fn propagate_through_stmt(&mut self, stmt: &Stmt, succ: LiveNode) + fn propagate_through_stmt(&mut self, stmt: &ast::Stmt, succ: LiveNode) -> LiveNode { match stmt.node { - StmtDecl(ref decl, _) => { + ast::StmtDecl(ref decl, _) => { self.propagate_through_decl(&**decl, succ) } - StmtExpr(ref expr, _) | StmtSemi(ref expr, _) => { + ast::StmtExpr(ref expr, _) | ast::StmtSemi(ref expr, _) => { self.propagate_through_expr(&**expr, succ) } - StmtMac(..) => { + ast::StmtMac(..) => { self.ir.tcx.sess.span_bug(stmt.span, "unexpanded macro"); } } } - fn propagate_through_decl(&mut self, decl: &Decl, succ: LiveNode) + fn propagate_through_decl(&mut self, decl: &ast::Decl, succ: LiveNode) -> LiveNode { match decl.node { - DeclLocal(ref local) => { + ast::DeclLocal(ref local) => { self.propagate_through_local(&**local, succ) } - DeclItem(_) => succ, + ast::DeclItem(_) => succ, } } @@ -961,21 +963,21 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { match expr.node { // Interesting cases with control flow or which gen/kill - ExprPath(_) => { + ast::ExprPath(_) => { self.access_path(expr, succ, ACC_READ | ACC_USE) } - ExprField(ref e, _, _) => { + ast::ExprField(ref e, _, _) => { self.propagate_through_expr(&**e, succ) } - ExprTupField(ref e, _, _) => { + ast::ExprTupField(ref e, _, _) => { self.propagate_through_expr(&**e, succ) } - ExprFnBlock(_, _, ref blk) | - ExprProc(_, ref blk) | - ExprUnboxedFn(_, _, _, ref blk) => { + ast::ExprFnBlock(_, _, ref blk) | + ast::ExprProc(_, ref blk) | + ast::ExprUnboxedFn(_, _, _, ref blk) => { debug!("{} is an ExprFnBlock, ExprProc, or ExprUnboxedFn", expr_to_string(expr)); @@ -1003,7 +1005,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { }) } - ExprIf(ref cond, ref then, ref els) => { + ast::ExprIf(ref cond, ref then, ref els) => { // // (cond) // | @@ -1025,30 +1027,30 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.propagate_through_expr(&**cond, ln) } - ExprIfLet(..) => { + ast::ExprIfLet(..) => { self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet"); } - ExprWhile(ref cond, ref blk, _) => { + ast::ExprWhile(ref cond, ref blk, _) => { self.propagate_through_loop(expr, WhileLoop(&**cond), &**blk, succ) } - ExprWhileLet(..) => { + ast::ExprWhileLet(..) => { self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ExprForLoop(ref pat, ref head, ref blk, _) => { + ast::ExprForLoop(ref pat, ref head, ref blk, _) => { let ln = self.propagate_through_loop(expr, ForLoop(&**pat), &**blk, succ); self.propagate_through_expr(&**head, ln) } // Note that labels have been resolved, so we don't need to look // at the label ident - ExprLoop(ref blk, _) => { + ast::ExprLoop(ref blk, _) => { self.propagate_through_loop(expr, LoopLoop, &**blk, succ) } - ExprMatch(ref e, ref arms, _) => { + ast::ExprMatch(ref e, ref arms, _) => { // // (e) // | @@ -1083,13 +1085,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.propagate_through_expr(&**e, ln) } - ExprRet(ref o_e) => { + ast::ExprRet(ref o_e) => { // ignore succ and subst exit_ln: let exit_ln = self.s.exit_ln; self.propagate_through_opt_expr(o_e.as_ref().map(|e| &**e), exit_ln) } - ExprBreak(opt_label) => { + ast::ExprBreak(opt_label) => { // Find which label this break jumps to let sc = self.find_loop_scope(opt_label, expr.id, expr.span); @@ -1103,7 +1105,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } } - ExprAgain(opt_label) => { + ast::ExprAgain(opt_label) => { // Find which label this expr continues to let sc = self.find_loop_scope(opt_label, expr.id, expr.span); @@ -1117,7 +1119,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } } - ExprAssign(ref l, ref r) => { + ast::ExprAssign(ref l, ref r) => { // see comment on lvalues in // propagate_through_lvalue_components() let succ = self.write_lvalue(&**l, succ, ACC_WRITE); @@ -1125,7 +1127,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.propagate_through_expr(&**r, succ) } - ExprAssignOp(_, ref l, ref r) => { + ast::ExprAssignOp(_, ref l, ref r) => { // see comment on lvalues in // propagate_through_lvalue_components() let succ = self.write_lvalue(&**l, succ, ACC_WRITE|ACC_READ); @@ -1135,23 +1137,23 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // Uninteresting cases: just propagate in rev exec order - ExprVec(ref exprs) => { + ast::ExprVec(ref exprs) => { self.propagate_through_exprs(exprs.as_slice(), succ) } - ExprRepeat(ref element, ref count) => { + ast::ExprRepeat(ref element, ref count) => { let succ = self.propagate_through_expr(&**count, succ); self.propagate_through_expr(&**element, succ) } - ExprStruct(_, ref fields, ref with_expr) => { + ast::ExprStruct(_, ref fields, ref with_expr) => { let succ = self.propagate_through_opt_expr(with_expr.as_ref().map(|e| &**e), succ); fields.iter().rev().fold(succ, |succ, field| { self.propagate_through_expr(&*field.expr, succ) }) } - ExprCall(ref f, ref args) => { + ast::ExprCall(ref f, ref args) => { let diverges = !self.ir.tcx.is_method_call(expr.id) && { let t_ret = ty::ty_fn_ret(ty::expr_ty(self.ir.tcx, &**f)); t_ret == ty::FnDiverging @@ -1165,7 +1167,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.propagate_through_expr(&**f, succ) } - ExprMethodCall(_, _, ref args) => { + ast::ExprMethodCall(_, _, ref args) => { let method_call = typeck::MethodCall::expr(expr.id); let method_ty = self.ir.tcx.method_map.borrow().get(&method_call).unwrap().ty; let diverges = ty::ty_fn_ret(method_ty) == ty::FnDiverging; @@ -1177,11 +1179,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.propagate_through_exprs(args.as_slice(), succ) } - ExprTup(ref exprs) => { + ast::ExprTup(ref exprs) => { self.propagate_through_exprs(exprs.as_slice(), succ) } - ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op) => { + ast::ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op) => { let r_succ = self.propagate_through_expr(&**r, succ); let ln = self.live_node(expr.id, expr.span); @@ -1191,27 +1193,27 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.propagate_through_expr(&**l, ln) } - ExprIndex(ref l, ref r) | - ExprBinary(_, ref l, ref r) | - ExprBox(ref l, ref r) => { + ast::ExprIndex(ref l, ref r) | + ast::ExprBinary(_, ref l, ref r) | + ast::ExprBox(ref l, ref r) => { let r_succ = self.propagate_through_expr(&**r, succ); self.propagate_through_expr(&**l, r_succ) } - ExprSlice(ref e1, ref e2, ref e3, _) => { + ast::ExprSlice(ref e1, ref e2, ref e3, _) => { let succ = e3.as_ref().map_or(succ, |e| self.propagate_through_expr(&**e, succ)); let succ = e2.as_ref().map_or(succ, |e| self.propagate_through_expr(&**e, succ)); self.propagate_through_expr(&**e1, succ) } - ExprAddrOf(_, ref e) | - ExprCast(ref e, _) | - ExprUnary(_, ref e) | - ExprParen(ref e) => { + ast::ExprAddrOf(_, ref e) | + ast::ExprCast(ref e, _) | + ast::ExprUnary(_, ref e) | + ast::ExprParen(ref e) => { self.propagate_through_expr(&**e, succ) } - ExprInlineAsm(ref ia) => { + ast::ExprInlineAsm(ref ia) => { let succ = ia.outputs.iter().rev().fold(succ, |succ, &(_, ref expr, _)| { // see comment on lvalues @@ -1225,15 +1227,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { }) } - ExprLit(..) => { + ast::ExprLit(..) => { succ } - ExprBlock(ref blk) => { + ast::ExprBlock(ref blk) => { self.propagate_through_block(&**blk, succ) } - ExprMac(..) => { + ast::ExprMac(..) => { self.ir.tcx.sess.span_bug(expr.span, "unexpanded macro"); } } @@ -1293,9 +1295,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // just ignore such cases and treat them as reads. match expr.node { - ExprPath(_) => succ, - ExprField(ref e, _, _) => self.propagate_through_expr(&**e, succ), - ExprTupField(ref e, _, _) => self.propagate_through_expr(&**e, succ), + ast::ExprPath(_) => succ, + ast::ExprField(ref e, _, _) => self.propagate_through_expr(&**e, succ), + ast::ExprTupField(ref e, _, _) => self.propagate_through_expr(&**e, succ), _ => self.propagate_through_expr(expr, succ) } } @@ -1304,7 +1306,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn write_lvalue(&mut self, expr: &Expr, succ: LiveNode, acc: uint) -> LiveNode { match expr.node { - ExprPath(_) => self.access_path(expr, succ, acc), + ast::ExprPath(_) => self.access_path(expr, succ, acc), // We do not track other lvalues, so just propagate through // to their subcomponents. Also, it may happen that @@ -1333,7 +1335,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn propagate_through_loop(&mut self, expr: &Expr, kind: LoopKind, - body: &Block, + body: &ast::Block, succ: LiveNode) -> LiveNode { @@ -1437,7 +1439,7 @@ fn check_local(this: &mut Liveness, local: &ast::Local) { visit::walk_local(this, local); } -fn check_arm(this: &mut Liveness, arm: &Arm) { +fn check_arm(this: &mut Liveness, arm: &ast::Arm) { // only consider the first pattern; any later patterns must have // the same bindings, and we also consider the first pattern to be // the "authoritative" set of ids @@ -1449,20 +1451,20 @@ fn check_arm(this: &mut Liveness, arm: &Arm) { fn check_expr(this: &mut Liveness, expr: &Expr) { match expr.node { - ExprAssign(ref l, ref r) => { + ast::ExprAssign(ref l, ref r) => { this.check_lvalue(&**l); this.visit_expr(&**r); visit::walk_expr(this, expr); } - ExprAssignOp(_, ref l, _) => { + ast::ExprAssignOp(_, ref l, _) => { this.check_lvalue(&**l); visit::walk_expr(this, expr); } - ExprInlineAsm(ref ia) => { + ast::ExprInlineAsm(ref ia) => { for &(_, ref input) in ia.inputs.iter() { this.visit_expr(&**input); } @@ -1476,7 +1478,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) { visit::walk_expr(this, expr); } - ExprForLoop(ref pat, _, _, _) => { + ast::ExprForLoop(ref pat, _, _, _) => { this.pat_bindings(&**pat, |this, ln, var, sp, id| { this.warn_about_unused(sp, id, ln, var); }); @@ -1485,20 +1487,22 @@ fn check_expr(this: &mut Liveness, expr: &Expr) { } // no correctness conditions related to liveness - ExprCall(..) | ExprMethodCall(..) | ExprIf(..) | ExprMatch(..) | - ExprWhile(..) | ExprLoop(..) | ExprIndex(..) | ExprField(..) | - ExprTupField(..) | ExprVec(..) | ExprTup(..) | ExprBinary(..) | - ExprCast(..) | ExprUnary(..) | ExprRet(..) | ExprBreak(..) | - ExprAgain(..) | ExprLit(_) | ExprBlock(..) | ExprSlice(..) | - ExprMac(..) | ExprAddrOf(..) | ExprStruct(..) | ExprRepeat(..) | - ExprParen(..) | ExprFnBlock(..) | ExprProc(..) | ExprUnboxedFn(..) | - ExprPath(..) | ExprBox(..) => { + ast::ExprCall(..) | ast::ExprMethodCall(..) | ast::ExprIf(..) | + ast::ExprMatch(..) | ast::ExprWhile(..) | ast::ExprLoop(..) | + ast::ExprIndex(..) | ast::ExprField(..) | ast::ExprTupField(..) | + ast::ExprVec(..) | ast::ExprTup(..) | ast::ExprBinary(..) | + ast::ExprCast(..) | ast::ExprUnary(..) | ast::ExprRet(..) | + ast::ExprBreak(..) | ast::ExprAgain(..) | ast::ExprLit(_) | + ast::ExprBlock(..) | ast::ExprMac(..) | ast::ExprAddrOf(..) | + ast::ExprStruct(..) | ast::ExprRepeat(..) | ast::ExprParen(..) | + ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprUnboxedFn(..) | + ast::ExprPath(..) | ast::ExprBox(..) | ast::ExprSlice(..) => { visit::walk_expr(this, expr); } - ExprIfLet(..) => { + ast::ExprIfLet(..) => { this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet"); } - ExprWhileLet(..) => { + ast::ExprWhileLet(..) => { this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } } @@ -1506,17 +1510,17 @@ fn check_expr(this: &mut Liveness, expr: &Expr) { fn check_fn(_v: &Liveness, _fk: FnKind, - _decl: &FnDecl, - _body: &Block, + _decl: &ast::FnDecl, + _body: &ast::Block, _sp: Span, _id: NodeId) { // do not check contents of nested fns } impl<'a, 'tcx> Liveness<'a, 'tcx> { - fn fn_ret(&self, id: NodeId) -> ty::FnOutput { + fn fn_ret(&self, id: NodeId) -> ty::FnOutput<'tcx> { let fn_ty = ty::node_id_to_type(self.ir.tcx, id); - match ty::get(fn_ty).sty { + match fn_ty.sty { ty::ty_unboxed_closure(closure_def_id, _, _) => self.ir.tcx.unboxed_closures() .borrow() @@ -1534,7 +1538,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { sp: Span, _fk: FnKind, entry_ln: LiveNode, - body: &Block) { + body: &ast::Block) { match self.fn_ret(id) { ty::FnConverging(t_ret) if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() => { @@ -1545,9 +1549,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let ends_with_stmt = match body.expr { None if body.stmts.len() > 0 => match body.stmts.last().unwrap().node { - StmtSemi(ref e, _) => { - let t_stmt = ty::expr_ty(self.ir.tcx, &**e); - ty::get(t_stmt).sty == ty::get(t_ret).sty + ast::StmtSemi(ref e, _) => { + ty::expr_ty(self.ir.tcx, &**e) == t_ret }, _ => false }, @@ -1581,7 +1584,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn check_lvalue(&mut self, expr: &Expr) { match expr.node { - ExprPath(_) => { + ast::ExprPath(_) => { match self.ir.tcx.def_map.borrow()[expr.id].clone() { DefLocal(nid) => { // Assignment to an immutable variable or argument: only legal @@ -1613,7 +1616,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } } - fn warn_about_unused_args(&self, decl: &FnDecl, entry_ln: LiveNode) { + fn warn_about_unused_args(&self, decl: &ast::FnDecl, entry_ln: LiveNode) { for arg in decl.inputs.iter() { pat_util::pat_bindings(&self.ir.tcx.def_map, &*arg.pat, @@ -1628,7 +1631,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } } - fn warn_about_unused_or_dead_vars_in_pat(&mut self, pat: &Pat) { + fn warn_about_unused_or_dead_vars_in_pat(&mut self, pat: &ast::Pat) { self.pat_bindings(pat, |this, ln, var, sp, id| { if !this.warn_about_unused(sp, id, ln, var) { this.warn_about_dead_assign(sp, id, ln, var); diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index c9e5bbbc54e1d..93c2e8f0d9933 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -74,7 +74,7 @@ pub use self::deref_kind::*; pub use self::categorization::*; use middle::def; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck; use util::nodemap::{DefIdMap, NodeMap}; use util::ppaux::{ty_to_string, Repr}; @@ -90,14 +90,14 @@ use std::cell::RefCell; use std::rc::Rc; #[deriving(Clone, PartialEq, Show)] -pub enum categorization { - cat_rvalue(ty::Region), // temporary val, argument is its scope +pub enum categorization<'tcx> { + cat_rvalue(ty::Region), // temporary val, argument is its scope cat_static_item, - cat_upvar(Upvar), // upvar referenced by closure env - cat_local(ast::NodeId), // local variable - cat_deref(cmt, uint, PointerKind), // deref of a ptr - cat_interior(cmt, InteriorKind), // something interior: field, tuple, etc - cat_downcast(cmt), // selects a particular enum variant (*1) + cat_upvar(Upvar), // upvar referenced by closure env + cat_local(ast::NodeId), // local variable + cat_deref(cmt<'tcx>, uint, PointerKind), // deref of a ptr + cat_interior(cmt<'tcx>, InteriorKind), // something interior: field, tuple, etc + cat_downcast(cmt<'tcx>), // selects a particular enum variant (*1) // (*1) downcast is only required if the enum has more than one variant } @@ -175,16 +175,16 @@ pub enum Note { // (`@T`). So use `cmt.ty` to find the type of the value in a consistent // fashion. For more details, see the method `cat_pattern` #[deriving(Clone, PartialEq, Show)] -pub struct cmt_ { - pub id: ast::NodeId, // id of expr/pat producing this value +pub struct cmt_<'tcx> { + pub id: ast::NodeId, // id of expr/pat producing this value pub span: Span, // span of same expr/pat - pub cat: categorization, // categorization of expr + pub cat: categorization<'tcx>, // categorization of expr pub mutbl: MutabilityCategory, // mutability of expr as lvalue - pub ty: ty::t, // type of the expr (*see WARNING above*) + pub ty: Ty<'tcx>, // type of the expr (*see WARNING above*) pub note: Note, // Note about the provenance of this cmt } -pub type cmt = Rc; +pub type cmt<'tcx> = Rc>; // We pun on *T to mean both actual deref of a ptr as well // as accessing of components: @@ -196,8 +196,8 @@ pub enum deref_kind { // Categorizes a derefable type. Note that we include vectors and strings as // derefable (we model an index as the combination of a deref and then a // pointer adjustment). -pub fn opt_deref_kind(t: ty::t) -> Option { - match ty::get(t).sty { +pub fn opt_deref_kind(t: Ty) -> Option { + match t.sty { ty::ty_uniq(_) | ty::ty_closure(box ty::ClosureTy {store: ty::UniqTraitStore, ..}) => { Some(deref_ptr(OwnedPtr)) @@ -232,7 +232,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option { } } -pub fn deref_kind(tcx: &ty::ctxt, t: ty::t) -> deref_kind { +pub fn deref_kind<'tcx>(tcx: &ty::ctxt<'tcx>, t: Ty<'tcx>) -> deref_kind { debug!("deref_kind {}", ty_to_string(tcx, t)); match opt_deref_kind(t) { Some(k) => k, @@ -285,16 +285,16 @@ pub type McResult = Result; */ pub trait Typer<'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>; - fn node_ty(&self, id: ast::NodeId) -> McResult; - fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option; - fn adjustments<'a>(&'a self) -> &'a RefCell>; + fn node_ty(&self, id: ast::NodeId) -> McResult>; + fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option>; + fn adjustments<'a>(&'a self) -> &'a RefCell>>; fn is_method_call(&self, id: ast::NodeId) -> bool; fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option; fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow; fn capture_mode(&self, closure_expr_id: ast::NodeId) -> ast::CaptureClause; fn unboxed_closures<'a>(&'a self) - -> &'a RefCell>; + -> &'a RefCell>>; } impl MutabilityCategory { @@ -393,26 +393,26 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { self.typer.tcx() } - fn expr_ty(&self, expr: &ast::Expr) -> McResult { + fn expr_ty(&self, expr: &ast::Expr) -> McResult> { self.typer.node_ty(expr.id) } - fn expr_ty_adjusted(&self, expr: &ast::Expr) -> McResult { + fn expr_ty_adjusted(&self, expr: &ast::Expr) -> McResult> { let unadjusted_ty = if_ok!(self.expr_ty(expr)); Ok(ty::adjust_ty(self.tcx(), expr.span, expr.id, unadjusted_ty, self.typer.adjustments().borrow().get(&expr.id), |method_call| self.typer.node_method_ty(method_call))) } - fn node_ty(&self, id: ast::NodeId) -> McResult { + fn node_ty(&self, id: ast::NodeId) -> McResult> { self.typer.node_ty(id) } - fn pat_ty(&self, pat: &ast::Pat) -> McResult { + fn pat_ty(&self, pat: &ast::Pat) -> McResult> { self.typer.node_ty(pat.id) } - pub fn cat_expr(&self, expr: &ast::Expr) -> McResult { + pub fn cat_expr(&self, expr: &ast::Expr) -> McResult> { match self.typer.adjustments().borrow().get(&expr.id) { None => { // No adjustments. @@ -455,7 +455,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { pub fn cat_expr_autoderefd(&self, expr: &ast::Expr, autoderefs: uint) - -> McResult { + -> McResult> { let mut cmt = if_ok!(self.cat_expr_unadjusted(expr)); debug!("cat_expr_autoderefd: autoderefs={}, cmt={}", autoderefs, @@ -466,7 +466,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { return Ok(cmt); } - pub fn cat_expr_unadjusted(&self, expr: &ast::Expr) -> McResult { + pub fn cat_expr_unadjusted(&self, expr: &ast::Expr) -> McResult> { debug!("cat_expr: id={} expr={}", expr.id, expr.repr(self.tcx())); let expr_ty = if_ok!(self.expr_ty(expr)); @@ -546,9 +546,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { pub fn cat_def(&self, id: ast::NodeId, span: Span, - expr_ty: ty::t, + expr_ty: Ty<'tcx>, def: def::Def) - -> McResult { + -> McResult> { debug!("cat_def: id={} expr={} def={}", id, expr_ty.repr(self.tcx()), def); @@ -585,7 +585,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { def::DefUpvar(var_id, fn_node_id, _) => { let ty = if_ok!(self.node_ty(fn_node_id)); - match ty::get(ty).sty { + match ty.sty { ty::ty_closure(ref closure_ty) => { // Translate old closure type info into unboxed // closure kind/capture mode @@ -644,7 +644,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { kind: ty::UnboxedClosureKind, mode: ast::CaptureClause, is_unboxed: bool) - -> McResult { + -> McResult> { // An upvar can have up to 3 components. The base is a // `cat_upvar`. Next, we add a deref through the implicit // environment pointer with an anonymous free region 'env and @@ -804,11 +804,11 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { pub fn cat_rvalue_node(&self, id: ast::NodeId, span: Span, - expr_ty: ty::t) - -> cmt { + expr_ty: Ty<'tcx>) + -> cmt<'tcx> { match self.typer.temporary_scope(id) { Some(scope) => { - match ty::get(expr_ty).sty { + match expr_ty.sty { ty::ty_vec(_, Some(0)) => self.cat_rvalue(id, span, ty::ReStatic, expr_ty), _ => self.cat_rvalue(id, span, ty::ReScope(scope), expr_ty) } @@ -823,7 +823,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { cmt_id: ast::NodeId, span: Span, temp_scope: ty::Region, - expr_ty: ty::t) -> cmt { + expr_ty: Ty<'tcx>) -> cmt<'tcx> { Rc::new(cmt_ { id:cmt_id, span:span, @@ -836,10 +836,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { pub fn cat_field(&self, node: &N, - base_cmt: cmt, + base_cmt: cmt<'tcx>, f_name: ast::Name, - f_ty: ty::t) - -> cmt { + f_ty: Ty<'tcx>) + -> cmt<'tcx> { Rc::new(cmt_ { id: node.id(), span: node.span(), @@ -852,10 +852,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { pub fn cat_tup_field(&self, node: &N, - base_cmt: cmt, + base_cmt: cmt<'tcx>, f_idx: uint, - f_ty: ty::t) - -> cmt { + f_ty: Ty<'tcx>) + -> cmt<'tcx> { Rc::new(cmt_ { id: node.id(), span: node.span(), @@ -868,10 +868,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { fn cat_deref(&self, node: &N, - base_cmt: cmt, + base_cmt: cmt<'tcx>, deref_cnt: uint, implicit: bool) - -> cmt { + -> cmt<'tcx> { let adjustment = match self.typer.adjustments().borrow().get(&node.id()) { Some(adj) if ty::adjust_is_object(adj) => typeck::AutoObject, _ if deref_cnt != 0 => typeck::AutoDeref(deref_cnt), @@ -907,11 +907,11 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { fn cat_deref_common(&self, node: &N, - base_cmt: cmt, + base_cmt: cmt<'tcx>, deref_cnt: uint, - deref_ty: ty::t, + deref_ty: Ty<'tcx>, implicit: bool) - -> cmt { + -> cmt<'tcx> { let (m, cat) = match deref_kind(self.tcx(), base_cmt.ty) { deref_ptr(ptr) => { let ptr = if implicit { @@ -944,8 +944,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { pub fn cat_index(&self, elt: &N, - mut base_cmt: cmt) - -> cmt { + mut base_cmt: cmt<'tcx>) + -> cmt<'tcx> { //! Creates a cmt for an indexing operation (`[]`). //! //! One subtle aspect of indexing that may not be @@ -988,11 +988,11 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { let m = base_cmt.mutbl.inherit(); return interior(elt, base_cmt.clone(), base_cmt.ty, m, element_ty); - fn interior(elt: &N, - of_cmt: cmt, - vec_ty: ty::t, - mutbl: MutabilityCategory, - element_ty: ty::t) -> cmt + fn interior<'tcx, N: ast_node>(elt: &N, + of_cmt: cmt<'tcx>, + vec_ty: Ty<'tcx>, + mutbl: MutabilityCategory, + element_ty: Ty<'tcx>) -> cmt<'tcx> { Rc::new(cmt_ { id:elt.id(), @@ -1009,8 +1009,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { // underlying vec. fn deref_vec(&self, elt: &N, - base_cmt: cmt) - -> cmt { + base_cmt: cmt<'tcx>) + -> cmt<'tcx> { match deref_kind(self.tcx(), base_cmt.ty) { deref_ptr(ptr) => { // for unique ptrs, we inherit mutability from the @@ -1038,9 +1038,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { } pub fn cat_slice_pattern(&self, - vec_cmt: cmt, + vec_cmt: cmt<'tcx>, slice_pat: &ast::Pat) - -> McResult<(cmt, ast::Mutability, ty::Region)> { + -> McResult<(cmt<'tcx>, ast::Mutability, ty::Region)> { /*! * Given a pattern P like: `[_, ..Q, _]`, where `vec_cmt` is * the cmt for `P`, `slice_pat` is the pattern `Q`, returns: @@ -1060,7 +1060,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { fn vec_slice_info(tcx: &ty::ctxt, pat: &ast::Pat, - slice_ty: ty::t) + slice_ty: Ty) -> (ast::Mutability, ty::Region) { /*! * In a pattern like [a, b, ..c], normally `c` has slice type, @@ -1069,8 +1069,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { * to recurse through rptrs. */ - match ty::get(slice_ty).sty { - ty::ty_rptr(r, ref mt) => match ty::get(mt.ty).sty { + match slice_ty.sty { + ty::ty_rptr(r, ref mt) => match mt.ty.sty { ty::ty_vec(_, None) => (mt.mutbl, r), _ => vec_slice_info(tcx, pat, mt.ty), }, @@ -1085,10 +1085,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { pub fn cat_imm_interior(&self, node: &N, - base_cmt: cmt, - interior_ty: ty::t, + base_cmt: cmt<'tcx>, + interior_ty: Ty<'tcx>, interior: InteriorKind) - -> cmt { + -> cmt<'tcx> { Rc::new(cmt_ { id: node.id(), span: node.span(), @@ -1101,9 +1101,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { pub fn cat_downcast(&self, node: &N, - base_cmt: cmt, - downcast_ty: ty::t) - -> cmt { + base_cmt: cmt<'tcx>, + downcast_ty: Ty<'tcx>) + -> cmt<'tcx> { Rc::new(cmt_ { id: node.id(), span: node.span(), @@ -1115,10 +1115,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { } pub fn cat_pattern(&self, - cmt: cmt, + cmt: cmt<'tcx>, pat: &ast::Pat, op: |&MemCategorizationContext, - cmt, + cmt<'tcx>, &ast::Pat|) -> McResult<()> { // Here, `cmt` is the categorization for the value being @@ -1291,7 +1291,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { Ok(()) } - pub fn cmt_to_string(&self, cmt: &cmt_) -> String { + pub fn cmt_to_string(&self, cmt: &cmt_<'tcx>) -> String { fn upvar_to_string(upvar: &Upvar, is_copy: bool) -> String { if upvar.is_unboxed { let kind = match upvar.kind { @@ -1376,8 +1376,8 @@ pub enum AliasableReason { AliasableStaticMut(InteriorSafety), } -impl cmt_ { - pub fn guarantor(&self) -> cmt { +impl<'tcx> cmt_<'tcx> { + pub fn guarantor(&self) -> cmt<'tcx> { //! Returns `self` after stripping away any owned pointer derefs or //! interior content. The return value is basically the `cmt` which //! determines how long the value in `self` remains live. @@ -1400,7 +1400,8 @@ impl cmt_ { } } - pub fn freely_aliasable(&self, ctxt: &ty::ctxt) -> Option { + pub fn freely_aliasable(&self, ctxt: &ty::ctxt<'tcx>) + -> Option { /*! * Returns `Some(_)` if this lvalue represents a freely aliasable * pointer type. @@ -1455,7 +1456,7 @@ impl cmt_ { // Digs down through one or two layers of deref and grabs the cmt // for the upvar if a note indicates there is one. - pub fn upvar(&self) -> Option { + pub fn upvar(&self) -> Option> { match self.note { NoteClosureEnv(..) | NoteUpvarRef(..) => { Some(match self.cat { @@ -1474,8 +1475,8 @@ impl cmt_ { } } -impl Repr for cmt_ { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for cmt_<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("{{{} id:{} m:{} ty:{}}}", self.cat.repr(tcx), self.id, @@ -1484,8 +1485,8 @@ impl Repr for cmt_ { } } -impl Repr for categorization { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for categorization<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { cat_static_item | cat_rvalue(..) | @@ -1519,7 +1520,7 @@ pub fn ptr_sigil(ptr: PointerKind) -> &'static str { } } -impl Repr for InteriorKind { +impl<'tcx> Repr<'tcx> for InteriorKind { fn repr(&self, _tcx: &ty::ctxt) -> String { match *self { InteriorField(NamedField(fld)) => { @@ -1531,10 +1532,10 @@ impl Repr for InteriorKind { } } -fn element_kind(t: ty::t) -> ElementKind { - match ty::get(t).sty { +fn element_kind(t: Ty) -> ElementKind { + match t.sty { ty::ty_rptr(_, ty::mt{ty, ..}) | - ty::ty_uniq(ty) => match ty::get(ty).sty { + ty::ty_uniq(ty) => match ty.sty { ty::ty_vec(_, None) => VecElement, _ => OtherElement }, diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index bf524c85ed526..a51956797cad0 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -13,15 +13,15 @@ use middle::resolve; use middle::ty; use util::nodemap::FnvHashMap; -use syntax::ast::*; +use syntax::ast; use syntax::ast_util::{walk_pat}; use syntax::codemap::{Span, DUMMY_SP}; -pub type PatIdMap = FnvHashMap; +pub type PatIdMap = FnvHashMap; // This is used because same-named variables in alternative patterns need to // use the NodeId of their namesake in the first pattern. -pub fn pat_id_map(dm: &resolve::DefMap, pat: &Pat) -> PatIdMap { +pub fn pat_id_map(dm: &resolve::DefMap, pat: &ast::Pat) -> PatIdMap { let mut map = FnvHashMap::new(); pat_bindings(dm, pat, |_bm, p_id, _s, path1| { map.insert(path1.node, p_id); @@ -29,23 +29,27 @@ pub fn pat_id_map(dm: &resolve::DefMap, pat: &Pat) -> PatIdMap { map } -pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &ast::Pat) -> bool { match pat.node { - PatLit(_) | PatRange(_, _) => true, - PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => { + ast::PatLit(_) | ast::PatRange(_, _) => true, + ast::PatEnum(_, _) | + ast::PatIdent(_, _, None) | + ast::PatStruct(..) => { match dm.borrow().get(&pat.id) { Some(&DefVariant(..)) => true, _ => false } } - PatVec(_, _, _) => true, + ast::PatVec(_, _, _) => true, _ => false } } -pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &ast::Pat) -> bool { match pat.node { - PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => { + ast::PatEnum(_, _) | + ast::PatIdent(_, _, None) | + ast::PatStruct(..) => { match dm.borrow().get(&pat.id) { Some(&DefVariant(..)) | Some(&DefStruct(..)) => true, _ => false @@ -55,9 +59,9 @@ pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &Pat) -> bool { } } -pub fn pat_is_const(dm: &resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_is_const(dm: &resolve::DefMap, pat: &ast::Pat) -> bool { match pat.node { - PatIdent(_, _, None) | PatEnum(..) => { + ast::PatIdent(_, _, None) | ast::PatEnum(..) => { match dm.borrow().get(&pat.id) { Some(&DefConst(..)) => true, _ => false @@ -67,9 +71,9 @@ pub fn pat_is_const(dm: &resolve::DefMap, pat: &Pat) -> bool { } } -pub fn pat_is_binding(dm: &resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_is_binding(dm: &resolve::DefMap, pat: &ast::Pat) -> bool { match pat.node { - PatIdent(..) => { + ast::PatIdent(..) => { !pat_is_variant_or_struct(dm, pat) && !pat_is_const(dm, pat) } @@ -77,10 +81,10 @@ pub fn pat_is_binding(dm: &resolve::DefMap, pat: &Pat) -> bool { } } -pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &ast::Pat) -> bool { match pat.node { - PatIdent(..) => pat_is_binding(dm, pat), - PatWild(_) => true, + ast::PatIdent(..) => pat_is_binding(dm, pat), + ast::PatWild(_) => true, _ => false } } @@ -88,11 +92,11 @@ pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &Pat) -> bool { /// Call `it` on every "binding" in a pattern, e.g., on `a` in /// `match foo() { Some(a) => (), None => () }` pub fn pat_bindings(dm: &resolve::DefMap, - pat: &Pat, - it: |BindingMode, NodeId, Span, &SpannedIdent|) { + pat: &ast::Pat, + it: |ast::BindingMode, ast::NodeId, Span, &ast::SpannedIdent|) { walk_pat(pat, |p| { match p.node { - PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => { + ast::PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => { it(binding_mode, p.id, p.span, pth); } _ => {} @@ -103,7 +107,7 @@ pub fn pat_bindings(dm: &resolve::DefMap, /// Checks if the pattern contains any patterns that bind something to /// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`. -pub fn pat_contains_bindings(dm: &resolve::DefMap, pat: &Pat) -> bool { +pub fn pat_contains_bindings(dm: &resolve::DefMap, pat: &ast::Pat) -> bool { let mut contains_bindings = false; walk_pat(pat, |p| { if pat_is_binding(dm, p) { @@ -116,9 +120,9 @@ pub fn pat_contains_bindings(dm: &resolve::DefMap, pat: &Pat) -> bool { contains_bindings } -pub fn simple_identifier<'a>(pat: &'a Pat) -> Option<&'a Ident> { +pub fn simple_identifier<'a>(pat: &'a ast::Pat) -> Option<&'a ast::Ident> { match pat.node { - PatIdent(BindByValue(_), ref path1, None) => { + ast::PatIdent(ast::BindByValue(_), ref path1, None) => { Some(&path1.node) } _ => { @@ -127,12 +131,12 @@ pub fn simple_identifier<'a>(pat: &'a Pat) -> Option<&'a Ident> { } } -pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path { - ty::with_path(tcx, id, |mut path| Path { +pub fn def_to_path(tcx: &ty::ctxt, id: ast::DefId) -> ast::Path { + ty::with_path(tcx, id, |mut path| ast::Path { global: false, - segments: path.last().map(|elem| PathSegment { - identifier: Ident::new(elem.name()), - parameters: PathParameters::none(), + segments: path.last().map(|elem| ast::PathSegment { + identifier: ast::Ident::new(elem.name()), + parameters: ast::PathParameters::none(), }).into_iter().collect(), span: DUMMY_SP, }) diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 098108b25e5d4..c2835ba5647e8 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -19,7 +19,7 @@ use std::mem::replace; use metadata::csearch; use middle::def; use middle::resolve; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::{MethodCall, MethodMap, MethodOrigin, MethodParam, MethodTypeParam}; use middle::typeck::{MethodStatic, MethodStaticUnboxedClosure, MethodObject, MethodTraitObject}; use util::nodemap::{NodeMap, NodeSet}; @@ -32,7 +32,7 @@ use syntax::parse::token; use syntax::visit; use syntax::visit::Visitor; -type Context<'a> = (&'a MethodMap, &'a resolve::ExportMap2); +type Context<'a, 'tcx> = (&'a MethodMap<'tcx>, &'a resolve::ExportMap2); /// A set of AST nodes exported by the crate. pub type ExportedItems = NodeSet; @@ -667,7 +667,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { } let struct_type = ty::lookup_item_type(self.tcx, id).ty; - let struct_desc = match ty::get(struct_type).sty { + let struct_desc = match struct_type.sty { ty::ty_struct(_, _) => format!("struct `{}`", ty::item_path_str(self.tcx, id)), // struct variant fields have inherited visibility @@ -837,7 +837,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &ast::Expr) { match expr.node { ast::ExprField(ref base, ident, _) => { - match ty::get(ty::expr_ty_adjusted(self.tcx, &**base)).sty { + match ty::expr_ty_adjusted(self.tcx, &**base).sty { ty::ty_struct(id, _) => { self.check_field(expr.span, id, NamedField(ident.node)); } @@ -845,7 +845,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { } } ast::ExprTupField(ref base, idx, _) => { - match ty::get(ty::expr_ty_adjusted(self.tcx, &**base)).sty { + match ty::expr_ty_adjusted(self.tcx, &**base).sty { ty::ty_struct(id, _) => { self.check_field(expr.span, id, UnnamedField(idx.node)); } @@ -867,7 +867,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { } } ast::ExprStruct(_, ref fields, _) => { - match ty::get(ty::expr_ty(self.tcx, expr)).sty { + match ty::expr_ty(self.tcx, expr).sty { ty::ty_struct(id, _) => { for field in (*fields).iter() { self.check_field(expr.span, id, @@ -976,7 +976,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { match pattern.node { ast::PatStruct(_, ref fields, _) => { - match ty::get(ty::pat_ty(self.tcx, pattern)).sty { + match ty::pat_ty(self.tcx, pattern).sty { ty::ty_struct(id, _) => { for field in fields.iter() { self.check_field(pattern.span, id, @@ -1007,7 +1007,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { // Patterns which bind no fields are allowable (the path is check // elsewhere). ast::PatEnum(_, Some(ref fields)) => { - match ty::get(ty::pat_ty(self.tcx, pattern)).sty { + match ty::pat_ty(self.tcx, pattern).sty { ty::ty_struct(id, _) => { for (i, field) in fields.iter().enumerate() { match field.node { diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index f3d62988cc091..0c0861eda3e7a 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -23,7 +23,7 @@ Most of the documentation on regions can be found in use session::Session; use middle::ty::{FreeRegion}; -use middle::ty; +use middle::ty::{mod, Ty}; use util::nodemap::{FnvHashMap, NodeMap, NodeSet}; use util::common::can_reach; diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index 4fabdabf3db4b..bac417c8218a4 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -13,7 +13,7 @@ pub use self::ParamSpace::*; pub use self::RegionSubsts::*; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty_fold::{mod, TypeFoldable, TypeFolder}; use util::ppaux::Repr; @@ -31,8 +31,8 @@ use syntax::codemap::{Span, DUMMY_SP}; * `ParamSpace`). */ #[deriving(Clone, PartialEq, Eq, Hash, Show)] -pub struct Substs { - pub types: VecPerParamSpace, +pub struct Substs<'tcx> { + pub types: VecPerParamSpace>, pub regions: RegionSubsts, } @@ -46,45 +46,45 @@ pub enum RegionSubsts { NonerasedRegions(VecPerParamSpace) } -impl Substs { - pub fn new(t: VecPerParamSpace, +impl<'tcx> Substs<'tcx> { + pub fn new(t: VecPerParamSpace>, r: VecPerParamSpace) - -> Substs + -> Substs<'tcx> { Substs { types: t, regions: NonerasedRegions(r) } } - pub fn new_type(t: Vec, + pub fn new_type(t: Vec>, r: Vec) - -> Substs + -> Substs<'tcx> { Substs::new(VecPerParamSpace::new(t, Vec::new(), Vec::new(), Vec::new()), VecPerParamSpace::new(r, Vec::new(), Vec::new(), Vec::new())) } - pub fn new_trait(t: Vec, + pub fn new_trait(t: Vec>, r: Vec, - a: Vec, - s: ty::t) - -> Substs + a: Vec>, + s: Ty<'tcx>) + -> Substs<'tcx> { Substs::new(VecPerParamSpace::new(t, vec!(s), a, Vec::new()), VecPerParamSpace::new(r, Vec::new(), Vec::new(), Vec::new())) } - pub fn erased(t: VecPerParamSpace) -> Substs + pub fn erased(t: VecPerParamSpace>) -> Substs<'tcx> { Substs { types: t, regions: ErasedRegions } } - pub fn empty() -> Substs { + pub fn empty() -> Substs<'tcx> { Substs { types: VecPerParamSpace::empty(), regions: NonerasedRegions(VecPerParamSpace::empty()), } } - pub fn trans_empty() -> Substs { + pub fn trans_empty() -> Substs<'tcx> { Substs { types: VecPerParamSpace::empty(), regions: ErasedRegions @@ -111,18 +111,18 @@ impl Substs { } } - pub fn self_ty(&self) -> Option { +pub fn self_ty(&self) -> Option> { self.types.get_self().map(|&t| t) } - pub fn with_self_ty(&self, self_ty: ty::t) -> Substs { + pub fn with_self_ty(&self, self_ty: Ty<'tcx>) -> Substs<'tcx> { assert!(self.self_ty().is_none()); let mut s = (*self).clone(); s.types.push(SelfSpace, self_ty); s } - pub fn erase_regions(self) -> Substs { + pub fn erase_regions(self) -> Substs<'tcx> { let Substs { types, regions: _ } = self; Substs { types: types, regions: ErasedRegions } } @@ -154,9 +154,9 @@ impl Substs { } pub fn with_method(self, - m_types: Vec, + m_types: Vec>, m_regions: Vec) - -> Substs + -> Substs<'tcx> { let Substs { types, regions } = self; let types = types.with_vec(FnSpace, m_types); @@ -536,21 +536,21 @@ impl<'a,T> Iterator<(ParamSpace, uint, &'a T)> for EnumeratedItems<'a,T> { // `foo`. Or use `foo.subst_spanned(tcx, substs, Some(span))` when // there is more information available (for better errors). -pub trait Subst { - fn subst(&self, tcx: &ty::ctxt, substs: &Substs) -> Self { +pub trait Subst<'tcx> { + fn subst(&self, tcx: &ty::ctxt<'tcx>, substs: &Substs<'tcx>) -> Self { self.subst_spanned(tcx, substs, None) } - fn subst_spanned(&self, tcx: &ty::ctxt, - substs: &Substs, + fn subst_spanned(&self, tcx: &ty::ctxt<'tcx>, + substs: &Substs<'tcx>, span: Option) -> Self; } -impl Subst for T { +impl<'tcx, T:TypeFoldable<'tcx>> Subst<'tcx> for T { fn subst_spanned(&self, - tcx: &ty::ctxt, - substs: &Substs, + tcx: &ty::ctxt<'tcx>, + substs: &Substs<'tcx>, span: Option) -> T { @@ -569,13 +569,13 @@ impl Subst for T { struct SubstFolder<'a, 'tcx: 'a> { tcx: &'a ty::ctxt<'tcx>, - substs: &'a Substs, + substs: &'a Substs<'tcx>, // The location for which the substitution is performed, if available. span: Option, // The root type that is being substituted, if available. - root_ty: Option, + root_ty: Option>, // Depth of type stack ty_stack_depth: uint, @@ -629,7 +629,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { } } - fn fold_ty(&mut self, t: ty::t) -> ty::t { + fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { if !ty::type_needs_subst(t) { return t; } @@ -641,7 +641,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { } self.ty_stack_depth += 1; - let t1 = match ty::get(t).sty { + let t1 = match t.sty { ty::ty_param(p) => { self.ty_for_param(p, t) } @@ -661,7 +661,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { } impl<'a,'tcx> SubstFolder<'a,'tcx> { - fn ty_for_param(&self, p: ty::ParamTy, source_ty: ty::t) -> ty::t { + fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> { // Look up the type in the substitutions. It really should be in there. let opt_ty = self.substs.types.opt_get(p.space, p.idx); let ty = match opt_ty { @@ -684,7 +684,7 @@ impl<'a,'tcx> SubstFolder<'a,'tcx> { self.shift_regions_through_binders(ty) } - fn shift_regions_through_binders(&self, ty: ty::t) -> ty::t { + fn shift_regions_through_binders(&self, ty: Ty<'tcx>) -> Ty<'tcx> { /*! * It is sometimes necessary to adjust the debruijn indices * during substitution. This occurs when we are substituting a diff --git a/src/librustc/middle/traits/coherence.rs b/src/librustc/middle/traits/coherence.rs index 405f6509e596d..c84a2a0d11e6b 100644 --- a/src/librustc/middle/traits/coherence.rs +++ b/src/librustc/middle/traits/coherence.rs @@ -16,7 +16,7 @@ use super::util; use middle::subst; use middle::subst::Subst; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::infer::{mod, InferCtxt}; use syntax::ast; use syntax::codemap::DUMMY_SP; @@ -76,13 +76,10 @@ pub fn impl_is_local(tcx: &ty::ctxt, trait_ref.input_types().iter().any(|&t| ty_is_local(tcx, t)) } -pub fn ty_is_local(tcx: &ty::ctxt, - ty: ty::t) - -> bool -{ +pub fn ty_is_local<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool { debug!("ty_is_local({})", ty.repr(tcx)); - match ty::get(ty).sty { + match ty.sty { ty::ty_bool | ty::ty_char | ty::ty_int(..) | diff --git a/src/librustc/middle/traits/fulfill.rs b/src/librustc/middle/traits/fulfill.rs index ff5d80c8a16a2..5b8edacb28d67 100644 --- a/src/librustc/middle/traits/fulfill.rs +++ b/src/librustc/middle/traits/fulfill.rs @@ -31,10 +31,10 @@ use super::select::SelectionContext; * method `select_all_or_error` can be used to report any remaining * ambiguous cases as errors. */ -pub struct FulfillmentContext { +pub struct FulfillmentContext<'tcx> { // A list of all obligations that have been registered with this // fulfillment context. - trait_obligations: Vec, + trait_obligations: Vec>, // Remembers the count of trait obligations that we have already // attempted to select. This is used to avoid repeating work @@ -42,8 +42,8 @@ pub struct FulfillmentContext { attempted_mark: uint, } -impl FulfillmentContext { - pub fn new() -> FulfillmentContext { +impl<'tcx> FulfillmentContext<'tcx> { + pub fn new() -> FulfillmentContext<'tcx> { FulfillmentContext { trait_obligations: Vec::new(), attempted_mark: 0, @@ -51,19 +51,19 @@ impl FulfillmentContext { } pub fn register_obligation(&mut self, - tcx: &ty::ctxt, - obligation: Obligation) + tcx: &ty::ctxt<'tcx>, + obligation: Obligation<'tcx>) { debug!("register_obligation({})", obligation.repr(tcx)); assert!(!obligation.trait_ref.has_escaping_regions()); self.trait_obligations.push(obligation); } - pub fn select_all_or_error<'a,'tcx>(&mut self, - infcx: &InferCtxt<'a,'tcx>, - param_env: &ty::ParameterEnvironment, - typer: &Typer<'tcx>) - -> Result<(),Vec> + pub fn select_all_or_error<'a>(&mut self, + infcx: &InferCtxt<'a,'tcx>, + param_env: &ty::ParameterEnvironment<'tcx>, + typer: &Typer<'tcx>) + -> Result<(),Vec>> { try!(self.select_where_possible(infcx, param_env, typer)); @@ -81,11 +81,11 @@ impl FulfillmentContext { } } - pub fn select_new_obligations<'a,'tcx>(&mut self, - infcx: &InferCtxt<'a,'tcx>, - param_env: &ty::ParameterEnvironment, - typer: &Typer<'tcx>) - -> Result<(),Vec> + pub fn select_new_obligations<'a>(&mut self, + infcx: &InferCtxt<'a,'tcx>, + param_env: &ty::ParameterEnvironment<'tcx>, + typer: &Typer<'tcx>) + -> Result<(),Vec>> { /*! * Attempts to select obligations that were registered since @@ -99,20 +99,20 @@ impl FulfillmentContext { self.select(&mut selcx, true) } - pub fn select_where_possible<'a,'tcx>(&mut self, - infcx: &InferCtxt<'a,'tcx>, - param_env: &ty::ParameterEnvironment, - typer: &Typer<'tcx>) - -> Result<(),Vec> + pub fn select_where_possible<'a>(&mut self, + infcx: &InferCtxt<'a,'tcx>, + param_env: &ty::ParameterEnvironment<'tcx>, + typer: &Typer<'tcx>) + -> Result<(),Vec>> { let mut selcx = SelectionContext::new(infcx, param_env, typer); self.select(&mut selcx, false) } - fn select(&mut self, - selcx: &mut SelectionContext, - only_new_obligations: bool) - -> Result<(),Vec> + fn select<'a>(&mut self, + selcx: &mut SelectionContext<'a, 'tcx>, + only_new_obligations: bool) + -> Result<(),Vec>> { /*! * Attempts to select obligations using `selcx`. If diff --git a/src/librustc/middle/traits/mod.rs b/src/librustc/middle/traits/mod.rs index c9c9e3bd4ffdc..c5eacf35da92f 100644 --- a/src/librustc/middle/traits/mod.rs +++ b/src/librustc/middle/traits/mod.rs @@ -19,7 +19,7 @@ pub use self::ObligationCauseCode::*; use middle::mem_categorization::Typer; use middle::subst; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::infer::InferCtxt; use std::rc::Rc; use std::slice::Items; @@ -50,23 +50,23 @@ mod util; * scope. The eventual result is usually a `Selection` (defined below). */ #[deriving(Clone)] -pub struct Obligation { - pub cause: ObligationCause, +pub struct Obligation<'tcx> { + pub cause: ObligationCause<'tcx>, pub recursion_depth: uint, - pub trait_ref: Rc, + pub trait_ref: Rc>, } /** * Why did we incur this obligation? Used for error reporting. */ #[deriving(Clone)] -pub struct ObligationCause { +pub struct ObligationCause<'tcx> { pub span: Span, - pub code: ObligationCauseCode + pub code: ObligationCauseCode<'tcx> } #[deriving(Clone)] -pub enum ObligationCauseCode { +pub enum ObligationCauseCode<'tcx> { /// Not well classified or should be obvious from span. MiscObligation, @@ -75,7 +75,7 @@ pub enum ObligationCauseCode { ItemObligation(ast::DefId), /// Obligation incurred due to an object cast. - ObjectCastObligation(/* Object type */ ty::t), + ObjectCastObligation(/* Object type */ Ty<'tcx>), /// To implement drop, type must be sendable. DropTrait, @@ -99,25 +99,25 @@ pub enum ObligationCauseCode { #[deriving(Clone,Show)] pub struct ErrorReported; -pub type Obligations = subst::VecPerParamSpace; +pub type Obligations<'tcx> = subst::VecPerParamSpace>; -pub type Selection = Vtable; +pub type Selection<'tcx> = Vtable<'tcx, Obligation<'tcx>>; #[deriving(Clone,Show)] -pub enum SelectionError { +pub enum SelectionError<'tcx> { Unimplemented, Overflow, - OutputTypeParameterMismatch(Rc, ty::type_err) + OutputTypeParameterMismatch(Rc>, ty::type_err<'tcx>) } -pub struct FulfillmentError { - pub obligation: Obligation, - pub code: FulfillmentErrorCode +pub struct FulfillmentError<'tcx> { + pub obligation: Obligation<'tcx>, + pub code: FulfillmentErrorCode<'tcx> } #[deriving(Clone)] -pub enum FulfillmentErrorCode { - CodeSelectionError(SelectionError), +pub enum FulfillmentErrorCode<'tcx> { + CodeSelectionError(SelectionError<'tcx>), CodeAmbiguity, } @@ -130,7 +130,7 @@ pub enum FulfillmentErrorCode { * to inconclusive type inference. * - `Err(e)`: error `e` occurred */ -pub type SelectionResult = Result, SelectionError>; +pub type SelectionResult<'tcx, T> = Result, SelectionError<'tcx>>; /** * Given the successful resolution of an obligation, the `Vtable` @@ -173,19 +173,19 @@ pub type SelectionResult = Result, SelectionError>; * See explanation on `VtableImplData`. */ #[deriving(Show,Clone)] -pub enum Vtable { +pub enum Vtable<'tcx, N> { /// Vtable identifying a particular impl. - VtableImpl(VtableImplData), + VtableImpl(VtableImplData<'tcx, N>), /// Vtable automatically generated for an unboxed closure. The def /// ID is the ID of the closure expression. This is a `VtableImpl` /// in spirit, but the impl is generated by the compiler and does /// not appear in the source. - VtableUnboxedClosure(ast::DefId, subst::Substs), + VtableUnboxedClosure(ast::DefId, subst::Substs<'tcx>), /// Successful resolution to an obligation provided by the caller /// for some type parameter. - VtableParam(VtableParamData), + VtableParam(VtableParamData<'tcx>), /// Successful resolution for a builtin trait. VtableBuiltin(VtableBuiltinData), @@ -204,9 +204,9 @@ pub enum Vtable { * impl, and nested obligations are satisfied later. */ #[deriving(Clone)] -pub struct VtableImplData { +pub struct VtableImplData<'tcx, N> { pub impl_def_id: ast::DefId, - pub substs: subst::Substs, + pub substs: subst::Substs<'tcx>, pub nested: subst::VecPerParamSpace } @@ -221,18 +221,19 @@ pub struct VtableBuiltinData { * on an instance of `T`, the vtable would be of type `VtableParam`. */ #[deriving(PartialEq,Eq,Clone)] -pub struct VtableParamData { +pub struct VtableParamData<'tcx> { // In the above example, this would `Eq` - pub bound: Rc, + pub bound: Rc>, } pub fn select_inherent_impl<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>, - param_env: &ty::ParameterEnvironment, + param_env: &ty::ParameterEnvironment<'tcx>, typer: &Typer<'tcx>, - cause: ObligationCause, + cause: ObligationCause<'tcx>, impl_def_id: ast::DefId, - self_ty: ty::t) - -> SelectionResult> + self_ty: Ty<'tcx>) + -> SelectionResult<'tcx, + VtableImplData<'tcx, Obligation<'tcx>>> { /*! * Matches the self type of the inherent impl `impl_def_id` @@ -281,11 +282,11 @@ pub fn overlapping_impls(infcx: &InferCtxt, coherence::impl_can_satisfy(infcx, impl2_def_id, impl1_def_id) } -pub fn obligations_for_generics(tcx: &ty::ctxt, - cause: ObligationCause, - generic_bounds: &ty::GenericBounds, - type_substs: &subst::VecPerParamSpace) - -> subst::VecPerParamSpace +pub fn obligations_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>, + cause: ObligationCause<'tcx>, + generic_bounds: &ty::GenericBounds<'tcx>, + type_substs: &subst::VecPerParamSpace>) + -> subst::VecPerParamSpace> { /*! * Given generic bounds from an impl like: @@ -305,46 +306,48 @@ pub fn obligations_for_generics(tcx: &ty::ctxt, util::obligations_for_generics(tcx, cause, 0, generic_bounds, type_substs) } -pub fn obligation_for_builtin_bound(tcx: &ty::ctxt, - cause: ObligationCause, - source_ty: ty::t, - builtin_bound: ty::BuiltinBound) - -> Result +pub fn obligation_for_builtin_bound<'tcx>(tcx: &ty::ctxt<'tcx>, + cause: ObligationCause<'tcx>, + source_ty: Ty<'tcx>, + builtin_bound: ty::BuiltinBound) + -> Result, ErrorReported> { util::obligation_for_builtin_bound(tcx, cause, builtin_bound, 0, source_ty) } -impl Obligation { - pub fn new(cause: ObligationCause, trait_ref: Rc) -> Obligation { +impl<'tcx> Obligation<'tcx> { + pub fn new(cause: ObligationCause<'tcx>, trait_ref: Rc>) + -> Obligation<'tcx> { Obligation { cause: cause, recursion_depth: 0, trait_ref: trait_ref } } - pub fn misc(span: Span, trait_ref: Rc) -> Obligation { + pub fn misc(span: Span, trait_ref: Rc>) -> Obligation<'tcx> { Obligation::new(ObligationCause::misc(span), trait_ref) } - pub fn self_ty(&self) -> ty::t { + pub fn self_ty(&self) -> Ty<'tcx> { self.trait_ref.self_ty() } } -impl ObligationCause { - pub fn new(span: Span, code: ObligationCauseCode) -> ObligationCause { +impl<'tcx> ObligationCause<'tcx> { + pub fn new(span: Span, code: ObligationCauseCode<'tcx>) + -> ObligationCause<'tcx> { ObligationCause { span: span, code: code } } - pub fn misc(span: Span) -> ObligationCause { + pub fn misc(span: Span) -> ObligationCause<'tcx> { ObligationCause { span: span, code: MiscObligation } } - pub fn dummy() -> ObligationCause { + pub fn dummy() -> ObligationCause<'tcx> { ObligationCause { span: DUMMY_SP, code: MiscObligation } } } -impl Vtable { +impl<'tcx, N> Vtable<'tcx, N> { pub fn iter_nested(&self) -> Items { match *self { VtableImpl(ref i) => i.iter_nested(), @@ -354,7 +357,7 @@ impl Vtable { } } - pub fn map_nested(&self, op: |&N| -> M) -> Vtable { + pub fn map_nested(&self, op: |&N| -> M) -> Vtable<'tcx, M> { match *self { VtableImpl(ref i) => VtableImpl(i.map_nested(op)), VtableUnboxedClosure(d, ref s) => VtableUnboxedClosure(d, s.clone()), @@ -363,7 +366,7 @@ impl Vtable { } } - pub fn map_move_nested(self, op: |N| -> M) -> Vtable { + pub fn map_move_nested(self, op: |N| -> M) -> Vtable<'tcx, M> { match self { VtableImpl(i) => VtableImpl(i.map_move_nested(op)), VtableUnboxedClosure(d, s) => VtableUnboxedClosure(d, s), @@ -373,14 +376,14 @@ impl Vtable { } } -impl VtableImplData { +impl<'tcx, N> VtableImplData<'tcx, N> { pub fn iter_nested(&self) -> Items { self.nested.iter() } pub fn map_nested(&self, op: |&N| -> M) - -> VtableImplData + -> VtableImplData<'tcx, M> { VtableImplData { impl_def_id: self.impl_def_id, @@ -389,7 +392,8 @@ impl VtableImplData { } } - pub fn map_move_nested(self, op: |N| -> M) -> VtableImplData { + pub fn map_move_nested(self, op: |N| -> M) + -> VtableImplData<'tcx, M> { let VtableImplData { impl_def_id, substs, nested } = self; VtableImplData { impl_def_id: impl_def_id, @@ -420,9 +424,9 @@ impl VtableBuiltinData { } } -impl FulfillmentError { - fn new(obligation: Obligation, code: FulfillmentErrorCode) - -> FulfillmentError +impl<'tcx> FulfillmentError<'tcx> { + fn new(obligation: Obligation<'tcx>, code: FulfillmentErrorCode<'tcx>) + -> FulfillmentError<'tcx> { FulfillmentError { obligation: obligation, code: code } } diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index a941d2b079e21..b884cb535d7a5 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -30,7 +30,7 @@ use super::{util}; use middle::fast_reject; use middle::mem_categorization::Typer; use middle::subst::{Subst, Substs, VecPerParamSpace}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::infer; use middle::typeck::infer::{InferCtxt, TypeSkolemizer}; use middle::ty_fold::TypeFoldable; @@ -42,7 +42,7 @@ use util::ppaux::Repr; pub struct SelectionContext<'cx, 'tcx:'cx> { infcx: &'cx InferCtxt<'cx, 'tcx>, - param_env: &'cx ty::ParameterEnvironment, + param_env: &'cx ty::ParameterEnvironment<'tcx>, typer: &'cx Typer<'tcx>+'cx, /// Skolemizer used specifically for skolemizing entries on the @@ -70,18 +70,19 @@ pub struct SelectionContext<'cx, 'tcx:'cx> { } // A stack that walks back up the stack frame. -struct ObligationStack<'prev> { - obligation: &'prev Obligation, +struct ObligationStack<'prev, 'tcx: 'prev> { + obligation: &'prev Obligation<'tcx>, /// Trait ref from `obligation` but skolemized with the /// selection-context's skolemizer. Used to check for recursion. - skol_trait_ref: Rc, + skol_trait_ref: Rc>, - previous: Option<&'prev ObligationStack<'prev>> + previous: Option<&'prev ObligationStack<'prev, 'tcx>> } -pub struct SelectionCache { - hashmap: RefCell, SelectionResult>>, +pub struct SelectionCache<'tcx> { + hashmap: RefCell>, + SelectionResult<'tcx, Candidate<'tcx>>>>, } pub enum MethodMatchResult { @@ -128,21 +129,21 @@ pub enum MethodMatchedData { * parameters) that would have to be inferred from the impl. */ #[deriving(PartialEq,Eq,Show,Clone)] -enum Candidate { +enum Candidate<'tcx> { BuiltinCandidate(ty::BuiltinBound), - ParamCandidate(VtableParamData), + ParamCandidate(VtableParamData<'tcx>), ImplCandidate(ast::DefId), - UnboxedClosureCandidate(/* closure */ ast::DefId, Substs), + UnboxedClosureCandidate(/* closure */ ast::DefId, Substs<'tcx>), ErrorCandidate, } -struct CandidateSet { - vec: Vec, +struct CandidateSet<'tcx> { + vec: Vec>, ambiguous: bool } -enum BuiltinBoundConditions { - If(Vec), +enum BuiltinBoundConditions<'tcx> { + If(Vec>), ParameterBuiltin, AmbiguousBuiltin } @@ -156,7 +157,7 @@ enum EvaluationResult { impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { pub fn new(infcx: &'cx InferCtxt<'cx, 'tcx>, - param_env: &'cx ty::ParameterEnvironment, + param_env: &'cx ty::ParameterEnvironment<'tcx>, typer: &'cx Typer<'tcx>) -> SelectionContext<'cx, 'tcx> { SelectionContext { @@ -169,7 +170,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } pub fn intercrate(infcx: &'cx InferCtxt<'cx, 'tcx>, - param_env: &'cx ty::ParameterEnvironment, + param_env: &'cx ty::ParameterEnvironment<'tcx>, typer: &'cx Typer<'tcx>) -> SelectionContext<'cx, 'tcx> { SelectionContext { @@ -200,7 +201,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // is `Vec:Iterable`, but the impl specifies // `impl Iterable for Vec`, than an error would result. - pub fn select(&mut self, obligation: &Obligation) -> SelectionResult { + pub fn select(&mut self, obligation: &Obligation<'tcx>) + -> SelectionResult<'tcx, Selection<'tcx>> { /*! * Evaluates whether the obligation can be satisfied. Returns * an indication of whether the obligation can be satisfied @@ -220,9 +222,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { pub fn select_inherent_impl(&mut self, impl_def_id: ast::DefId, - obligation_cause: ObligationCause, - obligation_self_ty: ty::t) - -> SelectionResult> + obligation_cause: ObligationCause<'tcx>, + obligation_self_ty: Ty<'tcx>) + -> SelectionResult<'tcx, VtableImplData<'tcx, Obligation<'tcx>>> { debug!("select_inherent_impl(impl_def_id={}, obligation_self_ty={})", impl_def_id.repr(self.tcx()), @@ -252,7 +254,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // we can be sure it does not. pub fn evaluate_obligation(&mut self, - obligation: &Obligation) + obligation: &Obligation<'tcx>) -> bool { /*! @@ -268,11 +270,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.evaluate_stack(&stack).may_apply() } - fn evaluate_builtin_bound_recursively(&mut self, - bound: ty::BuiltinBound, - previous_stack: &ObligationStack, - ty: ty::t) - -> EvaluationResult + fn evaluate_builtin_bound_recursively<'o>(&mut self, + bound: ty::BuiltinBound, + previous_stack: &ObligationStack<'o, 'tcx>, + ty: Ty<'tcx>) + -> EvaluationResult { let obligation = util::obligation_for_builtin_bound( @@ -292,10 +294,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - fn evaluate_obligation_recursively(&mut self, - previous_stack: Option<&ObligationStack>, - obligation: &Obligation) - -> EvaluationResult + fn evaluate_obligation_recursively<'o>(&mut self, + previous_stack: Option<&ObligationStack<'o, 'tcx>>, + obligation: &Obligation<'tcx>) + -> EvaluationResult { debug!("evaluate_obligation_recursively({})", obligation.repr(self.tcx())); @@ -308,9 +310,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { result } - fn evaluate_stack(&mut self, - stack: &ObligationStack) - -> EvaluationResult + fn evaluate_stack<'o>(&mut self, + stack: &ObligationStack<'o, 'tcx>) + -> EvaluationResult { // In intercrate mode, whenever any of the types are unbound, // there can always be an impl. Even if there are no impls in @@ -387,7 +389,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { pub fn evaluate_impl(&mut self, impl_def_id: ast::DefId, - obligation: &Obligation) + obligation: &Obligation<'tcx>) -> bool { /*! @@ -434,9 +436,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // the algorithm. pub fn evaluate_method_obligation(&mut self, - rcvr_ty: ty::t, - xform_self_ty: ty::t, - obligation: &Obligation) + rcvr_ty: Ty<'tcx>, + xform_self_ty: Ty<'tcx>, + obligation: &Obligation<'tcx>) -> MethodMatchResult { /*! @@ -562,9 +564,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } pub fn confirm_method_match(&mut self, - rcvr_ty: ty::t, - xform_self_ty: ty::t, - obligation: &Obligation, + rcvr_ty: Ty<'tcx>, + xform_self_ty: Ty<'tcx>, + obligation: &Obligation<'tcx>, data: MethodMatchedData) { /*! @@ -596,9 +598,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn match_method_precise(&mut self, - rcvr_ty: ty::t, - xform_self_ty: ty::t, - obligation: &Obligation) + rcvr_ty: Ty<'tcx>, + xform_self_ty: Ty<'tcx>, + obligation: &Obligation<'tcx>) -> Result<(),()> { /*! @@ -622,9 +624,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn assemble_method_candidates_from_impls(&mut self, - rcvr_ty: ty::t, - xform_self_ty: ty::t, - obligation: &Obligation) + rcvr_ty: Ty<'tcx>, + xform_self_ty: Ty<'tcx>, + obligation: &Obligation<'tcx>) -> Vec { /*! @@ -650,10 +652,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn match_method_coerce(&mut self, impl_def_id: ast::DefId, - rcvr_ty: ty::t, - xform_self_ty: ty::t, - obligation: &Obligation) - -> Result + rcvr_ty: Ty<'tcx>, + xform_self_ty: Ty<'tcx>, + obligation: &Obligation<'tcx>) + -> Result, ()> { /*! * Applies the *coercive match* procedure described in @@ -683,9 +685,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn winnow_method_impl(&mut self, impl_def_id: ast::DefId, - rcvr_ty: ty::t, - xform_self_ty: ty::t, - obligation: &Obligation) + rcvr_ty: Ty<'tcx>, + xform_self_ty: Ty<'tcx>, + obligation: &Obligation<'tcx>) -> bool { /*! @@ -724,9 +726,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // caller obligations, and so forth and assembling a list of // candidates. See `doc.rs` and the `Candidate` type for more details. - fn candidate_from_obligation(&mut self, - stack: &ObligationStack) - -> SelectionResult + fn candidate_from_obligation<'o>(&mut self, + stack: &ObligationStack<'o, 'tcx>) + -> SelectionResult<'tcx, Candidate<'tcx>> { // Watch out for overflow. This intentionally bypasses (and does // not update) the cache. @@ -767,9 +769,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { candidate } - fn candidate_from_obligation_no_cache(&mut self, - stack: &ObligationStack) - -> SelectionResult + fn candidate_from_obligation_no_cache<'o>(&mut self, + stack: &ObligationStack<'o, 'tcx>) + -> SelectionResult<'tcx, Candidate<'tcx>> { if ty::type_is_error(stack.obligation.self_ty()) { return Ok(Some(ErrorCandidate)); @@ -863,8 +865,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn pick_candidate_cache(&self, - cache_skol_trait_ref: &Rc) - -> &SelectionCache + cache_skol_trait_ref: &Rc>) + -> &SelectionCache<'tcx> { // High-level idea: we have to decide whether to consult the // cache that is specific to this scope, or to consult the @@ -910,8 +912,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn check_candidate_cache(&mut self, - cache_skol_trait_ref: Rc) - -> Option> + cache_skol_trait_ref: Rc>) + -> Option>> { let cache = self.pick_candidate_cache(&cache_skol_trait_ref); let hashmap = cache.hashmap.borrow(); @@ -919,17 +921,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn insert_candidate_cache(&mut self, - cache_skol_trait_ref: Rc, - candidate: SelectionResult) + cache_skol_trait_ref: Rc>, + candidate: SelectionResult<'tcx, Candidate<'tcx>>) { let cache = self.pick_candidate_cache(&cache_skol_trait_ref); let mut hashmap = cache.hashmap.borrow_mut(); hashmap.insert(cache_skol_trait_ref, candidate); } - fn assemble_candidates(&mut self, - stack: &ObligationStack) - -> Result + fn assemble_candidates<'o>(&mut self, + stack: &ObligationStack<'o, 'tcx>) + -> Result, SelectionError<'tcx>> { // Check for overflow. @@ -961,9 +963,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn assemble_candidates_from_caller_bounds(&mut self, - obligation: &Obligation, - candidates: &mut CandidateSet) - -> Result<(),SelectionError> + obligation: &Obligation<'tcx>, + candidates: &mut CandidateSet<'tcx>) + -> Result<(),SelectionError<'tcx>> { /*! * Given an obligation like ``, search the obligations @@ -1001,9 +1003,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn assemble_unboxed_candidates(&mut self, - obligation: &Obligation, - candidates: &mut CandidateSet) - -> Result<(),SelectionError> + obligation: &Obligation<'tcx>, + candidates: &mut CandidateSet<'tcx>) + -> Result<(),SelectionError<'tcx>> { /*! * Check for the artificial impl that the compiler will create @@ -1028,7 +1030,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { }; let self_ty = self.infcx.shallow_resolve(obligation.self_ty()); - let (closure_def_id, substs) = match ty::get(self_ty).sty { + let (closure_def_id, substs) = match self_ty.sty { ty::ty_unboxed_closure(id, _, ref substs) => (id, substs.clone()), ty::ty_infer(ty::TyVar(_)) => { candidates.ambiguous = true; @@ -1059,9 +1061,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn assemble_candidates_from_impls(&mut self, - obligation: &Obligation, - candidates: &mut CandidateSet) - -> Result<(), SelectionError> + obligation: &Obligation<'tcx>, + candidates: &mut CandidateSet<'tcx>) + -> Result<(), SelectionError<'tcx>> { /*! * Search for impls that might apply to `obligation`. @@ -1090,10 +1092,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // attempt to evaluate recursive bounds to see if they are // satisfied. - fn winnow_candidate(&mut self, - stack: &ObligationStack, - candidate: &Candidate) - -> EvaluationResult + fn winnow_candidate<'o>(&mut self, + stack: &ObligationStack<'o, 'tcx>, + candidate: &Candidate<'tcx>) + -> EvaluationResult { /*! * Further evaluate `candidate` to decide whether all type parameters match @@ -1111,10 +1113,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { }) } - fn winnow_selection(&mut self, - stack: Option<&ObligationStack>, - selection: Selection) - -> EvaluationResult + fn winnow_selection<'o>(&mut self, + stack: Option<&ObligationStack<'o, 'tcx>>, + selection: Selection<'tcx>) + -> EvaluationResult { let mut result = EvaluatedToOk; for obligation in selection.iter_nested() { @@ -1127,11 +1129,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { result } - fn candidate_should_be_dropped_in_favor_of(&mut self, - stack: &ObligationStack, - candidate_i: &Candidate, - candidate_j: &Candidate) - -> bool + fn candidate_should_be_dropped_in_favor_of<'o>(&mut self, + stack: &ObligationStack<'o, 'tcx>, + candidate_i: &Candidate<'tcx>, + candidate_j: &Candidate<'tcx>) + -> bool { /*! * Returns true if `candidate_i` should be dropped in favor of `candidate_j`. @@ -1194,11 +1196,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // those will hopefully change to library-defined traits in the // future. - fn assemble_builtin_bound_candidates(&mut self, - bound: ty::BuiltinBound, - stack: &ObligationStack, - candidates: &mut CandidateSet) - -> Result<(),SelectionError> + fn assemble_builtin_bound_candidates<'o>(&mut self, + bound: ty::BuiltinBound, + stack: &ObligationStack<'o, 'tcx>, + candidates: &mut CandidateSet<'tcx>) + -> Result<(),SelectionError<'tcx>> { // FIXME -- To be more like a normal impl, we should just // ignore the nested cases here, and instead generate nested @@ -1227,11 +1229,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn builtin_bound(&mut self, bound: ty::BuiltinBound, - self_ty: ty::t) - -> Result + self_ty: Ty<'tcx>) + -> Result,SelectionError<'tcx>> { let self_ty = self.infcx.shallow_resolve(self_ty); - return match ty::get(self_ty).sty { + return match self_ty.sty { ty::ty_infer(ty::IntVar(_)) | ty::ty_infer(ty::FloatVar(_)) | ty::ty_uint(_) | @@ -1443,7 +1445,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } Some(freevars) => { - let tys: Vec = + let tys: Vec = freevars .iter() .map(|freevar| { @@ -1458,7 +1460,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::ty_struct(def_id, ref substs) => { - let types: Vec = + let types: Vec = ty::struct_fields(self.tcx(), def_id, substs) .iter() .map(|f| f.mt.ty) @@ -1467,7 +1469,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::ty_enum(def_id, ref substs) => { - let types: Vec = + let types: Vec = ty::substd_enum_variants(self.tcx(), def_id, substs) .iter() .flat_map(|variant| variant.args.iter()) @@ -1505,11 +1507,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } }; - fn nominal(this: &mut SelectionContext, - bound: ty::BuiltinBound, - def_id: ast::DefId, - types: Vec) - -> Result + fn nominal<'cx, 'tcx>(this: &mut SelectionContext<'cx, 'tcx>, + bound: ty::BuiltinBound, + def_id: ast::DefId, + types: Vec>) + -> Result,SelectionError<'tcx>> { // First check for markers and other nonsense. let tcx = this.tcx(); @@ -1564,9 +1566,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // type error. See `doc.rs` for more details. fn confirm_candidate(&mut self, - obligation: &Obligation, - candidate: Candidate) - -> Result + obligation: &Obligation<'tcx>, + candidate: Candidate<'tcx>) + -> Result,SelectionError<'tcx>> { debug!("confirm_candidate({}, {})", obligation.repr(self.tcx()), @@ -1598,9 +1600,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn confirm_param_candidate(&mut self, - obligation: &Obligation, - param: VtableParamData) - -> Result + obligation: &Obligation<'tcx>, + param: VtableParamData<'tcx>) + -> Result, + SelectionError<'tcx>> { debug!("confirm_param_candidate({},{})", obligation.repr(self.tcx()), @@ -1613,9 +1616,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn confirm_builtin_candidate(&mut self, - obligation: &Obligation, + obligation: &Obligation<'tcx>, bound: ty::BuiltinBound) - -> Result,SelectionError> + -> Result>, + SelectionError<'tcx>> { debug!("confirm_builtin_candidate({})", obligation.repr(self.tcx())); @@ -1633,10 +1637,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn vtable_builtin_data(&mut self, - obligation: &Obligation, + obligation: &Obligation<'tcx>, bound: ty::BuiltinBound, - nested: Vec) - -> VtableBuiltinData + nested: Vec>) + -> VtableBuiltinData> { let obligations = nested.iter().map(|&t| { util::obligation_for_builtin_bound( @@ -1656,9 +1660,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn confirm_impl_candidate(&mut self, - obligation: &Obligation, + obligation: &Obligation<'tcx>, impl_def_id: ast::DefId) - -> Result,SelectionError> + -> Result>, + SelectionError<'tcx>> { debug!("confirm_impl_candidate({},{})", obligation.repr(self.tcx()), @@ -1672,10 +1677,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn vtable_impl(&mut self, impl_def_id: ast::DefId, - substs: Substs, - cause: ObligationCause, + substs: Substs<'tcx>, + cause: ObligationCause<'tcx>, recursion_depth: uint) - -> VtableImplData + -> VtableImplData<'tcx, Obligation<'tcx>> { let impl_obligations = self.impl_obligations(cause, @@ -1688,10 +1693,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn confirm_unboxed_closure_candidate(&mut self, - obligation: &Obligation, + obligation: &Obligation<'tcx>, closure_def_id: ast::DefId, - substs: &Substs) - -> Result<(),SelectionError> + substs: &Substs<'tcx>) + -> Result<(),SelectionError<'tcx>> { debug!("confirm_unboxed_closure_candidate({},{},{})", obligation.repr(self.tcx()), @@ -1739,8 +1744,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn rematch_impl(&mut self, impl_def_id: ast::DefId, - obligation: &Obligation) - -> Substs + obligation: &Obligation<'tcx>) + -> Substs<'tcx> { match self.match_impl(impl_def_id, obligation) { Ok(substs) => { @@ -1758,8 +1763,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn match_impl(&mut self, impl_def_id: ast::DefId, - obligation: &Obligation) - -> Result + obligation: &Obligation<'tcx>) + -> Result, ()> { let impl_trait_ref = ty::impl_trait_ref(self.tcx(), impl_def_id).unwrap(); @@ -1808,8 +1813,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn match_trait_refs(&mut self, - obligation: &Obligation, - trait_ref: Rc) + obligation: &Obligation<'tcx>, + trait_ref: Rc>) -> Result<(),()> { debug!("match_trait_refs: obligation={} trait_ref={}", @@ -1829,8 +1834,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn match_inherent_impl(&mut self, impl_def_id: ast::DefId, obligation_cause: ObligationCause, - obligation_self_ty: ty::t) - -> Result + obligation_self_ty: Ty<'tcx>) + -> Result,()> { /*! * Determines whether the self type declared against @@ -1878,10 +1883,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { cause: ObligationCause, // The self type provided by the impl/caller-obligation: - provided_self_ty: ty::t, + provided_self_ty: Ty<'tcx>, // The self type the obligation is for: - required_self_ty: ty::t) + required_self_ty: Ty<'tcx>) -> Result<(),()> { // FIXME(#5781) -- equating the types is stronger than @@ -1908,10 +1913,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn confirm_impl_vtable(&mut self, impl_def_id: ast::DefId, - obligation_cause: ObligationCause, - obligation_trait_ref: Rc, - substs: &Substs) - -> Result<(), SelectionError> + obligation_cause: ObligationCause<'tcx>, + obligation_trait_ref: Rc>, + substs: &Substs<'tcx>) + -> Result<(), SelectionError<'tcx>> { /*! * Relates the output type parameters from an impl to the @@ -1938,9 +1943,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn confirm(&mut self, obligation_cause: ObligationCause, - obligation_trait_ref: Rc, - expected_trait_ref: Rc) - -> Result<(), SelectionError> + obligation_trait_ref: Rc>, + expected_trait_ref: Rc>) + -> Result<(), SelectionError<'tcx>> { /*! * After we have determined which impl applies, and with what @@ -1984,9 +1989,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Miscellany fn push_stack<'o,'s:'o>(&mut self, - previous_stack: Option<&'s ObligationStack<'s>>, - obligation: &'o Obligation) - -> ObligationStack<'o> + previous_stack: Option<&'s ObligationStack<'s, 'tcx>>, + obligation: &'o Obligation<'tcx>) + -> ObligationStack<'o, 'tcx> { let skol_trait_ref = obligation.trait_ref.fold_with(&mut self.skolemizer); @@ -2011,11 +2016,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn impl_obligations(&self, - cause: ObligationCause, + cause: ObligationCause<'tcx>, recursion_depth: uint, impl_def_id: ast::DefId, - impl_substs: &Substs) - -> VecPerParamSpace + impl_substs: &Substs<'tcx>) + -> VecPerParamSpace> { let impl_generics = ty::lookup_item_type(self.tcx(), impl_def_id).generics; let bounds = impl_generics.to_bounds(self.tcx(), impl_substs); @@ -2024,8 +2029,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } -impl Repr for Candidate { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for Candidate<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { ErrorCandidate => format!("ErrorCandidate"), BuiltinCandidate(b) => format!("BuiltinCandidate({})", b), @@ -2038,22 +2043,22 @@ impl Repr for Candidate { } } -impl SelectionCache { - pub fn new() -> SelectionCache { +impl<'tcx> SelectionCache<'tcx> { + pub fn new() -> SelectionCache<'tcx> { SelectionCache { hashmap: RefCell::new(HashMap::new()) } } } -impl<'o> ObligationStack<'o> { - fn iter(&self) -> Option<&ObligationStack> { +impl<'o, 'tcx> ObligationStack<'o, 'tcx> { + fn iter(&self) -> Option<&ObligationStack<'o, 'tcx>> { Some(self) } } -impl<'o> Iterator<&'o ObligationStack<'o>> for Option<&'o ObligationStack<'o>> { - fn next(&mut self) -> Option<&'o ObligationStack<'o>> { +impl<'o, 'tcx> Iterator<&'o ObligationStack<'o, 'tcx>> for Option<&'o ObligationStack<'o, 'tcx>> { + fn next(&mut self) -> Option<&'o ObligationStack<'o, 'tcx>> { match *self { Some(o) => { *self = o.previous; @@ -2066,8 +2071,8 @@ impl<'o> Iterator<&'o ObligationStack<'o>> for Option<&'o ObligationStack<'o>> { } } -impl<'o> Repr for ObligationStack<'o> { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'o, 'tcx> Repr<'tcx> for ObligationStack<'o, 'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("ObligationStack({})", self.obligation.repr(tcx)) } diff --git a/src/librustc/middle/traits/util.rs b/src/librustc/middle/traits/util.rs index 8f8203f0281b1..dfd436bdc4d30 100644 --- a/src/librustc/middle/traits/util.rs +++ b/src/librustc/middle/traits/util.rs @@ -12,7 +12,7 @@ use middle::subst; use middle::subst::{ParamSpace, Substs, VecPerParamSpace}; use middle::typeck::infer::InferCtxt; -use middle::ty; +use middle::ty::{mod, Ty}; use std::collections::HashSet; use std::fmt; use std::rc::Rc; @@ -28,17 +28,17 @@ use super::{ErrorReported, Obligation, ObligationCause, VtableImpl, pub struct Supertraits<'cx, 'tcx:'cx> { tcx: &'cx ty::ctxt<'tcx>, - stack: Vec, - visited: HashSet>, + stack: Vec>, + visited: HashSet>>, } -struct SupertraitEntry { +struct SupertraitEntry<'tcx> { position: uint, - supertraits: Vec>, + supertraits: Vec>>, } pub fn supertraits<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>, - trait_ref: Rc) + trait_ref: Rc>) -> Supertraits<'cx, 'tcx> { /*! @@ -61,7 +61,7 @@ pub fn supertraits<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>, } pub fn transitive_bounds<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>, - bounds: &[Rc]) + bounds: &[Rc>]) -> Supertraits<'cx, 'tcx> { let bounds = Vec::from_fn(bounds.len(), |i| bounds[i].clone()); @@ -76,7 +76,7 @@ pub fn transitive_bounds<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>, } impl<'cx, 'tcx> Supertraits<'cx, 'tcx> { - fn push(&mut self, trait_ref: &ty::TraitRef) { + fn push(&mut self, trait_ref: &ty::TraitRef<'tcx>) { let ty::ParamBounds { builtin_bounds, mut trait_bounds, .. } = ty::bounds_for_trait_ref(self.tcx, trait_ref); for builtin_bound in builtin_bounds.iter() { @@ -106,8 +106,8 @@ impl<'cx, 'tcx> Supertraits<'cx, 'tcx> { } } -impl<'cx, 'tcx> Iterator> for Supertraits<'cx, 'tcx> { - fn next(&mut self) -> Option> { +impl<'cx, 'tcx> Iterator>> for Supertraits<'cx, 'tcx> { + fn next(&mut self) -> Option>> { loop { // Extract next item from top-most stack frame, if any. let next_trait = match self.stack.last_mut() { @@ -148,34 +148,34 @@ impl<'cx, 'tcx> Iterator> for Supertraits<'cx, 'tcx> { // declared on the impl declaration e.g., `impl for ~[(A,B)]` // would return ($0, $1) where $0 and $1 are freshly instantiated type // variables. -pub fn fresh_substs_for_impl(infcx: &InferCtxt, - span: Span, - impl_def_id: ast::DefId) - -> Substs +pub fn fresh_substs_for_impl<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>, + span: Span, + impl_def_id: ast::DefId) + -> Substs<'tcx> { let tcx = infcx.tcx; let impl_generics = ty::lookup_item_type(tcx, impl_def_id).generics; infcx.fresh_substs_for_generics(span, &impl_generics) } -impl fmt::Show for VtableImplData { +impl<'tcx, N> fmt::Show for VtableImplData<'tcx, N> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "VtableImpl({})", self.impl_def_id) } } -impl fmt::Show for VtableParamData { +impl<'tcx> fmt::Show for VtableParamData<'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "VtableParam(...)") } } -pub fn obligations_for_generics(tcx: &ty::ctxt, - cause: ObligationCause, - recursion_depth: uint, - generic_bounds: &ty::GenericBounds, - type_substs: &VecPerParamSpace) - -> VecPerParamSpace +pub fn obligations_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>, + cause: ObligationCause<'tcx>, + recursion_depth: uint, + generic_bounds: &ty::GenericBounds<'tcx>, + type_substs: &VecPerParamSpace>) + -> VecPerParamSpace> { /*! See `super::obligations_for_generics` */ @@ -200,15 +200,15 @@ pub fn obligations_for_generics(tcx: &ty::ctxt, return obligations; } -fn push_obligations_for_param_bounds( - tcx: &ty::ctxt, - cause: ObligationCause, +fn push_obligations_for_param_bounds<'tcx>( + tcx: &ty::ctxt<'tcx>, + cause: ObligationCause<'tcx>, recursion_depth: uint, space: subst::ParamSpace, index: uint, - param_bounds: &ty::ParamBounds, - param_type_substs: &VecPerParamSpace, - obligations: &mut VecPerParamSpace) + param_bounds: &ty::ParamBounds<'tcx>, + param_type_substs: &VecPerParamSpace>, + obligations: &mut VecPerParamSpace>) { let param_ty = *param_type_substs.get(space, index); for builtin_bound in param_bounds.builtin_bounds.iter() { @@ -232,11 +232,11 @@ fn push_obligations_for_param_bounds( } } -pub fn trait_ref_for_builtin_bound( - tcx: &ty::ctxt, +pub fn trait_ref_for_builtin_bound<'tcx>( + tcx: &ty::ctxt<'tcx>, builtin_bound: ty::BuiltinBound, - param_ty: ty::t) - -> Option> + param_ty: Ty<'tcx>) + -> Option>> { match tcx.lang_items.from_builtin_kind(builtin_bound) { Ok(def_id) => { @@ -252,13 +252,13 @@ pub fn trait_ref_for_builtin_bound( } } -pub fn obligation_for_builtin_bound( - tcx: &ty::ctxt, - cause: ObligationCause, +pub fn obligation_for_builtin_bound<'tcx>( + tcx: &ty::ctxt<'tcx>, + cause: ObligationCause<'tcx>, builtin_bound: ty::BuiltinBound, recursion_depth: uint, - param_ty: ty::t) - -> Result + param_ty: Ty<'tcx>) + -> Result, ErrorReported> { let trait_ref = trait_ref_for_builtin_bound(tcx, builtin_bound, param_ty); match trait_ref { @@ -271,10 +271,10 @@ pub fn obligation_for_builtin_bound( } } -pub fn search_trait_and_supertraits_from_bound(tcx: &ty::ctxt, - caller_bound: Rc, - test: |ast::DefId| -> bool) - -> Option +pub fn search_trait_and_supertraits_from_bound<'tcx>(tcx: &ty::ctxt<'tcx>, + caller_bound: Rc>, + test: |ast::DefId| -> bool) + -> Option> { /*! * Starting from a caller obligation `caller_bound` (which has @@ -295,16 +295,16 @@ pub fn search_trait_and_supertraits_from_bound(tcx: &ty::ctxt, return None; } -impl Repr for super::Obligation { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for super::Obligation<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("Obligation(trait_ref={},depth={})", self.trait_ref.repr(tcx), self.recursion_depth) } } -impl Repr for super::Vtable { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx, N:Repr<'tcx>> Repr<'tcx> for super::Vtable<'tcx, N> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { super::VtableImpl(ref v) => v.repr(tcx), @@ -323,8 +323,8 @@ impl Repr for super::Vtable { } } -impl Repr for super::VtableImplData { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx, N:Repr<'tcx>> Repr<'tcx> for super::VtableImplData<'tcx, N> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("VtableImpl(impl_def_id={}, substs={}, nested={})", self.impl_def_id.repr(tcx), self.substs.repr(tcx), @@ -332,22 +332,22 @@ impl Repr for super::VtableImplData { } } -impl Repr for super::VtableBuiltinData { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx, N:Repr<'tcx>> Repr<'tcx> for super::VtableBuiltinData { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("VtableBuiltin(nested={})", self.nested.repr(tcx)) } } -impl Repr for super::VtableParamData { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for super::VtableParamData<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("VtableParam(bound={})", self.bound.repr(tcx)) } } -impl Repr for super::SelectionError { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for super::SelectionError<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { super::Overflow => format!("Overflow"), @@ -363,16 +363,16 @@ impl Repr for super::SelectionError { } } -impl Repr for super::FulfillmentError { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for super::FulfillmentError<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("FulfillmentError({},{})", self.obligation.repr(tcx), self.code.repr(tcx)) } } -impl Repr for super::FulfillmentErrorCode { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for super::FulfillmentErrorCode<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { super::CodeSelectionError(ref o) => o.repr(tcx), super::CodeAmbiguity => format!("Ambiguity") @@ -380,7 +380,7 @@ impl Repr for super::FulfillmentErrorCode { } } -impl fmt::Show for super::FulfillmentErrorCode { +impl<'tcx> fmt::Show for super::FulfillmentErrorCode<'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { super::CodeSelectionError(ref e) => write!(f, "{}", e), @@ -389,8 +389,8 @@ impl fmt::Show for super::FulfillmentErrorCode { } } -impl Repr for ty::type_err { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::type_err<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { ty::type_err_to_str(tcx, self) } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 9f90afa37490c..bf4260c46314b 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -61,6 +61,7 @@ use util::ppaux::{Repr, UserString}; use util::common::{indenter, memoized}; use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet}; use util::nodemap::{FnvHashMap, FnvHashSet}; +use std::borrow::BorrowFrom; use std::cell::{Cell, RefCell}; use std::cmp; use std::fmt::{mod, Show}; @@ -89,9 +90,9 @@ pub const INITIAL_DISCRIMINANT_VALUE: Disr = 0; // Data types #[deriving(PartialEq, Eq, Hash)] -pub struct field { +pub struct field<'tcx> { pub name: ast::Name, - pub mt: mt + pub mt: mt<'tcx> } #[deriving(Clone, Show)] @@ -110,12 +111,12 @@ impl ImplOrTraitItemContainer { } #[deriving(Clone)] -pub enum ImplOrTraitItem { - MethodTraitItem(Rc), +pub enum ImplOrTraitItem<'tcx> { + MethodTraitItem(Rc>), TypeTraitItem(Rc), } -impl ImplOrTraitItem { +impl<'tcx> ImplOrTraitItem<'tcx> { fn id(&self) -> ImplOrTraitItemId { match *self { MethodTraitItem(ref method) => MethodTraitItemId(method.def_id), @@ -146,7 +147,7 @@ impl ImplOrTraitItem { } } - pub fn as_opt_method(&self) -> Option> { + pub fn as_opt_method(&self) -> Option>> { match *self { MethodTraitItem(ref m) => Some((*m).clone()), TypeTraitItem(_) => None @@ -170,10 +171,10 @@ impl ImplOrTraitItemId { } #[deriving(Clone, Show)] -pub struct Method { +pub struct Method<'tcx> { pub name: ast::Name, - pub generics: ty::Generics, - pub fty: BareFnTy, + pub generics: ty::Generics<'tcx>, + pub fty: BareFnTy<'tcx>, pub explicit_self: ExplicitSelfCategory, pub vis: ast::Visibility, pub def_id: ast::DefId, @@ -183,16 +184,16 @@ pub struct Method { pub provided_source: Option } -impl Method { +impl<'tcx> Method<'tcx> { pub fn new(name: ast::Name, - generics: ty::Generics, - fty: BareFnTy, + generics: ty::Generics<'tcx>, + fty: BareFnTy<'tcx>, explicit_self: ExplicitSelfCategory, vis: ast::Visibility, def_id: ast::DefId, container: ImplOrTraitItemContainer, provided_source: Option) - -> Method { + -> Method<'tcx> { Method { name: name, generics: generics, @@ -222,8 +223,8 @@ pub struct AssociatedType { } #[deriving(Clone, PartialEq, Eq, Hash, Show)] -pub struct mt { - pub ty: t, +pub struct mt<'tcx> { + pub ty: Ty<'tcx>, pub mutbl: ast::Mutability, } @@ -252,35 +253,9 @@ pub struct creader_cache_key { pub len: uint } -pub struct intern_key { - sty: *const sty, -} - -// NB: Do not replace this with #[deriving(PartialEq)]. The automatically-derived -// implementation will not recurse through sty and you will get stack -// exhaustion. -impl cmp::PartialEq for intern_key { - fn eq(&self, other: &intern_key) -> bool { - unsafe { - *self.sty == *other.sty - } - } - fn ne(&self, other: &intern_key) -> bool { - !self.eq(other) - } -} - -impl Eq for intern_key {} - -impl Hash for intern_key { - fn hash(&self, s: &mut W) { - unsafe { (*self.sty).hash(s) } - } -} - -pub enum ast_ty_to_ty_cache_entry { +pub enum ast_ty_to_ty_cache_entry<'tcx> { atttce_unresolved, /* not resolved yet */ - atttce_resolved(t) /* resolved to a type, irrespective of region */ + atttce_resolved(Ty<'tcx>) /* resolved to a type, irrespective of region */ } #[deriving(Clone, PartialEq, Decodable, Encodable)] @@ -298,44 +273,44 @@ pub enum Variance { } #[deriving(Clone, Show)] -pub enum AutoAdjustment { +pub enum AutoAdjustment<'tcx> { AdjustAddEnv(ty::TraitStore), - AdjustDerefRef(AutoDerefRef) + AdjustDerefRef(AutoDerefRef<'tcx>) } #[deriving(Clone, PartialEq, Show)] -pub enum UnsizeKind { +pub enum UnsizeKind<'tcx> { // [T, ..n] -> [T], the uint field is n. UnsizeLength(uint), // An unsize coercion applied to the tail field of a struct. // The uint is the index of the type parameter which is unsized. - UnsizeStruct(Box, uint), - UnsizeVtable(TyTrait, /* the self type of the trait */ ty::t) + UnsizeStruct(Box>, uint), + UnsizeVtable(TyTrait<'tcx>, /* the self type of the trait */ Ty<'tcx>) } #[deriving(Clone, Show)] -pub struct AutoDerefRef { +pub struct AutoDerefRef<'tcx> { pub autoderefs: uint, - pub autoref: Option + pub autoref: Option> } #[deriving(Clone, PartialEq, Show)] -pub enum AutoRef { +pub enum AutoRef<'tcx> { /// Convert from T to &T /// The third field allows us to wrap other AutoRef adjustments. - AutoPtr(Region, ast::Mutability, Option>), + AutoPtr(Region, ast::Mutability, Option>>), /// Convert [T, ..n] to [T] (or similar, depending on the kind) - AutoUnsize(UnsizeKind), + AutoUnsize(UnsizeKind<'tcx>), /// Convert Box<[T, ..n]> to Box<[T]> or something similar in a Box. /// With DST and Box a library type, this should be replaced by UnsizeStruct. - AutoUnsizeUniq(UnsizeKind), + AutoUnsizeUniq(UnsizeKind<'tcx>), /// Convert from T to *T /// Value to thin pointer /// The second field allows us to wrap other AutoRef adjustments. - AutoUnsafe(ast::Mutability, Option>), + AutoUnsafe(ast::Mutability, Option>>), } // Ugly little helper function. The first bool in the returned tuple is true if @@ -397,8 +372,8 @@ pub fn adjust_is_object(adj: &AutoAdjustment) -> bool { // If possible, returns the type expected from the given adjustment. This is not // possible if the adjustment depends on the type of the adjusted expression. -pub fn type_of_adjust(cx: &ctxt, adj: &AutoAdjustment) -> Option { - fn type_of_autoref(cx: &ctxt, autoref: &AutoRef) -> Option { +pub fn type_of_adjust<'tcx>(cx: &ctxt<'tcx>, adj: &AutoAdjustment<'tcx>) -> Option> { + fn type_of_autoref<'tcx>(cx: &ctxt<'tcx>, autoref: &AutoRef<'tcx>) -> Option> { match autoref { &AutoUnsize(ref k) => match k { &UnsizeVtable(TyTrait { ref principal, bounds }, _) => { @@ -414,13 +389,13 @@ pub fn type_of_adjust(cx: &ctxt, adj: &AutoAdjustment) -> Option { }, &AutoPtr(r, m, Some(box ref autoref)) => { match type_of_autoref(cx, autoref) { - Some(t) => Some(mk_rptr(cx, r, mt {mutbl: m, ty: t})), + Some(ty) => Some(mk_rptr(cx, r, mt {mutbl: m, ty: ty})), None => None } } &AutoUnsafe(m, Some(box ref autoref)) => { match type_of_autoref(cx, autoref) { - Some(t) => Some(mk_ptr(cx, mt {mutbl: m, ty: t})), + Some(ty) => Some(mk_ptr(cx, mt {mutbl: m, ty: ty})), None => None } } @@ -440,13 +415,13 @@ pub fn type_of_adjust(cx: &ctxt, adj: &AutoAdjustment) -> Option { /// A restriction that certain types must be the same size. The use of /// `transmute` gives rise to these restrictions. -pub struct TransmuteRestriction { +pub struct TransmuteRestriction<'tcx> { /// The span from whence the restriction comes. pub span: Span, /// The type being transmuted from. - pub from: t, + pub from: Ty<'tcx>, /// The type being transmuted to. - pub to: t, + pub to: Ty<'tcx>, /// NodeIf of the transmute intrinsic. pub id: ast::NodeId, } @@ -456,11 +431,13 @@ pub struct TransmuteRestriction { /// later on. pub struct ctxt<'tcx> { /// The arena that types are allocated from. - type_arena: &'tcx TypedArena, + type_arena: &'tcx TypedArena>, /// Specifically use a speedy hash algorithm for this hash map, it's used /// quite often. - interner: RefCell>, + // FIXME(eddyb) use a FnvHashSet> when equivalent keys can + // queried from a HashSet. + interner: RefCell, Ty<'tcx>>>, pub sess: Session, pub def_map: resolve::DefMap, @@ -471,45 +448,45 @@ pub struct ctxt<'tcx> { /// Stores the types for various nodes in the AST. Note that this table /// is not guaranteed to be populated until after typeck. See /// typeck::check::fn_ctxt for details. - pub node_types: RefCell>, + pub node_types: RefCell>>, /// Stores the type parameters which were substituted to obtain the type /// of this node. This only applies to nodes that refer to entities /// parameterized by type parameters, such as generic fns, types, or /// other items. - pub item_substs: RefCell>, + pub item_substs: RefCell>>, /// Maps from a trait item to the trait item "descriptor" - pub impl_or_trait_items: RefCell>, + pub impl_or_trait_items: RefCell>>, /// Maps from a trait def-id to a list of the def-ids of its trait items pub trait_item_def_ids: RefCell>>>, /// A cache for the trait_items() routine - pub trait_items_cache: RefCell>>>, + pub trait_items_cache: RefCell>>>>, - pub impl_trait_cache: RefCell>>>, + pub impl_trait_cache: RefCell>>>>, - pub trait_refs: RefCell>>, - pub trait_defs: RefCell>>, + pub trait_refs: RefCell>>>, + pub trait_defs: RefCell>>>, /// Maps from node-id of a trait object cast (like `foo as /// Box`) to the trait reference. - pub object_cast_map: typeck::ObjectCastMap, + pub object_cast_map: typeck::ObjectCastMap<'tcx>, pub map: ast_map::Map<'tcx>, - pub intrinsic_defs: RefCell>, + pub intrinsic_defs: RefCell>>, pub freevars: RefCell, - pub tcache: RefCell>, - pub rcache: RefCell>, - pub short_names_cache: RefCell>, - pub needs_unwind_cleanup_cache: RefCell>, - pub tc_cache: RefCell>, - pub ast_ty_to_ty_cache: RefCell>, - pub enum_var_cache: RefCell>>>>, - pub ty_param_defs: RefCell>, - pub adjustments: RefCell>, - pub normalized_cache: RefCell>, + pub tcache: RefCell>>, + pub rcache: RefCell>>, + pub short_names_cache: RefCell, String>>, + pub needs_unwind_cleanup_cache: RefCell, bool>>, + pub tc_cache: RefCell, TypeContents>>, + pub ast_ty_to_ty_cache: RefCell>>, + pub enum_var_cache: RefCell>>>>>, + pub ty_param_defs: RefCell>>, + pub adjustments: RefCell>>, + pub normalized_cache: RefCell, Ty<'tcx>>>, pub lang_items: middle::lang_items::LanguageItems, /// A mapping of fake provided method def_ids to the default implementation pub provided_method_sources: RefCell>, @@ -570,13 +547,13 @@ pub struct ctxt<'tcx> { pub extern_const_statics: RefCell>, pub extern_const_variants: RefCell>, - pub method_map: typeck::MethodMap, + pub method_map: typeck::MethodMap<'tcx>, pub dependency_formats: RefCell, /// Records the type of each unboxed closure. The def ID is the ID of the /// expression defining the unboxed closure. - pub unboxed_closures: RefCell>, + pub unboxed_closures: RefCell>>, pub node_lint_levels: RefCell>, @@ -584,7 +561,7 @@ pub struct ctxt<'tcx> { /// The types that must be asserted to be the same size for `transmute` /// to be valid. We gather up these restrictions in the intrinsicck pass /// and check them in trans. - pub transmute_restrictions: RefCell>, + pub transmute_restrictions: RefCell>>, /// Maps any item's def-id to its stability index. pub stability: RefCell, @@ -597,7 +574,7 @@ pub struct ctxt<'tcx> { /// Caches the results of trait selection. This cache is used /// for things that do not have to do with the parameters in scope. - pub selection_cache: traits::SelectionCache, + pub selection_cache: traits::SelectionCache<'tcx>, /// Caches the representation hints for struct definitions. pub repr_hint_cache: RefCell>>>, @@ -621,11 +598,9 @@ bitflags! { } } -pub type t_box = &'static t_box_; - #[deriving(Show)] -pub struct t_box_ { - pub sty: sty, +pub struct TyS<'tcx> { + pub sty: sty<'tcx>, pub flags: TypeFlags, // the maximal depth of any bound regions appearing in this type. @@ -638,47 +613,64 @@ impl fmt::Show for TypeFlags { } } -// To reduce refcounting cost, we're representing types as unsafe pointers -// throughout the compiler. These are simply casted t_box values. Use ty::get -// to cast them back to a box. (Without the cast, compiler performance suffers -// ~15%.) This does mean that a t value relies on the ctxt to keep its box -// alive, and using ty::get is unsafe when the ctxt is no longer alive. -enum t_opaque {} +impl<'tcx> PartialEq for TyS<'tcx> { + fn eq(&self, other: &TyS<'tcx>) -> bool { + (self as *const _) == (other as *const _) + } +} +impl<'tcx> Eq for TyS<'tcx> {} -#[allow(raw_pointer_deriving)] -#[deriving(Clone, PartialEq, Eq, Hash)] -pub struct t { inner: *const t_opaque } +impl<'tcx, S: Writer> Hash for TyS<'tcx> { + fn hash(&self, s: &mut S) { + (self as *const _).hash(s) + } +} -impl fmt::Show for t { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", get(*self)) +pub type Ty<'tcx> = &'tcx TyS<'tcx>; + +/// An entry in the type interner. +pub struct InternedTy<'tcx> { + ty: Ty<'tcx> +} + +// NB: An InternedTy compares and hashes as a sty. +impl<'tcx> PartialEq for InternedTy<'tcx> { + fn eq(&self, other: &InternedTy<'tcx>) -> bool { + self.ty.sty == other.ty.sty } } +impl<'tcx> Eq for InternedTy<'tcx> {} -pub fn get(t: t) -> t_box { - unsafe { - let t2: t_box = mem::transmute(t); - t2 +impl<'tcx, S: Writer> Hash for InternedTy<'tcx> { + fn hash(&self, s: &mut S) { + self.ty.sty.hash(s) } } -fn tbox_has_flag(tb: t_box, flag: TypeFlags) -> bool { - tb.flags.intersects(flag) +impl<'tcx> BorrowFrom> for sty<'tcx> { + fn borrow_from<'a>(ty: &'a InternedTy<'tcx>) -> &'a sty<'tcx> { + &ty.ty.sty + } } -pub fn type_has_params(t: t) -> bool { - tbox_has_flag(get(t), HAS_PARAMS) + +pub fn type_has_params(ty: Ty) -> bool { + ty.flags.intersects(HAS_PARAMS) +} +pub fn type_has_self(ty: Ty) -> bool { + ty.flags.intersects(HAS_SELF) +} +pub fn type_has_ty_infer(ty: Ty) -> bool { + ty.flags.intersects(HAS_TY_INFER) } -pub fn type_has_self(t: t) -> bool { tbox_has_flag(get(t), HAS_SELF) } -pub fn type_has_ty_infer(t: t) -> bool { tbox_has_flag(get(t), HAS_TY_INFER) } -pub fn type_needs_infer(t: t) -> bool { - tbox_has_flag(get(t), HAS_TY_INFER | HAS_RE_INFER) +pub fn type_needs_infer(ty: Ty) -> bool { + ty.flags.intersects(HAS_TY_INFER | HAS_RE_INFER) } -pub fn type_has_late_bound_regions(ty: t) -> bool { - get(ty).flags.intersects(HAS_RE_LATE_BOUND) +pub fn type_has_late_bound_regions(ty: Ty) -> bool { + ty.flags.intersects(HAS_RE_LATE_BOUND) } -pub fn type_has_escaping_regions(t: t) -> bool { +pub fn type_has_escaping_regions(ty: Ty) -> bool { /*! * An "escaping region" is a bound region whose binder is not part of `t`. * @@ -711,40 +703,40 @@ pub fn type_has_escaping_regions(t: t) -> bool { * this processing has not yet been done. */ - type_escapes_depth(t, 0) + type_escapes_depth(ty, 0) } -pub fn type_escapes_depth(t: t, depth: uint) -> bool { - get(t).region_depth > depth +pub fn type_escapes_depth(ty: Ty, depth: uint) -> bool { + ty.region_depth > depth } #[deriving(Clone, PartialEq, Eq, Hash, Show)] -pub struct BareFnTy { +pub struct BareFnTy<'tcx> { pub fn_style: ast::FnStyle, pub abi: abi::Abi, - pub sig: FnSig, + pub sig: FnSig<'tcx>, } #[deriving(Clone, PartialEq, Eq, Hash, Show)] -pub struct ClosureTy { +pub struct ClosureTy<'tcx> { pub fn_style: ast::FnStyle, pub onceness: ast::Onceness, pub store: TraitStore, pub bounds: ExistentialBounds, - pub sig: FnSig, + pub sig: FnSig<'tcx>, pub abi: abi::Abi, } #[deriving(Clone, PartialEq, Eq, Hash)] -pub enum FnOutput { - FnConverging(ty::t), +pub enum FnOutput<'tcx> { + FnConverging(Ty<'tcx>), FnDiverging } -impl FnOutput { - pub fn unwrap(&self) -> ty::t { - match *self { - ty::FnConverging(ref t) => *t, +impl<'tcx> FnOutput<'tcx> { + pub fn unwrap(self) -> Ty<'tcx> { + match self { + ty::FnConverging(t) => t, ty::FnDiverging => unreachable!() } } @@ -763,9 +755,9 @@ impl FnOutput { * fn's arguments or the fn's return type. */ #[deriving(Clone, PartialEq, Eq, Hash)] -pub struct FnSig { - pub inputs: Vec, - pub output: FnOutput, +pub struct FnSig<'tcx> { + pub inputs: Vec>, + pub output: FnOutput<'tcx>, pub variadic: bool } @@ -1019,47 +1011,58 @@ pub enum BoundRegion { BrEnv } -mod primitives { - use super::t_box_; - - use syntax::ast; +#[inline] +pub fn mk_prim_t<'tcx>(primitive: &'tcx TyS<'static>) -> Ty<'tcx> { + // FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx. + unsafe { &*(primitive as *const _ as *const TyS<'tcx>) } +} - macro_rules! def_prim_ty( - ($name:ident, $sty:expr) => ( - pub static $name: t_box_ = t_box_ { +// Do not change these from static to const, interning types requires +// the primitives to have a significant address. +macro_rules! def_prim_tys( + ($($name:ident -> $sty:expr;)*) => ( + $(#[inline] pub fn $name<'tcx>() -> Ty<'tcx> { + static PRIM_TY: TyS<'static> = TyS { sty: $sty, - flags: super::NO_TYPE_FLAGS, + flags: NO_TYPE_FLAGS, region_depth: 0, }; - ) + mk_prim_t(&PRIM_TY) + })* ) +) + +def_prim_tys!{ + mk_bool -> ty_bool; + mk_char -> ty_char; + mk_int -> ty_int(ast::TyI); + mk_i8 -> ty_int(ast::TyI8); + mk_i16 -> ty_int(ast::TyI16); + mk_i32 -> ty_int(ast::TyI32); + mk_i64 -> ty_int(ast::TyI64); + mk_uint -> ty_uint(ast::TyU); + mk_u8 -> ty_uint(ast::TyU8); + mk_u16 -> ty_uint(ast::TyU16); + mk_u32 -> ty_uint(ast::TyU32); + mk_u64 -> ty_uint(ast::TyU64); + mk_f32 -> ty_float(ast::TyF32); + mk_f64 -> ty_float(ast::TyF64); +} - def_prim_ty!(TY_BOOL, super::ty_bool) - def_prim_ty!(TY_CHAR, super::ty_char) - def_prim_ty!(TY_INT, super::ty_int(ast::TyI)) - def_prim_ty!(TY_I8, super::ty_int(ast::TyI8)) - def_prim_ty!(TY_I16, super::ty_int(ast::TyI16)) - def_prim_ty!(TY_I32, super::ty_int(ast::TyI32)) - def_prim_ty!(TY_I64, super::ty_int(ast::TyI64)) - def_prim_ty!(TY_UINT, super::ty_uint(ast::TyU)) - def_prim_ty!(TY_U8, super::ty_uint(ast::TyU8)) - def_prim_ty!(TY_U16, super::ty_uint(ast::TyU16)) - def_prim_ty!(TY_U32, super::ty_uint(ast::TyU32)) - def_prim_ty!(TY_U64, super::ty_uint(ast::TyU64)) - def_prim_ty!(TY_F32, super::ty_float(ast::TyF32)) - def_prim_ty!(TY_F64, super::ty_float(ast::TyF64)) - - pub static TY_ERR: t_box_ = t_box_ { - sty: super::ty_err, - flags: super::HAS_TY_ERR, +#[inline] +pub fn mk_err<'tcx>() -> Ty<'tcx> { + static TY_ERR: TyS<'static> = TyS { + sty: ty_err, + flags: HAS_TY_ERR, region_depth: 0, }; + mk_prim_t(&TY_ERR) } // NB: If you change this, you'll probably want to change the corresponding // AST structure in libsyntax/ast.rs as well. #[deriving(Clone, PartialEq, Eq, Hash, Show)] -pub enum sty { +pub enum sty<'tcx> { ty_bool, ty_char, ty_int(ast::IntTy), @@ -1072,25 +1075,25 @@ pub enum sty { /// from the tcx, use the `NodeId` from the `ast::Ty` and look it up in /// the `ast_ty_to_ty_cache`. This is probably true for `ty_struct` as /// well.` - ty_enum(DefId, Substs), - ty_uniq(t), + ty_enum(DefId, Substs<'tcx>), + ty_uniq(Ty<'tcx>), ty_str, - ty_vec(t, Option), // Second field is length. - ty_ptr(mt), - ty_rptr(Region, mt), - ty_bare_fn(BareFnTy), - ty_closure(Box), - ty_trait(Box), - ty_struct(DefId, Substs), - ty_unboxed_closure(DefId, Region, Substs), - ty_tup(Vec), + ty_vec(Ty<'tcx>, Option), // Second field is length. + ty_ptr(mt<'tcx>), + ty_rptr(Region, mt<'tcx>), + ty_bare_fn(BareFnTy<'tcx>), + ty_closure(Box>), + ty_trait(Box>), + ty_struct(DefId, Substs<'tcx>), + ty_unboxed_closure(DefId, Region, Substs<'tcx>), + ty_tup(Vec>), ty_param(ParamTy), // type parameter - ty_open(t), // A deref'ed fat pointer, i.e., a dynamically sized value - // and its size. Only ever used in trans. It is not necessary - // earlier since we don't need to distinguish a DST with its - // size (e.g., in a deref) vs a DST with the size elsewhere ( - // e.g., in a field). + ty_open(Ty<'tcx>), // A deref'ed fat pointer, i.e., a dynamically sized value + // and its size. Only ever used in trans. It is not necessary + // earlier since we don't need to distinguish a DST with its + // size (e.g., in a deref) vs a DST with the size elsewhere ( + // e.g., in a field). ty_infer(InferTy), // something used only during inference/typeck ty_err, // Also only used during inference/typeck, to represent @@ -1099,9 +1102,9 @@ pub enum sty { } #[deriving(Clone, PartialEq, Eq, Hash, Show)] -pub struct TyTrait { +pub struct TyTrait<'tcx> { // Principal trait reference. - pub principal: TraitRef, // would use Rc, but it runs afoul of some static rules + pub principal: TraitRef<'tcx>, // would use Rc, but it runs afoul of some static rules pub bounds: ExistentialBounds } @@ -1123,9 +1126,9 @@ pub struct TyTrait { * U>` or higher-ranked object types. */ #[deriving(Clone, PartialEq, Eq, Hash, Show)] -pub struct TraitRef { +pub struct TraitRef<'tcx> { pub def_id: DefId, - pub substs: Substs, + pub substs: Substs<'tcx>, } /** @@ -1167,7 +1170,7 @@ pub struct expected_found { // Data structures used in type unification #[deriving(Clone, Show)] -pub enum type_err { +pub enum type_err<'tcx> { terr_mismatch, terr_fn_style_mismatch(expected_found), terr_onceness_mismatch(expected_found), @@ -1188,7 +1191,7 @@ pub enum type_err { terr_regions_insufficiently_polymorphic(BoundRegion, Region), terr_regions_overly_polymorphic(BoundRegion, Region), terr_trait_stores_differ(terr_vstore_kind, expected_found), - terr_sorts(expected_found), + terr_sorts(expected_found>), terr_integer_as_char, terr_int_mismatch(expected_found), terr_float_mismatch(expected_found), @@ -1202,10 +1205,10 @@ pub enum type_err { /// Bounds suitable for a named type parameter like `A` in `fn foo` /// as well as the existential type parameter in an object type. #[deriving(PartialEq, Eq, Hash, Clone, Show)] -pub struct ParamBounds { +pub struct ParamBounds<'tcx> { pub region_bounds: Vec, pub builtin_bounds: BuiltinBounds, - pub trait_bounds: Vec> + pub trait_bounds: Vec>> } /// Bounds suitable for an existentially quantified type parameter @@ -1340,7 +1343,7 @@ impl fmt::Show for RegionVid { } } -impl fmt::Show for FnSig { +impl<'tcx> fmt::Show for FnSig<'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // grr, without tcx not much we can do. write!(f, "(...)") @@ -1369,14 +1372,14 @@ impl fmt::Show for IntVarValue { } #[deriving(Clone, Show)] -pub struct TypeParameterDef { +pub struct TypeParameterDef<'tcx> { pub name: ast::Name, pub def_id: ast::DefId, pub space: subst::ParamSpace, pub index: uint, pub associated_with: Option, - pub bounds: ParamBounds, - pub default: Option, + pub bounds: ParamBounds<'tcx>, + pub default: Option>, } #[deriving(Encodable, Decodable, Clone, Show)] @@ -1391,13 +1394,13 @@ pub struct RegionParameterDef { /// Information about the type/lifetime parameters associated with an /// item or method. Analogous to ast::Generics. #[deriving(Clone, Show)] -pub struct Generics { - pub types: VecPerParamSpace, +pub struct Generics<'tcx> { + pub types: VecPerParamSpace>, pub regions: VecPerParamSpace, } -impl Generics { - pub fn empty() -> Generics { +impl<'tcx> Generics<'tcx> { + pub fn empty() -> Generics<'tcx> { Generics { types: VecPerParamSpace::empty(), regions: VecPerParamSpace::empty() } } @@ -1410,7 +1413,8 @@ impl Generics { !self.regions.is_empty_in(space) } - pub fn to_bounds(&self, tcx: &ty::ctxt, substs: &Substs) -> GenericBounds { + pub fn to_bounds(&self, tcx: &ty::ctxt<'tcx>, substs: &Substs<'tcx>) + -> GenericBounds<'tcx> { GenericBounds { types: self.types.map(|d| d.bounds.subst(tcx, substs)), regions: self.regions.map(|d| d.bounds.subst(tcx, substs)), @@ -1440,13 +1444,13 @@ impl Generics { * [uint:Bar]]`. */ #[deriving(Clone, Show)] -pub struct GenericBounds { - pub types: VecPerParamSpace, +pub struct GenericBounds<'tcx> { + pub types: VecPerParamSpace>, pub regions: VecPerParamSpace>, } -impl GenericBounds { - pub fn empty() -> GenericBounds { +impl<'tcx> GenericBounds<'tcx> { + pub fn empty() -> GenericBounds<'tcx> { GenericBounds { types: VecPerParamSpace::empty(), regions: VecPerParamSpace::empty() } } @@ -1457,16 +1461,16 @@ impl GenericBounds { } } -impl TraitRef { - pub fn new(def_id: ast::DefId, substs: Substs) -> TraitRef { +impl<'tcx> TraitRef<'tcx> { + pub fn new(def_id: ast::DefId, substs: Substs<'tcx>) -> TraitRef<'tcx> { TraitRef { def_id: def_id, substs: substs } } - pub fn self_ty(&self) -> ty::t { + pub fn self_ty(&self) -> Ty<'tcx> { self.substs.self_ty().unwrap() } - pub fn input_types(&self) -> &[ty::t] { + pub fn input_types(&self) -> &[Ty<'tcx>] { // Select only the "input types" from a trait-reference. For // now this is all the types that appear in the // trait-reference, but it should eventually exclude @@ -1495,16 +1499,16 @@ impl TraitRef { /// bound lifetime parameters are replaced with free ones, but in the /// future I hope to refine the representation of types so as to make /// more distinctions clearer. -pub struct ParameterEnvironment { +pub struct ParameterEnvironment<'tcx> { /// A substitution that can be applied to move from /// the "outer" view of a type or method to the "inner" view. /// In general, this means converting from bound parameters to /// free parameters. Since we currently represent bound/free type /// parameters in the same way, this only has an effect on regions. - pub free_substs: Substs, + pub free_substs: Substs<'tcx>, /// Bounds on the various type parameters - pub bounds: VecPerParamSpace, + pub bounds: VecPerParamSpace>, /// Each type parameter has an implicit region bound that /// indicates it must outlive at least the function body (the user @@ -1518,15 +1522,15 @@ pub struct ParameterEnvironment { /// /// Note: This effectively *duplicates* the `bounds` array for /// now. - pub caller_obligations: VecPerParamSpace, + pub caller_obligations: VecPerParamSpace>, /// Caches the results of trait selection. This cache is used /// for things that have to do with the parameters in scope. - pub selection_cache: traits::SelectionCache, + pub selection_cache: traits::SelectionCache<'tcx>, } -impl ParameterEnvironment { - pub fn for_item(cx: &ctxt, id: NodeId) -> ParameterEnvironment { +impl<'tcx> ParameterEnvironment<'tcx> { + pub fn for_item(cx: &ctxt<'tcx>, id: NodeId) -> ParameterEnvironment<'tcx> { match cx.map.find(id) { Some(ast_map::NodeImplItem(ref impl_item)) => { match **impl_item { @@ -1636,37 +1640,37 @@ impl ParameterEnvironment { /// - `ty`: the base types, which may reference the parameters defined /// in `generics` #[deriving(Clone, Show)] -pub struct Polytype { - pub generics: Generics, - pub ty: t +pub struct Polytype<'tcx> { + pub generics: Generics<'tcx>, + pub ty: Ty<'tcx> } /// As `Polytype` but for a trait ref. -pub struct TraitDef { +pub struct TraitDef<'tcx> { /// Generic type definitions. Note that `Self` is listed in here /// as having a single bound, the trait itself (e.g., in the trait /// `Eq`, there is a single bound `Self : Eq`). This is so that /// default methods get to assume that the `Self` parameters /// implements the trait. - pub generics: Generics, + pub generics: Generics<'tcx>, /// The "supertrait" bounds. - pub bounds: ParamBounds, - pub trait_ref: Rc, + pub bounds: ParamBounds<'tcx>, + pub trait_ref: Rc>, } /// Records the substitutions used to translate the polytype for an /// item into the monotype of an item reference. #[deriving(Clone)] -pub struct ItemSubsts { - pub substs: Substs, +pub struct ItemSubsts<'tcx> { + pub substs: Substs<'tcx>, } /// Records information about each unboxed closure. #[deriving(Clone)] -pub struct UnboxedClosure { +pub struct UnboxedClosure<'tcx> { /// The type of the unboxed closure. - pub closure_type: ClosureTy, + pub closure_type: ClosureTy<'tcx>, /// The kind of unboxed closure this is. pub kind: UnboxedClosureKind, } @@ -1697,7 +1701,7 @@ impl UnboxedClosureKind { } pub fn mk_ctxt<'tcx>(s: Session, - type_arena: &'tcx TypedArena, + type_arena: &'tcx TypedArena>, dm: resolve::DefMap, named_region_map: resolve_lifetime::NamedRegionMap, map: ast_map::Map<'tcx>, @@ -1768,8 +1772,8 @@ pub fn mk_ctxt<'tcx>(s: Session, // Type constructors // Interns a type/name combination, stores the resulting box in cx.interner, -// and returns the box as cast to an unsafe ptr (see comments for t above). -pub fn mk_t(cx: &ctxt, st: sty) -> t { +// and returns the box as cast to an unsafe ptr (see comments for Ty above). +pub fn mk_t<'tcx>(cx: &ctxt<'tcx>, st: sty<'tcx>) -> Ty<'tcx> { // Check for primitive types. match st { ty_err => return mk_err(), @@ -1781,32 +1785,22 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t { _ => {} }; - let key = intern_key { sty: &st }; - - match cx.interner.borrow().get(&key) { - Some(t) => unsafe { return mem::transmute(&t.sty); }, + match cx.interner.borrow().get(&st) { + Some(ty) => return *ty, _ => () } let flags = FlagComputation::for_sty(&st); - let t = cx.type_arena.alloc(t_box_ { + let ty = cx.type_arena.alloc(TyS { sty: st, flags: flags.flags, region_depth: flags.depth, }); - let sty_ptr = &t.sty as *const sty; - - let key = intern_key { - sty: sty_ptr, - }; - - cx.interner.borrow_mut().insert(key, t); + cx.interner.borrow_mut().insert(InternedTy { ty: ty }, ty); - unsafe { - mem::transmute::<*const sty, t>(sty_ptr) - } + ty } struct FlagComputation { @@ -1938,13 +1932,12 @@ impl FlagComputation { } } - fn add_ty(&mut self, t: t) { - let t_box = get(t); - self.add_flags(t_box.flags); - self.add_depth(t_box.region_depth); + fn add_ty(&mut self, ty: Ty) { + self.add_flags(ty.flags); + self.add_depth(ty.region_depth); } - fn add_tys(&mut self, tys: &[t]) { + fn add_tys(&mut self, tys: &[Ty]) { for &ty in tys.iter() { self.add_ty(ty); } @@ -1991,56 +1984,7 @@ impl FlagComputation { } } -#[inline] -pub fn mk_prim_t(primitive: &'static t_box_) -> t { - unsafe { - mem::transmute::<&'static t_box_, t>(primitive) - } -} - -#[inline] -pub fn mk_err() -> t { mk_prim_t(&primitives::TY_ERR) } - -#[inline] -pub fn mk_bool() -> t { mk_prim_t(&primitives::TY_BOOL) } - -#[inline] -pub fn mk_int() -> t { mk_prim_t(&primitives::TY_INT) } - -#[inline] -pub fn mk_i8() -> t { mk_prim_t(&primitives::TY_I8) } - -#[inline] -pub fn mk_i16() -> t { mk_prim_t(&primitives::TY_I16) } - -#[inline] -pub fn mk_i32() -> t { mk_prim_t(&primitives::TY_I32) } - -#[inline] -pub fn mk_i64() -> t { mk_prim_t(&primitives::TY_I64) } - -#[inline] -pub fn mk_f32() -> t { mk_prim_t(&primitives::TY_F32) } - -#[inline] -pub fn mk_f64() -> t { mk_prim_t(&primitives::TY_F64) } - -#[inline] -pub fn mk_uint() -> t { mk_prim_t(&primitives::TY_UINT) } - -#[inline] -pub fn mk_u8() -> t { mk_prim_t(&primitives::TY_U8) } - -#[inline] -pub fn mk_u16() -> t { mk_prim_t(&primitives::TY_U16) } - -#[inline] -pub fn mk_u32() -> t { mk_prim_t(&primitives::TY_U32) } - -#[inline] -pub fn mk_u64() -> t { mk_prim_t(&primitives::TY_U64) } - -pub fn mk_mach_int(tm: ast::IntTy) -> t { +pub fn mk_mach_int<'tcx>(tm: ast::IntTy) -> Ty<'tcx> { match tm { ast::TyI => mk_int(), ast::TyI8 => mk_i8(), @@ -2050,7 +1994,7 @@ pub fn mk_mach_int(tm: ast::IntTy) -> t { } } -pub fn mk_mach_uint(tm: ast::UintTy) -> t { +pub fn mk_mach_uint<'tcx>(tm: ast::UintTy) -> Ty<'tcx> { match tm { ast::TyU => mk_uint(), ast::TyU8 => mk_u8(), @@ -2060,21 +2004,18 @@ pub fn mk_mach_uint(tm: ast::UintTy) -> t { } } -pub fn mk_mach_float(tm: ast::FloatTy) -> t { +pub fn mk_mach_float<'tcx>(tm: ast::FloatTy) -> Ty<'tcx> { match tm { ast::TyF32 => mk_f32(), ast::TyF64 => mk_f64(), } } -#[inline] -pub fn mk_char() -> t { mk_prim_t(&primitives::TY_CHAR) } - -pub fn mk_str(cx: &ctxt) -> t { +pub fn mk_str<'tcx>(cx: &ctxt<'tcx>) -> Ty<'tcx> { mk_t(cx, ty_str) } -pub fn mk_str_slice(cx: &ctxt, r: Region, m: ast::Mutability) -> t { +pub fn mk_str_slice<'tcx>(cx: &ctxt<'tcx>, r: Region, m: ast::Mutability) -> Ty<'tcx> { mk_rptr(cx, r, mt { ty: mk_t(cx, ty_str), @@ -2082,41 +2023,43 @@ pub fn mk_str_slice(cx: &ctxt, r: Region, m: ast::Mutability) -> t { }) } -pub fn mk_enum(cx: &ctxt, did: ast::DefId, substs: Substs) -> t { +pub fn mk_enum<'tcx>(cx: &ctxt<'tcx>, did: ast::DefId, substs: Substs<'tcx>) -> Ty<'tcx> { // take a copy of substs so that we own the vectors inside mk_t(cx, ty_enum(did, substs)) } -pub fn mk_uniq(cx: &ctxt, ty: t) -> t { mk_t(cx, ty_uniq(ty)) } +pub fn mk_uniq<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { mk_t(cx, ty_uniq(ty)) } -pub fn mk_ptr(cx: &ctxt, tm: mt) -> t { mk_t(cx, ty_ptr(tm)) } +pub fn mk_ptr<'tcx>(cx: &ctxt<'tcx>, tm: mt<'tcx>) -> Ty<'tcx> { mk_t(cx, ty_ptr(tm)) } -pub fn mk_rptr(cx: &ctxt, r: Region, tm: mt) -> t { mk_t(cx, ty_rptr(r, tm)) } +pub fn mk_rptr<'tcx>(cx: &ctxt<'tcx>, r: Region, tm: mt<'tcx>) -> Ty<'tcx> { + mk_t(cx, ty_rptr(r, tm)) +} -pub fn mk_mut_rptr(cx: &ctxt, r: Region, ty: t) -> t { +pub fn mk_mut_rptr<'tcx>(cx: &ctxt<'tcx>, r: Region, ty: Ty<'tcx>) -> Ty<'tcx> { mk_rptr(cx, r, mt {ty: ty, mutbl: ast::MutMutable}) } -pub fn mk_imm_rptr(cx: &ctxt, r: Region, ty: t) -> t { +pub fn mk_imm_rptr<'tcx>(cx: &ctxt<'tcx>, r: Region, ty: Ty<'tcx>) -> Ty<'tcx> { mk_rptr(cx, r, mt {ty: ty, mutbl: ast::MutImmutable}) } -pub fn mk_mut_ptr(cx: &ctxt, ty: t) -> t { +pub fn mk_mut_ptr<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { mk_ptr(cx, mt {ty: ty, mutbl: ast::MutMutable}) } -pub fn mk_imm_ptr(cx: &ctxt, ty: t) -> t { +pub fn mk_imm_ptr<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { mk_ptr(cx, mt {ty: ty, mutbl: ast::MutImmutable}) } -pub fn mk_nil_ptr(cx: &ctxt) -> t { +pub fn mk_nil_ptr<'tcx>(cx: &ctxt<'tcx>) -> Ty<'tcx> { mk_ptr(cx, mt {ty: mk_nil(cx), mutbl: ast::MutImmutable}) } -pub fn mk_vec(cx: &ctxt, t: t, sz: Option) -> t { - mk_t(cx, ty_vec(t, sz)) +pub fn mk_vec<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, sz: Option) -> Ty<'tcx> { + mk_t(cx, ty_vec(ty, sz)) } -pub fn mk_slice(cx: &ctxt, r: Region, tm: mt) -> t { +pub fn mk_slice<'tcx>(cx: &ctxt<'tcx>, r: Region, tm: mt<'tcx>) -> Ty<'tcx> { mk_rptr(cx, r, mt { ty: mk_vec(cx, tm.ty, None), @@ -2124,26 +2067,26 @@ pub fn mk_slice(cx: &ctxt, r: Region, tm: mt) -> t { }) } -pub fn mk_tup(cx: &ctxt, ts: Vec) -> t { +pub fn mk_tup<'tcx>(cx: &ctxt<'tcx>, ts: Vec>) -> Ty<'tcx> { mk_t(cx, ty_tup(ts)) } -pub fn mk_nil(cx: &ctxt) -> t { +pub fn mk_nil<'tcx>(cx: &ctxt<'tcx>) -> Ty<'tcx> { mk_tup(cx, Vec::new()) } -pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t { +pub fn mk_closure<'tcx>(cx: &ctxt<'tcx>, fty: ClosureTy<'tcx>) -> Ty<'tcx> { mk_t(cx, ty_closure(box fty)) } -pub fn mk_bare_fn(cx: &ctxt, fty: BareFnTy) -> t { +pub fn mk_bare_fn<'tcx>(cx: &ctxt<'tcx>, fty: BareFnTy<'tcx>) -> Ty<'tcx> { mk_t(cx, ty_bare_fn(fty)) } -pub fn mk_ctor_fn(cx: &ctxt, - input_tys: &[ty::t], - output: ty::t) -> t { - let input_args = input_tys.iter().map(|t| *t).collect(); +pub fn mk_ctor_fn<'tcx>(cx: &ctxt<'tcx>, + input_tys: &[Ty<'tcx>], + output: Ty<'tcx>) -> Ty<'tcx> { + let input_args = input_tys.iter().map(|ty| *ty).collect(); mk_bare_fn(cx, BareFnTy { fn_style: ast::NormalFn, @@ -2157,10 +2100,10 @@ pub fn mk_ctor_fn(cx: &ctxt, } -pub fn mk_trait(cx: &ctxt, - principal: ty::TraitRef, - bounds: ExistentialBounds) - -> t { +pub fn mk_trait<'tcx>(cx: &ctxt<'tcx>, + principal: ty::TraitRef<'tcx>, + bounds: ExistentialBounds) + -> Ty<'tcx> { // take a copy of substs so that we own the vectors inside let inner = box TyTrait { principal: principal, @@ -2169,47 +2112,58 @@ pub fn mk_trait(cx: &ctxt, mk_t(cx, ty_trait(inner)) } -pub fn mk_struct(cx: &ctxt, struct_id: ast::DefId, substs: Substs) -> t { +pub fn mk_struct<'tcx>(cx: &ctxt<'tcx>, struct_id: ast::DefId, + substs: Substs<'tcx>) -> Ty<'tcx> { // take a copy of substs so that we own the vectors inside mk_t(cx, ty_struct(struct_id, substs)) } -pub fn mk_unboxed_closure(cx: &ctxt, closure_id: ast::DefId, region: Region, substs: Substs) - -> t { +pub fn mk_unboxed_closure<'tcx>(cx: &ctxt<'tcx>, closure_id: ast::DefId, + region: Region, substs: Substs<'tcx>) + -> Ty<'tcx> { mk_t(cx, ty_unboxed_closure(closure_id, region, substs)) } -pub fn mk_var(cx: &ctxt, v: TyVid) -> t { mk_infer(cx, TyVar(v)) } +pub fn mk_var<'tcx>(cx: &ctxt<'tcx>, v: TyVid) -> Ty<'tcx> { + mk_infer(cx, TyVar(v)) +} -pub fn mk_int_var(cx: &ctxt, v: IntVid) -> t { mk_infer(cx, IntVar(v)) } +pub fn mk_int_var<'tcx>(cx: &ctxt<'tcx>, v: IntVid) -> Ty<'tcx> { + mk_infer(cx, IntVar(v)) +} -pub fn mk_float_var(cx: &ctxt, v: FloatVid) -> t { mk_infer(cx, FloatVar(v)) } +pub fn mk_float_var<'tcx>(cx: &ctxt<'tcx>, v: FloatVid) -> Ty<'tcx> { + mk_infer(cx, FloatVar(v)) +} -pub fn mk_infer(cx: &ctxt, it: InferTy) -> t { mk_t(cx, ty_infer(it)) } +pub fn mk_infer<'tcx>(cx: &ctxt<'tcx>, it: InferTy) -> Ty<'tcx> { + mk_t(cx, ty_infer(it)) +} -pub fn mk_param(cx: &ctxt, space: subst::ParamSpace, n: uint, k: DefId) -> t { +pub fn mk_param<'tcx>(cx: &ctxt<'tcx>, space: subst::ParamSpace, + n: uint, k: DefId) -> Ty<'tcx> { mk_t(cx, ty_param(ParamTy { space: space, idx: n, def_id: k })) } -pub fn mk_self_type(cx: &ctxt, did: ast::DefId) -> t { +pub fn mk_self_type<'tcx>(cx: &ctxt<'tcx>, did: ast::DefId) -> Ty<'tcx> { mk_param(cx, subst::SelfSpace, 0, did) } -pub fn mk_param_from_def(cx: &ctxt, def: &TypeParameterDef) -> t { +pub fn mk_param_from_def<'tcx>(cx: &ctxt<'tcx>, def: &TypeParameterDef) -> Ty<'tcx> { mk_param(cx, def.space, def.index, def.def_id) } -pub fn mk_open(cx: &ctxt, t: t) -> t { mk_t(cx, ty_open(t)) } +pub fn mk_open<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { mk_t(cx, ty_open(ty)) } -pub fn walk_ty(ty: t, f: |t|) { - maybe_walk_ty(ty, |t| { f(t); true }); +pub fn walk_ty<'tcx>(ty: Ty<'tcx>, f: |Ty<'tcx>|) { + maybe_walk_ty(ty, |ty| { f(ty); true }); } -pub fn maybe_walk_ty(ty: t, f: |t| -> bool) { +pub fn maybe_walk_ty<'tcx>(ty: Ty<'tcx>, f: |Ty<'tcx>| -> bool) { if !f(ty) { return; } - match get(ty).sty { + match ty.sty { ty_bool | ty_char | ty_int(_) | ty_uint(_) | ty_float(_) | ty_str | ty_infer(_) | ty_param(_) | ty_err => {} ty_uniq(ty) | ty_vec(ty, _) | ty_open(ty) => maybe_walk_ty(ty, f), @@ -2245,7 +2199,9 @@ pub fn maybe_walk_ty(ty: t, f: |t| -> bool) { } // Folds types from the bottom up. -pub fn fold_ty(cx: &ctxt, t0: t, fldop: |t| -> t) -> t { +pub fn fold_ty<'tcx>(cx: &ctxt<'tcx>, t0: Ty<'tcx>, + fldop: |Ty<'tcx>| -> Ty<'tcx>) + -> Ty<'tcx> { let mut f = ty_fold::BottomUpFolder {tcx: cx, fldop: fldop}; f.fold_ty(t0) } @@ -2266,7 +2222,7 @@ impl ParamTy { ParamTy::new(def.space, def.index, def.def_id) } - pub fn to_ty(self, tcx: &ty::ctxt) -> ty::t { + pub fn to_ty<'tcx>(self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> { ty::mk_param(tcx, self.space, self.idx, self.def_id) } @@ -2275,8 +2231,8 @@ impl ParamTy { } } -impl ItemSubsts { - pub fn empty() -> ItemSubsts { +impl<'tcx> ItemSubsts<'tcx> { + pub fn empty() -> ItemSubsts<'tcx> { ItemSubsts { substs: Substs::empty() } } @@ -2285,8 +2241,8 @@ impl ItemSubsts { } } -impl ParamBounds { - pub fn empty() -> ParamBounds { +impl<'tcx> ParamBounds<'tcx> { + pub fn empty() -> ParamBounds<'tcx> { ParamBounds { builtin_bounds: empty_builtin_bounds(), trait_bounds: Vec::new(), @@ -2297,44 +2253,44 @@ impl ParamBounds { // Type utilities -pub fn type_is_nil(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_nil(ty: Ty) -> bool { + match ty.sty { ty_tup(ref tys) => tys.is_empty(), _ => false } } -pub fn type_is_error(ty: t) -> bool { - get(ty).flags.intersects(HAS_TY_ERR) +pub fn type_is_error(ty: Ty) -> bool { + ty.flags.intersects(HAS_TY_ERR) } -pub fn type_needs_subst(ty: t) -> bool { - tbox_has_flag(get(ty), NEEDS_SUBST) +pub fn type_needs_subst(ty: Ty) -> bool { + ty.flags.intersects(NEEDS_SUBST) } pub fn trait_ref_contains_error(tref: &ty::TraitRef) -> bool { - tref.substs.types.any(|&t| type_is_error(t)) + tref.substs.types.any(|&ty| type_is_error(ty)) } -pub fn type_is_ty_var(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_ty_var(ty: Ty) -> bool { + match ty.sty { ty_infer(TyVar(_)) => true, _ => false } } -pub fn type_is_bool(ty: t) -> bool { get(ty).sty == ty_bool } +pub fn type_is_bool(ty: Ty) -> bool { ty.sty == ty_bool } -pub fn type_is_self(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_self(ty: Ty) -> bool { + match ty.sty { ty_param(ref p) => p.space == subst::SelfSpace, _ => false } } -fn type_is_slice(ty: t) -> bool { - match get(ty).sty { - ty_ptr(mt) | ty_rptr(_, mt) => match get(mt.ty).sty { +fn type_is_slice(ty: Ty) -> bool { + match ty.sty { + ty_ptr(mt) | ty_rptr(_, mt) => match mt.ty.sty { ty_vec(_, None) | ty_str => true, _ => false, }, @@ -2342,11 +2298,11 @@ fn type_is_slice(ty: t) -> bool { } } -pub fn type_is_vec(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_vec(ty: Ty) -> bool { + match ty.sty { ty_vec(..) => true, - ty_ptr(mt{ty: t, ..}) | ty_rptr(_, mt{ty: t, ..}) | - ty_uniq(t) => match get(t).sty { + ty_ptr(mt{ty, ..}) | ty_rptr(_, mt{ty, ..}) | + ty_uniq(ty) => match ty.sty { ty_vec(_, None) => true, _ => false }, @@ -2354,23 +2310,23 @@ pub fn type_is_vec(ty: t) -> bool { } } -pub fn type_is_structural(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_structural(ty: Ty) -> bool { + match ty.sty { ty_struct(..) | ty_tup(_) | ty_enum(..) | ty_closure(_) | ty_vec(_, Some(_)) | ty_unboxed_closure(..) => true, _ => type_is_slice(ty) | type_is_trait(ty) } } -pub fn type_is_simd(cx: &ctxt, ty: t) -> bool { - match get(ty).sty { +pub fn type_is_simd(cx: &ctxt, ty: Ty) -> bool { + match ty.sty { ty_struct(did, _) => lookup_simd(cx, did), _ => false } } -pub fn sequence_element_type(cx: &ctxt, ty: t) -> t { - match get(ty).sty { +pub fn sequence_element_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + match ty.sty { ty_vec(ty, _) => ty, ty_str => mk_mach_uint(ast::TyU8), ty_open(ty) => sequence_element_type(cx, ty), @@ -2379,8 +2335,8 @@ pub fn sequence_element_type(cx: &ctxt, ty: t) -> t { } } -pub fn simd_type(cx: &ctxt, ty: t) -> t { - match get(ty).sty { +pub fn simd_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + match ty.sty { ty_struct(did, ref substs) => { let fields = lookup_struct_fields(cx, did); lookup_field_type(cx, did, fields[0].id, substs) @@ -2389,8 +2345,8 @@ pub fn simd_type(cx: &ctxt, ty: t) -> t { } } -pub fn simd_size(cx: &ctxt, ty: t) -> uint { - match get(ty).sty { +pub fn simd_size(cx: &ctxt, ty: Ty) -> uint { + match ty.sty { ty_struct(did, _) => { let fields = lookup_struct_fields(cx, did); fields.len() @@ -2399,23 +2355,23 @@ pub fn simd_size(cx: &ctxt, ty: t) -> uint { } } -pub fn type_is_region_ptr(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_region_ptr(ty: Ty) -> bool { + match ty.sty { ty_rptr(..) => true, _ => false } } -pub fn type_is_unsafe_ptr(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_unsafe_ptr(ty: Ty) -> bool { + match ty.sty { ty_ptr(_) => return true, _ => return false } } -pub fn type_is_unique(ty: t) -> bool { - match get(ty).sty { - ty_uniq(_) => match get(ty).sty { +pub fn type_is_unique(ty: Ty) -> bool { + match ty.sty { + ty_uniq(_) => match ty.sty { ty_trait(..) => false, _ => true }, @@ -2423,8 +2379,8 @@ pub fn type_is_unique(ty: t) -> bool { } } -pub fn type_is_fat_ptr(cx: &ctxt, ty: t) -> bool { - match get(ty).sty { +pub fn type_is_fat_ptr<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { + match ty.sty { ty_ptr(mt{ty, ..}) | ty_rptr(_, mt{ty, ..}) | ty_uniq(ty) if !type_is_sized(cx, ty) => true, _ => false, @@ -2436,8 +2392,8 @@ pub fn type_is_fat_ptr(cx: &ctxt, ty: t) -> bool { (A ty_ptr is scalar because it represents a non-managed pointer, so its contents are abstract to rustc.) */ -pub fn type_is_scalar(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_scalar(ty: Ty) -> bool { + match ty.sty { ty_bool | ty_char | ty_int(_) | ty_float(_) | ty_uint(_) | ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) | ty_bare_fn(..) | ty_ptr(_) => true, @@ -2447,14 +2403,14 @@ pub fn type_is_scalar(ty: t) -> bool { } /// Returns true if this type is a floating point type and false otherwise. -pub fn type_is_floating_point(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_floating_point(ty: Ty) -> bool { + match ty.sty { ty_float(_) => true, _ => false, } } -pub fn type_needs_drop(cx: &ctxt, ty: t) -> bool { +pub fn type_needs_drop<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { type_contents(cx, ty).needs_drop(cx) } @@ -2462,12 +2418,13 @@ pub fn type_needs_drop(cx: &ctxt, ty: t) -> bool { // task can free them all at once later. Currently only things // that only contain scalars and shared boxes can avoid unwind // cleanups. -pub fn type_needs_unwind_cleanup(cx: &ctxt, ty: t) -> bool { +pub fn type_needs_unwind_cleanup<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { return memoized(&cx.needs_unwind_cleanup_cache, ty, |ty| { type_needs_unwind_cleanup_(cx, ty, &mut FnvHashSet::new()) }); - fn type_needs_unwind_cleanup_(cx: &ctxt, ty: t, tycache: &mut FnvHashSet) -> bool { + fn type_needs_unwind_cleanup_<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, + tycache: &mut FnvHashSet>) -> bool { // Prevent infinite recursion if !tycache.insert(ty) { return false; @@ -2475,7 +2432,7 @@ pub fn type_needs_unwind_cleanup(cx: &ctxt, ty: t) -> bool { let mut needs_unwind_cleanup = false; maybe_walk_ty(ty, |ty| { - needs_unwind_cleanup |= match get(ty).sty { + needs_unwind_cleanup |= match ty.sty { ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) | ty_tup(_) | ty_ptr(_) => false, @@ -2651,7 +2608,7 @@ impl TypeContents { } pub fn union(v: &[T], f: |&T| -> TypeContents) -> TypeContents { - v.iter().fold(TC::None, |tc, t| tc | f(t)) + v.iter().fold(TC::None, |tc, ty| tc | f(ty)) } pub fn has_dtor(&self) -> bool { @@ -2683,18 +2640,18 @@ impl fmt::Show for TypeContents { } } -pub fn type_interior_is_unsafe(cx: &ctxt, t: ty::t) -> bool { - type_contents(cx, t).interior_unsafe() +pub fn type_interior_is_unsafe<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { + type_contents(cx, ty).interior_unsafe() } -pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { +pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { return memoized(&cx.tc_cache, ty, |ty| { tc_ty(cx, ty, &mut FnvHashMap::new()) }); - fn tc_ty(cx: &ctxt, - ty: t, - cache: &mut FnvHashMap) -> TypeContents + fn tc_ty<'tcx>(cx: &ctxt<'tcx>, + ty: Ty<'tcx>, + cache: &mut FnvHashMap, TypeContents>) -> TypeContents { // Subtle: Note that we are *not* using cx.tc_cache here but rather a // private cache for this walk. This is needed in the case of cyclic @@ -2727,7 +2684,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { } cache.insert(ty, TC::None); - let result = match get(ty).sty { + let result = match ty.sty { // uint and int are ffi-unsafe ty_uint(ast::TyU) | ty_int(ast::TyI) => { TC::ReachesFfiUnsafe @@ -2745,7 +2702,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { } ty_uniq(typ) => { - TC::ReachesFfiUnsafe | match get(typ).sty { + TC::ReachesFfiUnsafe | match typ.sty { ty_str => TC::OwnsOwned, _ => tc_ty(cx, typ, cache).owned_pointer(), } @@ -2760,19 +2717,19 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { } ty_rptr(r, ref mt) => { - TC::ReachesFfiUnsafe | match get(mt.ty).sty { + TC::ReachesFfiUnsafe | match mt.ty.sty { ty_str => borrowed_contents(r, ast::MutImmutable), ty_vec(..) => tc_ty(cx, mt.ty, cache).reference(borrowed_contents(r, mt.mutbl)), _ => tc_ty(cx, mt.ty, cache).reference(borrowed_contents(r, mt.mutbl)), } } - ty_vec(t, Some(_)) => { - tc_ty(cx, t, cache) + ty_vec(ty, Some(_)) => { + tc_ty(cx, ty, cache) } - ty_vec(t, None) => { - tc_ty(cx, t, cache) | TC::Nonsized + ty_vec(ty, None) => { + tc_ty(cx, ty, cache) | TC::Nonsized } ty_str => TC::Nonsized, @@ -2847,7 +2804,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { } if variants[data_idx].args.len() == 1 { - match get(variants[data_idx].args[0]).sty { + match variants[data_idx].args[0].sty { ty_bare_fn(..) => { res = res - TC::ReachesFfiUnsafe; } _ => { } } @@ -2884,8 +2841,8 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { TC::All } - ty_open(t) => { - let result = tc_ty(cx, t, cache); + ty_open(ty) => { + let result = tc_ty(cx, ty, cache); assert!(!result.is_sized(cx)) result.unsafe_pointer() | TC::Nonsized } @@ -2899,9 +2856,9 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { result } - fn tc_mt(cx: &ctxt, - mt: mt, - cache: &mut FnvHashMap) -> TypeContents + fn tc_mt<'tcx>(cx: &ctxt<'tcx>, + mt: mt<'tcx>, + cache: &mut FnvHashMap, TypeContents>) -> TypeContents { let mc = TC::ReachesMutable.when(mt.mutbl == MutMutable); mc | tc_ty(cx, mt.ty, cache) @@ -2969,10 +2926,10 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { kind_bounds_to_contents(cx, bounds.builtin_bounds, &[]) } - fn kind_bounds_to_contents(cx: &ctxt, - bounds: BuiltinBounds, - traits: &[Rc]) - -> TypeContents { + fn kind_bounds_to_contents<'tcx>(cx: &ctxt<'tcx>, + bounds: BuiltinBounds, + traits: &[Rc>]) + -> TypeContents { let _i = indenter(); let mut tc = TC::All; each_inherited_builtin_bound(cx, bounds, traits, |bound| { @@ -2986,10 +2943,10 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { // Iterates over all builtin bounds on the type parameter def, including // those inherited from traits with builtin-kind-supertraits. - fn each_inherited_builtin_bound(cx: &ctxt, - bounds: BuiltinBounds, - traits: &[Rc], - f: |BuiltinBound|) { + fn each_inherited_builtin_bound<'tcx>(cx: &ctxt<'tcx>, + bounds: BuiltinBounds, + traits: &[Rc>], + f: |BuiltinBound|) { for bound in bounds.iter() { f(bound); } @@ -3005,26 +2962,23 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { } } -pub fn type_moves_by_default(cx: &ctxt, ty: t) -> bool { +pub fn type_moves_by_default<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { type_contents(cx, ty).moves_by_default(cx) } -pub fn is_ffi_safe(cx: &ctxt, ty: t) -> bool { +pub fn is_ffi_safe<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { !type_contents(cx, ty).intersects(TC::ReachesFfiUnsafe) } // True if instantiating an instance of `r_ty` requires an instance of `r_ty`. -pub fn is_instantiable(cx: &ctxt, r_ty: t) -> bool { - fn type_requires(cx: &ctxt, seen: &mut Vec, - r_ty: t, ty: t) -> bool { +pub fn is_instantiable<'tcx>(cx: &ctxt<'tcx>, r_ty: Ty<'tcx>) -> bool { + fn type_requires<'tcx>(cx: &ctxt<'tcx>, seen: &mut Vec, + r_ty: Ty<'tcx>, ty: Ty<'tcx>) -> bool { debug!("type_requires({}, {})?", ::util::ppaux::ty_to_string(cx, r_ty), ::util::ppaux::ty_to_string(cx, ty)); - let r = { - get(r_ty).sty == get(ty).sty || - subtypes_require(cx, seen, r_ty, ty) - }; + let r = r_ty == ty || subtypes_require(cx, seen, r_ty, ty); debug!("type_requires({}, {})? {}", ::util::ppaux::ty_to_string(cx, r_ty), @@ -3033,13 +2987,13 @@ pub fn is_instantiable(cx: &ctxt, r_ty: t) -> bool { return r; } - fn subtypes_require(cx: &ctxt, seen: &mut Vec, - r_ty: t, ty: t) -> bool { + fn subtypes_require<'tcx>(cx: &ctxt<'tcx>, seen: &mut Vec, + r_ty: Ty<'tcx>, ty: Ty<'tcx>) -> bool { debug!("subtypes_require({}, {})?", ::util::ppaux::ty_to_string(cx, r_ty), ::util::ppaux::ty_to_string(cx, ty)); - let r = match get(ty).sty { + let r = match ty.sty { // fixed length vectors need special treatment compared to // normal vectors, since they don't necessarily have the // possibility to have length zero. @@ -3093,7 +3047,7 @@ pub fn is_instantiable(cx: &ctxt, r_ty: t) -> bool { } ty_tup(ref ts) => { - ts.iter().any(|t| type_requires(cx, seen, r_ty, *t)) + ts.iter().any(|ty| type_requires(cx, seen, r_ty, *ty)) } ty_enum(ref did, _) if seen.contains(did) => { @@ -3143,20 +3097,24 @@ pub enum Representability { /// Check whether a type is representable. This means it cannot contain unboxed /// structural recursion. This check is needed for structs and enums. -pub fn is_type_representable(cx: &ctxt, sp: Span, ty: t) -> Representability { +pub fn is_type_representable<'tcx>(cx: &ctxt<'tcx>, sp: Span, ty: Ty<'tcx>) + -> Representability { // Iterate until something non-representable is found - fn find_nonrepresentable>(cx: &ctxt, sp: Span, seen: &mut Vec, - mut iter: It) -> Representability { + fn find_nonrepresentable<'tcx, It: Iterator>>(cx: &ctxt<'tcx>, sp: Span, + seen: &mut Vec>, + mut iter: It) + -> Representability { iter.fold(Representable, |r, ty| cmp::max(r, is_type_structurally_recursive(cx, sp, seen, ty))) } - fn are_inner_types_recursive(cx: &ctxt, sp: Span, - seen: &mut Vec, ty: t) -> Representability { - match get(ty).sty { + fn are_inner_types_recursive<'tcx>(cx: &ctxt<'tcx>, sp: Span, + seen: &mut Vec>, ty: Ty<'tcx>) + -> Representability { + match ty.sty { ty_tup(ref ts) => { - find_nonrepresentable(cx, sp, seen, ts.iter().map(|t| *t)) + find_nonrepresentable(cx, sp, seen, ts.iter().map(|ty| *ty)) } // Fixed-length vectors. // FIXME(#11924) Behavior undecided for zero-length vectors. @@ -3183,8 +3141,8 @@ pub fn is_type_representable(cx: &ctxt, sp: Span, ty: t) -> Representability { } } - fn same_struct_or_enum_def_id(ty: t, did: DefId) -> bool { - match get(ty).sty { + fn same_struct_or_enum_def_id(ty: Ty, did: DefId) -> bool { + match ty.sty { ty_struct(ty_did, _) | ty_enum(ty_did, _) => { ty_did == did } @@ -3192,8 +3150,8 @@ pub fn is_type_representable(cx: &ctxt, sp: Span, ty: t) -> Representability { } } - fn same_type(a: t, b: t) -> bool { - match (&get(a).sty, &get(b).sty) { + fn same_type<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { + match (&a.sty, &b.sty) { (&ty_struct(did_a, ref substs_a), &ty_struct(did_b, ref substs_b)) | (&ty_enum(did_a, ref substs_a), &ty_enum(did_b, ref substs_b)) => { if did_a != did_b { @@ -3215,12 +3173,13 @@ pub fn is_type_representable(cx: &ctxt, sp: Span, ty: t) -> Representability { // Does the type `ty` directly (without indirection through a pointer) // contain any types on stack `seen`? - fn is_type_structurally_recursive(cx: &ctxt, sp: Span, seen: &mut Vec, - ty: t) -> Representability { + fn is_type_structurally_recursive<'tcx>(cx: &ctxt<'tcx>, sp: Span, + seen: &mut Vec>, + ty: Ty<'tcx>) -> Representability { debug!("is_type_structurally_recursive: {}", ::util::ppaux::ty_to_string(cx, ty)); - match get(ty).sty { + match ty.sty { ty_struct(did, _) | ty_enum(did, _) => { { // Iterate through stack of previously seen types. @@ -3285,20 +3244,20 @@ pub fn is_type_representable(cx: &ctxt, sp: Span, ty: t) -> Representability { // To avoid a stack overflow when checking an enum variant or struct that // contains a different, structurally recursive type, maintain a stack // of seen types and check recursion for each of them (issues #3008, #3779). - let mut seen: Vec = Vec::new(); + let mut seen: Vec = Vec::new(); let r = is_type_structurally_recursive(cx, sp, &mut seen, ty); debug!("is_type_representable: {} is {}", ::util::ppaux::ty_to_string(cx, ty), r); r } -pub fn type_is_trait(ty: t) -> bool { +pub fn type_is_trait(ty: Ty) -> bool { type_trait_info(ty).is_some() } -pub fn type_trait_info(ty: t) -> Option<&'static TyTrait> { - match get(ty).sty { - ty_uniq(ty) | ty_rptr(_, mt { ty, ..}) | ty_ptr(mt { ty, ..}) => match get(ty).sty { +pub fn type_trait_info<'tcx>(ty: Ty<'tcx>) -> Option<&'tcx TyTrait<'tcx>> { + match ty.sty { + ty_uniq(ty) | ty_rptr(_, mt { ty, ..}) | ty_ptr(mt { ty, ..}) => match ty.sty { ty_trait(ref t) => Some(&**t), _ => None }, @@ -3307,62 +3266,62 @@ pub fn type_trait_info(ty: t) -> Option<&'static TyTrait> { } } -pub fn type_is_integral(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_integral(ty: Ty) -> bool { + match ty.sty { ty_infer(IntVar(_)) | ty_int(_) | ty_uint(_) => true, _ => false } } -pub fn type_is_skolemized(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_skolemized(ty: Ty) -> bool { + match ty.sty { ty_infer(SkolemizedTy(_)) => true, ty_infer(SkolemizedIntTy(_)) => true, _ => false } } -pub fn type_is_uint(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_uint(ty: Ty) -> bool { + match ty.sty { ty_infer(IntVar(_)) | ty_uint(ast::TyU) => true, _ => false } } -pub fn type_is_char(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_char(ty: Ty) -> bool { + match ty.sty { ty_char => true, _ => false } } -pub fn type_is_bare_fn(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_bare_fn(ty: Ty) -> bool { + match ty.sty { ty_bare_fn(..) => true, _ => false } } -pub fn type_is_fp(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_fp(ty: Ty) -> bool { + match ty.sty { ty_infer(FloatVar(_)) | ty_float(_) => true, _ => false } } -pub fn type_is_numeric(ty: t) -> bool { +pub fn type_is_numeric(ty: Ty) -> bool { return type_is_integral(ty) || type_is_fp(ty); } -pub fn type_is_signed(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_signed(ty: Ty) -> bool { + match ty.sty { ty_int(_) => true, _ => false } } -pub fn type_is_machine(ty: t) -> bool { - match get(ty).sty { +pub fn type_is_machine(ty: Ty) -> bool { + match ty.sty { ty_int(ast::TyI) | ty_uint(ast::TyU) => false, ty_int(..) | ty_uint(..) | ty_float(..) => true, _ => false @@ -3370,22 +3329,22 @@ pub fn type_is_machine(ty: t) -> bool { } // Is the type's representation size known at compile time? -pub fn type_is_sized(cx: &ctxt, ty: t) -> bool { +pub fn type_is_sized<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { type_contents(cx, ty).is_sized(cx) } -pub fn lltype_is_sized(cx: &ctxt, ty: t) -> bool { - match get(ty).sty { +pub fn lltype_is_sized<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { + match ty.sty { ty_open(_) => true, _ => type_contents(cx, ty).is_sized(cx) } } -// Return the smallest part of t which is unsized. Fails if t is sized. +// Return the smallest part of ty which is unsized. Fails if ty is sized. // 'Smallest' here means component of the static representation of the type; not // the size of an object at runtime. -pub fn unsized_part_of_type(cx: &ctxt, ty: t) -> t { - match get(ty).sty { +pub fn unsized_part_of_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + match ty.sty { ty_str | ty_trait(..) | ty_vec(..) => ty, ty_struct(def_id, ref substs) => { let unsized_fields: Vec<_> = struct_fields(cx, def_id, substs).iter() @@ -3405,8 +3364,8 @@ pub fn unsized_part_of_type(cx: &ctxt, ty: t) -> t { // Whether a type is enum like, that is an enum type with only nullary // constructors -pub fn type_is_c_like_enum(cx: &ctxt, ty: t) -> bool { - match get(ty).sty { +pub fn type_is_c_like_enum(cx: &ctxt, ty: Ty) -> bool { + match ty.sty { ty_enum(did, _) => { let variants = enum_variants(cx, did); if variants.len() == 0 { @@ -3419,12 +3378,12 @@ pub fn type_is_c_like_enum(cx: &ctxt, ty: t) -> bool { } } -// Returns the type and mutability of *t. +// Returns the type and mutability of *ty. // // The parameter `explicit` indicates if this is an *explicit* dereference. // Some types---notably unsafe ptrs---can only be dereferenced explicitly. -pub fn deref(t: t, explicit: bool) -> Option { - match get(t).sty { +pub fn deref<'tcx>(ty: Ty<'tcx>, explicit: bool) -> Option> { + match ty.sty { ty_uniq(ty) => { Some(mt { ty: ty, @@ -3437,43 +3396,42 @@ pub fn deref(t: t, explicit: bool) -> Option { } } -pub fn deref_or_dont(t: t) -> t { - match get(t).sty { +pub fn deref_or_dont<'tcx>(ty: Ty<'tcx>) -> Ty<'tcx> { + match ty.sty { ty_uniq(ty) => ty, ty_rptr(_, mt) | ty_ptr(mt) => mt.ty, - _ => t + _ => ty } } -pub fn close_type(cx: &ctxt, t: t) -> t { - match get(t).sty { - ty_open(t) => mk_rptr(cx, ReStatic, mt {ty: t, mutbl:ast::MutImmutable}), +pub fn close_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + match ty.sty { + ty_open(ty) => mk_rptr(cx, ReStatic, mt {ty: ty, mutbl:ast::MutImmutable}), _ => cx.sess.bug(format!("Trying to close a non-open type {}", - ty_to_string(cx, t)).as_slice()) + ty_to_string(cx, ty)).as_slice()) } } -pub fn type_content(t: t) -> t { - match get(t).sty { +pub fn type_content<'tcx>(ty: Ty<'tcx>) -> Ty<'tcx> { + match ty.sty { ty_uniq(ty) => ty, ty_rptr(_, mt) |ty_ptr(mt) => mt.ty, - _ => t + _ => ty } - } -// Extract the unsized type in an open type (or just return t if it is not open). -pub fn unopen_type(t: t) -> t { - match get(t).sty { - ty_open(t) => t, - _ => t +// Extract the unsized type in an open type (or just return ty if it is not open). +pub fn unopen_type<'tcx>(ty: Ty<'tcx>) -> Ty<'tcx> { + match ty.sty { + ty_open(ty) => ty, + _ => ty } } -// Returns the type of t[i] -pub fn index(ty: t) -> Option { - match get(ty).sty { - ty_vec(t, _) => Some(t), +// Returns the type of ty[i] +pub fn index<'tcx>(ty: Ty<'tcx>) -> Option> { + match ty.sty { + ty_vec(ty, _) => Some(ty), _ => None } } @@ -3481,52 +3439,53 @@ pub fn index(ty: t) -> Option { // Returns the type of elements contained within an 'array-like' type. // This is exactly the same as the above, except it supports strings, // which can't actually be indexed. -pub fn array_element_ty(t: t) -> Option { - match get(t).sty { - ty_vec(t, _) => Some(t), +pub fn array_element_ty<'tcx>(ty: Ty<'tcx>) -> Option> { + match ty.sty { + ty_vec(ty, _) => Some(ty), ty_str => Some(mk_u8()), _ => None } } -pub fn node_id_to_trait_ref(cx: &ctxt, id: ast::NodeId) -> Rc { +pub fn node_id_to_trait_ref<'tcx>(cx: &ctxt<'tcx>, id: ast::NodeId) + -> Rc> { match cx.trait_refs.borrow().get(&id) { - Some(t) => t.clone(), + Some(ty) => ty.clone(), None => cx.sess.bug( format!("node_id_to_trait_ref: no trait ref for node `{}`", cx.map.node_to_string(id)).as_slice()) } } -pub fn try_node_id_to_type(cx: &ctxt, id: ast::NodeId) -> Option { +pub fn try_node_id_to_type<'tcx>(cx: &ctxt<'tcx>, id: ast::NodeId) -> Option> { cx.node_types.borrow().get(&id).cloned() } -pub fn node_id_to_type(cx: &ctxt, id: ast::NodeId) -> t { +pub fn node_id_to_type<'tcx>(cx: &ctxt<'tcx>, id: ast::NodeId) -> Ty<'tcx> { match try_node_id_to_type(cx, id) { - Some(t) => t, + Some(ty) => ty, None => cx.sess.bug( format!("node_id_to_type: no type for node `{}`", cx.map.node_to_string(id)).as_slice()) } } -pub fn node_id_to_type_opt(cx: &ctxt, id: ast::NodeId) -> Option { +pub fn node_id_to_type_opt<'tcx>(cx: &ctxt<'tcx>, id: ast::NodeId) -> Option> { match cx.node_types.borrow().get(&id) { - Some(&t) => Some(t), + Some(&ty) => Some(ty), None => None } } -pub fn node_id_item_substs(cx: &ctxt, id: ast::NodeId) -> ItemSubsts { +pub fn node_id_item_substs<'tcx>(cx: &ctxt<'tcx>, id: ast::NodeId) -> ItemSubsts<'tcx> { match cx.item_substs.borrow().get(&id) { None => ItemSubsts::empty(), Some(ts) => ts.clone(), } } -pub fn fn_is_variadic(fty: t) -> bool { - match get(fty).sty { +pub fn fn_is_variadic(fty: Ty) -> bool { + match fty.sty { ty_bare_fn(ref f) => f.sig.variadic, ty_closure(ref f) => f.sig.variadic, ref s => { @@ -3535,10 +3494,10 @@ pub fn fn_is_variadic(fty: t) -> bool { } } -pub fn ty_fn_sig(fty: t) -> FnSig { - match get(fty).sty { - ty_bare_fn(ref f) => f.sig.clone(), - ty_closure(ref f) => f.sig.clone(), +pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx FnSig<'tcx> { + match fty.sty { + ty_bare_fn(ref f) => &f.sig, + ty_closure(ref f) => &f.sig, ref s => { panic!("ty_fn_sig() called on non-fn type: {}", s) } @@ -3546,8 +3505,8 @@ pub fn ty_fn_sig(fty: t) -> FnSig { } /// Returns the ABI of the given function. -pub fn ty_fn_abi(fty: t) -> abi::Abi { - match get(fty).sty { +pub fn ty_fn_abi(fty: Ty) -> abi::Abi { + match fty.sty { ty_bare_fn(ref f) => f.abi, ty_closure(ref f) => f.abi, _ => panic!("ty_fn_abi() called on non-fn type"), @@ -3555,18 +3514,12 @@ pub fn ty_fn_abi(fty: t) -> abi::Abi { } // Type accessors for substructures of types -pub fn ty_fn_args(fty: t) -> Vec { - match get(fty).sty { - ty_bare_fn(ref f) => f.sig.inputs.clone(), - ty_closure(ref f) => f.sig.inputs.clone(), - ref s => { - panic!("ty_fn_args() called on non-fn type: {}", s) - } - } +pub fn ty_fn_args<'tcx>(fty: Ty<'tcx>) -> &'tcx [Ty<'tcx>] { + ty_fn_sig(fty).inputs.as_slice() } -pub fn ty_closure_store(fty: t) -> TraitStore { - match get(fty).sty { +pub fn ty_closure_store(fty: Ty) -> TraitStore { + match fty.sty { ty_closure(ref f) => f.store, ty_unboxed_closure(..) => { // Close enough for the purposes of all the callers of this @@ -3579,8 +3532,8 @@ pub fn ty_closure_store(fty: t) -> TraitStore { } } -pub fn ty_fn_ret(fty: t) -> FnOutput { - match get(fty).sty { +pub fn ty_fn_ret<'tcx>(fty: Ty<'tcx>) -> FnOutput<'tcx> { + match fty.sty { ty_bare_fn(ref f) => f.sig.output, ty_closure(ref f) => f.sig.output, ref s => { @@ -3589,8 +3542,8 @@ pub fn ty_fn_ret(fty: t) -> FnOutput { } } -pub fn is_fn_ty(fty: t) -> bool { - match get(fty).sty { +pub fn is_fn_ty(fty: Ty) -> bool { + match fty.sty { ty_bare_fn(_) => true, ty_closure(_) => true, _ => false @@ -3599,8 +3552,8 @@ pub fn is_fn_ty(fty: t) -> bool { pub fn ty_region(tcx: &ctxt, span: Span, - ty: t) -> Region { - match get(ty).sty { + ty: Ty) -> Region { + match ty.sty { ty_rptr(r, _) => r, ref s => { tcx.sess.span_bug( @@ -3621,7 +3574,7 @@ pub fn free_region_from_def(free_id: ast::NodeId, def: &RegionParameterDef) // Returns the type of a pattern as a monotype. Like @expr_ty, this function // doesn't provide type parameter substitutions. -pub fn pat_ty(cx: &ctxt, pat: &ast::Pat) -> t { +pub fn pat_ty<'tcx>(cx: &ctxt<'tcx>, pat: &ast::Pat) -> Ty<'tcx> { return node_id_to_type(cx, pat.id); } @@ -3635,16 +3588,16 @@ pub fn pat_ty(cx: &ctxt, pat: &ast::Pat) -> t { // // NB (2): This type doesn't provide type parameter substitutions; e.g. if you // ask for the type of "id" in "id(3)", it will return "fn(&int) -> int" -// instead of "fn(t) -> T with T = int". -pub fn expr_ty(cx: &ctxt, expr: &ast::Expr) -> t { +// instead of "fn(ty) -> T with T = int". +pub fn expr_ty<'tcx>(cx: &ctxt<'tcx>, expr: &ast::Expr) -> Ty<'tcx> { return node_id_to_type(cx, expr.id); } -pub fn expr_ty_opt(cx: &ctxt, expr: &ast::Expr) -> Option { +pub fn expr_ty_opt<'tcx>(cx: &ctxt<'tcx>, expr: &ast::Expr) -> Option> { return node_id_to_type_opt(cx, expr.id); } -pub fn expr_ty_adjusted(cx: &ctxt, expr: &ast::Expr) -> t { +pub fn expr_ty_adjusted<'tcx>(cx: &ctxt<'tcx>, expr: &ast::Expr) -> Ty<'tcx> { /*! * * Returns the type of `expr`, considering any `AutoAdjustment` @@ -3703,16 +3656,16 @@ pub fn local_var_name_str(cx: &ctxt, id: NodeId) -> InternedString { } } -pub fn adjust_ty(cx: &ctxt, - span: Span, - expr_id: ast::NodeId, - unadjusted_ty: ty::t, - adjustment: Option<&AutoAdjustment>, - method_type: |typeck::MethodCall| -> Option) - -> ty::t { +pub fn adjust_ty<'tcx>(cx: &ctxt<'tcx>, + span: Span, + expr_id: ast::NodeId, + unadjusted_ty: Ty<'tcx>, + adjustment: Option<&AutoAdjustment<'tcx>>, + method_type: |typeck::MethodCall| -> Option>) + -> Ty<'tcx> { /*! See `expr_ty_adjusted` */ - match get(unadjusted_ty).sty { + match unadjusted_ty.sty { ty_err => return unadjusted_ty, _ => {} } @@ -3721,7 +3674,7 @@ pub fn adjust_ty(cx: &ctxt, Some(adjustment) => { match *adjustment { AdjustAddEnv(store) => { - match ty::get(unadjusted_ty).sty { + match unadjusted_ty.sty { ty::ty_bare_fn(ref b) => { let bounds = ty::ExistentialBounds { region_bound: ReStatic, @@ -3783,11 +3736,11 @@ pub fn adjust_ty(cx: &ctxt, }; } -pub fn adjust_ty_for_autoref(cx: &ctxt, - span: Span, - ty: ty::t, - autoref: Option<&AutoRef>) - -> ty::t +pub fn adjust_ty_for_autoref<'tcx>(cx: &ctxt<'tcx>, + span: Span, + ty: Ty<'tcx>, + autoref: Option<&AutoRef<'tcx>>) + -> Ty<'tcx> { match autoref { None => ty, @@ -3819,22 +3772,22 @@ pub fn adjust_ty_for_autoref(cx: &ctxt, // Take a sized type and a sizing adjustment and produce an unsized version of // the type. -pub fn unsize_ty(cx: &ctxt, - ty: ty::t, - kind: &UnsizeKind, - span: Span) - -> ty::t { +pub fn unsize_ty<'tcx>(cx: &ctxt<'tcx>, + ty: Ty<'tcx>, + kind: &UnsizeKind<'tcx>, + span: Span) + -> Ty<'tcx> { match kind { - &UnsizeLength(len) => match get(ty).sty { - ty_vec(t, Some(n)) => { + &UnsizeLength(len) => match ty.sty { + ty_vec(ty, Some(n)) => { assert!(len == n); - mk_vec(cx, t, None) + mk_vec(cx, ty, None) } _ => cx.sess.span_bug(span, format!("UnsizeLength with bad sty: {}", ty_to_string(cx, ty)).as_slice()) }, - &UnsizeStruct(box ref k, tp_index) => match get(ty).sty { + &UnsizeStruct(box ref k, tp_index) => match ty.sty { ty_struct(did, ref substs) => { let ty_substs = substs.types.get_slice(subst::TypeSpace); let new_ty = unsize_ty(cx, ty_substs[tp_index], k, span); @@ -3921,7 +3874,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { } def::DefStruct(_) => { - match get(expr_ty(tcx, expr)).sty { + match expr_ty(tcx, expr).sty { ty_bare_fn(..) => RvalueDatumExpr, _ => RvalueDpsExpr } @@ -3991,8 +3944,8 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { ast::ExprCast(..) => { match tcx.node_types.borrow().get(&expr.id) { - Some(&t) => { - if type_is_trait(t) { + Some(&ty) => { + if type_is_trait(ty) { RvalueDpsExpr } else { RvalueDatumExpr @@ -4084,13 +4037,13 @@ pub fn impl_or_trait_item_idx(id: ast::Name, trait_items: &[ImplOrTraitItem]) trait_items.iter().position(|m| m.name() == id) } -pub fn ty_sort_string(cx: &ctxt, t: t) -> String { - match get(t).sty { +pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String { + match ty.sty { ty_bool | ty_char | ty_int(_) | ty_uint(_) | ty_float(_) | ty_str => { - ::util::ppaux::ty_to_string(cx, t) + ::util::ppaux::ty_to_string(cx, ty) } - ty_tup(ref tys) if tys.is_empty() => ::util::ppaux::ty_to_string(cx, t), + ty_tup(ref tys) if tys.is_empty() => ::util::ppaux::ty_to_string(cx, ty), ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)), ty_uniq(_) => "box".to_string(), @@ -4125,7 +4078,7 @@ pub fn ty_sort_string(cx: &ctxt, t: t) -> String { } } -pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> String { +pub fn type_err_to_str<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) -> String { /*! * * Explains the source of a type err in a short, @@ -4307,7 +4260,8 @@ pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option { cx.provided_method_sources.borrow().get(&id).map(|x| *x) } -pub fn provided_trait_methods(cx: &ctxt, id: ast::DefId) -> Vec> { +pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId) + -> Vec>> { if is_local(id) { match cx.map.find(id.node) { Some(ast_map::NodeItem(item)) => { @@ -4376,14 +4330,14 @@ fn lookup_locally_or_in_crate_store( v } -pub fn trait_item(cx: &ctxt, trait_did: ast::DefId, idx: uint) - -> ImplOrTraitItem { +pub fn trait_item<'tcx>(cx: &ctxt<'tcx>, trait_did: ast::DefId, idx: uint) + -> ImplOrTraitItem<'tcx> { let method_def_id = (*ty::trait_item_def_ids(cx, trait_did))[idx].def_id(); impl_or_trait_item(cx, method_def_id) } -pub fn trait_items(cx: &ctxt, trait_did: ast::DefId) - -> Rc> { +pub fn trait_items<'tcx>(cx: &ctxt<'tcx>, trait_did: ast::DefId) + -> Rc>> { let mut trait_items = cx.trait_items_cache.borrow_mut(); match trait_items.get(&trait_did).cloned() { Some(trait_items) => trait_items, @@ -4399,7 +4353,8 @@ pub fn trait_items(cx: &ctxt, trait_did: ast::DefId) } } -pub fn impl_or_trait_item(cx: &ctxt, id: ast::DefId) -> ImplOrTraitItem { +pub fn impl_or_trait_item<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId) + -> ImplOrTraitItem<'tcx> { lookup_locally_or_in_crate_store("impl_or_trait_items", id, &mut *cx.impl_or_trait_items @@ -4471,7 +4426,8 @@ pub fn trait_item_def_ids(cx: &ctxt, id: ast::DefId) }) } -pub fn impl_trait_ref(cx: &ctxt, id: ast::DefId) -> Option> { +pub fn impl_trait_ref<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId) + -> Option>> { memoized(&cx.impl_trait_cache, id, |id: ast::DefId| { if id.krate == ast::LOCAL_CRATE { debug!("(impl_trait_ref) searching for trait impl {}", id); @@ -4521,8 +4477,8 @@ pub fn try_add_builtin_trait( } } -pub fn ty_to_def_id(ty: t) -> Option { - match get(ty).sty { +pub fn ty_to_def_id(ty: Ty) -> Option { + match ty.sty { ty_trait(ref tt) => Some(tt.principal.def_id), ty_struct(id, _) | @@ -4536,24 +4492,24 @@ pub fn ty_to_def_id(ty: t) -> Option { // Enum information #[deriving(Clone)] -pub struct VariantInfo { - pub args: Vec, - pub arg_names: Option >, - pub ctor_ty: Option, +pub struct VariantInfo<'tcx> { + pub args: Vec>, + pub arg_names: Option>, + pub ctor_ty: Option>, pub name: ast::Name, pub id: ast::DefId, pub disr_val: Disr, pub vis: Visibility } -impl VariantInfo { +impl<'tcx> VariantInfo<'tcx> { /// Creates a new VariantInfo from the corresponding ast representation. /// /// Does not do any caching of the value in the type context. - pub fn from_ast_variant(cx: &ctxt, + pub fn from_ast_variant(cx: &ctxt<'tcx>, ast_variant: &ast::Variant, - discriminant: Disr) -> VariantInfo { + discriminant: Disr) -> VariantInfo<'tcx> { let ctor_ty = node_id_to_type(cx, ast_variant.node.id); match ast_variant.node.kind { @@ -4604,10 +4560,10 @@ impl VariantInfo { } } -pub fn substd_enum_variants(cx: &ctxt, - id: ast::DefId, - substs: &Substs) - -> Vec> { +pub fn substd_enum_variants<'tcx>(cx: &ctxt<'tcx>, + id: ast::DefId, + substs: &Substs<'tcx>) + -> Vec>> { enum_variants(cx, id).iter().map(|variant_info| { let substd_args = variant_info.args.iter() .map(|aty| aty.subst(cx, substs)).collect::>(); @@ -4676,14 +4632,15 @@ pub fn enum_is_univariant(cx: &ctxt, id: ast::DefId) -> bool { enum_variants(cx, id).len() == 1 } -pub fn type_is_empty(cx: &ctxt, t: t) -> bool { - match ty::get(t).sty { +pub fn type_is_empty(cx: &ctxt, ty: Ty) -> bool { + match ty.sty { ty_enum(did, _) => (*enum_variants(cx, did)).is_empty(), _ => false } } -pub fn enum_variants(cx: &ctxt, id: ast::DefId) -> Rc>> { +pub fn enum_variants<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId) + -> Rc>>> { memoized(&cx.enum_var_cache, id, |id: ast::DefId| { if ast::LOCAL_CRATE != id.krate { Rc::new(csearch::get_enum_variants(cx, id)) @@ -4746,10 +4703,10 @@ pub fn enum_variants(cx: &ctxt, id: ast::DefId) -> Rc>> { } // Returns information about the enum variant with the given ID: -pub fn enum_variant_with_id(cx: &ctxt, - enum_id: ast::DefId, - variant_id: ast::DefId) - -> Rc { +pub fn enum_variant_with_id<'tcx>(cx: &ctxt<'tcx>, + enum_id: ast::DefId, + variant_id: ast::DefId) + -> Rc> { enum_variants(cx, enum_id).iter() .find(|variant| variant.id == variant_id) .expect("enum_variant_with_id(): no variant exists with that ID") @@ -4759,16 +4716,17 @@ pub fn enum_variant_with_id(cx: &ctxt, // If the given item is in an external crate, looks up its type and adds it to // the type cache. Returns the type parameters and type. -pub fn lookup_item_type(cx: &ctxt, - did: ast::DefId) - -> Polytype { +pub fn lookup_item_type<'tcx>(cx: &ctxt<'tcx>, + did: ast::DefId) + -> Polytype<'tcx> { lookup_locally_or_in_crate_store( "tcache", did, &mut *cx.tcache.borrow_mut(), || csearch::get_type(cx, did)) } /// Given the did of a trait, returns its canonical trait ref. -pub fn lookup_trait_def(cx: &ctxt, did: DefId) -> Rc { +pub fn lookup_trait_def<'tcx>(cx: &ctxt<'tcx>, did: ast::DefId) + -> Rc> { memoized(&cx.trait_defs, did, |did: DefId| { assert!(did.krate != ast::LOCAL_CRATE); Rc::new(csearch::get_trait_def(cx, did)) @@ -4777,9 +4735,9 @@ pub fn lookup_trait_def(cx: &ctxt, did: DefId) -> Rc { /// Given a reference to a trait, returns the bounds declared on the /// trait, with appropriate substitutions applied. -pub fn bounds_for_trait_ref(tcx: &ctxt, - trait_ref: &TraitRef) - -> ty::ParamBounds +pub fn bounds_for_trait_ref<'tcx>(tcx: &ctxt<'tcx>, + trait_ref: &TraitRef<'tcx>) + -> ty::ParamBounds<'tcx> { let trait_def = lookup_trait_def(tcx, trait_ref.def_id); @@ -4940,12 +4898,12 @@ pub fn lookup_repr_hints(tcx: &ctxt, did: DefId) -> Rc> { // Look up a field ID, whether or not it's local // Takes a list of type substs in case the struct is generic -pub fn lookup_field_type(tcx: &ctxt, - struct_id: DefId, - id: DefId, - substs: &Substs) - -> ty::t { - let t = if id.krate == ast::LOCAL_CRATE { +pub fn lookup_field_type<'tcx>(tcx: &ctxt<'tcx>, + struct_id: DefId, + id: DefId, + substs: &Substs<'tcx>) + -> Ty<'tcx> { + let ty = if id.krate == ast::LOCAL_CRATE { node_id_to_type(tcx, id.node) } else { let mut tcache = tcx.tcache.borrow_mut(); @@ -4955,7 +4913,7 @@ pub fn lookup_field_type(tcx: &ctxt, }; pty.ty }; - t.subst(tcx, substs) + ty.subst(tcx, substs) } // Look up the list of field names and IDs for a given struct. @@ -4983,8 +4941,8 @@ pub fn is_tuple_struct(cx: &ctxt, did: ast::DefId) -> bool { // Returns a list of fields corresponding to the struct's items. trans uses // this. Takes a list of substs with which to instantiate field types. -pub fn struct_fields(cx: &ctxt, did: ast::DefId, substs: &Substs) - -> Vec { +pub fn struct_fields<'tcx>(cx: &ctxt<'tcx>, did: ast::DefId, substs: &Substs<'tcx>) + -> Vec> { lookup_struct_fields(cx, did).iter().map(|f| { field { name: f.name, @@ -4998,7 +4956,7 @@ pub fn struct_fields(cx: &ctxt, did: ast::DefId, substs: &Substs) // Returns a list of fields corresponding to the tuple's items. trans uses // this. -pub fn tup_fields(v: &[t]) -> Vec { +pub fn tup_fields<'tcx>(v: &[Ty<'tcx>]) -> Vec> { v.iter().enumerate().map(|(i, &f)| { field { name: token::intern(i.to_string().as_slice()), @@ -5010,15 +4968,15 @@ pub fn tup_fields(v: &[t]) -> Vec { }).collect() } -pub struct UnboxedClosureUpvar { +pub struct UnboxedClosureUpvar<'tcx> { pub def: def::Def, pub span: Span, - pub ty: t, + pub ty: Ty<'tcx>, } // Returns a list of `UnboxedClosureUpvar`s for each upvar. -pub fn unboxed_closure_upvars(tcx: &ctxt, closure_id: ast::DefId, substs: &Substs) - -> Vec { +pub fn unboxed_closure_upvars<'tcx>(tcx: &ctxt<'tcx>, closure_id: ast::DefId, substs: &Substs<'tcx>) + -> Vec> { // Presently an unboxed closure type cannot "escape" out of a // function, so we will only encounter ones that originated in the // local crate or were inlined into it along with some function. @@ -5053,7 +5011,7 @@ pub fn unboxed_closure_upvars(tcx: &ctxt, closure_id: ast::DefId, substs: &Subst } } -pub fn is_binopable(cx: &ctxt, ty: t, op: ast::BinOp) -> bool { +pub fn is_binopable<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, op: ast::BinOp) -> bool { #![allow(non_upper_case_globals)] static tycat_other: int = 0; static tycat_bool: int = 1; @@ -5095,11 +5053,11 @@ pub fn is_binopable(cx: &ctxt, ty: t, op: ast::BinOp) -> bool { } } - fn tycat(cx: &ctxt, ty: t) -> int { + fn tycat<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> int { if type_is_simd(cx, ty) { return tycat(cx, simd_type(cx, ty)) } - match get(ty).sty { + match ty.sty { ty_char => tycat_char, ty_bool => tycat_bool, ty_int(_) | ty_uint(_) | ty_infer(IntVar(_)) => tycat_int, @@ -5126,8 +5084,8 @@ pub fn is_binopable(cx: &ctxt, ty: t, op: ast::BinOp) -> bool { } /// Returns an equivalent type with all the typedefs and self regions removed. -pub fn normalize_ty(cx: &ctxt, t: t) -> t { - let u = TypeNormalizer(cx).fold_ty(t); +pub fn normalize_ty<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + let u = TypeNormalizer(cx).fold_ty(ty); return u; struct TypeNormalizer<'a, 'tcx: 'a>(&'a ctxt<'tcx>); @@ -5135,14 +5093,14 @@ pub fn normalize_ty(cx: &ctxt, t: t) -> t { impl<'a, 'tcx> TypeFolder<'tcx> for TypeNormalizer<'a, 'tcx> { fn tcx(&self) -> &ctxt<'tcx> { let TypeNormalizer(c) = *self; c } - fn fold_ty(&mut self, t: ty::t) -> ty::t { - match self.tcx().normalized_cache.borrow().get(&t).cloned() { + fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { + match self.tcx().normalized_cache.borrow().get(&ty).cloned() { None => {} Some(u) => return u } - let t_norm = ty_fold::super_fold_ty(self, t); - self.tcx().normalized_cache.borrow_mut().insert(t, t_norm); + let t_norm = ty_fold::super_fold_ty(self, ty); + self.tcx().normalized_cache.borrow_mut().insert(ty, t_norm); return t_norm; } @@ -5151,15 +5109,15 @@ pub fn normalize_ty(cx: &ctxt, t: t) -> t { } fn fold_substs(&mut self, - substs: &subst::Substs) - -> subst::Substs { + substs: &subst::Substs<'tcx>) + -> subst::Substs<'tcx> { subst::Substs { regions: subst::ErasedRegions, types: substs.types.fold_with(self) } } fn fold_fn_sig(&mut self, - sig: &ty::FnSig) - -> ty::FnSig { + sig: &ty::FnSig<'tcx>) + -> ty::FnSig<'tcx> { // The binder-id is only relevant to bound regions, which // are erased at trans time. ty::FnSig { @@ -5217,10 +5175,10 @@ pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint { // Here, the supertraits are the transitive closure of the supertrait // relation on the supertraits from each bounded trait's constraint // list. -pub fn each_bound_trait_and_supertraits(tcx: &ctxt, - bounds: &[Rc], - f: |Rc| -> bool) - -> bool +pub fn each_bound_trait_and_supertraits<'tcx>(tcx: &ctxt<'tcx>, + bounds: &[Rc>], + f: |Rc>| -> bool) + -> bool { for bound_trait_ref in traits::transitive_bounds(tcx, bounds) { if !f(bound_trait_ref) { @@ -5230,11 +5188,11 @@ pub fn each_bound_trait_and_supertraits(tcx: &ctxt, return true; } -pub fn required_region_bounds(tcx: &ctxt, - region_bounds: &[ty::Region], - builtin_bounds: BuiltinBounds, - trait_bounds: &[Rc]) - -> Vec +pub fn required_region_bounds<'tcx>(tcx: &ctxt<'tcx>, + region_bounds: &[ty::Region], + builtin_bounds: BuiltinBounds, + trait_bounds: &[Rc>]) + -> Vec { /*! * Given a type which must meet the builtin bounds and trait @@ -5285,7 +5243,7 @@ pub fn required_region_bounds(tcx: &ctxt, } } -pub fn get_tydesc_ty(tcx: &ctxt) -> Result { +pub fn get_tydesc_ty<'tcx>(tcx: &ctxt<'tcx>) -> Result, String> { tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| { tcx.intrinsic_defs.borrow().get(&tydesc_lang_item).cloned() .expect("Failed to resolve TyDesc") @@ -5491,9 +5449,9 @@ pub fn trait_item_of_item(tcx: &ctxt, def_id: ast::DefId) } } -/// Creates a hash of the type `t` which will be the same no matter what crate +/// Creates a hash of the type `Ty` which will be the same no matter what crate /// context it's calculated within. This is used by the `type_id` intrinsic. -pub fn hash_crate_independent(tcx: &ctxt, t: t, svh: &Svh) -> u64 { +pub fn hash_crate_independent(tcx: &ctxt, ty: Ty, svh: &Svh) -> u64 { let mut state = sip::SipState::new(); macro_rules! byte( ($b:expr) => { ($b as u8).hash(&mut state) } ); macro_rules! hash( ($e:expr) => { $e.hash(&mut state) } ); @@ -5524,8 +5482,8 @@ pub fn hash_crate_independent(tcx: &ctxt, t: t, svh: &Svh) -> u64 { let mt = |state: &mut sip::SipState, mt: mt| { mt.mutbl.hash(state); }; - ty::walk_ty(t, |t| { - match ty::get(t).sty { + ty::walk_ty(ty, |ty| { + match ty.sty { ty_bool => byte!(2), ty_char => byte!(3), ty_int(i) => { @@ -5628,7 +5586,7 @@ impl Variance { } } -pub fn empty_parameter_environment() -> ParameterEnvironment { +pub fn empty_parameter_environment<'tcx>() -> ParameterEnvironment<'tcx> { /*! * Construct a parameter environment suitable for static contexts * or other contexts where there are no free type/lifetime @@ -5642,12 +5600,12 @@ pub fn empty_parameter_environment() -> ParameterEnvironment { selection_cache: traits::SelectionCache::new(), } } -pub fn construct_parameter_environment( - tcx: &ctxt, +pub fn construct_parameter_environment<'tcx>( + tcx: &ctxt<'tcx>, span: Span, - generics: &ty::Generics, + generics: &ty::Generics<'tcx>, free_id: ast::NodeId) - -> ParameterEnvironment + -> ParameterEnvironment<'tcx> { /*! See `ParameterEnvironment` struct def'n for details */ @@ -5722,10 +5680,10 @@ pub fn construct_parameter_environment( } } - fn push_types_from_defs(tcx: &ty::ctxt, - types: &mut subst::VecPerParamSpace, - space: subst::ParamSpace, - defs: &[TypeParameterDef]) { + fn push_types_from_defs<'tcx>(tcx: &ty::ctxt<'tcx>, + types: &mut subst::VecPerParamSpace>, + space: subst::ParamSpace, + defs: &[TypeParameterDef<'tcx>]) { for (i, def) in defs.iter().enumerate() { debug!("construct_parameter_environment(): push_types_from_defs: \ space={} def={} index={}", @@ -5737,10 +5695,10 @@ pub fn construct_parameter_environment( } } - fn record_region_bounds(tcx: &ty::ctxt, - space: subst::ParamSpace, - free_substs: &Substs, - bound_sets: &[Vec]) { + fn record_region_bounds<'tcx>(tcx: &ty::ctxt<'tcx>, + space: subst::ParamSpace, + free_substs: &Substs<'tcx>, + bound_sets: &[Vec]) { for (subst_region, bound_set) in free_substs.regions().get_slice(space).iter().zip( bound_sets.iter()) @@ -5810,15 +5768,15 @@ impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> { self } - fn node_ty(&self, id: ast::NodeId) -> mc::McResult { + fn node_ty(&self, id: ast::NodeId) -> mc::McResult> { Ok(ty::node_id_to_type(self, id)) } - fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option { + fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option> { self.method_map.borrow().get(&method_call).map(|method| method.ty) } - fn adjustments<'a>(&'a self) -> &'a RefCell> { + fn adjustments<'a>(&'a self) -> &'a RefCell>> { &self.adjustments } @@ -5840,7 +5798,7 @@ impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> { } fn unboxed_closures<'a>(&'a self) - -> &'a RefCell> { + -> &'a RefCell>> { &self.unboxed_closures } } @@ -5859,9 +5817,9 @@ pub enum ExplicitSelfCategory { /// in a list of type substitutions. This does *not* traverse into nominal /// types, nor does it resolve fictitious types. pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec, - typ: t) { - walk_ty(typ, |typ| { - match get(typ).sty { + ty: Ty) { + walk_ty(ty, |ty| { + match ty.sty { ty_rptr(region, _) => { accumulator.push(region) } @@ -5934,7 +5892,7 @@ pub fn with_freevars(tcx: &ty::ctxt, fid: ast::NodeId, f: |&[Freevar]| -> T) } } -impl AutoAdjustment { +impl<'tcx> AutoAdjustment<'tcx> { pub fn is_identity(&self) -> bool { match *self { AdjustAddEnv(..) => false, @@ -5943,18 +5901,18 @@ impl AutoAdjustment { } } -impl AutoDerefRef { +impl<'tcx> AutoDerefRef<'tcx> { pub fn is_identity(&self) -> bool { self.autoderefs == 0 && self.autoref.is_none() } } -pub fn liberate_late_bound_regions
( - tcx: &ty::ctxt, +pub fn liberate_late_bound_regions<'tcx, HR>( + tcx: &ty::ctxt<'tcx>, scope_id: ast::NodeId, value: &HR) -> HR - where HR : HigherRankedFoldable + where HR : HigherRankedFoldable<'tcx> { /*! * Replace any late-bound regions bound in `value` with free variants @@ -5966,11 +5924,11 @@ pub fn liberate_late_bound_regions
( |br, _| ty::ReFree(ty::FreeRegion{scope_id: scope_id, bound_region: br})).0 } -pub fn erase_late_bound_regions
( - tcx: &ty::ctxt, +pub fn erase_late_bound_regions<'tcx, HR>( + tcx: &ty::ctxt<'tcx>, value: &HR) -> HR - where HR : HigherRankedFoldable + where HR : HigherRankedFoldable<'tcx> { /*! * Replace any late-bound regions bound in `value` with `'static`. @@ -5981,12 +5939,12 @@ pub fn erase_late_bound_regions
( replace_late_bound_regions(tcx, value, |_, _| ty::ReStatic).0 } -pub fn replace_late_bound_regions
( - tcx: &ty::ctxt, +pub fn replace_late_bound_regions<'tcx, HR>( + tcx: &ty::ctxt<'tcx>, value: &HR, mapf: |BoundRegion, DebruijnIndex| -> ty::Region) -> (HR, FnvHashMap) - where HR : HigherRankedFoldable + where HR : HigherRankedFoldable<'tcx> { /*! * Replaces the late-bound-regions in `value` that are bound by `value`. diff --git a/src/librustc/middle/ty_fold.rs b/src/librustc/middle/ty_fold.rs index 4dfee673bca16..913919fe774f3 100644 --- a/src/librustc/middle/ty_fold.rs +++ b/src/librustc/middle/ty_fold.rs @@ -38,7 +38,7 @@ use middle::subst; use middle::subst::VecPerParamSpace; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::traits; use middle::typeck; use std::rc::Rc; @@ -50,8 +50,8 @@ use util::ppaux::Repr; /// The TypeFoldable trait is implemented for every type that can be folded. /// Basically, every type that has a corresponding method in TypeFolder. -pub trait TypeFoldable { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self; +pub trait TypeFoldable<'tcx> { + fn fold_with>(&self, folder: &mut F) -> Self; } /// The TypeFolder trait defines the actual *folding*. There is a @@ -73,50 +73,50 @@ pub trait TypeFolder<'tcx> { /// track the Debruijn index nesting level. fn exit_region_binder(&mut self) { } - fn fold_ty(&mut self, t: ty::t) -> ty::t { + fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { super_fold_ty(self, t) } - fn fold_mt(&mut self, t: &ty::mt) -> ty::mt { + fn fold_mt(&mut self, t: &ty::mt<'tcx>) -> ty::mt<'tcx> { super_fold_mt(self, t) } - fn fold_trait_ref(&mut self, t: &ty::TraitRef) -> ty::TraitRef { + fn fold_trait_ref(&mut self, t: &ty::TraitRef<'tcx>) -> ty::TraitRef<'tcx> { super_fold_trait_ref(self, t) } - fn fold_sty(&mut self, sty: &ty::sty) -> ty::sty { + fn fold_sty(&mut self, sty: &ty::sty<'tcx>) -> ty::sty<'tcx> { super_fold_sty(self, sty) } fn fold_substs(&mut self, - substs: &subst::Substs) - -> subst::Substs { + substs: &subst::Substs<'tcx>) + -> subst::Substs<'tcx> { super_fold_substs(self, substs) } fn fold_fn_sig(&mut self, - sig: &ty::FnSig) - -> ty::FnSig { + sig: &ty::FnSig<'tcx>) + -> ty::FnSig<'tcx> { super_fold_fn_sig(self, sig) } fn fold_output(&mut self, - output: &ty::FnOutput) - -> ty::FnOutput { + output: &ty::FnOutput<'tcx>) + -> ty::FnOutput<'tcx> { super_fold_output(self, output) } fn fold_bare_fn_ty(&mut self, - fty: &ty::BareFnTy) - -> ty::BareFnTy + fty: &ty::BareFnTy<'tcx>) + -> ty::BareFnTy<'tcx> { super_fold_bare_fn_ty(self, fty) } fn fold_closure_ty(&mut self, - fty: &ty::ClosureTy) - -> ty::ClosureTy { + fty: &ty::ClosureTy<'tcx>) + -> ty::ClosureTy<'tcx> { super_fold_closure_ty(self, fty) } @@ -133,15 +133,16 @@ pub trait TypeFolder<'tcx> { super_fold_existential_bounds(self, s) } - fn fold_autoref(&mut self, ar: &ty::AutoRef) -> ty::AutoRef { + fn fold_autoref(&mut self, ar: &ty::AutoRef<'tcx>) -> ty::AutoRef<'tcx> { super_fold_autoref(self, ar) } - fn fold_item_substs(&mut self, i: ty::ItemSubsts) -> ty::ItemSubsts { + fn fold_item_substs(&mut self, i: ty::ItemSubsts<'tcx>) -> ty::ItemSubsts<'tcx> { super_fold_item_substs(self, i) } - fn fold_obligation(&mut self, o: &traits::Obligation) -> traits::Obligation { + fn fold_obligation(&mut self, o: &traits::Obligation<'tcx>) + -> traits::Obligation<'tcx> { super_fold_obligation(self, o) } } @@ -157,38 +158,38 @@ pub trait TypeFolder<'tcx> { // can easily refactor the folding into the TypeFolder trait as // needed. -impl TypeFoldable for () { - fn fold_with<'tcx, F:TypeFolder<'tcx>>(&self, _: &mut F) -> () { +impl<'tcx> TypeFoldable<'tcx> for () { + fn fold_with>(&self, _: &mut F) -> () { () } } -impl TypeFoldable for (T, U) { - fn fold_with<'tcx, F:TypeFolder<'tcx>>(&self, folder: &mut F) -> (T, U) { +impl<'tcx, T:TypeFoldable<'tcx>, U:TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) { + fn fold_with>(&self, folder: &mut F) -> (T, U) { (self.0.fold_with(folder), self.1.fold_with(folder)) } } -impl TypeFoldable for Option { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Option { +impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Option { + fn fold_with>(&self, folder: &mut F) -> Option { self.as_ref().map(|t| t.fold_with(folder)) } } -impl TypeFoldable for Rc { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Rc { +impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc { + fn fold_with>(&self, folder: &mut F) -> Rc { Rc::new((**self).fold_with(folder)) } } -impl TypeFoldable for Vec { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Vec { +impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec { + fn fold_with>(&self, folder: &mut F) -> Vec { self.iter().map(|t| t.fold_with(folder)).collect() } } -impl TypeFoldable for ty::Binder { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Binder { +impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder { + fn fold_with>(&self, folder: &mut F) -> ty::Binder { folder.enter_region_binder(); let result = ty::bind(self.value.fold_with(folder)); folder.exit_region_binder(); @@ -196,14 +197,14 @@ impl TypeFoldable for ty::Binder { } } -impl TypeFoldable for OwnedSlice { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> OwnedSlice { +impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for OwnedSlice { + fn fold_with>(&self, folder: &mut F) -> OwnedSlice { self.iter().map(|t| t.fold_with(folder)).collect() } } -impl TypeFoldable for VecPerParamSpace { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> VecPerParamSpace { +impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for VecPerParamSpace { + fn fold_with>(&self, folder: &mut F) -> VecPerParamSpace { // Things in the Fn space take place under an additional level // of region binding relative to the other spaces. This is @@ -225,88 +226,88 @@ impl TypeFoldable for VecPerParamSpace { } } -impl TypeFoldable for ty::TraitStore { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TraitStore { +impl<'tcx> TypeFoldable<'tcx> for ty::TraitStore { + fn fold_with>(&self, folder: &mut F) -> ty::TraitStore { folder.fold_trait_store(*self) } } -impl TypeFoldable for ty::t { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::t { +impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { + fn fold_with>(&self, folder: &mut F) -> Ty<'tcx> { folder.fold_ty(*self) } } -impl TypeFoldable for ty::BareFnTy { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::BareFnTy { +impl<'tcx> TypeFoldable<'tcx> for ty::BareFnTy<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::BareFnTy<'tcx> { folder.fold_bare_fn_ty(self) } } -impl TypeFoldable for ty::ClosureTy { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::ClosureTy { +impl<'tcx> TypeFoldable<'tcx> for ty::ClosureTy<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::ClosureTy<'tcx> { folder.fold_closure_ty(self) } } -impl TypeFoldable for ty::mt { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::mt { +impl<'tcx> TypeFoldable<'tcx> for ty::mt<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::mt<'tcx> { folder.fold_mt(self) } } -impl TypeFoldable for ty::FnOutput { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::FnOutput { +impl<'tcx> TypeFoldable<'tcx> for ty::FnOutput<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::FnOutput<'tcx> { folder.fold_output(self) } } -impl TypeFoldable for ty::FnSig { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::FnSig { +impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::FnSig<'tcx> { folder.fold_fn_sig(self) } } -impl TypeFoldable for ty::sty { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::sty { +impl<'tcx> TypeFoldable<'tcx> for ty::sty<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::sty<'tcx> { folder.fold_sty(self) } } -impl TypeFoldable for ty::TraitRef { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TraitRef { +impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::TraitRef<'tcx> { folder.fold_trait_ref(self) } } -impl TypeFoldable for ty::Region { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Region { +impl<'tcx> TypeFoldable<'tcx> for ty::Region { + fn fold_with>(&self, folder: &mut F) -> ty::Region { folder.fold_region(*self) } } -impl TypeFoldable for subst::Substs { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> subst::Substs { +impl<'tcx> TypeFoldable<'tcx> for subst::Substs<'tcx> { + fn fold_with>(&self, folder: &mut F) -> subst::Substs<'tcx> { folder.fold_substs(self) } } -impl TypeFoldable for ty::ItemSubsts { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::ItemSubsts { +impl<'tcx> TypeFoldable<'tcx> for ty::ItemSubsts<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::ItemSubsts<'tcx> { ty::ItemSubsts { substs: self.substs.fold_with(folder), } } } -impl TypeFoldable for ty::AutoRef { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::AutoRef { +impl<'tcx> TypeFoldable<'tcx> for ty::AutoRef<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::AutoRef<'tcx> { folder.fold_autoref(self) } } -impl TypeFoldable for typeck::MethodOrigin { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> typeck::MethodOrigin { +impl<'tcx> TypeFoldable<'tcx> for typeck::MethodOrigin<'tcx> { + fn fold_with>(&self, folder: &mut F) -> typeck::MethodOrigin<'tcx> { match *self { typeck::MethodStatic(def_id) => { typeck::MethodStatic(def_id) @@ -332,8 +333,8 @@ impl TypeFoldable for typeck::MethodOrigin { } } -impl TypeFoldable for typeck::vtable_origin { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> typeck::vtable_origin { +impl<'tcx> TypeFoldable<'tcx> for typeck::vtable_origin<'tcx> { + fn fold_with>(&self, folder: &mut F) -> typeck::vtable_origin<'tcx> { match *self { typeck::vtable_static(def_id, ref substs, ref origins) => { let r_substs = substs.fold_with(folder); @@ -353,20 +354,20 @@ impl TypeFoldable for typeck::vtable_origin { } } -impl TypeFoldable for ty::BuiltinBounds { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> ty::BuiltinBounds { +impl<'tcx> TypeFoldable<'tcx> for ty::BuiltinBounds { + fn fold_with>(&self, _folder: &mut F) -> ty::BuiltinBounds { *self } } -impl TypeFoldable for ty::ExistentialBounds { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::ExistentialBounds { +impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialBounds { + fn fold_with>(&self, folder: &mut F) -> ty::ExistentialBounds { folder.fold_existential_bounds(*self) } } -impl TypeFoldable for ty::ParamBounds { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::ParamBounds { +impl<'tcx> TypeFoldable<'tcx> for ty::ParamBounds<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::ParamBounds<'tcx> { ty::ParamBounds { region_bounds: self.region_bounds.fold_with(folder), builtin_bounds: self.builtin_bounds.fold_with(folder), @@ -375,8 +376,8 @@ impl TypeFoldable for ty::ParamBounds { } } -impl TypeFoldable for ty::TypeParameterDef { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TypeParameterDef { +impl<'tcx> TypeFoldable<'tcx> for ty::TypeParameterDef<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::TypeParameterDef<'tcx> { ty::TypeParameterDef { name: self.name, def_id: self.def_id, @@ -389,8 +390,8 @@ impl TypeFoldable for ty::TypeParameterDef { } } -impl TypeFoldable for ty::RegionParameterDef { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::RegionParameterDef { +impl<'tcx> TypeFoldable<'tcx> for ty::RegionParameterDef { + fn fold_with>(&self, folder: &mut F) -> ty::RegionParameterDef { ty::RegionParameterDef { name: self.name, def_id: self.def_id, @@ -401,8 +402,8 @@ impl TypeFoldable for ty::RegionParameterDef { } } -impl TypeFoldable for ty::Generics { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Generics { +impl<'tcx> TypeFoldable<'tcx> for ty::Generics<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::Generics<'tcx> { ty::Generics { types: self.types.fold_with(folder), regions: self.regions.fold_with(folder), @@ -410,8 +411,8 @@ impl TypeFoldable for ty::Generics { } } -impl TypeFoldable for ty::GenericBounds { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::GenericBounds { +impl<'tcx> TypeFoldable<'tcx> for ty::GenericBounds<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::GenericBounds<'tcx> { ty::GenericBounds { types: self.types.fold_with(folder), regions: self.regions.fold_with(folder), @@ -419,8 +420,8 @@ impl TypeFoldable for ty::GenericBounds { } } -impl TypeFoldable for ty::UnsizeKind { - fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::UnsizeKind { +impl<'tcx> TypeFoldable<'tcx> for ty::UnsizeKind<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::UnsizeKind<'tcx> { match *self { ty::UnsizeLength(len) => ty::UnsizeLength(len), ty::UnsizeStruct(box ref k, n) => ty::UnsizeStruct(box k.fold_with(folder), n), @@ -436,14 +437,14 @@ impl TypeFoldable for ty::UnsizeKind { } } -impl TypeFoldable for traits::Obligation { - fn fold_with<'tcx, F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::Obligation { +impl<'tcx> TypeFoldable<'tcx> for traits::Obligation<'tcx> { + fn fold_with>(&self, folder: &mut F) -> traits::Obligation<'tcx> { folder.fold_obligation(self) } } -impl TypeFoldable for traits::VtableImplData { - fn fold_with<'tcx, F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::VtableImplData { +impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableImplData<'tcx, N> { + fn fold_with>(&self, folder: &mut F) -> traits::VtableImplData<'tcx, N> { traits::VtableImplData { impl_def_id: self.impl_def_id, substs: self.substs.fold_with(folder), @@ -452,16 +453,16 @@ impl TypeFoldable for traits::VtableImplData { } } -impl TypeFoldable for traits::VtableBuiltinData { - fn fold_with<'tcx, F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::VtableBuiltinData { +impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableBuiltinData { + fn fold_with>(&self, folder: &mut F) -> traits::VtableBuiltinData { traits::VtableBuiltinData { nested: self.nested.fold_with(folder), } } } -impl TypeFoldable for traits::Vtable { - fn fold_with<'tcx, F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::Vtable { +impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Vtable<'tcx, N> { + fn fold_with>(&self, folder: &mut F) -> traits::Vtable<'tcx, N> { match *self { traits::VtableImpl(ref v) => traits::VtableImpl(v.fold_with(folder)), traits::VtableUnboxedClosure(d, ref s) => { @@ -473,8 +474,8 @@ impl TypeFoldable for traits::Vtable { } } -impl TypeFoldable for traits::VtableParamData { - fn fold_with<'tcx, F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::VtableParamData { +impl<'tcx> TypeFoldable<'tcx> for traits::VtableParamData<'tcx> { + fn fold_with>(&self, folder: &mut F) -> traits::VtableParamData<'tcx> { traits::VtableParamData { bound: self.bound.fold_with(folder), } @@ -487,15 +488,15 @@ impl TypeFoldable for traits::VtableParamData { // They should invoke `foo.fold_with()` to do recursive folding. pub fn super_fold_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - t: ty::t) - -> ty::t { - let sty = ty::get(t).sty.fold_with(this); + t: Ty<'tcx>) + -> Ty<'tcx> { + let sty = t.sty.fold_with(this); ty::mk_t(this.tcx(), sty) } pub fn super_fold_substs<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - substs: &subst::Substs) - -> subst::Substs { + substs: &subst::Substs<'tcx>) + -> subst::Substs<'tcx> { let regions = match substs.regions { subst::ErasedRegions => { subst::ErasedRegions @@ -510,8 +511,8 @@ pub fn super_fold_substs<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_fn_sig<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - sig: &ty::FnSig) - -> ty::FnSig + sig: &ty::FnSig<'tcx>) + -> ty::FnSig<'tcx> { this.enter_region_binder(); let result = super_fold_fn_sig_contents(this, sig); @@ -520,8 +521,8 @@ pub fn super_fold_fn_sig<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_fn_sig_contents<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - sig: &ty::FnSig) - -> ty::FnSig + sig: &ty::FnSig<'tcx>) + -> ty::FnSig<'tcx> { ty::FnSig { inputs: sig.inputs.fold_with(this), output: sig.output.fold_with(this), @@ -529,8 +530,8 @@ pub fn super_fold_fn_sig_contents<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_output<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - output: &ty::FnOutput) - -> ty::FnOutput { + output: &ty::FnOutput<'tcx>) + -> ty::FnOutput<'tcx> { match *output { ty::FnConverging(ref ty) => ty::FnConverging(ty.fold_with(this)), ty::FnDiverging => ty::FnDiverging @@ -538,8 +539,8 @@ pub fn super_fold_output<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_bare_fn_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - fty: &ty::BareFnTy) - -> ty::BareFnTy + fty: &ty::BareFnTy<'tcx>) + -> ty::BareFnTy<'tcx> { ty::BareFnTy { sig: fty.sig.fold_with(this), abi: fty.abi, @@ -547,8 +548,8 @@ pub fn super_fold_bare_fn_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_closure_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - fty: &ty::ClosureTy) - -> ty::ClosureTy + fty: &ty::ClosureTy<'tcx>) + -> ty::ClosureTy<'tcx> { ty::ClosureTy { store: fty.store.fold_with(this), @@ -561,8 +562,8 @@ pub fn super_fold_closure_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_trait_ref<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - t: &ty::TraitRef) - -> ty::TraitRef + t: &ty::TraitRef<'tcx>) + -> ty::TraitRef<'tcx> { this.enter_region_binder(); let result = super_fold_trait_ref_contents(this, t); @@ -571,8 +572,8 @@ pub fn super_fold_trait_ref<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_trait_ref_contents<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - t: &ty::TraitRef) - -> ty::TraitRef + t: &ty::TraitRef<'tcx>) + -> ty::TraitRef<'tcx> { ty::TraitRef { def_id: t.def_id, @@ -581,13 +582,15 @@ pub fn super_fold_trait_ref_contents<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_mt<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - mt: &ty::mt) -> ty::mt { + mt: &ty::mt<'tcx>) + -> ty::mt<'tcx> { ty::mt {ty: mt.ty.fold_with(this), mutbl: mt.mutbl} } pub fn super_fold_sty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - sty: &ty::sty) -> ty::sty { + sty: &ty::sty<'tcx>) + -> ty::sty<'tcx> { match *sty { ty::ty_uniq(typ) => { ty::ty_uniq(typ.fold_with(this)) @@ -658,8 +661,8 @@ pub fn super_fold_existential_bounds<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_autoref<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - autoref: &ty::AutoRef) - -> ty::AutoRef + autoref: &ty::AutoRef<'tcx>) + -> ty::AutoRef<'tcx> { match *autoref { ty::AutoPtr(r, m, None) => ty::AutoPtr(this.fold_region(r), m, None), @@ -676,8 +679,8 @@ pub fn super_fold_autoref<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_item_substs<'tcx, T: TypeFolder<'tcx>>(this: &mut T, - substs: ty::ItemSubsts) - -> ty::ItemSubsts + substs: ty::ItemSubsts<'tcx>) + -> ty::ItemSubsts<'tcx> { ty::ItemSubsts { substs: substs.substs.fold_with(this), @@ -685,8 +688,8 @@ pub fn super_fold_item_substs<'tcx, T: TypeFolder<'tcx>>(this: &mut T, } pub fn super_fold_obligation<'tcx, T:TypeFolder<'tcx>>(this: &mut T, - obligation: &traits::Obligation) - -> traits::Obligation + obligation: &traits::Obligation<'tcx>) + -> traits::Obligation<'tcx> { traits::Obligation { cause: obligation.cause, @@ -701,32 +704,32 @@ pub fn super_fold_obligation<'tcx, T:TypeFolder<'tcx>>(this: &mut T, /** * Designates a "binder" for late-bound regions. */ -pub trait HigherRankedFoldable : Repr { +pub trait HigherRankedFoldable<'tcx>: Repr<'tcx> { /// Folds the contents of `self`, ignoring the region binder created /// by `self`. - fn fold_contents<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self; + fn fold_contents>(&self, folder: &mut F) -> Self; } -impl HigherRankedFoldable for ty::FnSig { - fn fold_contents<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::FnSig { +impl<'tcx> HigherRankedFoldable<'tcx> for ty::FnSig<'tcx> { + fn fold_contents>(&self, folder: &mut F) -> ty::FnSig<'tcx> { super_fold_fn_sig_contents(folder, self) } } -impl HigherRankedFoldable for ty::TraitRef { - fn fold_contents<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TraitRef { +impl<'tcx> HigherRankedFoldable<'tcx> for ty::TraitRef<'tcx> { + fn fold_contents>(&self, folder: &mut F) -> ty::TraitRef<'tcx> { super_fold_trait_ref_contents(folder, self) } } -impl HigherRankedFoldable for ty::Binder { - fn fold_contents<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Binder { +impl<'tcx, T:TypeFoldable<'tcx>+Repr<'tcx>> HigherRankedFoldable<'tcx> for ty::Binder { + fn fold_contents>(&self, folder: &mut F) -> ty::Binder { ty::bind(self.value.fold_with(folder)) } } -impl HigherRankedFoldable for Rc { - fn fold_contents<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Rc { +impl<'tcx, T:HigherRankedFoldable<'tcx>> HigherRankedFoldable<'tcx> for Rc { + fn fold_contents>(&self, folder: &mut F) -> Rc { Rc::new((**self).fold_contents(folder)) } } @@ -736,13 +739,13 @@ impl HigherRankedFoldable for Rc { pub struct BottomUpFolder<'a, 'tcx: 'a> { pub tcx: &'a ty::ctxt<'tcx>, - pub fldop: |ty::t|: 'a -> ty::t, + pub fldop: |Ty<'tcx>|: 'a -> Ty<'tcx>, } impl<'a, 'tcx> TypeFolder<'tcx> for BottomUpFolder<'a, 'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } - fn fold_ty(&mut self, ty: ty::t) -> ty::t { + fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { let t1 = super_fold_ty(self, ty); (self.fldop)(t1) } @@ -754,7 +757,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BottomUpFolder<'a, 'tcx> { /// Folds over the substructure of a type, visiting its component /// types and all regions that occur *free* within it. /// -/// That is, `ty::t` can contain function or method types that bind +/// That is, `Ty` can contain function or method types that bind /// regions at the call site (`ReLateBound`), and occurrences of /// regions (aka "lifetimes") that are bound within a type are not /// visited by this folder; only regions that occur free will be @@ -816,7 +819,7 @@ pub struct RegionEraser<'a, 'tcx: 'a> { tcx: &'a ty::ctxt<'tcx>, } -pub fn erase_regions(tcx: &ty::ctxt, t: T) -> T { +pub fn erase_regions<'tcx, T: TypeFoldable<'tcx>>(tcx: &ty::ctxt<'tcx>, t: T) -> T { let mut eraser = RegionEraser { tcx: tcx }; t.fold_with(&mut eraser) } @@ -852,7 +855,8 @@ pub fn shift_region(region: ty::Region, amount: uint) -> ty::Region { } } -pub fn shift_regions(tcx: &ty::ctxt, amount: uint, value: &T) -> T { +pub fn shift_regions<'tcx, T:TypeFoldable<'tcx>+Repr<'tcx>>(tcx: &ty::ctxt<'tcx>, + amount: uint, value: &T) -> T { debug!("shift_regions(value={}, amount={})", value.repr(tcx), amount); diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 6867749264961..ea652bc7e6599 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -53,7 +53,7 @@ use middle::def; use middle::resolve_lifetime as rl; use middle::subst::{FnSpace, TypeSpace, AssocSpace, SelfSpace, Subst, Substs}; use middle::subst::{VecPerParamSpace}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::lookup_def_tcx; use middle::typeck::rscope::{UnelidableRscope, RegionScope, SpecificRscope, ShiftedRscope, BindingRscope}; @@ -71,26 +71,26 @@ use syntax::print::pprust; pub trait AstConv<'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>; - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype; - fn get_trait_def(&self, id: ast::DefId) -> Rc; + fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx>; + fn get_trait_def(&self, id: ast::DefId) -> Rc>; /// What type should we use when a type is omitted? - fn ty_infer(&self, span: Span) -> ty::t; + fn ty_infer(&self, span: Span) -> Ty<'tcx>; /// Returns true if associated types from the given trait and type are /// allowed to be used here and false otherwise. fn associated_types_of_trait_are_valid(&self, - ty: ty::t, + ty: Ty<'tcx>, trait_id: ast::DefId) -> bool; /// Returns the binding of the given associated type for some type. fn associated_type_binding(&self, span: Span, - ty: Option, + ty: Option>, trait_id: ast::DefId, associated_type_id: ast::DefId) - -> ty::t; + -> Ty<'tcx>; } pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &ast::Lifetime) @@ -205,11 +205,11 @@ fn ast_path_substs_for_ty<'tcx,AC,RS>( this: &AC, rscope: &RS, decl_def_id: ast::DefId, - decl_generics: &ty::Generics, - self_ty: Option, - associated_ty: Option, + decl_generics: &ty::Generics<'tcx>, + self_ty: Option>, + associated_ty: Option>, path: &ast::Path) - -> Substs + -> Substs<'tcx> where AC: AstConv<'tcx>, RS: RegionScope { /*! @@ -251,12 +251,12 @@ fn create_substs_for_ast_path<'tcx,AC,RS>( rscope: &RS, span: Span, decl_def_id: ast::DefId, - decl_generics: &ty::Generics, - self_ty: Option, - types: Vec, + decl_generics: &ty::Generics<'tcx>, + self_ty: Option>, + types: Vec>, regions: Vec, - associated_ty: Option) - -> Substs + associated_ty: Option>) + -> Substs<'tcx> where AC: AstConv<'tcx>, RS: RegionScope { let tcx = this.tcx(); @@ -377,7 +377,7 @@ fn create_substs_for_ast_path<'tcx,AC,RS>( fn convert_angle_bracketed_parameters<'tcx, AC, RS>(this: &AC, rscope: &RS, data: &ast::AngleBracketedParameterData) - -> (Vec, Vec) + -> (Vec, Vec>) where AC: AstConv<'tcx>, RS: RegionScope { let regions: Vec<_> = @@ -395,7 +395,7 @@ fn convert_angle_bracketed_parameters<'tcx, AC, RS>(this: &AC, fn convert_parenthesized_parameters<'tcx,AC>(this: &AC, data: &ast::ParenthesizedParameterData) - -> Vec + -> Vec> where AC: AstConv<'tcx> { let binding_rscope = BindingRscope::new(); @@ -417,9 +417,9 @@ pub fn instantiate_poly_trait_ref<'tcx,AC,RS>( this: &AC, rscope: &RS, ast_trait_ref: &ast::PolyTraitRef, - self_ty: Option, - associated_type: Option) - -> Rc + self_ty: Option>, + associated_type: Option>) + -> Rc> where AC: AstConv<'tcx>, RS: RegionScope { instantiate_trait_ref(this, rscope, &ast_trait_ref.trait_ref, self_ty, associated_type) @@ -428,9 +428,9 @@ pub fn instantiate_poly_trait_ref<'tcx,AC,RS>( pub fn instantiate_trait_ref<'tcx,AC,RS>(this: &AC, rscope: &RS, ast_trait_ref: &ast::TraitRef, - self_ty: Option, - associated_type: Option) - -> Rc + self_ty: Option>, + associated_type: Option>) + -> Rc> where AC: AstConv<'tcx>, RS: RegionScope { @@ -462,10 +462,10 @@ fn ast_path_to_trait_ref<'tcx,AC,RS>( this: &AC, rscope: &RS, trait_def_id: ast::DefId, - self_ty: Option, - associated_type: Option, + self_ty: Option>, + associated_type: Option>, path: &ast::Path) - -> ty::TraitRef + -> ty::TraitRef<'tcx> where AC: AstConv<'tcx>, RS: RegionScope { let trait_def = this.get_trait_def(trait_def_id); @@ -504,7 +504,7 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( rscope: &RS, did: ast::DefId, path: &ast::Path) - -> TypeAndSubsts + -> TypeAndSubsts<'tcx> { let tcx = this.tcx(); let ty::Polytype { @@ -533,7 +533,7 @@ pub fn ast_path_to_ty_relaxed<'tcx,AC,RS>( rscope: &RS, did: ast::DefId, path: &ast::Path) - -> TypeAndSubsts + -> TypeAndSubsts<'tcx> where AC : AstConv<'tcx>, RS : RegionScope { let tcx = this.tcx(); @@ -589,7 +589,8 @@ fn check_path_args(tcx: &ty::ctxt, } } -pub fn ast_ty_to_prim_ty(tcx: &ty::ctxt, ast_ty: &ast::Ty) -> Option { +pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty) + -> Option> { match ast_ty.node { ast::TyPath(ref path, _, id) => { let a_def = match tcx.def_map.borrow().get(&id) { @@ -641,7 +642,7 @@ pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( this: &AC, rscope: &RS, ast_ty: &ast::Ty) - -> Option { + -> Option> { match ast_ty_to_prim_ty(this.tcx(), ast_ty) { Some(typ) => return Some(typ), None => {} @@ -666,7 +667,7 @@ pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( def::DefTy(did, _) | def::DefStruct(did) if Some(did) == this.tcx().lang_items.owned_box() => { let ty = ast_path_to_ty(this, rscope, did, path).ty; - match ty::get(ty).sty { + match ty.sty { ty::ty_struct(struct_def_id, ref substs) => { assert_eq!(struct_def_id, did); assert_eq!(substs.types.len(TypeSpace), 1); @@ -697,8 +698,8 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( a_seq_mutbl: ast::Mutability, a_seq_ty: &ast::Ty, region: ty::Region, - constr: |ty::t| -> ty::t) - -> ty::t + constr: |Ty<'tcx>| -> Ty<'tcx>) + -> Ty<'tcx> { let tcx = this.tcx(); @@ -755,7 +756,7 @@ fn associated_ty_to_ty<'tcx,AC,RS>(this: &AC, for_ast_type: &ast::Ty, trait_type_id: ast::DefId, span: Span) - -> ty::t + -> Ty<'tcx> where AC: AstConv<'tcx>, RS: RegionScope { debug!("associated_ty_to_ty(trait_path={}, for_ast_type={}, trait_type_id={})", @@ -811,7 +812,7 @@ fn associated_ty_to_ty<'tcx,AC,RS>(this: &AC, // Parses the programmer's textual representation of a type into our // internal notion of a type. pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( - this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> ty::t + this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> Ty<'tcx> { debug!("ast_ty_to_ty(ast_ty={})", ast_ty.repr(this.tcx())); @@ -1060,8 +1061,8 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( pub fn ty_of_arg<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(this: &AC, rscope: &RS, a: &ast::Arg, - expected_ty: Option) - -> ty::t { + expected_ty: Option>) + -> Ty<'tcx> { match a.ty.node { ast::TyInfer if expected_ty.is_some() => expected_ty.unwrap(), ast::TyInfer => this.ty_infer(a.ty.span), @@ -1069,19 +1070,19 @@ pub fn ty_of_arg<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(this: &AC, rscope: &R } } -struct SelfInfo<'a> { - untransformed_self_ty: ty::t, +struct SelfInfo<'a, 'tcx> { + untransformed_self_ty: Ty<'tcx>, explicit_self: &'a ast::ExplicitSelf, } pub fn ty_of_method<'tcx, AC: AstConv<'tcx>>( this: &AC, fn_style: ast::FnStyle, - untransformed_self_ty: ty::t, + untransformed_self_ty: Ty<'tcx>, explicit_self: &ast::ExplicitSelf, decl: &ast::FnDecl, abi: abi::Abi) - -> (ty::BareFnTy, ty::ExplicitSelfCategory) { + -> (ty::BareFnTy<'tcx>, ty::ExplicitSelfCategory) { let self_info = Some(SelfInfo { untransformed_self_ty: untransformed_self_ty, explicit_self: explicit_self, @@ -1096,18 +1097,18 @@ pub fn ty_of_method<'tcx, AC: AstConv<'tcx>>( } pub fn ty_of_bare_fn<'tcx, AC: AstConv<'tcx>>(this: &AC, fn_style: ast::FnStyle, abi: abi::Abi, - decl: &ast::FnDecl) -> ty::BareFnTy { + decl: &ast::FnDecl) -> ty::BareFnTy<'tcx> { let (bare_fn_ty, _) = ty_of_method_or_bare_fn(this, fn_style, abi, None, decl); bare_fn_ty } -fn ty_of_method_or_bare_fn<'tcx, AC: AstConv<'tcx>>( +fn ty_of_method_or_bare_fn<'a, 'tcx, AC: AstConv<'tcx>>( this: &AC, fn_style: ast::FnStyle, abi: abi::Abi, - opt_self_info: Option, + opt_self_info: Option>, decl: &ast::FnDecl) - -> (ty::BareFnTy, + -> (ty::BareFnTy<'tcx>, Option) { debug!("ty_of_method_or_bare_fn"); @@ -1163,7 +1164,7 @@ fn ty_of_method_or_bare_fn<'tcx, AC: AstConv<'tcx>>( let input_pats: Vec = input_params.iter() .map(|a| pprust::pat_to_string(&*a.pat)) .collect(); - let self_and_input_tys: Vec = + let self_and_input_tys: Vec = self_ty.into_iter().chain(input_tys).collect(); let mut lifetimes_for_params: Vec<(String, Vec)> = Vec::new(); @@ -1229,11 +1230,11 @@ fn ty_of_method_or_bare_fn<'tcx, AC: AstConv<'tcx>>( }, explicit_self_category_result) } -fn determine_explicit_self_category<'tcx, AC: AstConv<'tcx>, +fn determine_explicit_self_category<'a, 'tcx, AC: AstConv<'tcx>, RS:RegionScope>( this: &AC, rscope: &RS, - self_info: &SelfInfo) + self_info: &SelfInfo<'a, 'tcx>) -> ty::ExplicitSelfCategory { return match self_info.explicit_self.node { @@ -1293,7 +1294,7 @@ fn determine_explicit_self_category<'tcx, AC: AstConv<'tcx>, if impl_modifiers >= method_modifiers { ty::ByValueExplicitSelfCategory } else { - match ty::get(explicit_type).sty { + match explicit_type.sty { ty::ty_rptr(r, mt) => ty::ByReferenceExplicitSelfCategory(r, mt.mutbl), ty::ty_uniq(_) => ty::ByBoxExplicitSelfCategory, _ => ty::ByValueExplicitSelfCategory, @@ -1302,8 +1303,8 @@ fn determine_explicit_self_category<'tcx, AC: AstConv<'tcx>, } }; - fn count_modifiers(ty: ty::t) -> uint { - match ty::get(ty).sty { + fn count_modifiers(ty: Ty) -> uint { + match ty.sty { ty::ty_rptr(_, mt) => count_modifiers(mt.ty) + 1, ty::ty_uniq(t) => count_modifiers(t) + 1, _ => 0, @@ -1319,8 +1320,8 @@ pub fn ty_of_closure<'tcx, AC: AstConv<'tcx>>( store: ty::TraitStore, decl: &ast::FnDecl, abi: abi::Abi, - expected_sig: Option) - -> ty::ClosureTy + expected_sig: Option>) + -> ty::ClosureTy<'tcx> { debug!("ty_of_closure(expected_sig={})", expected_sig.repr(this.tcx())); @@ -1373,7 +1374,7 @@ pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>( this: &AC, rscope: &RS, span: Span, - main_trait_refs: &[Rc], + main_trait_refs: &[Rc>], ast_bounds: &[ast::TyParamBound]) -> ty::ExistentialBounds { @@ -1402,7 +1403,7 @@ fn conv_ty_poly_trait_ref<'tcx, AC, RS>( rscope: &RS, span: Span, ast_bounds: &[ast::TyParamBound]) - -> ty::t + -> Ty<'tcx> where AC: AstConv<'tcx>, RS:RegionScope { let ast_bounds: Vec<&ast::TyParamBound> = ast_bounds.iter().collect(); @@ -1436,7 +1437,7 @@ pub fn conv_existential_bounds_from_partitioned_bounds<'tcx, AC, RS>( this: &AC, rscope: &RS, span: Span, - main_trait_refs: &[Rc], + main_trait_refs: &[Rc>], partitioned_bounds: PartitionedBounds) -> ty::ExistentialBounds where AC: AstConv<'tcx>, RS:RegionScope @@ -1483,12 +1484,12 @@ pub fn conv_existential_bounds_from_partitioned_bounds<'tcx, AC, RS>( } } -pub fn compute_opt_region_bound(tcx: &ty::ctxt, - span: Span, - builtin_bounds: ty::BuiltinBounds, - region_bounds: &[&ast::Lifetime], - trait_bounds: &[Rc]) - -> Option +pub fn compute_opt_region_bound<'tcx>(tcx: &ty::ctxt<'tcx>, + span: Span, + builtin_bounds: ty::BuiltinBounds, + region_bounds: &[&ast::Lifetime], + trait_bounds: &[Rc>]) + -> Option { /*! * Given the bounds on a type parameter / existential type, @@ -1552,7 +1553,7 @@ fn compute_region_bound<'tcx, AC: AstConv<'tcx>, RS:RegionScope>( span: Span, builtin_bounds: ty::BuiltinBounds, region_bounds: &[&ast::Lifetime], - trait_bounds: &[Rc]) + trait_bounds: &[Rc>]) -> ty::Region { /*! diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index a79edf28b3617..92b30cd7af8f7 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -11,7 +11,7 @@ use middle::def; use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding, pat_is_const}; use middle::subst::{Subst, Substs}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::check::{check_expr, check_expr_has_type, demand, FnCtxt}; use middle::typeck::check::{instantiate_path, structurally_resolved_type, valid_range_bounds}; use middle::typeck::infer::{mod, resolve}; @@ -27,7 +27,8 @@ use syntax::parse::token; use syntax::print::pprust; use syntax::ptr::P; -pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) { +pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, + pat: &ast::Pat, expected: Ty<'tcx>) { let fcx = pcx.fcx; let tcx = pcx.fcx.ccx.tcx; @@ -164,7 +165,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) { ast::PatVec(ref before, ref slice, ref after) => { let expected_ty = structurally_resolved_type(fcx, pat.span, expected); let inner_ty = fcx.infcx().next_ty_var(); - let pat_ty = match ty::get(expected_ty).sty { + let pat_ty = match expected_ty.sty { ty::ty_vec(_, Some(size)) => ty::mk_vec(tcx, inner_ty, Some({ let min_len = before.len() + after.len(); match *slice { @@ -207,15 +208,16 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) { } } -pub fn check_dereferencable(pcx: &pat_ctxt, span: Span, expected: ty::t, - inner: &ast::Pat) -> bool { +pub fn check_dereferencable<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, + span: Span, expected: Ty<'tcx>, + inner: &ast::Pat) -> bool { let fcx = pcx.fcx; let tcx = pcx.fcx.ccx.tcx; match infer::resolve_type( fcx.infcx(), Some(span), expected, resolve::try_resolve_tvar_shallow) { Ok(t) if pat_is_binding(&tcx.def_map, inner) => { - ty::deref(t, true).map_or(true, |mt| match ty::get(mt.ty).sty { + ty::deref(t, true).map_or(true, |mt| match mt.ty.sty { ty::ty_trait(_) => { // This is "x = SomeTrait" being reduced from // "let &x = &SomeTrait" or "let box x = Box", an error. @@ -290,9 +292,9 @@ pub struct pat_ctxt<'a, 'tcx: 'a> { pub map: PatIdMap, } -pub fn check_pat_struct(pcx: &pat_ctxt, pat: &ast::Pat, - path: &ast::Path, fields: &[Spanned], - etc: bool, expected: ty::t) { +pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &ast::Pat, + path: &ast::Path, fields: &[Spanned], + etc: bool, expected: Ty<'tcx>) { let fcx = pcx.fcx; let tcx = pcx.fcx.ccx.tcx; @@ -311,7 +313,7 @@ pub fn check_pat_struct(pcx: &pat_ctxt, pat: &ast::Pat, }, _ => { let def_type = ty::lookup_item_type(tcx, def.def_id()); - match ty::get(def_type.ty).sty { + match def_type.ty.sty { ty::ty_struct(struct_def_id, _) => (struct_def_id, struct_def_id), ty::ty_enum(enum_def_id, _) @@ -349,9 +351,9 @@ pub fn check_pat_struct(pcx: &pat_ctxt, pat: &ast::Pat, variant_def_id, etc); } -pub fn check_pat_enum(pcx: &pat_ctxt, pat: &ast::Pat, - path: &ast::Path, subpats: &Option>>, - expected: ty::t) { +pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &ast::Pat, + path: &ast::Path, subpats: &Option>>, + expected: Ty<'tcx>) { // Typecheck the path. let fcx = pcx.fcx; @@ -376,7 +378,7 @@ pub fn check_pat_enum(pcx: &pat_ctxt, pat: &ast::Pat, demand::eqtype(fcx, pat.span, expected, pat_ty); let real_path_ty = fcx.node_ty(pat.id); - let (arg_tys, kind_name) = match ty::get(real_path_ty).sty { + let (arg_tys, kind_name) = match real_path_ty.sty { ty::ty_enum(enum_def_id, ref expected_substs) => { let variant = ty::enum_variant_with_id(tcx, enum_def_id, def.def_id()); (variant.args.iter().map(|t| t.subst(tcx, expected_substs)).collect::>(), @@ -434,12 +436,12 @@ pub fn check_pat_enum(pcx: &pat_ctxt, pat: &ast::Pat, /// `struct_fields` describes the type of each field of the struct. /// `struct_id` is the ID of the struct. /// `etc` is true if the pattern said '...' and false otherwise. -pub fn check_struct_pat_fields(pcx: &pat_ctxt, - span: Span, - fields: &[Spanned], - struct_fields: &[ty::field], - struct_id: ast::DefId, - etc: bool) { +pub fn check_struct_pat_fields<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, + span: Span, + fields: &[Spanned], + struct_fields: &[ty::field<'tcx>], + struct_id: ast::DefId, + etc: bool) { let tcx = pcx.fcx.ccx.tcx; // Index the struct fields' types. diff --git a/src/librustc/middle/typeck/check/demand.rs b/src/librustc/middle/typeck/check/demand.rs index 2359f9d72d2b7..1e45d059b849b 100644 --- a/src/librustc/middle/typeck/check/demand.rs +++ b/src/librustc/middle/typeck/check/demand.rs @@ -9,7 +9,7 @@ // except according to those terms. -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::check::FnCtxt; use middle::typeck::infer; use middle::typeck::infer::resolve_type; @@ -23,22 +23,24 @@ use util::ppaux::Repr; // Requires that the two types unify, and prints an error message if they // don't. -pub fn suptype(fcx: &FnCtxt, sp: Span, expected: ty::t, actual: ty::t) { +pub fn suptype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, + expected: Ty<'tcx>, actual: Ty<'tcx>) { suptype_with_fn(fcx, sp, false, expected, actual, |sp, e, a, s| { fcx.report_mismatched_types(sp, e, a, s) }) } -pub fn subtype(fcx: &FnCtxt, sp: Span, expected: ty::t, actual: ty::t) { +pub fn subtype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, + expected: Ty<'tcx>, actual: Ty<'tcx>) { suptype_with_fn(fcx, sp, true, actual, expected, |sp, a, e, s| { fcx.report_mismatched_types(sp, e, a, s) }) } -pub fn suptype_with_fn(fcx: &FnCtxt, - sp: Span, - b_is_expected: bool, - ty_a: ty::t, - ty_b: ty::t, - handle_err: |Span, ty::t, ty::t, &ty::type_err|) { +pub fn suptype_with_fn<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + sp: Span, + b_is_expected: bool, + ty_a: Ty<'tcx>, + ty_b: Ty<'tcx>, + handle_err: |Span, Ty<'tcx>, Ty<'tcx>, &ty::type_err<'tcx>|) { // n.b.: order of actual, expected is reversed match infer::mk_subty(fcx.infcx(), b_is_expected, infer::Misc(sp), ty_b, ty_a) { @@ -49,7 +51,8 @@ pub fn suptype_with_fn(fcx: &FnCtxt, } } -pub fn eqtype(fcx: &FnCtxt, sp: Span, expected: ty::t, actual: ty::t) { +pub fn eqtype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, + expected: Ty<'tcx>, actual: Ty<'tcx>) { match infer::mk_eqty(fcx.infcx(), false, infer::Misc(sp), actual, expected) { Ok(()) => { /* ok */ } Err(ref err) => { @@ -59,7 +62,8 @@ pub fn eqtype(fcx: &FnCtxt, sp: Span, expected: ty::t, actual: ty::t) { } // Checks that the type `actual` can be coerced to `expected`. -pub fn coerce(fcx: &FnCtxt, sp: Span, expected: ty::t, expr: &ast::Expr) { +pub fn coerce<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, + expected: Ty<'tcx>, expr: &ast::Expr) { let expr_ty = fcx.expr_ty(expr); debug!("demand::coerce(expected = {}, expr_ty = {})", expected.repr(fcx.ccx.tcx), diff --git a/src/librustc/middle/typeck/check/method/confirm.rs b/src/librustc/middle/typeck/check/method/confirm.rs index b4d22f117d4b7..af8ef09d2a072 100644 --- a/src/librustc/middle/typeck/check/method/confirm.rs +++ b/src/librustc/middle/typeck/check/method/confirm.rs @@ -13,7 +13,7 @@ use super::probe; use middle::subst; use middle::subst::Subst; use middle::traits; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::check; use middle::typeck::check::{FnCtxt, NoPreference, PreferMutLvalue}; use middle::typeck::{MethodCall, MethodCallee, MethodObject, MethodOrigin, @@ -33,34 +33,33 @@ struct ConfirmContext<'a, 'tcx:'a> { self_expr: &'a ast::Expr, } -struct InstantiatedMethodSig { +struct InstantiatedMethodSig<'tcx> { /// Function signature of the method being invoked. The 0th /// argument is the receiver. - method_sig: ty::FnSig, + method_sig: ty::FnSig<'tcx>, /// Substitutions for all types/early-bound-regions declared on /// the method. - all_substs: subst::Substs, + all_substs: subst::Substs<'tcx>, /// Substitution to use when adding obligations from the method /// bounds. Normally equal to `all_substs` except for object /// receivers. See FIXME in instantiate_method_sig() for /// explanation. - method_bounds_substs: subst::Substs, + method_bounds_substs: subst::Substs<'tcx>, /// Generic bounds on the method's parameters which must be added /// as pending obligations. - method_bounds: ty::GenericBounds, + method_bounds: ty::GenericBounds<'tcx>, } - -pub fn confirm(fcx: &FnCtxt, - span: Span, - self_expr: &ast::Expr, - unadjusted_self_ty: ty::t, - pick: probe::Pick, - supplied_method_types: Vec) - -> MethodCallee +pub fn confirm<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + self_expr: &ast::Expr, + unadjusted_self_ty: Ty<'tcx>, + pick: probe::Pick<'tcx>, + supplied_method_types: Vec>) + -> MethodCallee<'tcx> { debug!("confirm(unadjusted_self_ty={}, pick={}, supplied_method_types={})", unadjusted_self_ty.repr(fcx.tcx()), @@ -81,10 +80,10 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { } fn confirm(&mut self, - unadjusted_self_ty: ty::t, - pick: probe::Pick, - supplied_method_types: Vec) - -> MethodCallee + unadjusted_self_ty: Ty<'tcx>, + pick: probe::Pick<'tcx>, + supplied_method_types: Vec>) + -> MethodCallee<'tcx> { // Adjust the self expression the user provided and obtain the adjusted type. let self_ty = self.adjust_self_ty(unadjusted_self_ty, &pick.adjustment); @@ -136,9 +135,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { // ADJUSTMENTS fn adjust_self_ty(&mut self, - unadjusted_self_ty: ty::t, + unadjusted_self_ty: Ty<'tcx>, adjustment: &probe::PickAdjustment) - -> ty::t + -> Ty<'tcx> { // Construct the actual adjustment and write it into the table let auto_deref_ref = self.create_ty_adjustment(adjustment); @@ -164,7 +163,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { fn create_ty_adjustment(&mut self, adjustment: &probe::PickAdjustment) - -> ty::AutoDerefRef + -> ty::AutoDerefRef<'tcx> { match *adjustment { probe::AutoDeref(num) => { @@ -191,9 +190,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { // fn fresh_receiver_substs(&mut self, - self_ty: ty::t, - pick: &probe::Pick) - -> (subst::Substs, MethodOrigin) + self_ty: Ty<'tcx>, + pick: &probe::Pick<'tcx>) + -> (subst::Substs<'tcx>, MethodOrigin<'tcx>) { /*! * Returns a set of substitutions for the method *receiver* @@ -292,8 +291,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { } fn extract_trait_ref(&mut self, - self_ty: ty::t, - closure: |&mut ConfirmContext<'a,'tcx>, ty::t, &ty::TyTrait| -> R) + self_ty: Ty<'tcx>, + closure: |&mut ConfirmContext<'a,'tcx>, + Ty<'tcx>, &ty::TyTrait<'tcx>| -> R) -> R { // If we specified that this is an object method, then the @@ -305,7 +305,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { check::autoderef( self.fcx, self.span, self_ty, None, NoPreference, |ty, _| { - match ty::get(ty).sty { + match ty.sty { ty::ty_trait(ref data) => Some(closure(self, ty, &**data)), _ => None, } @@ -323,9 +323,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { } fn instantiate_method_substs(&mut self, - pick: &probe::Pick, - supplied_method_types: Vec) - -> (Vec, Vec) + pick: &probe::Pick<'tcx>, + supplied_method_types: Vec>) + -> (Vec>, Vec) { // Determine the values for the generic parameters of the method. // If they were not explicitly supplied, just construct fresh @@ -361,8 +361,8 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { } fn unify_receivers(&mut self, - self_ty: ty::t, - method_self_ty: ty::t) + self_ty: Ty<'tcx>, + method_self_ty: Ty<'tcx>) { match self.fcx.mk_subty(false, infer::Misc(self.span), self_ty, method_self_ty) { Ok(_) => {} @@ -381,9 +381,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { // fn instantiate_method_sig(&mut self, - pick: &probe::Pick, - all_substs: subst::Substs) - -> InstantiatedMethodSig + pick: &probe::Pick<'tcx>, + all_substs: subst::Substs<'tcx>) + -> InstantiatedMethodSig<'tcx> { // If this method comes from an impl (as opposed to a trait), // it may have late-bound regions from the impl that appear in @@ -457,9 +457,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { } fn add_obligations(&mut self, - pick: &probe::Pick, - method_bounds_substs: &subst::Substs, - method_bounds: &ty::GenericBounds) { + pick: &probe::Pick<'tcx>, + method_bounds_substs: &subst::Substs<'tcx>, + method_bounds: &ty::GenericBounds<'tcx>) { debug!("add_obligations: pick={} method_bounds_substs={} method_bounds={}", pick.repr(self.tcx()), method_bounds_substs.repr(self.tcx()), @@ -482,13 +482,13 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { * `DerefMut` and `IndexMut` respectively. */ - let sig = match ty::get(method_callee.ty).sty { + let sig = match method_callee.ty.sty { ty::ty_bare_fn(ref f) => f.sig.clone(), ty::ty_closure(ref f) => f.sig.clone(), _ => return, }; - match ty::get(sig.inputs[0]).sty { + match sig.inputs[0].sty { ty::ty_rptr(_, ty::mt { ty: _, mutbl: ast::MutMutable, @@ -647,9 +647,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { } fn upcast(&mut self, - source_trait_ref: Rc, + source_trait_ref: Rc>, target_trait_def_id: ast::DefId) - -> Rc + -> Rc> { for super_trait_ref in traits::supertraits(self.tcx(), source_trait_ref.clone()) { if super_trait_ref.def_id == target_trait_def_id { @@ -665,16 +665,16 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { } fn replace_late_bound_regions_with_fresh_var(&self, value: &T) -> T - where T : HigherRankedFoldable + where T : HigherRankedFoldable<'tcx> { self.infcx().replace_late_bound_regions_with_fresh_var( self.span, infer::FnCall, value).0 } } -fn wrap_autoref(mut deref: ty::AutoDerefRef, - base_fn: |Option>| -> ty::AutoRef) - -> ty::AutoDerefRef { +fn wrap_autoref<'tcx>(mut deref: ty::AutoDerefRef<'tcx>, + base_fn: |Option>>| -> ty::AutoRef<'tcx>) + -> ty::AutoDerefRef<'tcx> { let autoref = mem::replace(&mut deref.autoref, None); let autoref = autoref.map(|r| box r); deref.autoref = Some(base_fn(autoref)); diff --git a/src/librustc/middle/typeck/check/method/mod.rs b/src/librustc/middle/typeck/check/method/mod.rs index 6c7df2cd07ed2..411948ed6b4ac 100644 --- a/src/librustc/middle/typeck/check/method/mod.rs +++ b/src/librustc/middle/typeck/check/method/mod.rs @@ -56,12 +56,12 @@ pub enum CandidateSource { type MethodIndex = uint; // just for doc purposes -pub fn exists(fcx: &FnCtxt, - span: Span, - method_name: ast::Name, - self_ty: ty::t, - call_expr_id: ast::NodeId) - -> bool +pub fn exists<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + method_name: ast::Name, + self_ty: Ty<'tcx>, + call_expr_id: ast::NodeId) + -> bool { /*! * Determines whether the type `self_ty` supports a method name `method_name` or not. @@ -74,14 +74,14 @@ pub fn exists(fcx: &FnCtxt, } } -pub fn lookup(fcx: &FnCtxt, - span: Span, - method_name: ast::Name, - self_ty: ty::t, - supplied_method_types: Vec, - call_expr_id: ast::NodeId, - self_expr: &ast::Expr) - -> Result +pub fn lookup<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + method_name: ast::Name, + self_ty: Ty<'tcx>, + supplied_method_types: Vec>, + call_expr_id: ast::NodeId, + self_expr: &ast::Expr) + -> Result, MethodError> { /*! * Performs method lookup. If lookup is successful, it will return the callee @@ -115,9 +115,9 @@ pub fn lookup_in_trait<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>, self_expr: Option<&'a ast::Expr>, m_name: ast::Name, trait_def_id: DefId, - self_ty: ty::t, - opt_input_types: Option>) - -> Option + self_ty: Ty<'tcx>, + opt_input_types: Option>>) + -> Option> { lookup_in_trait_adjusted(fcx, span, self_expr, m_name, trait_def_id, ty::AutoDerefRef { autoderefs: 0, autoref: None }, @@ -129,10 +129,10 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>, self_expr: Option<&'a ast::Expr>, m_name: ast::Name, trait_def_id: DefId, - autoderefref: ty::AutoDerefRef, - self_ty: ty::t, - opt_input_types: Option>) - -> Option + autoderefref: ty::AutoDerefRef<'tcx>, + self_ty: Ty<'tcx>, + opt_input_types: Option>>) + -> Option> { /*! * `lookup_in_trait_adjusted` is used for overloaded operators. It @@ -262,7 +262,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>, ty::ByReferenceExplicitSelfCategory(..) => { // Trait method is fn(&self) or fn(&mut self), need an // autoref. Pull the region etc out of the type of first argument. - match ty::get(transformed_self_ty).sty { + match transformed_self_ty.sty { ty::ty_rptr(region, ty::mt { mutbl, ty: _ }) => { let ty::AutoDerefRef { autoderefs, autoref } = autoderefref; let autoref = autoref.map(|r| box r); @@ -308,11 +308,11 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>, Some(callee) } -pub fn report_error(fcx: &FnCtxt, - span: Span, - rcvr_ty: ty::t, - method_name: ast::Name, - error: MethodError) +pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + rcvr_ty: Ty<'tcx>, + method_name: ast::Name, + error: MethodError) { match error { NoMatch(static_sources) => { @@ -321,7 +321,7 @@ pub fn report_error(fcx: &FnCtxt, // True if the type is a struct and contains a field with // the same name as the not-found method - let is_field = match ty::get(rcvr_ty).sty { + let is_field = match rcvr_ty.sty { ty_struct(did, _) => ty::lookup_struct_fields(cx, did) .iter() @@ -408,10 +408,10 @@ pub fn report_error(fcx: &FnCtxt, } } -fn trait_method(tcx: &ty::ctxt, - trait_def_id: ast::DefId, - method_name: ast::Name) - -> Option<(uint, Rc)> +fn trait_method<'tcx>(tcx: &ty::ctxt<'tcx>, + trait_def_id: ast::DefId, + method_name: ast::Name) + -> Option<(uint, Rc>)> { /*! * Find method with name `method_name` defined in `trait_def_id` and return it, @@ -426,10 +426,10 @@ fn trait_method(tcx: &ty::ctxt, .and_then(|(idx, item)| item.as_opt_method().map(|m| (idx, m))) } -fn impl_method(tcx: &ty::ctxt, - impl_def_id: ast::DefId, - method_name: ast::Name) - -> Option> +fn impl_method<'tcx>(tcx: &ty::ctxt<'tcx>, + impl_def_id: ast::DefId, + method_name: ast::Name) + -> Option>> { let impl_items = tcx.impl_items.borrow(); let impl_items = impl_items.get(&impl_def_id).unwrap(); diff --git a/src/librustc/middle/typeck/check/method/probe.rs b/src/librustc/middle/typeck/check/method/probe.rs index f9c3fa86752ea..a98b4cf011d97 100644 --- a/src/librustc/middle/typeck/check/method/probe.rs +++ b/src/librustc/middle/typeck/check/method/probe.rs @@ -16,7 +16,7 @@ use middle::fast_reject; use middle::subst; use middle::subst::Subst; use middle::traits; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty_fold::HigherRankedFoldable; use middle::typeck::check; use middle::typeck::check::{FnCtxt, NoPreference}; @@ -37,49 +37,50 @@ struct ProbeContext<'a, 'tcx:'a> { fcx: &'a FnCtxt<'a, 'tcx>, span: Span, method_name: ast::Name, - steps: Rc>, + steps: Rc>>, opt_simplified_steps: Option>, - inherent_candidates: Vec, - extension_candidates: Vec, + inherent_candidates: Vec>, + extension_candidates: Vec>, impl_dups: HashSet, static_candidates: Vec, } -struct CandidateStep { - self_ty: ty::t, +struct CandidateStep<'tcx> { + self_ty: Ty<'tcx>, adjustment: PickAdjustment, } -struct Candidate { - xform_self_ty: ty::t, - method_ty: Rc, - kind: CandidateKind, +struct Candidate<'tcx> { + xform_self_ty: Ty<'tcx>, + method_ty: Rc>, + kind: CandidateKind<'tcx>, } -enum CandidateKind { - InherentImplCandidate(/* Impl */ ast::DefId, subst::Substs), - ObjectCandidate(MethodObject), - ExtensionImplCandidate(/* Impl */ ast::DefId, Rc, subst::Substs, MethodIndex), +enum CandidateKind<'tcx> { + InherentImplCandidate(/* Impl */ ast::DefId, subst::Substs<'tcx>), + ObjectCandidate(MethodObject<'tcx>), + ExtensionImplCandidate(/* Impl */ ast::DefId, Rc>, + subst::Substs<'tcx>, MethodIndex), UnboxedClosureCandidate(/* Trait */ ast::DefId, MethodIndex), - WhereClauseCandidate(Rc, MethodIndex), + WhereClauseCandidate(Rc>, MethodIndex), } -pub struct Pick { - pub method_ty: Rc, +pub struct Pick<'tcx> { + pub method_ty: Rc>, pub adjustment: PickAdjustment, - pub kind: PickKind, + pub kind: PickKind<'tcx>, } #[deriving(Clone,Show)] -pub enum PickKind { +pub enum PickKind<'tcx> { InherentImplPick(/* Impl */ ast::DefId), ObjectPick(/* Trait */ ast::DefId, /* method_num */ uint, /* real_index */ uint), ExtensionImplPick(/* Impl */ ast::DefId, MethodIndex), TraitPick(/* Trait */ ast::DefId, MethodIndex), - WhereClausePick(/* Trait */ Rc, MethodIndex), + WhereClausePick(/* Trait */ Rc>, MethodIndex), } -pub type PickResult = Result; +pub type PickResult<'tcx> = Result, MethodError>; // This is a kind of "abstracted" version of ty::AutoAdjustment. The // difference is that it doesn't embed any regions or other @@ -105,12 +106,12 @@ pub enum PickAdjustment { AutoRef(ast::Mutability, Box), } -pub fn probe(fcx: &FnCtxt, - span: Span, - method_name: ast::Name, - self_ty: ty::t, - call_expr_id: ast::NodeId) - -> PickResult +pub fn probe<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + method_name: ast::Name, + self_ty: Ty<'tcx>, + call_expr_id: ast::NodeId) + -> PickResult<'tcx> { debug!("probe(self_ty={}, method_name={}, call_expr_id={})", self_ty.repr(fcx.tcx()), @@ -157,7 +158,10 @@ pub fn probe(fcx: &FnCtxt, }) } -fn create_steps(fcx: &FnCtxt, span: Span, self_ty: ty::t) -> Vec { +fn create_steps<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + self_ty: Ty<'tcx>) + -> Vec> { let mut steps = Vec::new(); let (fully_dereferenced_ty, dereferences, _) = @@ -169,7 +173,7 @@ fn create_steps(fcx: &FnCtxt, span: Span, self_ty: ty::t) -> Vec None::<()> // keep iterating until we can't anymore }); - match ty::get(fully_dereferenced_ty).sty { + match fully_dereferenced_ty.sty { ty::ty_vec(elem_ty, Some(len)) => { steps.push(CandidateStep { self_ty: ty::mk_vec(fcx.tcx(), elem_ty, None), @@ -182,9 +186,9 @@ fn create_steps(fcx: &FnCtxt, span: Span, self_ty: ty::t) -> Vec return steps; - fn consider_reborrow(t: ty::t, d: uint) -> PickAdjustment { + fn consider_reborrow(ty: Ty, d: uint) -> PickAdjustment { // Insert a `&*` or `&mut *` if this is a reference type: - match ty::get(t).sty { + match ty.sty { ty::ty_rptr(_, ref mt) => AutoRef(mt.mutbl, box AutoDeref(d+1)), _ => AutoDeref(d), } @@ -195,7 +199,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { fn new(fcx: &'a FnCtxt<'a,'tcx>, span: Span, method_name: ast::Name, - steps: Vec, + steps: Vec>, opt_simplified_steps: Option>) -> ProbeContext<'a,'tcx> { @@ -230,11 +234,11 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { } } - fn assemble_probe(&mut self, self_ty: ty::t) { + fn assemble_probe(&mut self, self_ty: Ty<'tcx>) { debug!("assemble_probe: self_ty={}", self_ty.repr(self.tcx())); - match ty::get(self_ty).sty { + match self_ty.sty { ty::ty_trait(box ty::TyTrait { ref principal, bounds, .. }) => { self.assemble_inherent_candidates_from_object(self_ty, &*principal, bounds); self.assemble_inherent_impl_candidates_for_type(principal.def_id); @@ -293,8 +297,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { } fn assemble_inherent_candidates_from_object(&mut self, - self_ty: ty::t, - principal: &ty::TraitRef, + self_ty: Ty<'tcx>, + principal: &ty::TraitRef<'tcx>, _bounds: ty::ExistentialBounds) { debug!("assemble_inherent_candidates_from_object(self_ty={})", self_ty.repr(self.tcx())); @@ -353,8 +357,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { } fn assemble_inherent_candidates_from_param(&mut self, - _rcvr_ty: ty::t, - param_ty: ty::ParamTy) { + _rcvr_ty: Ty<'tcx>, + param_ty: ty::ParamTy) { // FIXME -- Do we want to commit to this behavior for param bounds? let ty::ParamTy { space, idx: index, .. } = param_ty; @@ -397,11 +401,11 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { // create the candidates. fn elaborate_bounds( &mut self, - bounds: &[Rc], - mk_cand: |this: &mut ProbeContext, - tr: Rc, - m: Rc, - method_num: uint|) + bounds: &[Rc>], + mk_cand: for<'a> |this: &mut ProbeContext<'a, 'tcx>, + tr: Rc>, + m: Rc>, + method_num: uint|) { let tcx = self.tcx(); let mut cache = HashSet::new(); @@ -475,7 +479,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { fn assemble_extension_candidates_for_trait_impls(&mut self, trait_def_id: ast::DefId, - method: Rc, + method: Rc>, method_index: uint) { ty::populate_implementations_for_trait_if_necessary(self.tcx(), @@ -539,7 +543,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { fn assemble_unboxed_closure_candidates(&mut self, trait_def_id: ast::DefId, - method_ty: Rc, + method_ty: Rc>, method_index: uint) { // Check if this is one of the Fn,FnMut,FnOnce traits. @@ -558,7 +562,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { // If so, add "synthetic impls". let steps = self.steps.clone(); for step in steps.iter() { - let (closure_def_id, _, _) = match ty::get(step.self_ty).sty { + let (closure_def_id, _, _) = match step.self_ty.sty { ty::ty_unboxed_closure(a, b, ref c) => (a, b, c), _ => continue, }; @@ -600,7 +604,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { /////////////////////////////////////////////////////////////////////////// // THE ACTUAL SEARCH - fn pick(mut self) -> PickResult { + fn pick(mut self) -> PickResult<'tcx> { let steps = self.steps.clone(); for step in steps.iter() { @@ -615,7 +619,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { Err(NoMatch(self.static_candidates)) } - fn pick_step(&mut self, step: &CandidateStep) -> Option { + fn pick_step(&mut self, step: &CandidateStep<'tcx>) -> Option> { debug!("pick_step: step={}", step.repr(self.tcx())); if ty::type_is_error(step.self_ty) { @@ -634,22 +638,22 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { // FIXME -- Super hack. For DST types, we will convert to // &&[T] or &&str, as part of a kind of legacy lookup scheme. - match ty::get(step.self_ty).sty { + match step.self_ty.sty { ty::ty_str | ty::ty_vec(_, None) => self.pick_autorefrefd_method(step), _ => None } } fn pick_adjusted_method(&mut self, - step: &CandidateStep) - -> Option + step: &CandidateStep<'tcx>) + -> Option> { self.pick_method(step.self_ty).map(|r| self.adjust(r, step.adjustment.clone())) } fn pick_autorefd_method(&mut self, - step: &CandidateStep) - -> Option + step: &CandidateStep<'tcx>) + -> Option> { let tcx = self.tcx(); self.search_mutabilities( @@ -658,8 +662,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { } fn pick_autorefrefd_method(&mut self, - step: &CandidateStep) - -> Option + step: &CandidateStep<'tcx>) + -> Option> { let tcx = self.tcx(); self.search_mutabilities( @@ -671,8 +675,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { fn search_mutabilities(&mut self, mk_adjustment: |ast::Mutability| -> PickAdjustment, - mk_autoref_ty: |ast::Mutability, ty::Region| -> ty::t) - -> Option + mk_autoref_ty: |ast::Mutability, ty::Region| -> Ty<'tcx>) + -> Option> { // In general, during probing we erase regions. See // `impl_self_ty()` for an explanation. @@ -690,7 +694,10 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { .nth(0) } - fn adjust(&mut self, result: PickResult, adjustment: PickAdjustment) -> PickResult { + fn adjust(&mut self, + result: PickResult<'tcx>, + adjustment: PickAdjustment) + -> PickResult<'tcx> { match result { Err(e) => Err(e), Ok(mut pick) => { @@ -700,7 +707,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { } } - fn pick_method(&mut self, self_ty: ty::t) -> Option { + fn pick_method(&mut self, self_ty: Ty<'tcx>) -> Option> { debug!("pick_method(self_ty={})", self.infcx().ty_to_string(self_ty)); debug!("searching inherent candidates"); @@ -715,7 +722,10 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { self.consider_candidates(self_ty, self.extension_candidates[]) } - fn consider_candidates(&self, self_ty: ty::t, probes: &[Candidate]) -> Option { + fn consider_candidates(&self, + self_ty: Ty<'tcx>, + probes: &[Candidate<'tcx>]) + -> Option> { let mut applicable_candidates: Vec<_> = probes.iter() .filter(|&probe| self.consider_probe(self_ty, probe)) @@ -741,7 +751,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { }) } - fn consider_probe(&self, self_ty: ty::t, probe: &Candidate) -> bool { + fn consider_probe(&self, self_ty: Ty<'tcx>, probe: &Candidate<'tcx>) -> bool { debug!("consider_probe: self_ty={} probe={}", self_ty.repr(self.tcx()), probe.repr(self.tcx())); @@ -797,7 +807,9 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { }) } - fn collapse_candidates_to_trait_pick(&self, probes: &[&Candidate]) -> Option { + fn collapse_candidates_to_trait_pick(&self, + probes: &[&Candidate<'tcx>]) + -> Option> { /*! * Sometimes we get in a situation where we have multiple * probes that are all impls of the same trait, but we don't @@ -844,7 +856,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { /////////////////////////////////////////////////////////////////////////// // MISCELLANY - fn make_sub_ty(&self, sub: ty::t, sup: ty::t) -> infer::ures { + fn make_sub_ty(&self, sub: Ty<'tcx>, sup: Ty<'tcx>) -> infer::ures<'tcx> { self.infcx().sub_types(false, infer::Misc(DUMMY_SP), sub, sup) } @@ -874,7 +886,10 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { self.static_candidates.push(source); } - fn xform_self_ty(&self, method: &Rc, substs: &subst::Substs) -> ty::t { + fn xform_self_ty(&self, + method: &Rc>, + substs: &subst::Substs<'tcx>) + -> Ty<'tcx> { debug!("xform_self_ty(self_ty={}, substs={})", method.fty.sig.inputs[0].repr(self.tcx()), substs.repr(self.tcx())); @@ -922,7 +937,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { fn impl_substs(&self, impl_def_id: ast::DefId) - -> subst::Substs + -> subst::Substs<'tcx> { let impl_pty = ty::lookup_item_type(self.tcx(), impl_def_id); @@ -938,7 +953,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { } fn erase_late_bound_regions(&self, value: &T) -> T - where T : HigherRankedFoldable + where T : HigherRankedFoldable<'tcx> { /*! * Replace late-bound-regions bound by `value` with `'static` @@ -971,10 +986,10 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { } } -fn impl_method(tcx: &ty::ctxt, - impl_def_id: ast::DefId, - method_name: ast::Name) - -> Option> +fn impl_method<'tcx>(tcx: &ty::ctxt<'tcx>, + impl_def_id: ast::DefId, + method_name: ast::Name) + -> Option>> { let impl_items = tcx.impl_items.borrow(); let impl_items = impl_items.get(&impl_def_id).unwrap(); @@ -985,10 +1000,10 @@ fn impl_method(tcx: &ty::ctxt, .and_then(|item| item.as_opt_method()) } -fn trait_method(tcx: &ty::ctxt, - trait_def_id: ast::DefId, - method_name: ast::Name) - -> Option<(uint, Rc)> +fn trait_method<'tcx>(tcx: &ty::ctxt<'tcx>, + trait_def_id: ast::DefId, + method_name: ast::Name) + -> Option<(uint, Rc>)> { /*! * Find method with name `method_name` defined in `trait_def_id` and return it, @@ -1005,10 +1020,10 @@ fn trait_method(tcx: &ty::ctxt, // Determine the index of a method in the list of all methods belonging // to a trait and its supertraits. -fn get_method_index(tcx: &ty::ctxt, - trait_ref: &ty::TraitRef, - subtrait: Rc, - n_method: uint) -> uint { +fn get_method_index<'tcx>(tcx: &ty::ctxt<'tcx>, + trait_ref: &ty::TraitRef<'tcx>, + subtrait: Rc>, + n_method: uint) -> uint { // We need to figure the "real index" of the method in a // listing of all the methods of an object. We do this by // iterating down the supertraits of the object's trait until @@ -1032,8 +1047,8 @@ fn get_method_index(tcx: &ty::ctxt, method_count + n_method } -impl Candidate { - fn to_unadjusted_pick(&self) -> Pick { +impl<'tcx> Candidate<'tcx> { + fn to_unadjusted_pick(&self) -> Pick<'tcx> { Pick { method_ty: self.method_ty.clone(), adjustment: AutoDeref(0), @@ -1091,16 +1106,16 @@ impl Candidate { } } -impl Repr for Candidate { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for Candidate<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("Candidate(xform_self_ty={}, kind={})", self.xform_self_ty.repr(tcx), self.kind.repr(tcx)) } } -impl Repr for CandidateKind { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for CandidateKind<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { InherentImplCandidate(ref a, ref b) => format!("InherentImplCandidate({},{})", a.repr(tcx), b.repr(tcx)), @@ -1117,28 +1132,28 @@ impl Repr for CandidateKind { } } -impl Repr for CandidateStep { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for CandidateStep<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("CandidateStep({},{})", self.self_ty.repr(tcx), self.adjustment) } } -impl Repr for PickAdjustment { +impl<'tcx> Repr<'tcx> for PickAdjustment { fn repr(&self, _tcx: &ty::ctxt) -> String { format!("{}", self) } } -impl Repr for PickKind { +impl<'tcx> Repr<'tcx> for PickKind<'tcx> { fn repr(&self, _tcx: &ty::ctxt) -> String { format!("{}", self) } } -impl Repr for Pick { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for Pick<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("Pick(method_ty={}, adjustment={}, kind={})", self.method_ty.repr(tcx), self.adjustment, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 8ae5c3a0a9597..543eb44697c06 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -96,7 +96,7 @@ use middle::traits; use middle::ty::{FnSig, VariantInfo}; use middle::ty::{Polytype}; use middle::ty::{Disr, ParamTy, ParameterEnvironment}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty::{replace_late_bound_regions, liberate_late_bound_regions}; use middle::ty_fold::TypeFolder; use middle::typeck::astconv::AstConv; @@ -160,22 +160,22 @@ pub mod wf; /// share the inherited fields. pub struct Inherited<'a, 'tcx: 'a> { infcx: infer::InferCtxt<'a, 'tcx>, - locals: RefCell>, - param_env: ty::ParameterEnvironment, + locals: RefCell>>, + param_env: ty::ParameterEnvironment<'tcx>, // Temporary tables: - node_types: RefCell>, - item_substs: RefCell>, - adjustments: RefCell>, - method_map: MethodMap, + node_types: RefCell>>, + item_substs: RefCell>>, + adjustments: RefCell>>, + method_map: MethodMap<'tcx>, upvar_borrow_map: RefCell, - unboxed_closures: RefCell>, - object_cast_map: ObjectCastMap, + unboxed_closures: RefCell>>, + object_cast_map: ObjectCastMap<'tcx>, // A mapping from each fn's id to its signature, with all bound // regions replaced with free ones. Unlike the other tables, this // one is never copied into the tcx: it is only used by regionck. - fn_sig_map: RefCell>>, + fn_sig_map: RefCell>>>, // A set of constraints that regionck must validate. Each // constraint has the form `T:'a`, meaning "some type `T` must @@ -201,29 +201,29 @@ pub struct Inherited<'a, 'tcx: 'a> { // regionck to be sure that it has found *all* the region // obligations (otherwise, it's easy to fail to walk to a // particular node-id). - region_obligations: RefCell>>, + region_obligations: RefCell>>>, // Tracks trait obligations incurred during this function body. - fulfillment_cx: RefCell, + fulfillment_cx: RefCell>, } -struct RegionObligation { +struct RegionObligation<'tcx> { sub_region: ty::Region, - sup_type: ty::t, - origin: infer::SubregionOrigin, + sup_type: Ty<'tcx>, + origin: infer::SubregionOrigin<'tcx>, } /// When type-checking an expression, we propagate downward /// whatever type hint we are able in the form of an `Expectation`. -enum Expectation { +enum Expectation<'tcx> { /// We know nothing about what type this expression should have. NoExpectation, /// This expression should have the type given (or some subtype) - ExpectHasType(ty::t), + ExpectHasType(Ty<'tcx>), - /// This expression will be cast to the `ty::t` - ExpectCastableToType(ty::t), + /// This expression will be cast to the `Ty` + ExpectCastableToType(Ty<'tcx>), } #[deriving(Clone)] @@ -282,7 +282,7 @@ pub struct FnCtxt<'a, 'tcx: 'a> { // expects the types within the function to be consistent. err_count_on_creation: uint, - ret_ty: ty::FnOutput, + ret_ty: ty::FnOutput<'tcx>, ps: RefCell, @@ -295,14 +295,14 @@ impl<'a, 'tcx> mem_categorization::Typer<'tcx> for FnCtxt<'a, 'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.ccx.tcx } - fn node_ty(&self, id: ast::NodeId) -> McResult { + fn node_ty(&self, id: ast::NodeId) -> McResult> { Ok(self.node_ty(id)) } fn node_method_ty(&self, method_call: typeck::MethodCall) - -> Option { + -> Option> { self.inh.method_map.borrow().get(&method_call).map(|m| m.ty) } - fn adjustments<'a>(&'a self) -> &'a RefCell> { + fn adjustments<'a>(&'a self) -> &'a RefCell>> { &self.inh.adjustments } fn is_method_call(&self, id: ast::NodeId) -> bool { @@ -318,14 +318,15 @@ impl<'a, 'tcx> mem_categorization::Typer<'tcx> for FnCtxt<'a, 'tcx> { -> ast::CaptureClause { self.ccx.tcx.capture_mode(closure_expr_id) } - fn unboxed_closures<'a>(&'a self) -> &'a RefCell> { + fn unboxed_closures<'a>(&'a self) + -> &'a RefCell>> { &self.inh.unboxed_closures } } impl<'a, 'tcx> Inherited<'a, 'tcx> { fn new(tcx: &'a ty::ctxt<'tcx>, - param_env: ty::ParameterEnvironment) + param_env: ty::ParameterEnvironment<'tcx>) -> Inherited<'a, 'tcx> { Inherited { infcx: infer::new_infer_ctxt(tcx), @@ -348,7 +349,7 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> { // Used by check_const and check_enum_variants pub fn blank_fn_ctxt<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>, inh: &'a Inherited<'a, 'tcx>, - rty: ty::FnOutput, + rty: ty::FnOutput<'tcx>, body_id: ast::NodeId) -> FnCtxt<'a, 'tcx> { FnCtxt { @@ -394,17 +395,17 @@ pub fn check_item_types(ccx: &CrateCtxt) { ccx.tcx.sess.abort_if_errors(); } -fn check_bare_fn(ccx: &CrateCtxt, - decl: &ast::FnDecl, - body: &ast::Block, - id: ast::NodeId, - fty: ty::t, - param_env: ty::ParameterEnvironment) { +fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + decl: &ast::FnDecl, + body: &ast::Block, + id: ast::NodeId, + fty: Ty<'tcx>, + param_env: ty::ParameterEnvironment<'tcx>) { // Compute the fty from point of view of inside fn // (replace any type-scheme with a type) let fty = fty.subst(ccx.tcx, ¶m_env.free_substs); - match ty::get(fty).sty { + match fty.sty { ty::ty_bare_fn(ref fn_ty) => { let inh = Inherited::new(ccx.tcx, param_env); let fcx = check_fn(ccx, fn_ty.fn_style, id, &fn_ty.sig, @@ -425,7 +426,7 @@ struct GatherLocalsVisitor<'a, 'tcx: 'a> { } impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> { - fn assign(&mut self, _span: Span, nid: ast::NodeId, ty_opt: Option) -> ty::t { + fn assign(&mut self, _span: Span, nid: ast::NodeId, ty_opt: Option>) -> Ty<'tcx> { match ty_opt { None => { // infer the variable's type @@ -507,7 +508,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for GatherLocalsVisitor<'a, 'tcx> { fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>, fn_style: ast::FnStyle, fn_style_id: ast::NodeId, - fn_sig: &ty::FnSig, + fn_sig: &ty::FnSig<'tcx>, decl: &ast::FnDecl, fn_id: ast::NodeId, body: &ast::Block, @@ -551,7 +552,7 @@ fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>, }; // Remember return type so that regionck can access it later. - let mut fn_sig_tys: Vec = + let mut fn_sig_tys: Vec = arg_tys.iter() .map(|&ty| ty) .collect(); @@ -719,9 +720,9 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) { } } -fn check_method_body(ccx: &CrateCtxt, - item_generics: &ty::Generics, - method: &ast::Method) { +fn check_method_body<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + item_generics: &ty::Generics<'tcx>, + method: &ast::Method) { /*! * Type checks a method body. * @@ -752,11 +753,11 @@ fn check_method_body(ccx: &CrateCtxt, param_env); } -fn check_impl_items_against_trait(ccx: &CrateCtxt, - impl_span: Span, - ast_trait_ref: &ast::TraitRef, - impl_trait_ref: &ty::TraitRef, - impl_items: &[ast::ImplItem]) { +fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + impl_span: Span, + ast_trait_ref: &ast::TraitRef, + impl_trait_ref: &ty::TraitRef<'tcx>, + impl_items: &[ast::ImplItem]) { // Locate trait methods let tcx = ccx.tcx; let trait_items = ty::trait_items(tcx, impl_trait_ref.def_id); @@ -927,12 +928,12 @@ fn check_impl_items_against_trait(ccx: &CrateCtxt, * - trait_m: the method in the trait * - trait_to_impl_substs: the substitutions used on the type of the trait */ -fn compare_impl_method(tcx: &ty::ctxt, - impl_m: &ty::Method, - impl_m_span: Span, - impl_m_body_id: ast::NodeId, - trait_m: &ty::Method, - impl_trait_ref: &ty::TraitRef) { +fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>, + impl_m: &ty::Method<'tcx>, + impl_m_span: Span, + impl_m_body_id: ast::NodeId, + trait_m: &ty::Method<'tcx>, + impl_trait_ref: &ty::TraitRef<'tcx>) { debug!("compare_impl_method(impl_trait_ref={})", impl_trait_ref.repr(tcx)); @@ -1236,15 +1237,15 @@ fn compare_impl_method(tcx: &ty::ctxt, // parameters. infcx.resolve_regions_and_report_errors(); - fn check_region_bounds_on_impl_method(tcx: &ty::ctxt, - span: Span, - impl_m: &ty::Method, - impl_m_body_id: ast::NodeId, - trait_generics: &ty::Generics, - impl_generics: &ty::Generics, - trait_to_skol_substs: &Substs, - impl_to_skol_substs: &Substs) - -> bool + fn check_region_bounds_on_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>, + span: Span, + impl_m: &ty::Method<'tcx>, + impl_m_body_id: ast::NodeId, + trait_generics: &ty::Generics<'tcx>, + impl_generics: &ty::Generics<'tcx>, + trait_to_skol_substs: &Substs<'tcx>, + impl_to_skol_substs: &Substs<'tcx>) + -> bool { /*! @@ -1435,7 +1436,7 @@ fn check_cast(fcx: &FnCtxt, fcx.type_error_message(span, |actual| { format!("cast to unsized type: `{}` as `{}`", actual, tstr) }, t_e, None); - match ty::get(t_e).sty { + match t_e.sty { ty::ty_rptr(_, ty::mt { mutbl: mt, .. }) => { let mtstr = match mt { ast::MutMutable => "mut ", @@ -1504,19 +1505,19 @@ fn check_cast(fcx: &FnCtxt, // casts from C-like enums are allowed } else if t_1_is_char { let t_e = fcx.infcx().shallow_resolve(t_e); - if ty::get(t_e).sty != ty::ty_uint(ast::TyU8) { + if t_e.sty != ty::ty_uint(ast::TyU8) { fcx.type_error_message(span, |actual| { format!("only `u8` can be cast as \ `char`, not `{}`", actual) }, t_e, None); } - } else if ty::get(t_1).sty == ty::ty_bool { + } else if t_1.sty == ty::ty_bool { span_err!(fcx.tcx().sess, span, E0054, "cannot cast as `bool`, compare with zero instead"); } else if ty::type_is_region_ptr(t_e) && ty::type_is_unsafe_ptr(t_1) { - fn types_compatible(fcx: &FnCtxt, sp: Span, - t1: ty::t, t2: ty::t) -> bool { - match ty::get(t1).sty { + fn types_compatible<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, + t1: Ty<'tcx>, t2: Ty<'tcx>) -> bool { + match t1.sty { ty::ty_vec(_, Some(_)) => {} _ => return false } @@ -1544,7 +1545,7 @@ fn check_cast(fcx: &FnCtxt, /* this cast is only allowed from &[T, ..n] to *T or &T to *T. */ - match (&ty::get(t_e).sty, &ty::get(t_1).sty) { + match (&t_e.sty, &t_1.sty) { (&ty::ty_rptr(_, ty::mt { ty: mt1, mutbl: ast::MutImmutable }), &ty::ty_ptr(ty::mt { ty: mt2, mutbl: ast::MutImmutable })) if types_compatible(fcx, e.span, mt1, mt2) => { @@ -1580,29 +1581,29 @@ fn check_cast(fcx: &FnCtxt, impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.ccx.tcx } - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { + fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { ty::lookup_item_type(self.tcx(), id) } - fn get_trait_def(&self, id: ast::DefId) -> Rc { + fn get_trait_def(&self, id: ast::DefId) -> Rc> { ty::lookup_trait_def(self.tcx(), id) } - fn ty_infer(&self, _span: Span) -> ty::t { + fn ty_infer(&self, _span: Span) -> Ty<'tcx> { self.infcx().next_ty_var() } - fn associated_types_of_trait_are_valid(&self, _: ty::t, _: ast::DefId) + fn associated_types_of_trait_are_valid(&self, _: Ty, _: ast::DefId) -> bool { false } fn associated_type_binding(&self, span: Span, - _: Option, + _: Option>, _: ast::DefId, _: ast::DefId) - -> ty::t { + -> Ty<'tcx> { self.tcx().sess.span_err(span, "unsupported associated type binding"); ty::mk_err() } @@ -1642,7 +1643,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { format!("{}", self as *const FnCtxt) } - pub fn local_ty(&self, span: Span, nid: ast::NodeId) -> ty::t { + pub fn local_ty(&self, span: Span, nid: ast::NodeId) -> Ty<'tcx> { match self.inh.locals.borrow().get(&nid) { Some(&t) => t, None => { @@ -1663,7 +1664,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } #[inline] - pub fn write_ty(&self, node_id: ast::NodeId, ty: ty::t) { + pub fn write_ty(&self, node_id: ast::NodeId, ty: Ty<'tcx>) { debug!("write_ty({}, {}) in fcx {}", node_id, ppaux::ty_to_string(self.tcx(), ty), self.tag()); self.inh.node_types.borrow_mut().insert(node_id, ty); @@ -1671,13 +1672,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn write_object_cast(&self, key: ast::NodeId, - trait_ref: Rc) { + trait_ref: Rc>) { debug!("write_object_cast key={} trait_ref={}", key, trait_ref.repr(self.tcx())); self.inh.object_cast_map.borrow_mut().insert(key, trait_ref); } - pub fn write_substs(&self, node_id: ast::NodeId, substs: ty::ItemSubsts) { + pub fn write_substs(&self, node_id: ast::NodeId, substs: ty::ItemSubsts<'tcx>) { if !substs.substs.is_noop() { debug!("write_substs({}, {}) in fcx {}", node_id, @@ -1705,7 +1706,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn write_adjustment(&self, node_id: ast::NodeId, span: Span, - adj: ty::AutoAdjustment) { + adj: ty::AutoAdjustment<'tcx>) { debug!("write_adjustment(node_id={}, adj={})", node_id, adj); if adj.is_identity() { @@ -1724,7 +1725,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn register_adjustment_obligations(&self, span: Span, - adj: &ty::AutoAdjustment) { + adj: &ty::AutoAdjustment<'tcx>) { match *adj { ty::AdjustAddEnv(..) => { } ty::AdjustDerefRef(ref d_r) => { @@ -1740,7 +1741,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn register_autoref_obligations(&self, span: Span, - autoref: &ty::AutoRef) { + autoref: &ty::AutoRef<'tcx>) { match *autoref { ty::AutoUnsize(ref unsize) => { self.register_unsize_obligations(span, unsize); @@ -1760,7 +1761,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn register_unsize_obligations(&self, span: Span, - unsize: &ty::UnsizeKind) { + unsize: &ty::UnsizeKind<'tcx>) { debug!("register_unsize_obligations: unsize={}", unsize); match *unsize { @@ -1788,7 +1789,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn instantiate_type(&self, span: Span, def_id: ast::DefId) - -> TypeAndSubsts + -> TypeAndSubsts<'tcx> { /*! * Returns the type of `def_id` with all generics replaced by @@ -1833,9 +1834,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } pub fn require_type_meets(&self, - ty: ty::t, + ty: Ty<'tcx>, span: Span, - code: traits::ObligationCauseCode, + code: traits::ObligationCauseCode<'tcx>, bound: ty::BuiltinBound) { let obligation = traits::obligation_for_builtin_bound( @@ -1850,22 +1851,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } pub fn require_type_is_sized(&self, - ty: ty::t, + ty: Ty<'tcx>, span: Span, - code: traits::ObligationCauseCode) + code: traits::ObligationCauseCode<'tcx>) { self.require_type_meets(ty, span, code, ty::BoundSized); } pub fn require_expr_have_sized_type(&self, expr: &ast::Expr, - code: traits::ObligationCauseCode) + code: traits::ObligationCauseCode<'tcx>) { self.require_type_is_sized(self.expr_ty(expr), expr.span, code); } pub fn register_obligation(&self, - obligation: traits::Obligation) + obligation: traits::Obligation<'tcx>) { debug!("register_obligation({})", obligation.repr(self.tcx())); @@ -1875,7 +1876,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .register_obligation(self.tcx(), obligation); } - pub fn to_ty(&self, ast_t: &ast::Ty) -> ty::t { + pub fn to_ty(&self, ast_t: &ast::Ty) -> Ty<'tcx> { let t = ast_ty_to_ty(self, self.infcx(), ast_t); let mut bounds_checker = wf::BoundsChecker::new(self, @@ -1891,7 +1892,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pat.repr(self.tcx()) } - pub fn expr_ty(&self, ex: &ast::Expr) -> ty::t { + pub fn expr_ty(&self, ex: &ast::Expr) -> Ty<'tcx> { match self.inh.node_types.borrow().get(&ex.id) { Some(&t) => t, None => { @@ -1901,7 +1902,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub fn expr_ty_adjusted(&self, expr: &ast::Expr) -> ty::t { + pub fn expr_ty_adjusted(&self, expr: &ast::Expr) -> Ty<'tcx> { /*! * Fetch type of `expr` after applying adjustments that * have been recorded in the fcx. @@ -1914,8 +1915,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn adjust_expr_ty(&self, expr: &ast::Expr, - adjustment: Option<&ty::AutoAdjustment>) - -> ty::t + adjustment: Option<&ty::AutoAdjustment<'tcx>>) + -> Ty<'tcx> { /*! * Apply `adjustment` to the type of `expr` @@ -1933,7 +1934,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .map(|method| method.ty)) } - pub fn node_ty(&self, id: ast::NodeId) -> ty::t { + pub fn node_ty(&self, id: ast::NodeId) -> Ty<'tcx> { match self.inh.node_types.borrow().get(&id) { Some(&t) => t, None => { @@ -1945,13 +1946,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub fn item_substs<'a>(&'a self) -> Ref<'a, NodeMap> { + pub fn item_substs<'a>(&'a self) -> Ref<'a, NodeMap>> { self.inh.item_substs.borrow() } pub fn opt_node_ty_substs(&self, id: ast::NodeId, - f: |&ty::ItemSubsts|) { + f: |&ty::ItemSubsts<'tcx>|) { match self.inh.item_substs.borrow().get(&id) { Some(s) => { f(s) } None => { } @@ -1961,27 +1962,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn mk_subty(&self, a_is_expected: bool, origin: infer::TypeOrigin, - sub: ty::t, - sup: ty::t) - -> Result<(), ty::type_err> { + sub: Ty<'tcx>, + sup: Ty<'tcx>) + -> Result<(), ty::type_err<'tcx>> { infer::mk_subty(self.infcx(), a_is_expected, origin, sub, sup) } - pub fn can_mk_subty(&self, sub: ty::t, sup: ty::t) - -> Result<(), ty::type_err> { + pub fn can_mk_subty(&self, sub: Ty<'tcx>, sup: Ty<'tcx>) + -> Result<(), ty::type_err<'tcx>> { infer::can_mk_subty(self.infcx(), sub, sup) } - pub fn can_mk_eqty(&self, sub: ty::t, sup: ty::t) - -> Result<(), ty::type_err> { + pub fn can_mk_eqty(&self, sub: Ty<'tcx>, sup: Ty<'tcx>) + -> Result<(), ty::type_err<'tcx>> { infer::can_mk_eqty(self.infcx(), sub, sup) } pub fn mk_assignty(&self, expr: &ast::Expr, - sub: ty::t, - sup: ty::t) - -> Result<(), ty::type_err> { + sub: Ty<'tcx>, + sup: Ty<'tcx>) + -> Result<(), ty::type_err<'tcx>> { match infer::mk_coercety(self.infcx(), false, infer::ExprAssignable(expr.span), @@ -1999,14 +2000,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn mk_eqty(&self, a_is_expected: bool, origin: infer::TypeOrigin, - sub: ty::t, - sup: ty::t) - -> Result<(), ty::type_err> { + sub: Ty<'tcx>, + sup: Ty<'tcx>) + -> Result<(), ty::type_err<'tcx>> { infer::mk_eqty(self.infcx(), a_is_expected, origin, sub, sup) } pub fn mk_subr(&self, - origin: infer::SubregionOrigin, + origin: infer::SubregionOrigin<'tcx>, sub: ty::Region, sup: ty::Region) { infer::mk_subr(self.infcx(), origin, sub, sup) @@ -2015,22 +2016,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn type_error_message(&self, sp: Span, mk_msg: |String| -> String, - actual_ty: ty::t, - err: Option<&ty::type_err>) { + actual_ty: Ty<'tcx>, + err: Option<&ty::type_err<'tcx>>) { self.infcx().type_error_message(sp, mk_msg, actual_ty, err); } pub fn report_mismatched_types(&self, sp: Span, - e: ty::t, - a: ty::t, - err: &ty::type_err) { + e: Ty<'tcx>, + a: Ty<'tcx>, + err: &ty::type_err<'tcx>) { self.infcx().report_mismatched_types(sp, e, a, err) } pub fn register_region_obligation(&self, - origin: infer::SubregionOrigin, - ty: ty::t, + origin: infer::SubregionOrigin<'tcx>, + ty: Ty<'tcx>, r: ty::Region) { /*! @@ -2050,9 +2051,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } pub fn add_obligations_for_parameters(&self, - cause: traits::ObligationCause, - substs: &Substs, - generic_bounds: &ty::GenericBounds) + cause: traits::ObligationCause<'tcx>, + substs: &Substs<'tcx>, + generic_bounds: &ty::GenericBounds<'tcx>) { /*! * Given a fully substituted set of bounds (`generic_bounds`), @@ -2085,9 +2086,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } fn add_trait_obligations_for_generics(&self, - cause: traits::ObligationCause, - substs: &Substs, - generic_bounds: &ty::GenericBounds) { + cause: traits::ObligationCause<'tcx>, + substs: &Substs<'tcx>, + generic_bounds: &ty::GenericBounds<'tcx>) { assert!(!generic_bounds.has_escaping_regions()); assert!(!substs.has_regions_escaping_depth(0)); @@ -2100,9 +2101,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } fn add_region_obligations_for_generics(&self, - cause: traits::ObligationCause, - substs: &Substs, - generic_bounds: &ty::GenericBounds) + cause: traits::ObligationCause<'tcx>, + substs: &Substs<'tcx>, + generic_bounds: &ty::GenericBounds<'tcx>) { assert!(!generic_bounds.has_escaping_regions()); assert_eq!(generic_bounds.types.iter().len(), substs.types.iter().len()); @@ -2128,8 +2129,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn add_region_obligations_for_type_parameter(&self, span: Span, - param_bound: &ty::ParamBounds, - ty: ty::t) + param_bound: &ty::ParamBounds<'tcx>, + ty: Ty<'tcx>) { // For each declared region bound `T:r`, `T` must outlive `r`. let region_bounds = @@ -2164,11 +2165,12 @@ pub enum LvaluePreference { NoPreference } -pub fn autoderef(fcx: &FnCtxt, sp: Span, base_ty: ty::t, - expr_id: Option, - mut lvalue_pref: LvaluePreference, - should_stop: |ty::t, uint| -> Option) - -> (ty::t, uint, Option) { +pub fn autoderef<'a, 'tcx, T>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, + base_ty: Ty<'tcx>, + expr_id: Option, + mut lvalue_pref: LvaluePreference, + should_stop: |Ty<'tcx>, uint| -> Option) + -> (Ty<'tcx>, uint, Option) { /*! * Executes an autoderef loop for the type `t`. At each step, invokes * `should_stop` to decide whether to terminate the loop. Returns @@ -2219,12 +2221,12 @@ pub fn autoderef(fcx: &FnCtxt, sp: Span, base_ty: ty::t, } /// Attempts to resolve a call expression as an overloaded call. -fn try_overloaded_call<'a>(fcx: &FnCtxt, - call_expression: &ast::Expr, - callee: &ast::Expr, - callee_type: ty::t, - args: &[&'a P]) - -> bool { +fn try_overloaded_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + call_expression: &ast::Expr, + callee: &ast::Expr, + callee_type: Ty<'tcx>, + args: &[&P]) + -> bool { // Bail out if the callee is a bare function or a closure. We check those // manually. match *structure_of(fcx, callee.span, callee_type) { @@ -2278,13 +2280,13 @@ fn try_overloaded_call<'a>(fcx: &FnCtxt, false } -fn try_overloaded_deref(fcx: &FnCtxt, - span: Span, - method_call: Option, - base_expr: Option<&ast::Expr>, - base_ty: ty::t, - lvalue_pref: LvaluePreference) - -> Option +fn try_overloaded_deref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + method_call: Option, + base_expr: Option<&ast::Expr>, + base_ty: Ty<'tcx>, + lvalue_pref: LvaluePreference) + -> Option> { // Try DerefMut first, if preferred. let method = match (lvalue_pref, fcx.tcx().lang_items.deref_mut_trait()) { @@ -2309,10 +2311,10 @@ fn try_overloaded_deref(fcx: &FnCtxt, make_overloaded_lvalue_return_type(fcx, method_call, method) } -fn make_overloaded_lvalue_return_type(fcx: &FnCtxt, - method_call: Option, - method: Option) - -> Option +fn make_overloaded_lvalue_return_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + method_call: Option, + method: Option>) + -> Option> { /*! * For the overloaded lvalue expressions (`*x`, `x[3]`), the trait @@ -2345,12 +2347,12 @@ fn make_overloaded_lvalue_return_type(fcx: &FnCtxt, } } -fn autoderef_for_index(fcx: &FnCtxt, - base_expr: &ast::Expr, - base_ty: ty::t, - lvalue_pref: LvaluePreference, - step: |ty::t, ty::AutoDerefRef| -> Option) - -> Option +fn autoderef_for_index<'a, 'tcx, T>(fcx: &FnCtxt<'a, 'tcx>, + base_expr: &ast::Expr, + base_ty: Ty<'tcx>, + lvalue_pref: LvaluePreference, + step: |Ty<'tcx>, ty::AutoDerefRef<'tcx>| -> Option) + -> Option { // FIXME(#18741) -- this is almost but not quite the same as the // autoderef that normal method probing does. They could likely be @@ -2368,7 +2370,7 @@ fn autoderef_for_index(fcx: &FnCtxt, // After we have fully autoderef'd, if the resulting type is [T, ..n], then // do a final unsized coercion to yield [T]. - match ty::get(ty).sty { + match ty.sty { ty::ty_vec(element_ty, Some(n)) => { let adjusted_ty = ty::mk_vec(fcx.tcx(), element_ty, None); let autoderefref = ty::AutoDerefRef { @@ -2383,15 +2385,15 @@ fn autoderef_for_index(fcx: &FnCtxt, } } -fn try_overloaded_slice(fcx: &FnCtxt, - method_call: MethodCall, - expr: &ast::Expr, - base_expr: &ast::Expr, - base_ty: ty::t, - start_expr: &Option>, - end_expr: &Option>, - mutbl: ast::Mutability) - -> Option // return type is result of slice +fn try_overloaded_slice<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + method_call: MethodCall, + expr: &ast::Expr, + base_expr: &ast::Expr, + base_ty: Ty<'tcx>, + start_expr: &Option>, + end_expr: &Option>, + mutbl: ast::Mutability) + -> Option> // return type is result of slice { /*! * Autoderefs `base_expr`, looking for a `Slice` impl. If it @@ -2439,16 +2441,17 @@ fn try_overloaded_slice(fcx: &FnCtxt, }) } -fn try_overloaded_slice_step(fcx: &FnCtxt, - method_call: MethodCall, - expr: &ast::Expr, - base_expr: &ast::Expr, - base_ty: ty::t, // autoderef'd type - autoderefref: ty::AutoDerefRef, - mutbl: ast::Mutability, - start_expr: &Option>, - end_expr: &Option>) - -> Option // result type is type of method being called +fn try_overloaded_slice_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + method_call: MethodCall, + expr: &ast::Expr, + base_expr: &ast::Expr, + base_ty: Ty<'tcx>, // autoderef'd type + autoderefref: ty::AutoDerefRef<'tcx>, + mutbl: ast::Mutability, + start_expr: &Option>, + end_expr: &Option>) + // result type is type of method being called + -> Option> { /*! * Checks for a `Slice` (or `SliceMut`) impl at the relevant level @@ -2512,14 +2515,14 @@ fn try_overloaded_slice_step(fcx: &FnCtxt, }) } -fn try_index_step(fcx: &FnCtxt, - method_call: MethodCall, - expr: &ast::Expr, - base_expr: &ast::Expr, - adjusted_ty: ty::t, - adjustment: ty::AutoDerefRef, - lvalue_pref: LvaluePreference) - -> Option<(/*index type*/ ty::t, /*element type*/ ty::t)> +fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + method_call: MethodCall, + expr: &ast::Expr, + base_expr: &ast::Expr, + adjusted_ty: Ty<'tcx>, + adjustment: ty::AutoDerefRef<'tcx>, + lvalue_pref: LvaluePreference) + -> Option<(/*index type*/ Ty<'tcx>, /*element type*/ Ty<'tcx>)> { /*! * To type-check `base_expr[index_expr]`, we progressively autoderef (and otherwise adjust) @@ -2591,10 +2594,10 @@ fn try_index_step(fcx: &FnCtxt, /// /// The return type of this function represents the concrete element type /// `A` in the type `Iterator
` that the method returns. -fn lookup_method_for_for_loop(fcx: &FnCtxt, - iterator_expr: &ast::Expr, - loop_id: ast::NodeId) - -> ty::t { +fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + iterator_expr: &ast::Expr, + loop_id: ast::NodeId) + -> Ty<'tcx> { let trait_did = match fcx.tcx().lang_items.require(IteratorItem) { Ok(trait_did) => trait_did, Err(ref err_string) => { @@ -2650,7 +2653,7 @@ fn lookup_method_for_for_loop(fcx: &FnCtxt, structurally_resolved_type(fcx, iterator_expr.span, return_type), ty::FnDiverging => ty::mk_err() }; - match ty::get(return_type).sty { + match return_type.sty { ty::ty_enum(_, ref substs) if !substs.types.is_empty_in(subst::TypeSpace) => { *substs.types.get(subst::TypeSpace, 0) @@ -2672,14 +2675,14 @@ fn lookup_method_for_for_loop(fcx: &FnCtxt, } } -fn check_method_argument_types<'a>(fcx: &FnCtxt, - sp: Span, - method_fn_ty: ty::t, - callee_expr: &ast::Expr, - args_no_rcvr: &[&'a P], - deref_args: DerefArgs, - tuple_arguments: TupleArgumentsFlag) - -> ty::FnOutput { +fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + sp: Span, + method_fn_ty: Ty<'tcx>, + callee_expr: &ast::Expr, + args_no_rcvr: &[&P], + deref_args: DerefArgs, + tuple_arguments: TupleArgumentsFlag) + -> ty::FnOutput<'tcx> { if ty::type_is_error(method_fn_ty) { let err_inputs = err_args(args_no_rcvr.len()); check_argument_types(fcx, @@ -2692,7 +2695,7 @@ fn check_method_argument_types<'a>(fcx: &FnCtxt, tuple_arguments); ty::FnConverging(ty::mk_err()) } else { - match ty::get(method_fn_ty).sty { + match method_fn_ty.sty { ty::ty_bare_fn(ref fty) => { // HACK(eddyb) ignore self in the definition (see above). check_argument_types(fcx, @@ -2713,14 +2716,14 @@ fn check_method_argument_types<'a>(fcx: &FnCtxt, } } -fn check_argument_types<'a>(fcx: &FnCtxt, - sp: Span, - fn_inputs: &[ty::t], - _callee_expr: &ast::Expr, - args: &[&'a P], - deref_args: DerefArgs, - variadic: bool, - tuple_arguments: TupleArgumentsFlag) { +fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + sp: Span, + fn_inputs: &[Ty<'tcx>], + _callee_expr: &ast::Expr, + args: &[&P], + deref_args: DerefArgs, + variadic: bool, + tuple_arguments: TupleArgumentsFlag) { /*! * * Generic function that factors out common logic from @@ -2740,7 +2743,7 @@ fn check_argument_types<'a>(fcx: &FnCtxt, let expected_arg_count = fn_inputs.len(); let formal_tys = if tuple_arguments == TupleArguments { let tuple_type = structurally_resolved_type(fcx, sp, fn_inputs[0]); - match ty::get(tuple_type).sty { + match tuple_type.sty { ty::ty_tup(ref arg_types) => { if arg_types.len() != args.len() { span_err!(tcx.sess, sp, E0057, @@ -2831,7 +2834,7 @@ fn check_argument_types<'a>(fcx: &FnCtxt, match deref_args { DoDerefArgs => { - match ty::get(formal_ty).sty { + match formal_ty.sty { ty::ty_rptr(_, mt) => formal_ty = mt.ty, ty::ty_err => (), _ => { @@ -2863,7 +2866,7 @@ fn check_argument_types<'a>(fcx: &FnCtxt, // in C but we just error out instead and require explicit casts. let arg_ty = structurally_resolved_type(fcx, arg.span, fcx.expr_ty(&***arg)); - match ty::get(arg_ty).sty { + match arg_ty.sty { ty::ty_float(ast::TyF32) => { fcx.type_error_message(arg.span, |t| { @@ -2891,11 +2894,14 @@ fn check_argument_types<'a>(fcx: &FnCtxt, } } -fn err_args(len: uint) -> Vec { +// FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx. +fn err_args<'tcx>(len: uint) -> Vec> { Vec::from_fn(len, |_| ty::mk_err()) } -fn write_call(fcx: &FnCtxt, call_expr: &ast::Expr, output: ty::FnOutput) { +fn write_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + call_expr: &ast::Expr, + output: ty::FnOutput<'tcx>) { fcx.write_ty(call_expr.id, match output { ty::FnConverging(output_ty) => output_ty, ty::FnDiverging => fcx.infcx().next_diverging_ty_var() @@ -2903,10 +2909,10 @@ fn write_call(fcx: &FnCtxt, call_expr: &ast::Expr, output: ty::FnOutput) { } // AST fragment checking -fn check_lit(fcx: &FnCtxt, - lit: &ast::Lit, - expected: Expectation) - -> ty::t +fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + lit: &ast::Lit, + expected: Expectation<'tcx>) + -> Ty<'tcx> { let tcx = fcx.ccx.tcx; @@ -2958,40 +2964,41 @@ pub fn valid_range_bounds(ccx: &CrateCtxt, } } -pub fn check_expr_has_type(fcx: &FnCtxt, - expr: &ast::Expr, - expected: ty::t) { +pub fn check_expr_has_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + expr: &ast::Expr, + expected: Ty<'tcx>) { check_expr_with_unifier( fcx, expr, ExpectHasType(expected), NoPreference, || demand::suptype(fcx, expr.span, expected, fcx.expr_ty(expr))); } -fn check_expr_coercable_to_type(fcx: &FnCtxt, - expr: &ast::Expr, - expected: ty::t) { +fn check_expr_coercable_to_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + expr: &ast::Expr, + expected: Ty<'tcx>) { check_expr_with_unifier( fcx, expr, ExpectHasType(expected), NoPreference, || demand::coerce(fcx, expr.span, expected, expr)); } -fn check_expr_with_hint(fcx: &FnCtxt, expr: &ast::Expr, expected: ty::t) { +fn check_expr_with_hint<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, expr: &ast::Expr, + expected: Ty<'tcx>) { check_expr_with_unifier( fcx, expr, ExpectHasType(expected), NoPreference, || ()) } -fn check_expr_with_expectation(fcx: &FnCtxt, - expr: &ast::Expr, - expected: Expectation) { +fn check_expr_with_expectation<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + expr: &ast::Expr, + expected: Expectation<'tcx>) { check_expr_with_unifier( fcx, expr, expected, NoPreference, || ()) } -fn check_expr_with_expectation_and_lvalue_pref(fcx: &FnCtxt, - expr: &ast::Expr, - expected: Expectation, - lvalue_pref: LvaluePreference) +fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + expr: &ast::Expr, + expected: Expectation<'tcx>, + lvalue_pref: LvaluePreference) { check_expr_with_unifier(fcx, expr, expected, lvalue_pref, || ()) } @@ -3009,10 +3016,10 @@ fn check_expr_with_lvalue_pref(fcx: &FnCtxt, expr: &ast::Expr, // declared on the impl declaration e.g., `impl for ~[(A,B)]` // would return ($0, $1) where $0 and $1 are freshly instantiated type // variables. -pub fn impl_self_ty(fcx: &FnCtxt, - span: Span, // (potential) receiver for this impl - did: ast::DefId) - -> TypeAndSubsts { +pub fn impl_self_ty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, // (potential) receiver for this impl + did: ast::DefId) + -> TypeAndSubsts<'tcx> { let tcx = fcx.tcx(); let ity = ty::lookup_item_type(tcx, did); @@ -3031,21 +3038,23 @@ pub fn impl_self_ty(fcx: &FnCtxt, // Only for fields! Returns for methods> // Indifferent to privacy flags -pub fn lookup_field_ty(tcx: &ty::ctxt, - class_id: ast::DefId, - items: &[ty::field_ty], - fieldname: ast::Name, - substs: &subst::Substs) -> Option { +pub fn lookup_field_ty<'tcx>(tcx: &ty::ctxt<'tcx>, + class_id: ast::DefId, + items: &[ty::field_ty], + fieldname: ast::Name, + substs: &subst::Substs<'tcx>) + -> Option> { let o_field = items.iter().find(|f| f.name == fieldname); o_field.map(|f| ty::lookup_field_type(tcx, class_id, f.id, substs)) } -pub fn lookup_tup_field_ty(tcx: &ty::ctxt, - class_id: ast::DefId, - items: &[ty::field_ty], - idx: uint, - substs: &subst::Substs) -> Option { +pub fn lookup_tup_field_ty<'tcx>(tcx: &ty::ctxt<'tcx>, + class_id: ast::DefId, + items: &[ty::field_ty], + idx: uint, + substs: &subst::Substs<'tcx>) + -> Option> { let o_field = if idx < items.len() { Some(&items[idx]) } else { None }; o_field.map(|f| ty::lookup_field_type(tcx, class_id, f.id, substs)) @@ -3090,20 +3099,20 @@ enum TupleArgumentsFlag { /// Note that inspecting a type's structure *directly* may expose the fact /// that there are actually multiple representations for `ty_err`, so avoid /// that when err needs to be handled differently. -fn check_expr_with_unifier(fcx: &FnCtxt, - expr: &ast::Expr, - expected: Expectation, - lvalue_pref: LvaluePreference, - unifier: ||) +fn check_expr_with_unifier<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + expr: &ast::Expr, + expected: Expectation<'tcx>, + lvalue_pref: LvaluePreference, + unifier: ||) { debug!(">> typechecking: expr={} expected={}", expr.repr(fcx.tcx()), expected.repr(fcx.tcx())); // A generic function for doing all of the checking for call expressions - fn check_call<'a>(fcx: &FnCtxt, - call_expr: &ast::Expr, - f: &ast::Expr, - args: &[&'a P]) { + fn check_call(fcx: &FnCtxt, + call_expr: &ast::Expr, + f: &ast::Expr, + args: &[&P]) { // Store the type of `f` as the type of the callee let fn_ty = fcx.expr_ty(f); @@ -3201,13 +3210,13 @@ fn check_expr_with_unifier(fcx: &FnCtxt, // A generic function for checking the then and else in an if // or if-check - fn check_then_else(fcx: &FnCtxt, - cond_expr: &ast::Expr, - then_blk: &ast::Block, - opt_else_expr: Option<&ast::Expr>, - id: ast::NodeId, - sp: Span, - expected: Expectation) { + fn check_then_else<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + cond_expr: &ast::Expr, + then_blk: &ast::Block, + opt_else_expr: Option<&ast::Expr>, + id: ast::NodeId, + sp: Span, + expected: Expectation<'tcx>) { check_expr_has_type(fcx, cond_expr, ty::mk_bool()); // Disregard "castable to" expectations because they @@ -3271,12 +3280,12 @@ fn check_expr_with_unifier(fcx: &FnCtxt, fn lookup_op_method<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>, op_ex: &ast::Expr, - lhs_ty: ty::t, + lhs_ty: Ty<'tcx>, opname: ast::Name, trait_did: Option, lhs: &'a ast::Expr, rhs: Option<&P>, - unbound_method: ||) -> ty::t { + unbound_method: ||) -> Ty<'tcx> { let method = match trait_did { Some(trait_did) => { // We do eager coercions to make using operators @@ -3289,7 +3298,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, // could also solve this with variance or different // traits that don't force left and right to have same // type. - let (adj_ty, adjustment) = match ty::get(lhs_ty).sty { + let (adj_ty, adjustment) = match lhs_ty.sty { ty::ty_rptr(r_in, mt) => { let r_adj = fcx.infcx().next_region_var(infer::Autoref(lhs.span)); fcx.mk_subr(infer::Reborrow(lhs.span), r_adj, r_in); @@ -3454,12 +3463,12 @@ fn check_expr_with_unifier(fcx: &FnCtxt, } } - fn check_user_binop(fcx: &FnCtxt, - ex: &ast::Expr, - lhs_expr: &ast::Expr, - lhs_resolved_t: ty::t, - op: ast::BinOp, - rhs: &P) -> ty::t { + fn check_user_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + ex: &ast::Expr, + lhs_expr: &ast::Expr, + lhs_resolved_t: Ty<'tcx>, + op: ast::BinOp, + rhs: &P) -> Ty<'tcx> { let tcx = fcx.ccx.tcx; let lang = &tcx.lang_items; let (name, trait_did) = match op { @@ -3494,13 +3503,13 @@ fn check_expr_with_unifier(fcx: &FnCtxt, }) } - fn check_user_unop(fcx: &FnCtxt, - op_str: &str, - mname: &str, - trait_did: Option, - ex: &ast::Expr, - rhs_expr: &ast::Expr, - rhs_t: ty::t) -> ty::t { + fn check_user_unop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + op_str: &str, + mname: &str, + trait_did: Option, + ex: &ast::Expr, + rhs_expr: &ast::Expr, + rhs_t: Ty<'tcx>) -> Ty<'tcx> { lookup_op_method(fcx, ex, rhs_t, token::intern(mname), trait_did, rhs_expr, None, || { fcx.type_error_message(ex.span, |actual| { @@ -3579,12 +3588,12 @@ fn check_expr_with_unifier(fcx: &FnCtxt, .insert(local_def(expr.id), unboxed_closure); } - fn check_expr_fn(fcx: &FnCtxt, - expr: &ast::Expr, - store: ty::TraitStore, - decl: &ast::FnDecl, - body: &ast::Block, - expected: Expectation) { + fn check_expr_fn<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + expr: &ast::Expr, + store: ty::TraitStore, + decl: &ast::FnDecl, + body: &ast::Block, + expected: Expectation<'tcx>) { let tcx = fcx.ccx.tcx; debug!("check_expr_fn(expr={}, expected={})", @@ -3691,7 +3700,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, // FIXME(eddyb) #12808 Integrate privacy into this auto-deref loop. let (_, autoderefs, field_ty) = autoderef(fcx, expr.span, expr_t, Some(base.id), lvalue_pref, |base_t, _| { - match ty::get(base_t).sty { + match base_t.sty { ty::ty_struct(base_id, ref substs) => { debug!("struct named {}", ppaux::ty_to_string(tcx, base_t)); let fields = ty::lookup_struct_fields(tcx, base_id); @@ -3752,7 +3761,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, // FIXME(eddyb) #12808 Integrate privacy into this auto-deref loop. let (_, autoderefs, field_ty) = autoderef(fcx, expr.span, expr_t, Some(base.id), lvalue_pref, |base_t, _| { - match ty::get(base_t).sty { + match base_t.sty { ty::ty_struct(base_id, ref substs) => { tuple_like = ty::is_tuple_struct(tcx, base_id); if tuple_like { @@ -3799,15 +3808,15 @@ fn check_expr_with_unifier(fcx: &FnCtxt, fcx.write_error(expr.id); } - fn check_struct_or_variant_fields(fcx: &FnCtxt, - struct_ty: ty::t, - span: Span, - class_id: ast::DefId, - node_id: ast::NodeId, - substitutions: subst::Substs, - field_types: &[ty::field_ty], - ast_fields: &[ast::Field], - check_completeness: bool) { + fn check_struct_or_variant_fields<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + struct_ty: Ty<'tcx>, + span: Span, + class_id: ast::DefId, + node_id: ast::NodeId, + substitutions: subst::Substs<'tcx>, + field_types: &[ty::field_ty], + ast_fields: &[ast::Field], + check_completeness: bool) { let tcx = fcx.ccx.tcx; let mut class_field_map = FnvHashMap::new(); @@ -3975,7 +3984,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, } } - type ExprCheckerWithTy = fn(&FnCtxt, &ast::Expr, ty::t); + type ExprCheckerWithTy = fn(&FnCtxt, &ast::Expr, Ty); let tcx = fcx.ccx.tcx; let id = expr.id; @@ -4083,7 +4092,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, Some(&**oprnd), oprnd_t, lvalue_pref) { Some(mt) => mt.ty, None => { - let is_newtype = match ty::get(oprnd_t).sty { + let is_newtype = match oprnd_t.sty { ty::ty_struct(did, ref substs) => { let fields = ty::struct_fields(fcx.tcx(), did, substs); fields.len() == 1 @@ -4112,7 +4121,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, oprnd_t = structurally_resolved_type(fcx, oprnd.span, oprnd_t); if !(ty::type_is_integral(oprnd_t) || - ty::get(oprnd_t).sty == ty::ty_bool) { + oprnd_t.sty == ty::ty_bool) { oprnd_t = check_user_unop(fcx, "!", "not", tcx.lang_items.not_trait(), expr, &**oprnd, oprnd_t); @@ -4378,7 +4387,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, ast::ExprVec(ref args) => { let uty = match expected { ExpectHasType(uty) => { - match ty::get(uty).sty { + match uty.sty { ty::ty_vec(ty, _) => Some(ty), _ => None } @@ -4394,7 +4403,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, uty } None => { - let t: ty::t = fcx.infcx().next_ty_var(); + let t: Ty = fcx.infcx().next_ty_var(); for e in args.iter() { check_expr_has_type(fcx, &**e, t); } @@ -4410,7 +4419,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, let uty = match expected { ExpectHasType(uty) => { - match ty::get(uty).sty { + match uty.sty { ty::ty_vec(ty, _) => Some(ty), _ => None } @@ -4424,7 +4433,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, (uty, uty) } None => { - let t: ty::t = fcx.infcx().next_ty_var(); + let t: Ty = fcx.infcx().next_ty_var(); check_expr_has_type(fcx, &**element, t); (fcx.expr_ty(&**element), t) } @@ -4501,7 +4510,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, Some(def) => { // Verify that this was actually a struct. let typ = ty::lookup_item_type(fcx.ccx.tcx, def.def_id()); - match ty::get(typ.ty).sty { + match typ.ty.sty { ty::ty_struct(struct_did, _) => { check_struct_constructor(fcx, id, @@ -4692,8 +4701,8 @@ fn constrain_path_type_parameters(fcx: &FnCtxt, }); } -impl Expectation { - fn only_has_type(self) -> Expectation { +impl<'tcx> Expectation<'tcx> { + fn only_has_type(self) -> Expectation<'tcx> { match self { NoExpectation | ExpectCastableToType(..) => NoExpectation, ExpectHasType(t) => ExpectHasType(t) @@ -4703,7 +4712,7 @@ impl Expectation { // Resolves `expected` by a single level if it is a variable. If // there is no expected type or resolution is not possible (e.g., // no constraints yet present), just returns `None`. - fn resolve(self, fcx: &FnCtxt) -> Expectation { + fn resolve<'a>(self, fcx: &FnCtxt<'a, 'tcx>) -> Expectation<'tcx> { match self { NoExpectation => { NoExpectation @@ -4719,27 +4728,29 @@ impl Expectation { } } - fn map(self, fcx: &FnCtxt, unpack: |&ty::sty| -> Expectation) -> Expectation { + fn map<'a>(self, fcx: &FnCtxt<'a, 'tcx>, + unpack: |&ty::sty<'tcx>| -> Expectation<'tcx>) + -> Expectation<'tcx> { match self.resolve(fcx) { NoExpectation => NoExpectation, - ExpectCastableToType(t) | ExpectHasType(t) => unpack(&ty::get(t).sty), + ExpectCastableToType(t) | ExpectHasType(t) => unpack(&t.sty), } } - fn map_to_option(self, - fcx: &FnCtxt, - unpack: |&ty::sty| -> Option) - -> Option + fn map_to_option<'a, O>(self, + fcx: &FnCtxt<'a, 'tcx>, + unpack: |&ty::sty<'tcx>| -> Option) + -> Option { match self.resolve(fcx) { NoExpectation => None, - ExpectCastableToType(t) | ExpectHasType(t) => unpack(&ty::get(t).sty), + ExpectCastableToType(t) | ExpectHasType(t) => unpack(&t.sty), } } } -impl Repr for Expectation { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for Expectation<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { NoExpectation => format!("NoExpectation"), ExpectHasType(t) => format!("ExpectHasType({})", @@ -4842,9 +4853,9 @@ pub fn check_block_no_value(fcx: &FnCtxt, blk: &ast::Block) { } } -fn check_block_with_expected(fcx: &FnCtxt, - blk: &ast::Block, - expected: Expectation) { +fn check_block_with_expected<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + blk: &ast::Block, + expected: Expectation<'tcx>) { let prev = { let mut fcx_ps = fcx.ps.borrow_mut(); let fn_style_state = fcx_ps.recurse(blk); @@ -4925,9 +4936,9 @@ fn check_block_with_expected(fcx: &FnCtxt, /// Checks a constant appearing in a type. At the moment this is just the /// length expression in a fixed-length vector, but someday it might be /// extended to type-level numeric literals. -pub fn check_const_in_type(tcx: &ty::ctxt, - expr: &ast::Expr, - expected_type: ty::t) { +pub fn check_const_in_type<'tcx>(tcx: &ty::ctxt<'tcx>, + expr: &ast::Expr, + expected_type: Ty<'tcx>) { // Synthesize a crate context. The trait map is not needed here (though I // imagine it will be if we have associated statics --pcwalton), so we // leave it blank. @@ -4951,10 +4962,10 @@ pub fn check_const(ccx: &CrateCtxt, check_const_with_ty(&fcx, sp, e, declty); } -pub fn check_const_with_ty(fcx: &FnCtxt, - _: Span, - e: &ast::Expr, - declty: ty::t) { +pub fn check_const_with_ty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + _: Span, + e: &ast::Expr, + declty: Ty<'tcx>) { // Gather locals in statics (because of block expressions). // This is technically unnecessary because locals in static items are forbidden, // but prevents type checking from blowing up before const checking can properly @@ -5031,7 +5042,7 @@ pub fn check_simd(tcx: &ty::ctxt, sp: Span, id: ast::NodeId) { span_err!(tcx.sess, sp, E0074, "SIMD vector cannot be generic"); return; } - match ty::get(t).sty { + match t.sty { ty::ty_struct(did, ref substs) => { let fields = ty::lookup_struct_fields(tcx, did); if fields.is_empty() { @@ -5086,11 +5097,11 @@ pub fn check_enum_variants(ccx: &CrateCtxt, } } - fn do_check(ccx: &CrateCtxt, - vs: &[P], - id: ast::NodeId, - hint: attr::ReprAttr) - -> Vec> { + fn do_check<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + vs: &[P], + id: ast::NodeId, + hint: attr::ReprAttr) + -> Vec>> { let rty = ty::node_id_to_type(ccx.tcx, id); let mut variants: Vec> = Vec::new(); @@ -5211,10 +5222,10 @@ pub fn lookup_def(fcx: &FnCtxt, sp: Span, id: ast::NodeId) -> def::Def { } // Returns the type parameter count and the type for the given definition. -pub fn polytype_for_def(fcx: &FnCtxt, - sp: Span, - defn: def::Def) - -> Polytype { +pub fn polytype_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + sp: Span, + defn: def::Def) + -> Polytype<'tcx> { match defn { def::DefLocal(nid) | def::DefUpvar(nid, _, _) => { let typ = fcx.local_ty(sp, nid); @@ -5255,12 +5266,12 @@ pub fn polytype_for_def(fcx: &FnCtxt, // Instantiates the given path, which must refer to an item with the given // number of type parameters and type. -pub fn instantiate_path(fcx: &FnCtxt, - path: &ast::Path, - polytype: Polytype, - def: def::Def, - span: Span, - node_id: ast::NodeId) { +pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + path: &ast::Path, + polytype: Polytype<'tcx>, + def: def::Def, + span: Span, + node_id: ast::NodeId) { debug!("instantiate_path(path={}, def={}, node_id={}, polytype={})", path.repr(fcx.tcx()), def.repr(fcx.tcx()), @@ -5472,14 +5483,14 @@ pub fn instantiate_path(fcx: &FnCtxt, } } - fn push_explicit_parameters_from_segment_to_substs( - fcx: &FnCtxt, + fn push_explicit_parameters_from_segment_to_substs<'a, 'tcx>( + fcx: &FnCtxt<'a, 'tcx>, space: subst::ParamSpace, span: Span, - type_defs: &VecPerParamSpace, + type_defs: &VecPerParamSpace>, region_defs: &VecPerParamSpace, segment: &ast::PathSegment, - substs: &mut Substs) + substs: &mut Substs<'tcx>) { /*! * Finds the parameters that the user provided and adds them @@ -5511,13 +5522,13 @@ pub fn instantiate_path(fcx: &FnCtxt, } } - fn push_explicit_angle_bracketed_parameters_from_segment_to_substs( - fcx: &FnCtxt, + fn push_explicit_angle_bracketed_parameters_from_segment_to_substs<'a, 'tcx>( + fcx: &FnCtxt<'a, 'tcx>, space: subst::ParamSpace, - type_defs: &VecPerParamSpace, + type_defs: &VecPerParamSpace>, region_defs: &VecPerParamSpace, data: &ast::AngleBracketedParameterData, - substs: &mut Substs) + substs: &mut Substs<'tcx>) { { let type_count = type_defs.len(space); @@ -5556,13 +5567,13 @@ pub fn instantiate_path(fcx: &FnCtxt, } } - fn push_explicit_parenthesized_parameters_from_segment_to_substs( - fcx: &FnCtxt, + fn push_explicit_parenthesized_parameters_from_segment_to_substs<'a, 'tcx>( + fcx: &FnCtxt<'a, 'tcx>, space: subst::ParamSpace, span: Span, - type_defs: &VecPerParamSpace, + type_defs: &VecPerParamSpace>, data: &ast::ParenthesizedParameterData, - substs: &mut Substs) + substs: &mut Substs<'tcx>) { /*! * As with @@ -5581,7 +5592,7 @@ pub fn instantiate_path(fcx: &FnCtxt, type_count); } - let input_tys: Vec = + let input_tys: Vec = data.inputs.iter().map(|ty| fcx.to_ty(&**ty)).collect(); let tuple_ty = @@ -5591,7 +5602,7 @@ pub fn instantiate_path(fcx: &FnCtxt, substs.types.push(space, tuple_ty); } - let output_ty: Option = + let output_ty: Option = data.output.as_ref().map(|ty| fcx.to_ty(&**ty)); let output_ty = @@ -5602,12 +5613,12 @@ pub fn instantiate_path(fcx: &FnCtxt, } } - fn adjust_type_parameters( - fcx: &FnCtxt, + fn adjust_type_parameters<'a, 'tcx>( + fcx: &FnCtxt<'a, 'tcx>, span: Span, space: ParamSpace, - defs: &VecPerParamSpace, - substs: &mut Substs) + defs: &VecPerParamSpace>, + substs: &mut Substs<'tcx>) { let provided_len = substs.types.len(space); let desired = defs.get_slice(space); @@ -5707,7 +5718,8 @@ pub fn instantiate_path(fcx: &FnCtxt, // Resolves `typ` by a single level if `typ` is a type variable. If no // resolution is possible, then an error is reported. -pub fn structurally_resolved_type(fcx: &FnCtxt, sp: Span, mut ty: ty::t) -> ty::t { +pub fn structurally_resolved_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, + mut ty: Ty<'tcx>) -> Ty<'tcx> { // If `ty` is a type variable, see whether we already know what it is. ty = fcx.infcx().shallow_resolve(ty); @@ -5736,9 +5748,9 @@ pub fn structurally_resolved_type(fcx: &FnCtxt, sp: Span, mut ty: ty::t) -> ty:: } // Returns the one-level-deep structure of the given type. -pub fn structure_of<'a>(fcx: &FnCtxt, sp: Span, typ: ty::t) - -> &'a ty::sty { - &ty::get(structurally_resolved_type(fcx, sp, typ)).sty +pub fn structure_of<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, typ: Ty<'tcx>) + -> &'tcx ty::sty<'tcx> { + &structurally_resolved_type(fcx, sp, typ).sty } // Returns true if b contains a break that can exit from b @@ -5765,10 +5777,10 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: &ast::Block) -> bool { }})) } -pub fn check_bounds_are_used(ccx: &CrateCtxt, - span: Span, - tps: &OwnedSlice, - ty: ty::t) { +pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + span: Span, + tps: &OwnedSlice, + ty: Ty<'tcx>) { debug!("check_bounds_are_used(n_tps={}, ty={})", tps.len(), ppaux::ty_to_string(ccx.tcx, ty)); @@ -5777,7 +5789,7 @@ pub fn check_bounds_are_used(ccx: &CrateCtxt, let mut tps_used = Vec::from_elem(tps.len(), false); ty::walk_ty(ty, |t| { - match ty::get(t).sty { + match t.sty { ty::ty_param(ParamTy {idx, ..}) => { debug!("Found use of ty param num {}", idx); tps_used[idx] = true; @@ -5796,7 +5808,7 @@ pub fn check_bounds_are_used(ccx: &CrateCtxt, } pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) { - fn param(ccx: &CrateCtxt, n: uint) -> ty::t { + fn param<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, n: uint) -> Ty<'tcx> { ty::mk_param(ccx.tcx, subst::FnSpace, n, local_def(0)) } @@ -6077,8 +6089,8 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) { } } -impl Repr for RegionObligation { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for RegionObligation<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("RegionObligation(sub_region={}, sup_type={}, origin={})", self.sub_region.repr(tcx), self.sup_type.repr(tcx), diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index c63e8944dbdca..44c11318038d3 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -122,7 +122,7 @@ use middle::def; use middle::mem_categorization as mc; use middle::traits; use middle::ty::{ReScope}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::astconv::AstConv; use middle::typeck::check::FnCtxt; use middle::typeck::check::regionmanip; @@ -176,9 +176,9 @@ pub fn regionck_fn(fcx: &FnCtxt, id: ast::NodeId, blk: &ast::Block) { fcx.infcx().resolve_regions_and_report_errors(); } -pub fn regionck_ensure_component_tys_wf(fcx: &FnCtxt, - span: Span, - component_tys: &[ty::t]) { +pub fn regionck_ensure_component_tys_wf<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + component_tys: &[Ty<'tcx>]) { /*! * Checks that the types in `component_tys` are well-formed. * This will add constraints into the region graph. @@ -215,15 +215,15 @@ macro_rules! ignore_err( // Stores parameters for a potential call to link_region() // to perform if an upvar reference is marked unique/mutable after // it has already been processed before. -struct MaybeLink { +struct MaybeLink<'tcx> { span: Span, borrow_region: ty::Region, borrow_kind: ty::BorrowKind, - borrow_cmt: mc::cmt + borrow_cmt: mc::cmt<'tcx> } // A map associating an upvar ID to a vector of the above -type MaybeLinkMap = RefCell>>; +type MaybeLinkMap<'tcx> = RefCell>>>; pub struct Rcx<'a, 'tcx: 'a> { fcx: &'a FnCtxt<'a, 'tcx>, @@ -235,7 +235,7 @@ pub struct Rcx<'a, 'tcx: 'a> { // Possible region links we will establish if an upvar // turns out to be unique/mutable - maybe_links: MaybeLinkMap + maybe_links: MaybeLinkMap<'tcx> } fn region_of_def(fcx: &FnCtxt, def: def::Def) -> ty::Region { @@ -282,7 +282,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { old_scope } - pub fn resolve_type(&self, unresolved_ty: ty::t) -> ty::t { + pub fn resolve_type(&self, unresolved_ty: Ty<'tcx>) -> Ty<'tcx> { /*! * Try to resolve the type for the given node, returning * t_err if an error results. Note that we never care @@ -319,19 +319,19 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { } /// Try to resolve the type for the given node. - fn resolve_node_type(&self, id: ast::NodeId) -> ty::t { + fn resolve_node_type(&self, id: ast::NodeId) -> Ty<'tcx> { let t = self.fcx.node_ty(id); self.resolve_type(t) } - fn resolve_method_type(&self, method_call: MethodCall) -> Option { + fn resolve_method_type(&self, method_call: MethodCall) -> Option> { let method_ty = self.fcx.inh.method_map.borrow() .get(&method_call).map(|method| method.ty); method_ty.map(|method_ty| self.resolve_type(method_ty)) } /// Try to resolve the type for the given node. - pub fn resolve_expr_type_adjusted(&mut self, expr: &ast::Expr) -> ty::t { + pub fn resolve_expr_type_adjusted(&mut self, expr: &ast::Expr) -> Ty<'tcx> { let ty_unadjusted = self.resolve_node_type(expr.id); if ty::type_is_error(ty_unadjusted) { ty_unadjusted @@ -384,7 +384,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { } fn relate_free_regions(&mut self, - fn_sig_tys: &[ty::t], + fn_sig_tys: &[Ty<'tcx>], body_id: ast::NodeId) { /*! * This method populates the region map's `free_region_map`. @@ -457,16 +457,16 @@ impl<'fcx, 'tcx> mc::Typer<'tcx> for Rcx<'fcx, 'tcx> { self.fcx.ccx.tcx } - fn node_ty(&self, id: ast::NodeId) -> mc::McResult { + fn node_ty(&self, id: ast::NodeId) -> mc::McResult> { let t = self.resolve_node_type(id); if ty::type_is_error(t) {Err(())} else {Ok(t)} } - fn node_method_ty(&self, method_call: MethodCall) -> Option { + fn node_method_ty(&self, method_call: MethodCall) -> Option> { self.resolve_method_type(method_call) } - fn adjustments<'a>(&'a self) -> &'a RefCell> { + fn adjustments<'a>(&'a self) -> &'a RefCell>> { &self.fcx.inh.adjustments } @@ -488,7 +488,7 @@ impl<'fcx, 'tcx> mc::Typer<'tcx> for Rcx<'fcx, 'tcx> { } fn unboxed_closures<'a>(&'a self) - -> &'a RefCell> { + -> &'a RefCell>> { &self.fcx.inh.unboxed_closures } } @@ -693,7 +693,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) { } None => rcx.resolve_node_type(base.id) }; - match ty::get(base_ty).sty { + match base_ty.sty { ty::ty_rptr(r_ptr, _) => { mk_subregion_due_to_dereference(rcx, expr.span, ty::ReScope(expr.id), r_ptr); @@ -807,14 +807,14 @@ fn constrain_cast(rcx: &mut Rcx, walk_cast(rcx, cast_expr, source_ty, target_ty); - fn walk_cast(rcx: &mut Rcx, - cast_expr: &ast::Expr, - from_ty: ty::t, - to_ty: ty::t) { + fn walk_cast<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>, + cast_expr: &ast::Expr, + from_ty: Ty<'tcx>, + to_ty: Ty<'tcx>) { debug!("walk_cast(from_ty={}, to_ty={})", from_ty.repr(rcx.tcx()), to_ty.repr(rcx.tcx())); - match (&ty::get(from_ty).sty, &ty::get(to_ty).sty) { + match (&from_ty.sty, &to_ty.sty) { /*From:*/ (&ty::ty_rptr(from_r, ref from_mt), /*To: */ &ty::ty_rptr(to_r, ref to_mt)) => { // Target cannot outlive source, naturally. @@ -846,7 +846,7 @@ fn check_expr_fn_block(rcx: &mut Rcx, let tcx = rcx.fcx.tcx(); let function_type = rcx.resolve_node_type(expr.id); - match ty::get(function_type).sty { + match function_type.sty { ty::ty_closure(box ty::ClosureTy{store: ty::RegionTraitStore(..), ref bounds, ..}) => { @@ -889,7 +889,7 @@ fn check_expr_fn_block(rcx: &mut Rcx, visit::walk_expr(rcx, expr); rcx.set_repeating_scope(repeating_scope); - match ty::get(function_type).sty { + match function_type.sty { ty::ty_closure(box ty::ClosureTy { store: ty::RegionTraitStore(..), .. }) => { ty::with_freevars(tcx, expr.id, |freevars| { propagate_upupvar_borrow_kind(rcx, expr, freevars); @@ -905,7 +905,7 @@ fn check_expr_fn_block(rcx: &mut Rcx, _ => {} } - match ty::get(function_type).sty { + match function_type.sty { ty::ty_closure(box ty::ClosureTy {bounds, ..}) => { ty::with_freevars(tcx, expr.id, |freevars| { ensure_free_variable_types_outlive_closure_bound(rcx, bounds, expr, freevars); @@ -1092,7 +1092,7 @@ fn constrain_callee(rcx: &mut Rcx, let call_region = ty::ReScope(call_expr.id); let callee_ty = rcx.resolve_node_type(callee_id); - match ty::get(callee_ty).sty { + match callee_ty.sty { ty::ty_bare_fn(..) => { } ty::ty_closure(ref closure_ty) => { let region = match closure_ty.store { @@ -1182,10 +1182,10 @@ fn constrain_call<'a, I: Iterator<&'a ast::Expr>>(rcx: &mut Rcx, } } -fn constrain_autoderefs(rcx: &mut Rcx, - deref_expr: &ast::Expr, - derefs: uint, - mut derefd_ty: ty::t) { +fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>, + deref_expr: &ast::Expr, + derefs: uint, + mut derefd_ty: Ty<'tcx>) { /*! * Invoked on any auto-dereference that occurs. Checks that if * this is a region pointer being dereferenced, the lifetime of @@ -1204,7 +1204,7 @@ fn constrain_autoderefs(rcx: &mut Rcx, // was applied on the base type, as that is always the case. let fn_sig = ty::ty_fn_sig(method.ty); let self_ty = fn_sig.inputs[0]; - let (m, r) = match ty::get(self_ty).sty { + let (m, r) = match self_ty.sty { ty::ty_rptr(r, ref m) => (m.mutbl, r), _ => rcx.tcx().sess.span_bug(deref_expr.span, format!("bad overloaded deref type {}", @@ -1232,7 +1232,7 @@ fn constrain_autoderefs(rcx: &mut Rcx, None => derefd_ty }; - match ty::get(derefd_ty).sty { + match derefd_ty.sty { ty::ty_rptr(r_ptr, _) => { mk_subregion_due_to_dereference(rcx, deref_expr.span, r_deref_expr, r_ptr); @@ -1258,9 +1258,9 @@ pub fn mk_subregion_due_to_dereference(rcx: &mut Rcx, } -fn constrain_index(rcx: &mut Rcx, - index_expr: &ast::Expr, - indexed_ty: ty::t) +fn constrain_index<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>, + index_expr: &ast::Expr, + indexed_ty: Ty<'tcx>) { /*! * Invoked on any index expression that occurs. Checks that if @@ -1272,8 +1272,8 @@ fn constrain_index(rcx: &mut Rcx, rcx.fcx.infcx().ty_to_string(indexed_ty)); let r_index_expr = ty::ReScope(index_expr.id); - match ty::get(indexed_ty).sty { - ty::ty_rptr(r_ptr, mt) => match ty::get(mt.ty).sty { + match indexed_ty.sty { + ty::ty_rptr(r_ptr, mt) => match mt.ty.sty { ty::ty_vec(_, None) | ty::ty_str => { rcx.fcx.mk_subr(infer::IndexSlice(index_expr.span), r_index_expr, r_ptr); @@ -1285,9 +1285,9 @@ fn constrain_index(rcx: &mut Rcx, } } -fn type_of_node_must_outlive( - rcx: &mut Rcx, - origin: infer::SubregionOrigin, +fn type_of_node_must_outlive<'a, 'tcx>( + rcx: &mut Rcx<'a, 'tcx>, + origin: infer::SubregionOrigin<'tcx>, id: ast::NodeId, minimum_lifetime: ty::Region) { @@ -1365,10 +1365,10 @@ fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) { } } -fn link_pattern(rcx: &Rcx, - mc: mc::MemCategorizationContext, - discr_cmt: mc::cmt, - root_pat: &ast::Pat) { +fn link_pattern<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, + mc: mc::MemCategorizationContext>, + discr_cmt: mc::cmt<'tcx>, + root_pat: &ast::Pat) { /*! * Link lifetimes of any ref bindings in `root_pat` to * the pointers found in the discriminant, if needed. @@ -1441,11 +1441,11 @@ fn link_by_ref(rcx: &Rcx, link_region(rcx, expr.span, borrow_region, ty::ImmBorrow, expr_cmt); } -fn link_region_from_node_type(rcx: &Rcx, - span: Span, - id: ast::NodeId, - mutbl: ast::Mutability, - cmt_borrowed: mc::cmt) { +fn link_region_from_node_type<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, + span: Span, + id: ast::NodeId, + mutbl: ast::Mutability, + cmt_borrowed: mc::cmt<'tcx>) { /*! * Like `link_region()`, except that the region is * extracted from the type of `id`, which must be some @@ -1462,11 +1462,11 @@ fn link_region_from_node_type(rcx: &Rcx, } } -fn link_region(rcx: &Rcx, - span: Span, - borrow_region: ty::Region, - borrow_kind: ty::BorrowKind, - borrow_cmt: mc::cmt) { +fn link_region<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, + span: Span, + borrow_region: ty::Region, + borrow_kind: ty::BorrowKind, + borrow_cmt: mc::cmt<'tcx>) { /*! * Informs the inference engine that `borrow_cmt` is being * borrowed with kind `borrow_kind` and lifetime `borrow_region`. @@ -1524,15 +1524,15 @@ fn link_region(rcx: &Rcx, } } -fn link_reborrowed_region(rcx: &Rcx, - span: Span, - borrow_region: ty::Region, - borrow_kind: ty::BorrowKind, - ref_cmt: mc::cmt, - ref_region: ty::Region, - mut ref_kind: ty::BorrowKind, - note: mc::Note) - -> Option<(mc::cmt, ty::BorrowKind)> +fn link_reborrowed_region<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, + span: Span, + borrow_region: ty::Region, + borrow_kind: ty::BorrowKind, + ref_cmt: mc::cmt<'tcx>, + ref_region: ty::Region, + mut ref_kind: ty::BorrowKind, + note: mc::Note) + -> Option<(mc::cmt<'tcx>, ty::BorrowKind)> { /*! * This is the most complicated case: the path being borrowed is @@ -1727,8 +1727,8 @@ fn adjust_borrow_kind_for_assignment_lhs(rcx: &Rcx, adjust_upvar_borrow_kind_for_mut(rcx, cmt); } -fn adjust_upvar_borrow_kind_for_mut(rcx: &Rcx, - cmt: mc::cmt) { +fn adjust_upvar_borrow_kind_for_mut<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, + cmt: mc::cmt<'tcx>) { /*! * Indicates that `cmt` is being directly mutated (e.g., assigned * to). If cmt contains any by-ref upvars, this implies that @@ -1785,7 +1785,7 @@ fn adjust_upvar_borrow_kind_for_mut(rcx: &Rcx, } } -fn adjust_upvar_borrow_kind_for_unique(rcx: &Rcx, cmt: mc::cmt) { +fn adjust_upvar_borrow_kind_for_unique<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, cmt: mc::cmt<'tcx>) { let mut cmt = cmt; loop { debug!("adjust_upvar_borrow_kind_for_unique(cmt={})", @@ -1910,10 +1910,10 @@ fn adjust_upvar_borrow_kind(rcx: &Rcx, } } -fn type_must_outlive(rcx: &mut Rcx, - origin: infer::SubregionOrigin, - ty: ty::t, - region: ty::Region) +fn type_must_outlive<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>, + origin: infer::SubregionOrigin<'tcx>, + ty: Ty<'tcx>, + region: ty::Region) { /*! * Ensures that all borrowed data reachable via `ty` outlives `region`. @@ -1949,10 +1949,10 @@ fn type_must_outlive(rcx: &mut Rcx, } } -fn param_must_outlive(rcx: &Rcx, - origin: infer::SubregionOrigin, - region: ty::Region, - param_ty: ty::ParamTy) { +fn param_must_outlive<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, + origin: infer::SubregionOrigin<'tcx>, + region: ty::Region, + param_ty: ty::ParamTy) { let param_env = &rcx.fcx.inh.param_env; debug!("param_must_outlive(region={}, param_ty={})", diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc/middle/typeck/check/regionmanip.rs index 2e727a8ef9aa5..9fd24c4ee784e 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc/middle/typeck/check/regionmanip.rs @@ -13,7 +13,7 @@ pub use self::WfConstraint::*; use middle::subst::{ParamSpace, Subst, Substs}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty_fold::{TypeFolder}; use syntax::ast; @@ -22,22 +22,22 @@ use util::ppaux::Repr; // Helper functions related to manipulating region types. -pub enum WfConstraint { - RegionSubRegionConstraint(Option, ty::Region, ty::Region), - RegionSubParamConstraint(Option, ty::Region, ty::ParamTy), +pub enum WfConstraint<'tcx> { + RegionSubRegionConstraint(Option>, ty::Region, ty::Region), + RegionSubParamConstraint(Option>, ty::Region, ty::ParamTy), } struct Wf<'a, 'tcx: 'a> { tcx: &'a ty::ctxt<'tcx>, - stack: Vec<(ty::Region, Option)>, - out: Vec, + stack: Vec<(ty::Region, Option>)>, + out: Vec>, } -pub fn region_wf_constraints( - tcx: &ty::ctxt, - ty: ty::t, +pub fn region_wf_constraints<'tcx>( + tcx: &ty::ctxt<'tcx>, + ty: Ty<'tcx>, outer_region: ty::Region) - -> Vec + -> Vec> { /*! * This routine computes the well-formedness constraints that must @@ -55,11 +55,11 @@ pub fn region_wf_constraints( } impl<'a, 'tcx> Wf<'a, 'tcx> { - fn accumulate_from_ty(&mut self, ty: ty::t) { + fn accumulate_from_ty(&mut self, ty: Ty<'tcx>) { debug!("Wf::accumulate_from_ty(ty={})", ty.repr(self.tcx)); - match ty::get(ty).sty { + match ty.sty { ty::ty_bool | ty::ty_char | ty::ty_int(..) | @@ -146,9 +146,9 @@ impl<'a, 'tcx> Wf<'a, 'tcx> { } fn accumulate_from_rptr(&mut self, - ty: ty::t, + ty: Ty<'tcx>, r_b: ty::Region, - ty_b: ty::t) { + ty_b: Ty<'tcx>) { // We are walking down a type like this, and current // position is indicated by caret: // @@ -193,7 +193,7 @@ impl<'a, 'tcx> Wf<'a, 'tcx> { } fn push_sub_region_constraint(&mut self, - opt_ty: Option, + opt_ty: Option>, r_a: ty::Region, r_b: ty::Region) { /*! Pushes a constraint that `r_a <= r_b`, due to `opt_ty` */ @@ -213,16 +213,16 @@ impl<'a, 'tcx> Wf<'a, 'tcx> { fn push_param_constraint(&mut self, region: ty::Region, - opt_ty: Option, + opt_ty: Option>, param_ty: ty::ParamTy) { /*! Pushes a constraint that `region <= param_ty`, due to `opt_ty` */ self.out.push(RegionSubParamConstraint(opt_ty, region, param_ty)); } fn accumulate_from_adt(&mut self, - ty: ty::t, + ty: Ty<'tcx>, def_id: ast::DefId, - substs: &Substs) + substs: &Substs<'tcx>) { // The generic declarations from the type, appropriately // substituted for the actual substitutions. @@ -322,8 +322,8 @@ impl<'a, 'tcx> Wf<'a, 'tcx> { } fn accumulate_from_closure_ty(&mut self, - ty: ty::t, - c: &ty::ClosureTy) + ty: Ty<'tcx>, + c: &ty::ClosureTy<'tcx>) { match c.store { ty::RegionTraitStore(r_b, _) => { @@ -336,7 +336,7 @@ impl<'a, 'tcx> Wf<'a, 'tcx> { } fn accumulate_from_object_ty(&mut self, - ty: ty::t, + ty: Ty<'tcx>, bounds: &ty::ExistentialBounds) { // Imagine a type like this: diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 041d21a8baf36..99ffe89862229 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -14,7 +14,7 @@ use middle::traits::{SelectionError, OutputTypeParameterMismatch, Overflow, Unim use middle::traits::{Obligation, obligation_for_builtin_bound}; use middle::traits::{FulfillmentError, CodeSelectionError, CodeAmbiguity}; use middle::traits::{ObligationCause}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::check::{FnCtxt, structurally_resolved_type}; use middle::typeck::infer; @@ -23,10 +23,10 @@ use syntax::ast; use syntax::codemap::Span; use util::ppaux::{UserString, Repr, ty_to_string}; -pub fn check_object_cast(fcx: &FnCtxt, - cast_expr: &ast::Expr, - source_expr: &ast::Expr, - target_object_ty: ty::t) +pub fn check_object_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + cast_expr: &ast::Expr, + source_expr: &ast::Expr, + target_object_ty: Ty<'tcx>) { debug!("check_object_cast(cast_expr={}, target_object_ty={})", cast_expr.repr(fcx.tcx()), @@ -39,7 +39,7 @@ pub fn check_object_cast(fcx: &FnCtxt, let source_ty = fcx.expr_ty(source_expr); let source_ty = structurally_resolved_type(fcx, source_expr.span, source_ty); debug!("source_ty={}", source_ty.repr(fcx.tcx())); - match (&ty::get(source_ty).sty, &ty::get(target_object_ty).sty) { + match (&source_ty.sty, &target_object_ty.sty) { (&ty::ty_uniq(referent_ty), &ty::ty_uniq(object_trait_ty)) => { let object_trait = object_trait(&object_trait_ty); @@ -96,11 +96,8 @@ pub fn check_object_cast(fcx: &FnCtxt, } } - // Because we currently give unsound lifetimes to the "t_box", I - // could have written &'static ty::TyTrait here, but it seems - // gratuitously unsafe. - fn object_trait<'a>(t: &'a ty::t) -> &'a ty::TyTrait { - match ty::get(*t).sty { + fn object_trait<'a, 'tcx>(t: &'a Ty<'tcx>) -> &'a ty::TyTrait<'tcx> { + match t.sty { ty::ty_trait(ref ty_trait) => &**ty_trait, _ => panic!("expected ty_trait") } @@ -113,10 +110,10 @@ pub fn check_object_cast(fcx: &FnCtxt, (a_mutbl == ast::MutMutable && b_mutbl == ast::MutImmutable) } - fn push_cast_obligation(fcx: &FnCtxt, - cast_expr: &ast::Expr, - object_trait: &ty::TyTrait, - referent_ty: ty::t) { + fn push_cast_obligation<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + cast_expr: &ast::Expr, + object_trait: &ty::TyTrait<'tcx>, + referent_ty: Ty<'tcx>) { let object_trait_ref = register_object_cast_obligations(fcx, cast_expr.span, @@ -135,7 +132,9 @@ pub fn check_object_cast(fcx: &FnCtxt, // methods are object-safe. A trait method is object-safe if it does not take // self by value, has no type parameters and does not use the `Self` type, except // in self position. -pub fn check_object_safety(tcx: &ty::ctxt, object_trait: &ty::TyTrait, span: Span) { +pub fn check_object_safety<'tcx>(tcx: &ty::ctxt<'tcx>, + object_trait: &ty::TyTrait<'tcx>, + span: Span) { // Skip the fn_once lang item trait since only the compiler should call // `call_once` which is the method which takes self by value. What could go // wrong? @@ -169,7 +168,9 @@ pub fn check_object_safety(tcx: &ty::ctxt, object_trait: &ty::TyTrait, span: Spa } // Returns a vec of error messages. If hte vec is empty - no errors! - fn check_object_safety_of_method(tcx: &ty::ctxt, method: &ty::Method) -> Vec { + fn check_object_safety_of_method<'tcx>(tcx: &ty::ctxt<'tcx>, + method: &ty::Method<'tcx>) + -> Vec { /*! * There are some limitations to calling functions through an * object, because (a) the self type is not known @@ -231,11 +232,11 @@ pub fn check_object_safety(tcx: &ty::ctxt, object_trait: &ty::TyTrait, span: Spa } } -pub fn register_object_cast_obligations(fcx: &FnCtxt, - span: Span, - object_trait: &ty::TyTrait, - referent_ty: ty::t) - -> Rc +pub fn register_object_cast_obligations<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + object_trait: &ty::TyTrait<'tcx>, + referent_ty: Ty<'tcx>) + -> Rc> { // This is just for better error reporting. Kinda goofy. The object type stuff // needs some refactoring so there is a more convenient type to pass around. @@ -299,8 +300,8 @@ pub fn select_all_fcx_obligations_or_error(fcx: &FnCtxt) { } } -fn resolve_trait_ref(fcx: &FnCtxt, obligation: &Obligation) - -> (Rc, ty::t) +fn resolve_trait_ref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, obligation: &Obligation<'tcx>) + -> (Rc>, Ty<'tcx>) { let trait_ref = fcx.infcx().resolve_type_vars_in_trait_ref_if_possible( @@ -310,15 +311,15 @@ fn resolve_trait_ref(fcx: &FnCtxt, obligation: &Obligation) (Rc::new(trait_ref), self_ty) } -pub fn report_fulfillment_errors(fcx: &FnCtxt, - errors: &Vec) { +pub fn report_fulfillment_errors<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + errors: &Vec>) { for error in errors.iter() { report_fulfillment_error(fcx, error); } } -pub fn report_fulfillment_error(fcx: &FnCtxt, - error: &FulfillmentError) { +pub fn report_fulfillment_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + error: &FulfillmentError<'tcx>) { match error.code { CodeSelectionError(ref e) => { report_selection_error(fcx, &error.obligation, e); @@ -329,9 +330,9 @@ pub fn report_fulfillment_error(fcx: &FnCtxt, } } -pub fn report_selection_error(fcx: &FnCtxt, - obligation: &Obligation, - error: &SelectionError) +pub fn report_selection_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + obligation: &Obligation<'tcx>, + error: &SelectionError<'tcx>) { match *error { Overflow => { @@ -377,7 +378,8 @@ pub fn report_selection_error(fcx: &FnCtxt, } } -pub fn maybe_report_ambiguity(fcx: &FnCtxt, obligation: &Obligation) { +pub fn maybe_report_ambiguity<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + obligation: &Obligation<'tcx>) { // Unable to successfully determine, probably means // insufficient type information, but could mean // ambiguous impls. The latter *ought* to be a @@ -469,8 +471,8 @@ pub fn select_new_fcx_obligations(fcx: &FnCtxt) { } } -fn note_obligation_cause(fcx: &FnCtxt, - obligation: &Obligation) { +fn note_obligation_cause<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + obligation: &Obligation<'tcx>) { let tcx = fcx.tcx(); let trait_name = ty::item_path_str(tcx, obligation.trait_ref.def_id); match obligation.cause.code { diff --git a/src/librustc/middle/typeck/check/wf.rs b/src/librustc/middle/typeck/check/wf.rs index 8e02f9f7bfd57..5cc619bba26ba 100644 --- a/src/librustc/middle/typeck/check/wf.rs +++ b/src/librustc/middle/typeck/check/wf.rs @@ -11,7 +11,7 @@ use middle::subst; use middle::subst::{Subst}; use middle::traits; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty::liberate_late_bound_regions; use middle::ty_fold::{TypeFolder, TypeFoldable}; use middle::typeck::astconv::AstConv; @@ -29,7 +29,7 @@ use syntax::visit::Visitor; pub struct CheckTypeWellFormedVisitor<'ccx, 'tcx:'ccx> { ccx: &'ccx CrateCtxt<'ccx, 'tcx>, - cache: HashSet + cache: HashSet> } impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { @@ -37,7 +37,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { CheckTypeWellFormedVisitor { ccx: ccx, cache: HashSet::new() } } - fn check_item_well_formed(&mut self, ccx: &CrateCtxt, item: &ast::Item) { + fn check_item_well_formed(&mut self, item: &ast::Item) { /*! * Checks that the field types (in a struct def'n) or * argument types (in an enum def'n) are well-formed, @@ -55,6 +55,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { * the types first. */ + let ccx = self.ccx; debug!("check_item_well_formed(it.id={}, it.ident={})", item.id, ty::item_path_str(ccx.tcx, local_def(item.id))); @@ -87,9 +88,10 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { } fn with_fcx(&mut self, - ccx: &CrateCtxt, item: &ast::Item, - f: |&mut CheckTypeWellFormedVisitor, &FnCtxt|) { + f: for<'fcx> |&mut CheckTypeWellFormedVisitor<'ccx, 'tcx>, + &FnCtxt<'fcx, 'tcx>|) { + let ccx = self.ccx; let item_def_id = local_def(item.id); let polytype = ty::lookup_item_type(ccx.tcx, item_def_id); let param_env = @@ -106,14 +108,15 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { fn check_type_defn(&mut self, item: &ast::Item, - lookup_fields: |&FnCtxt| -> Vec) + lookup_fields: for<'fcx> |&FnCtxt<'fcx, 'tcx>| + -> Vec>) { /*! * In a type definition, we check that to ensure that the types of the fields are * well-formed. */ - self.with_fcx(self.ccx, item, |this, fcx| { + self.with_fcx(item, |this, fcx| { let variants = lookup_fields(fcx); let mut bounds_checker = BoundsChecker::new(fcx, item.span, item.id, Some(&mut this.cache)); @@ -139,7 +142,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { } } - let field_tys: Vec = + let field_tys: Vec = variants.iter().flat_map(|v| v.fields.iter().map(|f| f.ty)).collect(); regionck::regionck_ensure_component_tys_wf( @@ -150,7 +153,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { fn check_item_type(&mut self, item: &ast::Item) { - self.with_fcx(self.ccx, item, |this, fcx| { + self.with_fcx(item, |this, fcx| { let mut bounds_checker = BoundsChecker::new(fcx, item.span, item.id, Some(&mut this.cache)); let polytype = ty::lookup_item_type(fcx.tcx(), local_def(item.id)); @@ -162,7 +165,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { fn check_impl(&mut self, item: &ast::Item) { - self.with_fcx(self.ccx, item, |this, fcx| { + self.with_fcx(item, |this, fcx| { let mut bounds_checker = BoundsChecker::new(fcx, item.span, item.id, Some(&mut this.cache)); @@ -190,7 +193,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { fcx.tcx().lang_items.drop_trait() == Some(trait_ref.def_id) && !attr::contains_name(item.attrs.as_slice(), "unsafe_destructor") { - match ty::get(self_ty).sty { + match self_ty.sty { ty::ty_struct(def_id, _) | ty::ty_enum(def_id, _) => { check_struct_safe_for_destructor(fcx, item.span, self_ty, def_id); @@ -245,8 +248,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { } impl<'ccx, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'ccx, 'tcx> { - fn visit_item(&mut self, i: &'v ast::Item) { - self.check_item_well_formed(self.ccx, i); + fn visit_item(&mut self, i: &ast::Item) { + self.check_item_well_formed(i); visit::walk_item(self, i); } } @@ -256,20 +259,20 @@ pub struct BoundsChecker<'cx,'tcx:'cx> { span: Span, scope_id: ast::NodeId, binding_count: uint, - cache: Option<&'cx mut HashSet>, + cache: Option<&'cx mut HashSet>>, } impl<'cx,'tcx> BoundsChecker<'cx,'tcx> { pub fn new(fcx: &'cx FnCtxt<'cx,'tcx>, span: Span, scope_id: ast::NodeId, - cache: Option<&'cx mut HashSet>) + cache: Option<&'cx mut HashSet>>) -> BoundsChecker<'cx,'tcx> { BoundsChecker { fcx: fcx, span: span, scope_id: scope_id, cache: cache, binding_count: 0 } } - pub fn check_trait_ref(&mut self, trait_ref: &ty::TraitRef) { + pub fn check_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>) { /*! * Given a trait ref like `A : Trait`, where `Trait` is * defined as (say): @@ -300,11 +303,11 @@ impl<'cx,'tcx> BoundsChecker<'cx,'tcx> { } } - pub fn check_ty(&mut self, ty: ty::t) { + pub fn check_ty(&mut self, ty: Ty<'tcx>) { ty.fold_with(self); } - fn check_traits_in_ty(&mut self, ty: ty::t) { + fn check_traits_in_ty(&mut self, ty: Ty<'tcx>) { // When checking types outside of a type def'n, we ignore // region obligations. See discussion below in fold_ty(). self.binding_count += 1; @@ -318,7 +321,7 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> { self.fcx.tcx() } - fn fold_ty(&mut self, t: ty::t) -> ty::t { + fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { debug!("BoundsChecker t={}", t.repr(self.tcx())); @@ -333,7 +336,7 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> { None => { } } - match ty::get(t).sty{ + match t.sty{ ty::ty_struct(type_id, ref substs) | ty::ty_enum(type_id, ref substs) => { let polytype = ty::lookup_item_type(self.fcx.tcx(), type_id); @@ -401,16 +404,18 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> { /////////////////////////////////////////////////////////////////////////// // ADT -struct AdtVariant { - fields: Vec, +struct AdtVariant<'tcx> { + fields: Vec>, } -struct AdtField { - ty: ty::t, +struct AdtField<'tcx> { + ty: Ty<'tcx>, span: Span, } -fn struct_variant(fcx: &FnCtxt, struct_def: &ast::StructDef) -> AdtVariant { +fn struct_variant<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + struct_def: &ast::StructDef) + -> AdtVariant<'tcx> { let fields = struct_def.fields .iter() @@ -423,7 +428,9 @@ fn struct_variant(fcx: &FnCtxt, struct_def: &ast::StructDef) -> AdtVariant { AdtVariant { fields: fields } } -fn enum_variants(fcx: &FnCtxt, enum_def: &ast::EnumDef) -> Vec { +fn enum_variants<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + enum_def: &ast::EnumDef) + -> Vec> { enum_def.variants.iter() .map(|variant| { match variant.node.kind { @@ -457,10 +464,10 @@ fn enum_variants(fcx: &FnCtxt, enum_def: &ast::EnumDef) -> Vec { /////////////////////////////////////////////////////////////////////////// // Special drop trait checking -fn check_struct_safe_for_destructor(fcx: &FnCtxt, - span: Span, - self_ty: ty::t, - struct_did: ast::DefId) { +fn check_struct_safe_for_destructor<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + self_ty: Ty<'tcx>, + struct_did: ast::DefId) { let struct_tpt = ty::lookup_item_type(fcx.tcx(), struct_did); if !struct_tpt.generics.has_type_params(subst::TypeSpace) && !struct_tpt.generics.has_region_params(subst::TypeSpace) diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 9ded3265f828e..76d9ed15e5180 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -15,7 +15,7 @@ use self::ResolveReason::*; use middle::def; use middle::pat_util; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty_fold::{TypeFolder,TypeFoldable}; use middle::typeck::astconv::AstConv; use middle::typeck::check::FnCtxt; @@ -340,7 +340,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } } - fn resolve(&self, t: &T, reason: ResolveReason) -> T { + fn resolve>(&self, t: &T, reason: ResolveReason) -> T { t.resolve_in(&mut Resolver::new(self.fcx, reason)) } } @@ -379,12 +379,12 @@ impl ResolveReason { /////////////////////////////////////////////////////////////////////////// // Convenience methods for resolving different kinds of things. -trait ResolveIn { - fn resolve_in(&self, resolver: &mut Resolver) -> Self; +trait ResolveIn<'tcx> { + fn resolve_in<'a>(&self, resolver: &mut Resolver<'a, 'tcx>) -> Self; } -impl ResolveIn for T { - fn resolve_in(&self, resolver: &mut Resolver) -> T { +impl<'tcx, T: TypeFoldable<'tcx>> ResolveIn<'tcx> for T { + fn resolve_in<'a>(&self, resolver: &mut Resolver<'a, 'tcx>) -> T { self.fold_with(resolver) } } @@ -465,7 +465,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> { self.tcx } - fn fold_ty(&mut self, t: ty::t) -> ty::t { + fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { if !ty::type_needs_infer(t) { return t; } diff --git a/src/librustc/middle/typeck/coherence/mod.rs b/src/librustc/middle/typeck/coherence/mod.rs index 09b2be2854508..1f32110a09338 100644 --- a/src/librustc/middle/typeck/coherence/mod.rs +++ b/src/librustc/middle/typeck/coherence/mod.rs @@ -20,10 +20,9 @@ use metadata::csearch::{each_impl, get_impl_trait}; use metadata::csearch; use middle::subst; use middle::subst::{Substs}; -use middle::ty::get; use middle::ty::{ImplContainer, ImplOrTraitItemId, MethodTraitItemId}; use middle::ty::{TypeTraitItemId, lookup_item_type}; -use middle::ty::{t, ty_bool, ty_char, ty_enum, ty_err}; +use middle::ty::{Ty, ty_bool, ty_char, ty_enum, ty_err}; use middle::ty::{ty_str, ty_vec, ty_float, ty_infer, ty_int, ty_open}; use middle::ty::{ty_param, Polytype, ty_ptr}; use middle::ty::{ty_rptr, ty_struct, ty_trait, ty_tup}; @@ -55,10 +54,10 @@ use util::ppaux::Repr; mod orphan; mod overlap; -fn get_base_type(inference_context: &InferCtxt, - span: Span, - original_type: t) - -> Option { +fn get_base_type<'a, 'tcx>(inference_context: &InferCtxt<'a, 'tcx>, + span: Span, + original_type: Ty<'tcx>) + -> Option> { let resolved_type = match resolve_type(inference_context, Some(span), original_type, @@ -71,7 +70,7 @@ fn get_base_type(inference_context: &InferCtxt, } }; - match get(resolved_type).sty { + match resolved_type.sty { ty_enum(..) | ty_struct(..) | ty_unboxed_closure(..) => { debug!("(getting base type) found base type"); Some(resolved_type) @@ -87,7 +86,7 @@ fn get_base_type(inference_context: &InferCtxt, ty_infer(..) | ty_param(..) | ty_err | ty_open(..) | ty_uniq(_) | ty_ptr(_) | ty_rptr(_, _) => { debug!("(getting base type) no base type; found {}", - get(original_type).sty); + original_type.sty); None } ty_trait(..) => panic!("should have been caught") @@ -95,14 +94,14 @@ fn get_base_type(inference_context: &InferCtxt, } // Returns the def ID of the base type, if there is one. -fn get_base_type_def_id(inference_context: &InferCtxt, - span: Span, - original_type: t) - -> Option { +fn get_base_type_def_id<'a, 'tcx>(inference_context: &InferCtxt<'a, 'tcx>, + span: Span, + original_type: Ty<'tcx>) + -> Option { match get_base_type(inference_context, span, original_type) { None => None, Some(base_type) => { - match get(base_type).sty { + match base_type.sty { ty_enum(def_id, _) | ty_struct(def_id, _) | ty_unboxed_closure(def_id, _, _) => { @@ -111,7 +110,7 @@ fn get_base_type_def_id(inference_context: &InferCtxt, ty_ptr(ty::mt {ty, ..}) | ty_rptr(_, ty::mt {ty, ..}) | ty_uniq(ty) => { - match ty::get(ty).sty { + match ty.sty { ty_trait(box ty::TyTrait { ref principal, .. }) => { Some(principal.def_id) } @@ -242,7 +241,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { fn instantiate_default_methods( &self, impl_id: DefId, - trait_ref: &ty::TraitRef, + trait_ref: &ty::TraitRef<'tcx>, all_impl_items: &mut Vec) { let tcx = self.crate_context.tcx; debug!("instantiate_default_methods(impl_id={}, trait_ref={})", @@ -316,7 +315,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { } fn get_self_type_for_implementation(&self, impl_did: DefId) - -> Polytype { + -> Polytype<'tcx> { self.crate_context.tcx.tcache.borrow()[impl_did].clone() } @@ -442,7 +441,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { let method_def_id = items[0]; let self_type = self.get_self_type_for_implementation(impl_did); - match ty::get(self_type.ty).sty { + match self_type.ty.sty { ty::ty_enum(type_def_id, _) | ty::ty_struct(type_def_id, _) | ty::ty_unboxed_closure(type_def_id, _, _) => { @@ -478,10 +477,10 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { } } -pub fn make_substs_for_receiver_types(tcx: &ty::ctxt, - trait_ref: &ty::TraitRef, - method: &ty::Method) - -> subst::Substs +pub fn make_substs_for_receiver_types<'tcx>(tcx: &ty::ctxt<'tcx>, + trait_ref: &ty::TraitRef<'tcx>, + method: &ty::Method<'tcx>) + -> subst::Substs<'tcx> { /*! * Substitutes the values for the receiver's type parameters @@ -489,7 +488,7 @@ pub fn make_substs_for_receiver_types(tcx: &ty::ctxt, * intact. */ - let meth_tps: Vec = + let meth_tps: Vec = method.generics.types.get_slice(subst::FnSpace) .iter() .map(|def| ty::mk_param_from_def(tcx, def)) @@ -503,14 +502,14 @@ pub fn make_substs_for_receiver_types(tcx: &ty::ctxt, trait_ref.substs.clone().with_method(meth_tps, meth_regions) } -fn subst_receiver_types_in_method_ty(tcx: &ty::ctxt, - impl_id: ast::DefId, - impl_poly_type: &ty::Polytype, - trait_ref: &ty::TraitRef, - new_def_id: ast::DefId, - method: &ty::Method, - provided_source: Option) - -> ty::Method +fn subst_receiver_types_in_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>, + impl_id: ast::DefId, + impl_poly_type: &ty::Polytype<'tcx>, + trait_ref: &ty::TraitRef<'tcx>, + new_def_id: ast::DefId, + method: &ty::Method<'tcx>, + provided_source: Option) + -> ty::Method<'tcx> { let combined_substs = make_substs_for_receiver_types(tcx, trait_ref, method); diff --git a/src/librustc/middle/typeck/coherence/orphan.rs b/src/librustc/middle/typeck/coherence/orphan.rs index ba362fb878c81..57ce7f79e030a 100644 --- a/src/librustc/middle/typeck/coherence/orphan.rs +++ b/src/librustc/middle/typeck/coherence/orphan.rs @@ -51,7 +51,7 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> { // defined in this crate. debug!("coherence2::orphan check: inherent impl {}", item.repr(self.tcx)); let self_ty = ty::lookup_item_type(self.tcx, def_id).ty; - match ty::get(self_ty).sty { + match self_ty.sty { ty::ty_enum(def_id, _) | ty::ty_struct(def_id, _) => { self.check_def_id(item.span, def_id); diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index a0b198a59c266..b0e8b664d06d7 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -40,7 +40,7 @@ use middle::subst; use middle::subst::{Substs}; use middle::ty::{ImplContainer, ImplOrTraitItemContainer, TraitContainer}; use middle::ty::{Polytype}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty_fold::TypeFolder; use middle::typeck::astconv::{AstConv, ty_of_arg}; use middle::typeck::astconv::{ast_ty_to_ty, ast_region_to_region}; @@ -136,18 +136,18 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for CollectItemTypesVisitor<'a, 'tcx> { /////////////////////////////////////////////////////////////////////////// // Utility types and common code for the above passes. -pub trait ToTy { - fn to_ty(&self, rs: &RS, ast_ty: &ast::Ty) -> ty::t; +pub trait ToTy<'tcx> { + fn to_ty(&self, rs: &RS, ast_ty: &ast::Ty) -> Ty<'tcx>; } -impl<'a,'tcx> ToTy for ImplCtxt<'a,'tcx> { - fn to_ty(&self, rs: &RS, ast_ty: &ast::Ty) -> ty::t { +impl<'a,'tcx> ToTy<'tcx> for ImplCtxt<'a,'tcx> { + fn to_ty(&self, rs: &RS, ast_ty: &ast::Ty) -> Ty<'tcx> { ast_ty_to_ty(self, rs, ast_ty) } } -impl<'a,'tcx> ToTy for CrateCtxt<'a,'tcx> { - fn to_ty(&self, rs: &RS, ast_ty: &ast::Ty) -> ty::t { +impl<'a,'tcx> ToTy<'tcx> for CrateCtxt<'a,'tcx> { + fn to_ty(&self, rs: &RS, ast_ty: &ast::Ty) -> Ty<'tcx> { ast_ty_to_ty(self, rs, ast_ty) } } @@ -155,7 +155,7 @@ impl<'a,'tcx> ToTy for CrateCtxt<'a,'tcx> { impl<'a, 'tcx> AstConv<'tcx> for CrateCtxt<'a, 'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { + fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { if id.krate != ast::LOCAL_CRATE { return csearch::get_type(self.tcx, id) } @@ -177,37 +177,37 @@ impl<'a, 'tcx> AstConv<'tcx> for CrateCtxt<'a, 'tcx> { } } - fn get_trait_def(&self, id: ast::DefId) -> Rc { + fn get_trait_def(&self, id: ast::DefId) -> Rc> { get_trait_def(self, id) } - fn ty_infer(&self, span: Span) -> ty::t { + fn ty_infer(&self, span: Span) -> Ty<'tcx> { span_err!(self.tcx.sess, span, E0121, "the type placeholder `_` is not allowed within types on item signatures."); ty::mk_err() } - fn associated_types_of_trait_are_valid(&self, _: ty::t, _: ast::DefId) + fn associated_types_of_trait_are_valid(&self, _: Ty<'tcx>, _: ast::DefId) -> bool { false } fn associated_type_binding(&self, span: Span, - _: Option, + _: Option>, _: ast::DefId, _: ast::DefId) - -> ty::t { + -> Ty<'tcx> { self.tcx().sess.span_err(span, "associated types may not be \ referenced here"); ty::mk_err() } } -pub fn get_enum_variant_types(ccx: &CrateCtxt, - enum_ty: ty::t, - variants: &[P], - generics: &ast::Generics) { +pub fn get_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + enum_ty: Ty<'tcx>, + variants: &[P], + generics: &ast::Generics) { let tcx = ccx.tcx; // Create a set of parameter types shared among all the variants. @@ -253,9 +253,9 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt, } } -fn collect_trait_methods(ccx: &CrateCtxt, - trait_id: ast::NodeId, - trait_def: &ty::TraitDef) { +fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + trait_id: ast::NodeId, + trait_def: &ty::TraitDef<'tcx>) { let tcx = ccx.tcx; match tcx.map.get(trait_id) { ast_map::NodeItem(item) => { @@ -365,7 +365,7 @@ fn collect_trait_methods(ccx: &CrateCtxt, _ => { /* Ignore things that aren't traits */ } } - fn make_method_ty(ccx: &CrateCtxt, m: &ty::Method) { + fn make_method_ty<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, m: &ty::Method<'tcx>) { ccx.tcx.tcache.borrow_mut().insert( m.def_id, Polytype { @@ -373,18 +373,18 @@ fn collect_trait_methods(ccx: &CrateCtxt, ty: ty::mk_bare_fn(ccx.tcx, m.fty.clone()) }); } - fn ty_method_of_trait_method(ccx: &CrateCtxt, - trait_id: ast::NodeId, - trait_generics: &ty::Generics, - trait_items: &[ast::TraitItem], - m_id: &ast::NodeId, - m_name: &ast::Name, - m_explicit_self: &ast::ExplicitSelf, - m_abi: abi::Abi, - m_generics: &ast::Generics, - m_fn_style: &ast::FnStyle, - m_decl: &ast::FnDecl) - -> ty::Method { + fn ty_method_of_trait_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + trait_id: ast::NodeId, + trait_generics: &ty::Generics<'tcx>, + trait_items: &[ast::TraitItem], + m_id: &ast::NodeId, + m_name: &ast::Name, + m_explicit_self: &ast::ExplicitSelf, + m_abi: abi::Abi, + m_generics: &ast::Generics, + m_fn_style: &ast::FnStyle, + m_decl: &ast::FnDecl) + -> ty::Method<'tcx> { let ty_generics = ty_generics_for_fn_or_method( ccx, @@ -423,10 +423,10 @@ fn collect_trait_methods(ccx: &CrateCtxt, } } -pub fn convert_field(ccx: &CrateCtxt, - struct_generics: &ty::Generics, - v: &ast::StructField, - origin: ast::DefId) -> ty::field_ty { +pub fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + struct_generics: &ty::Generics<'tcx>, + v: &ast::StructField, + origin: ast::DefId) -> ty::field_ty { let tt = ccx.to_ty(&ExplicitRscope, &*v.node.ty); write_ty_to_tcx(ccx.tcx, v.node.id, tt); /* add the field to the tcache */ @@ -456,10 +456,10 @@ pub fn convert_field(ccx: &CrateCtxt, } } -fn convert_associated_type(ccx: &CrateCtxt, - trait_def: &ty::TraitDef, - associated_type: &ast::AssociatedType) - -> ty::Polytype { +fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + trait_def: &ty::TraitDef<'tcx>, + associated_type: &ast::AssociatedType) + -> ty::Polytype<'tcx> { // Find the type parameter ID corresponding to this // associated type. let type_parameter_def = trait_def.generics @@ -515,14 +515,14 @@ enum ConvertMethodContext<'a> { TraitConvertMethodContext(ast::DefId, &'a [ast::TraitItem]), } -fn convert_methods<'a,I>(ccx: &CrateCtxt, - convert_method_context: ConvertMethodContext, - container: ImplOrTraitItemContainer, - mut ms: I, - untransformed_rcvr_ty: ty::t, - rcvr_ty_generics: &ty::Generics, - rcvr_visibility: ast::Visibility) - where I: Iterator<&'a ast::Method> { +fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>, + convert_method_context: ConvertMethodContext, + container: ImplOrTraitItemContainer, + mut ms: I, + untransformed_rcvr_ty: Ty<'tcx>, + rcvr_ty_generics: &ty::Generics<'tcx>, + rcvr_visibility: ast::Visibility) + where I: Iterator<&'i ast::Method> { debug!("convert_methods(untransformed_rcvr_ty={}, \ rcvr_ty_generics={})", untransformed_rcvr_ty.repr(ccx.tcx), @@ -564,14 +564,14 @@ fn convert_methods<'a,I>(ccx: &CrateCtxt, .insert(mty.def_id, ty::MethodTraitItem(mty)); } - fn ty_of_method(ccx: &CrateCtxt, + fn ty_of_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, convert_method_context: ConvertMethodContext, - container: ImplOrTraitItemContainer, - m: &ast::Method, - untransformed_rcvr_ty: ty::t, - rcvr_ty_generics: &ty::Generics, - rcvr_visibility: ast::Visibility) - -> ty::Method { + container: ImplOrTraitItemContainer, + m: &ast::Method, + untransformed_rcvr_ty: Ty<'tcx>, + rcvr_ty_generics: &ty::Generics<'tcx>, + rcvr_visibility: ast::Visibility) + -> ty::Method<'tcx> { let m_ty_generics = ty_generics_for_fn_or_method( ccx, @@ -659,11 +659,11 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt, } } -fn is_associated_type_valid_for_param(ty: ty::t, +fn is_associated_type_valid_for_param(ty: Ty, trait_id: ast::DefId, generics: &ty::Generics) -> bool { - match ty::get(ty).sty { + match ty.sty { ty::ty_param(param_ty) => { let type_parameter = generics.types.get(param_ty.space, param_ty.idx); @@ -679,12 +679,12 @@ fn is_associated_type_valid_for_param(ty: ty::t, false } -fn find_associated_type_in_generics(tcx: &ty::ctxt, - span: Span, - ty: Option, - associated_type_id: ast::DefId, - generics: &ty::Generics) - -> ty::t { +fn find_associated_type_in_generics<'tcx>(tcx: &ty::ctxt<'tcx>, + span: Span, + ty: Option>, + associated_type_id: ast::DefId, + generics: &ty::Generics<'tcx>) + -> Ty<'tcx> { let ty = match ty { None => { tcx.sess.span_bug(span, @@ -694,7 +694,7 @@ fn find_associated_type_in_generics(tcx: &ty::ctxt, Some(ty) => ty, }; - match ty::get(ty).sty { + match ty.sty { ty::ty_param(ref param_ty) => { /*let type_parameter = generics.types.get(param_ty.space, param_ty.idx); @@ -721,8 +721,8 @@ fn find_associated_type_in_generics(tcx: &ty::ctxt, } } -fn type_is_self(ty: ty::t) -> bool { - match ty::get(ty).sty { +fn type_is_self(ty: Ty) -> bool { + match ty.sty { ty::ty_param(ref param_ty) if param_ty.is_self() => true, _ => false, } @@ -732,7 +732,7 @@ struct ImplCtxt<'a,'tcx:'a> { ccx: &'a CrateCtxt<'a,'tcx>, opt_trait_ref_id: Option, impl_items: &'a [ast::ImplItem], - impl_generics: &'a ty::Generics, + impl_generics: &'a ty::Generics<'tcx>, } impl<'a,'tcx> AstConv<'tcx> for ImplCtxt<'a,'tcx> { @@ -740,20 +740,20 @@ impl<'a,'tcx> AstConv<'tcx> for ImplCtxt<'a,'tcx> { self.ccx.tcx } - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { + fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { self.ccx.get_item_ty(id) } - fn get_trait_def(&self, id: ast::DefId) -> Rc { + fn get_trait_def(&self, id: ast::DefId) -> Rc> { self.ccx.get_trait_def(id) } - fn ty_infer(&self, span: Span) -> ty::t { + fn ty_infer(&self, span: Span) -> Ty<'tcx> { self.ccx.ty_infer(span) } fn associated_types_of_trait_are_valid(&self, - ty: ty::t, + ty: Ty<'tcx>, trait_id: ast::DefId) -> bool { // OK if the trait with the associated type is the trait we're @@ -774,10 +774,10 @@ impl<'a,'tcx> AstConv<'tcx> for ImplCtxt<'a,'tcx> { fn associated_type_binding(&self, span: Span, - ty: Option, + ty: Option>, trait_id: ast::DefId, associated_type_id: ast::DefId) - -> ty::t + -> Ty<'tcx> { let trait_def = ty::lookup_trait_def(self.tcx(), trait_id); match self.opt_trait_ref_id { @@ -821,7 +821,7 @@ impl<'a,'tcx> AstConv<'tcx> for ImplCtxt<'a,'tcx> { struct FnCtxt<'a,'tcx:'a> { ccx: &'a CrateCtxt<'a,'tcx>, - generics: &'a ty::Generics, + generics: &'a ty::Generics<'tcx>, } impl<'a,'tcx> AstConv<'tcx> for FnCtxt<'a,'tcx> { @@ -829,20 +829,20 @@ impl<'a,'tcx> AstConv<'tcx> for FnCtxt<'a,'tcx> { self.ccx.tcx } - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { + fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { self.ccx.get_item_ty(id) } - fn get_trait_def(&self, id: ast::DefId) -> Rc { + fn get_trait_def(&self, id: ast::DefId) -> Rc> { self.ccx.get_trait_def(id) } - fn ty_infer(&self, span: Span) -> ty::t { + fn ty_infer(&self, span: Span) -> Ty<'tcx> { self.ccx.ty_infer(span) } fn associated_types_of_trait_are_valid(&self, - ty: ty::t, + ty: Ty<'tcx>, trait_id: ast::DefId) -> bool { // OK if the trait with the associated type is one of the traits in @@ -852,10 +852,10 @@ impl<'a,'tcx> AstConv<'tcx> for FnCtxt<'a,'tcx> { fn associated_type_binding(&self, span: Span, - ty: Option, + ty: Option>, _: ast::DefId, associated_type_id: ast::DefId) - -> ty::t { + -> Ty<'tcx> { debug!("collect::FnCtxt::associated_type_binding()"); // The ID should map to an associated type on one of the traits in @@ -870,7 +870,7 @@ impl<'a,'tcx> AstConv<'tcx> for FnCtxt<'a,'tcx> { struct ImplMethodCtxt<'a,'tcx:'a> { ccx: &'a CrateCtxt<'a,'tcx>, - method_generics: &'a ty::Generics, + method_generics: &'a ty::Generics<'tcx>, } impl<'a,'tcx> AstConv<'tcx> for ImplMethodCtxt<'a,'tcx> { @@ -878,20 +878,20 @@ impl<'a,'tcx> AstConv<'tcx> for ImplMethodCtxt<'a,'tcx> { self.ccx.tcx } - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { + fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { self.ccx.get_item_ty(id) } - fn get_trait_def(&self, id: ast::DefId) -> Rc { + fn get_trait_def(&self, id: ast::DefId) -> Rc> { self.ccx.get_trait_def(id) } - fn ty_infer(&self, span: Span) -> ty::t { + fn ty_infer(&self, span: Span) -> Ty<'tcx> { self.ccx.ty_infer(span) } fn associated_types_of_trait_are_valid(&self, - ty: ty::t, + ty: Ty<'tcx>, trait_id: ast::DefId) -> bool { is_associated_type_valid_for_param(ty, trait_id, self.method_generics) @@ -899,10 +899,10 @@ impl<'a,'tcx> AstConv<'tcx> for ImplMethodCtxt<'a,'tcx> { fn associated_type_binding(&self, span: Span, - ty: Option, + ty: Option>, _: ast::DefId, associated_type_id: ast::DefId) - -> ty::t { + -> Ty<'tcx> { debug!("collect::ImplMethodCtxt::associated_type_binding()"); // The ID should map to an associated type on one of the traits in @@ -919,7 +919,7 @@ struct TraitMethodCtxt<'a,'tcx:'a> { ccx: &'a CrateCtxt<'a,'tcx>, trait_id: ast::DefId, trait_items: &'a [ast::TraitItem], - method_generics: &'a ty::Generics, + method_generics: &'a ty::Generics<'tcx>, } impl<'a,'tcx> AstConv<'tcx> for TraitMethodCtxt<'a,'tcx> { @@ -927,20 +927,20 @@ impl<'a,'tcx> AstConv<'tcx> for TraitMethodCtxt<'a,'tcx> { self.ccx.tcx } - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { + fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { self.ccx.get_item_ty(id) } - fn get_trait_def(&self, id: ast::DefId) -> Rc { + fn get_trait_def(&self, id: ast::DefId) -> Rc> { self.ccx.get_trait_def(id) } - fn ty_infer(&self, span: Span) -> ty::t { + fn ty_infer(&self, span: Span) -> Ty<'tcx> { self.ccx.ty_infer(span) } fn associated_types_of_trait_are_valid(&self, - ty: ty::t, + ty: Ty<'tcx>, trait_id: ast::DefId) -> bool { // OK if the trait with the associated type is this trait. @@ -955,10 +955,10 @@ impl<'a,'tcx> AstConv<'tcx> for TraitMethodCtxt<'a,'tcx> { fn associated_type_binding(&self, span: Span, - ty: Option, + ty: Option>, trait_id: ast::DefId, associated_type_id: ast::DefId) - -> ty::t { + -> Ty<'tcx> { debug!("collect::TraitMethodCtxt::associated_type_binding()"); // If this is one of our own associated types, return it. @@ -997,30 +997,30 @@ impl<'a,'tcx> AstConv<'tcx> for TraitMethodCtxt<'a,'tcx> { } } -struct GenericsCtxt<'a,AC:'a> { +struct GenericsCtxt<'a,'tcx:'a,AC:'a> { chain: &'a AC, - associated_types_generics: &'a ty::Generics, + associated_types_generics: &'a ty::Generics<'tcx>, } -impl<'a,'tcx,AC:AstConv<'tcx>> AstConv<'tcx> for GenericsCtxt<'a,AC> { +impl<'a,'tcx,AC:AstConv<'tcx>> AstConv<'tcx> for GenericsCtxt<'a,'tcx,AC> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.chain.tcx() } - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { + fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { self.chain.get_item_ty(id) } - fn get_trait_def(&self, id: ast::DefId) -> Rc { + fn get_trait_def(&self, id: ast::DefId) -> Rc> { self.chain.get_trait_def(id) } - fn ty_infer(&self, span: Span) -> ty::t { + fn ty_infer(&self, span: Span) -> Ty<'tcx> { self.chain.ty_infer(span) } fn associated_types_of_trait_are_valid(&self, - ty: ty::t, + ty: Ty<'tcx>, trait_id: ast::DefId) -> bool { // OK if the trait with the associated type is one of the traits in @@ -1032,10 +1032,10 @@ impl<'a,'tcx,AC:AstConv<'tcx>> AstConv<'tcx> for GenericsCtxt<'a,AC> { fn associated_type_binding(&self, span: Span, - ty: Option, + ty: Option>, _: ast::DefId, associated_type_id: ast::DefId) - -> ty::t { + -> Ty<'tcx> { debug!("collect::GenericsCtxt::associated_type_binding()"); // The ID should map to an associated type on one of the traits in @@ -1241,10 +1241,10 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) { } } -pub fn convert_struct(ccx: &CrateCtxt, - struct_def: &ast::StructDef, - pty: ty::Polytype, - id: ast::NodeId) { +pub fn convert_struct<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + struct_def: &ast::StructDef, + pty: ty::Polytype<'tcx>, + id: ast::NodeId) { let tcx = ccx.tcx; // Write the type of each of the members and check for duplicate fields. @@ -1324,7 +1324,9 @@ pub fn convert_foreign(ccx: &CrateCtxt, i: &ast::ForeignItem) { ccx.tcx.tcache.borrow_mut().insert(local_def(i.id), pty); } -fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> Rc { +fn get_trait_def<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + trait_id: ast::DefId) + -> Rc> { if trait_id.krate != ast::LOCAL_CRATE { return ty::lookup_trait_def(ccx.tcx, trait_id) } @@ -1338,7 +1340,9 @@ fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> Rc { } } -pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc { +pub fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + it: &ast::Item) + -> Rc> { let def_id = local_def(it.id); let tcx = ccx.tcx; match tcx.trait_defs.borrow().get(&def_id) { @@ -1387,11 +1391,11 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc { return trait_def; - fn mk_trait_substs(ccx: &CrateCtxt, - trait_id: ast::NodeId, - generics: &ast::Generics, - items: &[ast::TraitItem]) - -> subst::Substs + fn mk_trait_substs<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + trait_id: ast::NodeId, + generics: &ast::Generics, + items: &[ast::TraitItem]) + -> subst::Substs<'tcx> { // Creates a no-op substitution for the trait's type parameters. let regions = @@ -1437,8 +1441,8 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc { } } -pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) - -> ty::Polytype { +pub fn ty_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item) + -> ty::Polytype<'tcx> { let def_id = local_def(it.id); let tcx = ccx.tcx; match tcx.tcache.borrow().get(&def_id) { @@ -1537,9 +1541,9 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) } } -pub fn ty_of_foreign_item(ccx: &CrateCtxt, - it: &ast::ForeignItem, - abi: abi::Abi) -> ty::Polytype +pub fn ty_of_foreign_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + it: &ast::ForeignItem, + abi: abi::Abi) -> ty::Polytype<'tcx> { match it.node { ast::ForeignItemFn(ref fn_decl, ref generics) => { @@ -1558,8 +1562,9 @@ pub fn ty_of_foreign_item(ccx: &CrateCtxt, } } -fn ty_of_trait_item(ccx: &CrateCtxt, trait_item: &ast::TraitItem) - -> ty::Polytype { +fn ty_of_trait_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + trait_item: &ast::TraitItem) + -> ty::Polytype<'tcx> { match *trait_item { ast::RequiredMethod(ref m) => { ccx.tcx.sess.span_bug(m.span, @@ -1584,11 +1589,11 @@ fn ty_of_trait_item(ccx: &CrateCtxt, trait_item: &ast::TraitItem) } } -fn ty_generics_for_type(ccx: &CrateCtxt, - generics: &ast::Generics, - create_type_parameters_for_associated_types: - CreateTypeParametersForAssociatedTypesFlag) - -> ty::Generics { +fn ty_generics_for_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + generics: &ast::Generics, + create_type_parameters_for_associated_types: + CreateTypeParametersForAssociatedTypesFlag) + -> ty::Generics<'tcx> { ty_generics(ccx, subst::TypeSpace, generics.lifetimes.as_slice(), @@ -1598,12 +1603,12 @@ fn ty_generics_for_type(ccx: &CrateCtxt, create_type_parameters_for_associated_types) } -fn ty_generics_for_trait(ccx: &CrateCtxt, - trait_id: ast::NodeId, - substs: &subst::Substs, - ast_generics: &ast::Generics, - items: &[ast::TraitItem]) - -> ty::Generics { +fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + trait_id: ast::NodeId, + substs: &subst::Substs<'tcx>, + ast_generics: &ast::Generics, + items: &[ast::TraitItem]) + -> ty::Generics<'tcx> { let mut generics = ty_generics(ccx, subst::TypeSpace, @@ -1667,10 +1672,10 @@ fn ty_generics_for_trait(ccx: &CrateCtxt, fn ty_generics_for_fn_or_method<'tcx,AC>( this: &AC, generics: &ast::Generics, - base_generics: ty::Generics, + base_generics: ty::Generics<'tcx>, create_type_parameters_for_associated_types: CreateTypeParametersForAssociatedTypesFlag) - -> ty::Generics + -> ty::Generics<'tcx> where AC: AstConv<'tcx> { let early_lifetimes = resolve_lifetime::early_bound_lifetimes(generics); ty_generics(this, @@ -1730,11 +1735,11 @@ fn ty_generics<'tcx,AC>(this: &AC, space: subst::ParamSpace, lifetime_defs: &[ast::LifetimeDef], types: &[ast::TyParam], - base_generics: ty::Generics, + base_generics: ty::Generics<'tcx>, where_clause: &ast::WhereClause, create_type_parameters_for_associated_types_flag: CreateTypeParametersForAssociatedTypesFlag) - -> ty::Generics + -> ty::Generics<'tcx> where AC: AstConv<'tcx> { let mut result = base_generics; @@ -1801,7 +1806,7 @@ fn ty_generics<'tcx,AC>(this: &AC, this: &AC, space: subst::ParamSpace, types: &[ast::TyParam], - associated_types_generics: &mut ty::Generics) + associated_types_generics: &mut ty::Generics<'tcx>) where AC: AstConv<'tcx> { // The idea here is roughly as follows. We start with @@ -1880,7 +1885,7 @@ fn get_or_create_type_parameter_def<'tcx,AC>(this: &AC, index: uint, where_clause: &ast::WhereClause, associated_with: Option) - -> ty::TypeParameterDef + -> ty::TypeParameterDef<'tcx> where AC: AstConv<'tcx> { match this.tcx().ty_param_defs.borrow().get(¶m.id) { @@ -1903,7 +1908,7 @@ fn get_or_create_type_parameter_def<'tcx,AC>(this: &AC, let cur_idx = index; ty::walk_ty(ty, |t| { - match ty::get(t).sty { + match t.sty { ty::ty_param(p) => if p.idx > cur_idx { span_err!(this.tcx().sess, path.span, E0128, "type parameters with a default cannot use \ @@ -1939,7 +1944,7 @@ fn compute_bounds<'tcx,AC>(this: &AC, unbound: &Option, span: Span, where_clause: &ast::WhereClause) - -> ty::ParamBounds + -> ty::ParamBounds<'tcx> where AC: AstConv<'tcx> { /*! * Translate the AST's notion of ty param bounds (which are an @@ -1971,10 +1976,10 @@ fn compute_bounds<'tcx,AC>(this: &AC, param_bounds } -fn check_bounds_compatible(tcx: &ty::ctxt, - name_of_bounded_thing: ast::Name, - param_bounds: &ty::ParamBounds, - span: Span) { +fn check_bounds_compatible<'tcx>(tcx: &ty::ctxt<'tcx>, + name_of_bounded_thing: ast::Name, + param_bounds: &ty::ParamBounds<'tcx>, + span: Span) { // Currently the only bound which is incompatible with other bounds is // Sized/Unsized. if !param_bounds.builtin_bounds.contains(&ty::BoundSized) { @@ -2000,7 +2005,7 @@ fn conv_param_bounds<'tcx,AC>(this: &AC, param_ty: ty::ParamTy, ast_bounds: &[ast::TyParamBound], where_clause: &ast::WhereClause) - -> ty::ParamBounds + -> ty::ParamBounds<'tcx> where AC: AstConv<'tcx> { let all_bounds = merge_param_bounds(this.tcx(), param_ty, ast_bounds, where_clause); @@ -2064,12 +2069,12 @@ fn merge_param_bounds<'a>(tcx: &ty::ctxt, result } -pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt, - decl: &ast::FnDecl, - def_id: ast::DefId, - ast_generics: &ast::Generics, - abi: abi::Abi) - -> ty::Polytype { +pub fn ty_of_foreign_fn_decl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + decl: &ast::FnDecl, + def_id: ast::DefId, + ast_generics: &ast::Generics, + abi: abi::Abi) + -> ty::Polytype<'tcx> { for i in decl.inputs.iter() { match (*i).pat.node { ast::PatIdent(_, _, _) => (), @@ -2117,9 +2122,9 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt, return pty; } -pub fn mk_item_substs(ccx: &CrateCtxt, - ty_generics: &ty::Generics) - -> subst::Substs +pub fn mk_item_substs<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, + ty_generics: &ty::Generics<'tcx>) + -> subst::Substs<'tcx> { let types = ty_generics.types.map( @@ -2135,17 +2140,17 @@ pub fn mk_item_substs(ccx: &CrateCtxt, /// Verifies that the explicit self type of a method matches the impl or /// trait. -fn check_method_self_type( - crate_context: &CrateCtxt, +fn check_method_self_type<'a, 'tcx, RS:RegionScope>( + crate_context: &CrateCtxt<'a, 'tcx>, rs: &RS, - required_type: ty::t, + required_type: Ty<'tcx>, explicit_self: &ast::ExplicitSelf, body_id: ast::NodeId) { match explicit_self.node { ast::SelfExplicit(ref ast_type, _) => { let typ = crate_context.to_ty(rs, &**ast_type); - let base_type = match ty::get(typ).sty { + let base_type = match typ.sty { ty::ty_ptr(tm) | ty::ty_rptr(_, tm) => tm.ty, ty::ty_uniq(typ) => typ, _ => typ, diff --git a/src/librustc/middle/typeck/infer/coercion.rs b/src/librustc/middle/typeck/infer/coercion.rs index 1bbbe2838b9be..49ac7178eb8db 100644 --- a/src/librustc/middle/typeck/infer/coercion.rs +++ b/src/librustc/middle/typeck/infer/coercion.rs @@ -67,7 +67,7 @@ we may want to adjust precisely when coercions occur. use middle::subst; use middle::ty::{AutoPtr, AutoDerefRef, AdjustDerefRef, AutoUnsize, AutoUnsafe}; use middle::ty::{mt}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::infer::{CoerceResult, resolve_type, Coercion}; use middle::typeck::infer::combine::{CombineFields, Combine}; use middle::typeck::infer::sub::Sub; @@ -88,7 +88,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let Coerce(ref v) = *self; v } - pub fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult { + pub fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> { debug!("Coerce.tys({} => {})", a.repr(self.get_ref().infcx.tcx), b.repr(self.get_ref().infcx.tcx)); @@ -105,9 +105,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // // Note: does not attempt to resolve type variables we encounter. // See above for details. - match ty::get(b).sty { + match b.sty { ty::ty_ptr(mt_b) => { - match ty::get(mt_b.ty).sty { + match mt_b.ty.sty { ty::ty_str => { return self.unpack_actual_value(a, |sty_a| { self.coerce_unsafe_ptr(a, sty_a, b, ast::MutImmutable) @@ -134,7 +134,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } ty::ty_rptr(_, mt_b) => { - match ty::get(mt_b.ty).sty { + match mt_b.ty.sty { ty::ty_str => { return self.unpack_actual_value(a, |sty_a| { self.coerce_borrowed_pointer(a, sty_a, b, ast::MutImmutable) @@ -190,19 +190,19 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { }) } - pub fn subtype(&self, a: ty::t, b: ty::t) -> CoerceResult { + pub fn subtype(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> { match Sub(self.get_ref().clone()).tys(a, b) { Ok(_) => Ok(None), // No coercion required. Err(ref e) => Err(*e) } } - pub fn unpack_actual_value(&self, a: ty::t, f: |&ty::sty| -> T) + pub fn unpack_actual_value(&self, a: Ty<'tcx>, f: |&ty::sty<'tcx>| -> T) -> T { match resolve_type(self.get_ref().infcx, None, a, try_resolve_tvar_shallow) { Ok(t) => { - f(&ty::get(t).sty) + f(&t.sty) } Err(e) => { self.get_ref().infcx.tcx.sess.span_bug( @@ -215,11 +215,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // ~T -> &T or &mut T -> &T (including where T = [U] or str) pub fn coerce_borrowed_pointer(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t, + a: Ty<'tcx>, + sty_a: &ty::sty<'tcx>, + b: Ty<'tcx>, mutbl_b: ast::Mutability) - -> CoerceResult { + -> CoerceResult<'tcx> { debug!("coerce_borrowed_pointer(a={}, sty_a={}, b={})", a.repr(self.get_ref().infcx.tcx), sty_a, b.repr(self.get_ref().infcx.tcx)); @@ -258,10 +258,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // or &mut [T, ..n] -> &mut [T] // or &Concrete -> &Trait, etc. fn coerce_unsized(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t) - -> CoerceResult { + a: Ty<'tcx>, + sty_a: &ty::sty<'tcx>, + b: Ty<'tcx>) + -> CoerceResult<'tcx> { debug!("coerce_unsized(a={}, sty_a={}, b={})", a.repr(self.get_ref().infcx.tcx), sty_a, b.repr(self.get_ref().infcx.tcx)); @@ -273,7 +273,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let sub = Sub(self.get_ref().clone()); - let sty_b = &ty::get(b).sty; + let sty_b = &b.sty; match (sty_a, sty_b) { (&ty::ty_rptr(_, ty::mt{ty: t_a, mutbl: mutbl_a}), &ty::ty_rptr(_, mt_b)) => { self.unpack_actual_value(t_a, |sty_a| { @@ -349,10 +349,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // performed to unsize it. // E.g., `[T, ..n]` -> `([T], UnsizeLength(n))` fn unsize_ty(&self, - ty_a: ty::t, - sty_a: &ty::sty, - ty_b: ty::t) - -> Option<(ty::t, ty::UnsizeKind)> { + ty_a: Ty<'tcx>, + sty_a: &ty::sty<'tcx>, + ty_b: Ty<'tcx>) + -> Option<(Ty<'tcx>, ty::UnsizeKind<'tcx>)> { debug!("unsize_ty(sty_a={}, ty_b={})", sty_a, ty_b.repr(self.get_ref().infcx.tcx)); let tcx = self.get_ref().infcx.tcx; @@ -425,10 +425,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } fn coerce_borrowed_object(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t, - b_mutbl: ast::Mutability) -> CoerceResult + a: Ty<'tcx>, + sty_a: &ty::sty<'tcx>, + b: Ty<'tcx>, + b_mutbl: ast::Mutability) -> CoerceResult<'tcx> { let tcx = self.get_ref().infcx.tcx; @@ -445,10 +445,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } fn coerce_unsafe_object(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t, - b_mutbl: ast::Mutability) -> CoerceResult + a: Ty<'tcx>, + sty_a: &ty::sty<'tcx>, + b: Ty<'tcx>, + b_mutbl: ast::Mutability) -> CoerceResult<'tcx> { let tcx = self.get_ref().infcx.tcx; @@ -462,17 +462,17 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } fn coerce_object(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t, + a: Ty<'tcx>, + sty_a: &ty::sty<'tcx>, + b: Ty<'tcx>, b_mutbl: ast::Mutability, - mk_ty: |ty::t| -> ty::t, - mk_adjust: || -> ty::AutoRef) -> CoerceResult + mk_ty: |Ty<'tcx>| -> Ty<'tcx>, + mk_adjust: || -> ty::AutoRef<'tcx>) -> CoerceResult<'tcx> { let tcx = self.get_ref().infcx.tcx; match *sty_a { - ty::ty_rptr(_, ty::mt{ty, mutbl}) => match ty::get(ty).sty { + ty::ty_rptr(_, ty::mt{ty, mutbl}) => match ty.sty { ty::ty_trait(box ty::TyTrait { ref principal, bounds }) => { debug!("mutbl={} b_mutbl={}", mutbl, b_mutbl); // FIXME what is purpose of this type `tr`? @@ -494,10 +494,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } pub fn coerce_borrowed_fn(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t) - -> CoerceResult { + a: Ty<'tcx>, + sty_a: &ty::sty<'tcx>, + b: Ty<'tcx>) + -> CoerceResult<'tcx> { debug!("coerce_borrowed_fn(a={}, sty_a={}, b={})", a.repr(self.get_ref().infcx.tcx), sty_a, b.repr(self.get_ref().infcx.tcx)); @@ -512,8 +512,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } } - fn coerce_from_bare_fn(&self, a: ty::t, fn_ty_a: &ty::BareFnTy, b: ty::t) - -> CoerceResult { + fn coerce_from_bare_fn(&self, a: Ty<'tcx>, fn_ty_a: &ty::BareFnTy<'tcx>, b: Ty<'tcx>) + -> CoerceResult<'tcx> { /*! * * Attempts to coerce from a bare Rust function (`extern @@ -546,11 +546,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } pub fn coerce_unsafe_ptr(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t, + a: Ty<'tcx>, + sty_a: &ty::sty<'tcx>, + b: Ty<'tcx>, mutbl_b: ast::Mutability) - -> CoerceResult { + -> CoerceResult<'tcx> { debug!("coerce_unsafe_ptr(a={}, sty_a={}, b={})", a.repr(self.get_ref().infcx.tcx), sty_a, b.repr(self.get_ref().infcx.tcx)); diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index 0f9554cd417f7..763f204dc98bc 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -38,7 +38,7 @@ use middle::subst::{ErasedRegions, NonerasedRegions, Substs}; use middle::ty::{FloatVar, FnSig, IntVar, TyVar}; use middle::ty::{IntType, UintType}; use middle::ty::{BuiltinBounds}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty_fold; use middle::typeck::infer::equate::Equate; use middle::typeck::infer::glb::Glb; @@ -62,22 +62,22 @@ pub trait Combine<'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.infcx().tcx } fn tag(&self) -> String; fn a_is_expected(&self) -> bool; - fn trace(&self) -> TypeTrace; + fn trace(&self) -> TypeTrace<'tcx>; fn equate<'a>(&'a self) -> Equate<'a, 'tcx>; fn sub<'a>(&'a self) -> Sub<'a, 'tcx>; fn lub<'a>(&'a self) -> Lub<'a, 'tcx>; fn glb<'a>(&'a self) -> Glb<'a, 'tcx>; - fn mts(&self, a: &ty::mt, b: &ty::mt) -> cres; - fn contratys(&self, a: ty::t, b: ty::t) -> cres; - fn tys(&self, a: ty::t, b: ty::t) -> cres; + fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>>; + fn contratys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>>; + fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>>; fn tps(&self, _: subst::ParamSpace, - as_: &[ty::t], - bs: &[ty::t]) - -> cres> { + as_: &[Ty<'tcx>], + bs: &[Ty<'tcx>]) + -> cres<'tcx, Vec>> { // FIXME -- In general, we treat variance a bit wrong // here. For historical reasons, we treat tps and Self // as invariant. This is overly conservative. @@ -90,15 +90,15 @@ pub trait Combine<'tcx> { try!(as_.iter().zip(bs.iter()) .map(|(a, b)| self.equate().tys(*a, *b)) - .collect::>>()); + .collect::>>()); Ok(as_.to_vec()) } fn substs(&self, item_def_id: ast::DefId, - a_subst: &subst::Substs, - b_subst: &subst::Substs) - -> cres + a_subst: &subst::Substs<'tcx>, + b_subst: &subst::Substs<'tcx>) + -> cres<'tcx, subst::Substs<'tcx>> { let variances = if self.infcx().tcx.variance_computed.get() { Some(ty::item_variances(self.infcx().tcx, item_def_id)) @@ -110,9 +110,9 @@ pub trait Combine<'tcx> { fn substs_variances(&self, variances: Option<&ty::ItemVariances>, - a_subst: &subst::Substs, - b_subst: &subst::Substs) - -> cres + a_subst: &subst::Substs<'tcx>, + b_subst: &subst::Substs<'tcx>) + -> cres<'tcx, subst::Substs<'tcx>> { let mut substs = subst::Substs::empty(); @@ -161,7 +161,7 @@ pub trait Combine<'tcx> { variances: &[ty::Variance], a_rs: &[ty::Region], b_rs: &[ty::Region]) - -> cres> { + -> cres<'tcx, Vec> { let tcx = this.infcx().tcx; let num_region_params = variances.len(); @@ -192,8 +192,8 @@ pub trait Combine<'tcx> { } } - fn bare_fn_tys(&self, a: &ty::BareFnTy, - b: &ty::BareFnTy) -> cres { + fn bare_fn_tys(&self, a: &ty::BareFnTy<'tcx>, + b: &ty::BareFnTy<'tcx>) -> cres<'tcx, ty::BareFnTy<'tcx>> { let fn_style = try!(self.fn_styles(a.fn_style, b.fn_style)); let abi = try!(self.abi(a.abi, b.abi)); let sig = try!(self.fn_sigs(&a.sig, &b.sig)); @@ -202,8 +202,8 @@ pub trait Combine<'tcx> { sig: sig}) } - fn closure_tys(&self, a: &ty::ClosureTy, - b: &ty::ClosureTy) -> cres { + fn closure_tys(&self, a: &ty::ClosureTy<'tcx>, + b: &ty::ClosureTy<'tcx>) -> cres<'tcx, ty::ClosureTy<'tcx>> { let store = match (a.store, b.store) { (ty::RegionTraitStore(a_r, a_m), @@ -235,15 +235,15 @@ pub trait Combine<'tcx> { }) } - fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres; + fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) -> cres<'tcx, ty::FnSig<'tcx>>; - fn args(&self, a: ty::t, b: ty::t) -> cres { + fn args(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> { self.contratys(a, b).and_then(|t| Ok(t)) } - fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres; + fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle>; - fn abi(&self, a: abi::Abi, b: abi::Abi) -> cres { + fn abi(&self, a: abi::Abi, b: abi::Abi) -> cres<'tcx, abi::Abi> { if a == b { Ok(a) } else { @@ -251,12 +251,12 @@ pub trait Combine<'tcx> { } } - fn oncenesses(&self, a: Onceness, b: Onceness) -> cres; + fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<'tcx, Onceness>; fn existential_bounds(&self, a: ty::ExistentialBounds, b: ty::ExistentialBounds) - -> cres + -> cres<'tcx, ty::ExistentialBounds> { let r = try!(self.contraregions(a.region_bound, b.region_bound)); let nb = try!(self.builtin_bounds(a.builtin_bounds, b.builtin_bounds)); @@ -267,18 +267,18 @@ pub trait Combine<'tcx> { fn builtin_bounds(&self, a: ty::BuiltinBounds, b: ty::BuiltinBounds) - -> cres; + -> cres<'tcx, ty::BuiltinBounds>; fn contraregions(&self, a: ty::Region, b: ty::Region) - -> cres; + -> cres<'tcx, ty::Region>; - fn regions(&self, a: ty::Region, b: ty::Region) -> cres; + fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region>; fn trait_stores(&self, vk: ty::terr_vstore_kind, a: ty::TraitStore, b: ty::TraitStore) - -> cres { + -> cres<'tcx, ty::TraitStore> { debug!("{}.trait_stores(a={}, b={})", self.tag(), a, b); match (a, b) { @@ -300,9 +300,9 @@ pub trait Combine<'tcx> { } fn trait_refs(&self, - a: &ty::TraitRef, - b: &ty::TraitRef) - -> cres; + a: &ty::TraitRef<'tcx>, + b: &ty::TraitRef<'tcx>) + -> cres<'tcx, ty::TraitRef<'tcx>>; // this must be overridden to do correctly, so as to account for higher-ranked // behavior } @@ -311,7 +311,7 @@ pub trait Combine<'tcx> { pub struct CombineFields<'a, 'tcx: 'a> { pub infcx: &'a InferCtxt<'a, 'tcx>, pub a_is_expected: bool, - pub trace: TypeTrace, + pub trace: TypeTrace<'tcx>, } pub fn expected_found<'tcx, C: Combine<'tcx>, T>( @@ -323,11 +323,14 @@ pub fn expected_found<'tcx, C: Combine<'tcx>, T>( } } -pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C, a: ty::t, b: ty::t) -> cres { +pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C, + a: Ty<'tcx>, + b: Ty<'tcx>) + -> cres<'tcx, Ty<'tcx>> { let tcx = this.infcx().tcx; - let a_sty = &ty::get(a).sty; - let b_sty = &ty::get(b).sty; + let a_sty = &a.sty; + let b_sty = &b.sty; debug!("super_tys: a_sty={} b_sty={}", a_sty, b_sty); return match (a_sty, b_sty) { // The "subtype" ought to be handling cases involving var: @@ -384,7 +387,7 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C, a: ty::t, b: ty::t) -> cres { - if ty::get(a).sty == ty::get(b).sty { + if a == b { Ok(a) } else { Err(ty::terr_sorts(expected_found(this, a, b))) @@ -446,7 +449,7 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C, a: ty::t, b: ty::t) -> cres { let ty = try!(this.tys(a_mt.ty, b_mt.ty)); ty::mt { ty: ty, mutbl: a_mt.mutbl } @@ -513,7 +516,7 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C, a: ty::t, b: ty::t) -> cres cres + val: ty::IntVarValue) -> cres<'tcx, Ty<'tcx>> { try!(this.infcx().simple_var_t(vid_is_expected, vid, val)); match val { @@ -526,7 +529,7 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C, a: ty::t, b: ty::t) -> cres cres + val: ast::FloatTy) -> cres<'tcx, Ty<'tcx>> { try!(this.infcx().simple_var_t(vid_is_expected, vid, val)); Ok(ty::mk_mach_float(val)) @@ -550,10 +553,10 @@ impl<'f, 'tcx> CombineFields<'f, 'tcx> { } pub fn instantiate(&self, - a_ty: ty::t, + a_ty: Ty<'tcx>, dir: RelationDir, b_vid: ty::TyVid) - -> cres<()> + -> cres<'tcx, ()> { let tcx = self.infcx.tcx; let mut stack = Vec::new(); @@ -640,10 +643,10 @@ impl<'f, 'tcx> CombineFields<'f, 'tcx> { } fn generalize(&self, - ty: ty::t, + ty: Ty<'tcx>, for_vid: ty::TyVid, make_region_vars: bool) - -> cres + -> cres<'tcx, Ty<'tcx>> { /*! * Attempts to generalize `ty` for the type variable @@ -681,7 +684,7 @@ impl<'cx, 'tcx> ty_fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> { self.infcx.tcx } - fn fold_ty(&mut self, t: ty::t) -> ty::t { + fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { // Check to see whether the type we are genealizing references // `vid`. At the same time, also update any type variables to // the values that they are bound to. This is needed to truly @@ -689,7 +692,7 @@ impl<'cx, 'tcx> ty_fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> { // // (In particular, you could have something like `$0 = Box<$1>` // where `$1` has already been instantiated with `Box<$0>`) - match ty::get(t).sty { + match t.sty { ty::ty_infer(ty::TyVar(vid)) => { if vid == self.for_vid { self.cycle_detected = true; diff --git a/src/librustc/middle/typeck/infer/equate.rs b/src/librustc/middle/typeck/infer/equate.rs index 3874f5fc5e4aa..356081c199afa 100644 --- a/src/librustc/middle/typeck/infer/equate.rs +++ b/src/librustc/middle/typeck/infer/equate.rs @@ -9,7 +9,7 @@ // except according to those terms. use middle::ty::{BuiltinBounds}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty::TyVar; use middle::typeck::infer::combine::*; use middle::typeck::infer::{cres}; @@ -36,22 +36,22 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> { fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx> { self.fields.infcx } fn tag(&self) -> String { "eq".to_string() } fn a_is_expected(&self) -> bool { self.fields.a_is_expected } - fn trace(&self) -> TypeTrace { self.fields.trace.clone() } + fn trace(&self) -> TypeTrace<'tcx> { self.fields.trace.clone() } fn equate<'a>(&'a self) -> Equate<'a, 'tcx> { Equate(self.fields.clone()) } fn sub<'a>(&'a self) -> Sub<'a, 'tcx> { Sub(self.fields.clone()) } fn lub<'a>(&'a self) -> Lub<'a, 'tcx> { Lub(self.fields.clone()) } fn glb<'a>(&'a self) -> Glb<'a, 'tcx> { Glb(self.fields.clone()) } - fn contratys(&self, a: ty::t, b: ty::t) -> cres { + fn contratys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> { self.tys(a, b) } - fn contraregions(&self, a: ty::Region, b: ty::Region) -> cres { + fn contraregions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region> { self.regions(a, b) } - fn regions(&self, a: ty::Region, b: ty::Region) -> cres { + fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region> { debug!("{}.regions({}, {})", self.tag(), a.repr(self.fields.infcx.tcx), @@ -60,7 +60,7 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> { Ok(a) } - fn mts(&self, a: &ty::mt, b: &ty::mt) -> cres { + fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> { debug!("mts({} <: {})", a.repr(self.fields.infcx.tcx), b.repr(self.fields.infcx.tcx)); @@ -70,7 +70,7 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> { Ok(ty::mt { mutbl: a.mutbl, ty: t }) } - fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres { + fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> { if a != b { Err(ty::terr_fn_style_mismatch(expected_found(self, a, b))) } else { @@ -78,7 +78,7 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> { } } - fn oncenesses(&self, a: Onceness, b: Onceness) -> cres { + fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<'tcx, Onceness> { if a != b { Err(ty::terr_onceness_mismatch(expected_found(self, a, b))) } else { @@ -89,7 +89,7 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> { fn builtin_bounds(&self, a: BuiltinBounds, b: BuiltinBounds) - -> cres + -> cres<'tcx, BuiltinBounds> { // More bounds is a subtype of fewer bounds. // @@ -103,7 +103,7 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> { } } - fn tys(&self, a: ty::t, b: ty::t) -> cres { + fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> { debug!("{}.tys({}, {})", self.tag(), a.repr(self.fields.infcx.tcx), b.repr(self.fields.infcx.tcx)); if a == b { return Ok(a); } @@ -111,7 +111,7 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> { let infcx = self.fields.infcx; let a = infcx.type_variables.borrow().replace_if_possible(a); let b = infcx.type_variables.borrow().replace_if_possible(b); - match (&ty::get(a).sty, &ty::get(b).sty) { + match (&a.sty, &b.sty) { (&ty::ty_infer(TyVar(a_id)), &ty::ty_infer(TyVar(b_id))) => { infcx.type_variables.borrow_mut().relate_vars(a_id, EqTo, b_id); Ok(a) @@ -133,12 +133,14 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> { } } - fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres { + fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) + -> cres<'tcx, ty::FnSig<'tcx>> { try!(self.sub().fn_sigs(a, b)); self.sub().fn_sigs(b, a) } - fn trait_refs(&self, a: &ty::TraitRef, b: &ty::TraitRef) -> cres { + fn trait_refs(&self, a: &ty::TraitRef<'tcx>, b: &ty::TraitRef<'tcx>) + -> cres<'tcx, ty::TraitRef<'tcx>> { try!(self.sub().trait_refs(a, b)); self.sub().trait_refs(b, a) } diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index 65bd21b14e025..7a7a7c796740a 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -63,7 +63,7 @@ use self::FreshOrKept::*; use std::collections::HashSet; use middle::def; use middle::subst; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty::{Region, ReFree}; use middle::typeck::infer; use middle::typeck::infer::InferCtxt; @@ -97,65 +97,65 @@ use util::ppaux::note_and_explain_region; // messages shouldn't include debug serializations. use util::ppaux::UserString; -pub trait ErrorReporting { +pub trait ErrorReporting<'tcx> { fn report_region_errors(&self, - errors: &Vec); + errors: &Vec>); - fn process_errors(&self, errors: &Vec) - -> Vec; + fn process_errors(&self, errors: &Vec>) + -> Vec>; - fn report_type_error(&self, trace: TypeTrace, terr: &ty::type_err); + fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::type_err<'tcx>); fn report_and_explain_type_error(&self, - trace: TypeTrace, - terr: &ty::type_err); + trace: TypeTrace<'tcx>, + terr: &ty::type_err<'tcx>); - fn values_str(&self, values: &ValuePairs) -> Option; + fn values_str(&self, values: &ValuePairs<'tcx>) -> Option; - fn expected_found_str( + fn expected_found_str + Resolvable<'tcx>>( &self, exp_found: &ty::expected_found) -> Option; fn report_concrete_failure(&self, - origin: SubregionOrigin, + origin: SubregionOrigin<'tcx>, sub: Region, sup: Region); fn report_param_bound_failure(&self, - origin: SubregionOrigin, + origin: SubregionOrigin<'tcx>, param_ty: ty::ParamTy, sub: Region, sups: Vec); fn report_sub_sup_conflict(&self, var_origin: RegionVariableOrigin, - sub_origin: SubregionOrigin, + sub_origin: SubregionOrigin<'tcx>, sub_region: Region, - sup_origin: SubregionOrigin, + sup_origin: SubregionOrigin<'tcx>, sup_region: Region); fn report_sup_sup_conflict(&self, var_origin: RegionVariableOrigin, - origin1: SubregionOrigin, + origin1: SubregionOrigin<'tcx>, region1: Region, - origin2: SubregionOrigin, + origin2: SubregionOrigin<'tcx>, region2: Region); fn report_processed_errors(&self, var_origin: &[RegionVariableOrigin], - trace_origin: &[(TypeTrace, ty::type_err)], + trace_origin: &[(TypeTrace<'tcx>, ty::type_err<'tcx>)], same_regions: &[SameRegions]); fn give_suggestion(&self, same_regions: &[SameRegions]); } -trait ErrorReportingHelpers { +trait ErrorReportingHelpers<'tcx> { fn report_inference_failure(&self, var_origin: RegionVariableOrigin); fn note_region_origin(&self, - origin: &SubregionOrigin); + origin: &SubregionOrigin<'tcx>); fn give_expl_lifetime_param(&self, decl: &ast::FnDecl, @@ -166,9 +166,9 @@ trait ErrorReportingHelpers { span: codemap::Span); } -impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { +impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> { fn report_region_errors(&self, - errors: &Vec) { + errors: &Vec>) { let p_errors = self.process_errors(errors); let errors = if p_errors.is_empty() { errors } else { &p_errors }; for error in errors.iter() { @@ -216,8 +216,8 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { // complete view of what lifetimes should be the same. // If the return value is an empty vector, it means that processing // failed (so the return value of this method should not be used) - fn process_errors(&self, errors: &Vec) - -> Vec { + fn process_errors(&self, errors: &Vec>) + -> Vec> { debug!("process_errors()"); let mut var_origins = Vec::new(); let mut trace_origins = Vec::new(); @@ -350,7 +350,7 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { } } - fn report_type_error(&self, trace: TypeTrace, terr: &ty::type_err) { + fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::type_err<'tcx>) { let expected_found_str = match self.values_str(&trace.values) { Some(v) => v, None => { @@ -385,13 +385,13 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { } fn report_and_explain_type_error(&self, - trace: TypeTrace, - terr: &ty::type_err) { + trace: TypeTrace<'tcx>, + terr: &ty::type_err<'tcx>) { self.report_type_error(trace, terr); ty::note_and_explain_type_err(self.tcx, terr); } - fn values_str(&self, values: &ValuePairs) -> Option { + fn values_str(&self, values: &ValuePairs<'tcx>) -> Option { /*! * Returns a string of the form "expected `{}`, found `{}`", * or None if this is a derived error. @@ -402,7 +402,7 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { } } - fn expected_found_str( + fn expected_found_str + Resolvable<'tcx>>( &self, exp_found: &ty::expected_found) -> Option @@ -423,7 +423,7 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { } fn report_param_bound_failure(&self, - origin: SubregionOrigin, + origin: SubregionOrigin<'tcx>, param_ty: ty::ParamTy, sub: Region, _sups: Vec) { @@ -488,7 +488,7 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { } fn report_concrete_failure(&self, - origin: SubregionOrigin, + origin: SubregionOrigin<'tcx>, sub: Region, sup: Region) { match origin { @@ -786,9 +786,9 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { fn report_sub_sup_conflict(&self, var_origin: RegionVariableOrigin, - sub_origin: SubregionOrigin, + sub_origin: SubregionOrigin<'tcx>, sub_region: Region, - sup_origin: SubregionOrigin, + sup_origin: SubregionOrigin<'tcx>, sup_region: Region) { self.report_inference_failure(var_origin); @@ -811,9 +811,9 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { fn report_sup_sup_conflict(&self, var_origin: RegionVariableOrigin, - origin1: SubregionOrigin, + origin1: SubregionOrigin<'tcx>, region1: Region, - origin2: SubregionOrigin, + origin2: SubregionOrigin<'tcx>, region2: Region) { self.report_inference_failure(var_origin); @@ -836,7 +836,7 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { fn report_processed_errors(&self, var_origins: &[RegionVariableOrigin], - trace_origins: &[(TypeTrace, ty::type_err)], + trace_origins: &[(TypeTrace<'tcx>, ty::type_err<'tcx>)], same_regions: &[SameRegions]) { for vo in var_origins.iter() { self.report_inference_failure(vo.clone()); @@ -1430,7 +1430,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { } } -impl<'a, 'tcx> ErrorReportingHelpers for InferCtxt<'a, 'tcx> { +impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> { fn give_expl_lifetime_param(&self, decl: &ast::FnDecl, fn_style: ast::FnStyle, @@ -1483,7 +1483,7 @@ impl<'a, 'tcx> ErrorReportingHelpers for InferCtxt<'a, 'tcx> { var_description).as_slice()); } - fn note_region_origin(&self, origin: &SubregionOrigin) { + fn note_region_origin(&self, origin: &SubregionOrigin<'tcx>) { match *origin { infer::Subtype(ref trace) => { let desc = match trace.origin { @@ -1674,13 +1674,13 @@ impl<'a, 'tcx> ErrorReportingHelpers for InferCtxt<'a, 'tcx> { } } -pub trait Resolvable { - fn resolve(&self, infcx: &InferCtxt) -> Self; +pub trait Resolvable<'tcx> { + fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx>) -> Self; fn contains_error(&self) -> bool; } -impl Resolvable for ty::t { - fn resolve(&self, infcx: &InferCtxt) -> ty::t { +impl<'tcx> Resolvable<'tcx> for Ty<'tcx> { + fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx>) -> Ty<'tcx> { infcx.resolve_type_vars_if_possible(*self) } fn contains_error(&self) -> bool { @@ -1688,8 +1688,9 @@ impl Resolvable for ty::t { } } -impl Resolvable for Rc { - fn resolve(&self, infcx: &InferCtxt) -> Rc { +impl<'tcx> Resolvable<'tcx> for Rc> { + fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx>) + -> Rc> { Rc::new(infcx.resolve_type_vars_in_trait_ref_if_possible(&**self)) } fn contains_error(&self) -> bool { diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index 287a5cfba9e34..671d2e3837c79 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -10,7 +10,7 @@ use middle::ty::{BuiltinBounds}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::infer::combine::*; use middle::typeck::infer::lattice::*; use middle::typeck::infer::equate::Equate; @@ -39,14 +39,14 @@ impl<'f, 'tcx> Combine<'tcx> for Glb<'f, 'tcx> { fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx> { self.fields.infcx } fn tag(&self) -> String { "glb".to_string() } fn a_is_expected(&self) -> bool { self.fields.a_is_expected } - fn trace(&self) -> TypeTrace { self.fields.trace.clone() } + fn trace(&self) -> TypeTrace<'tcx> { self.fields.trace.clone() } fn equate<'a>(&'a self) -> Equate<'a, 'tcx> { Equate(self.fields.clone()) } fn sub<'a>(&'a self) -> Sub<'a, 'tcx> { Sub(self.fields.clone()) } fn lub<'a>(&'a self) -> Lub<'a, 'tcx> { Lub(self.fields.clone()) } fn glb<'a>(&'a self) -> Glb<'a, 'tcx> { Glb(self.fields.clone()) } - fn mts(&self, a: &ty::mt, b: &ty::mt) -> cres { + fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> { let tcx = self.fields.infcx.tcx; debug!("{}.mts({}, {})", @@ -77,18 +77,18 @@ impl<'f, 'tcx> Combine<'tcx> for Glb<'f, 'tcx> { } } - fn contratys(&self, a: ty::t, b: ty::t) -> cres { + fn contratys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> { self.lub().tys(a, b) } - fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres { + fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> { match (a, b) { (NormalFn, _) | (_, NormalFn) => Ok(NormalFn), (UnsafeFn, UnsafeFn) => Ok(UnsafeFn) } } - fn oncenesses(&self, a: Onceness, b: Onceness) -> cres { + fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<'tcx, Onceness> { match (a, b) { (Many, _) | (_, Many) => Ok(Many), (Once, Once) => Ok(Once) @@ -98,13 +98,13 @@ impl<'f, 'tcx> Combine<'tcx> for Glb<'f, 'tcx> { fn builtin_bounds(&self, a: ty::BuiltinBounds, b: ty::BuiltinBounds) - -> cres { + -> cres<'tcx, ty::BuiltinBounds> { // More bounds is a subtype of fewer bounds, so // the GLB (mutual subtype) is the union. Ok(a.union(b)) } - fn regions(&self, a: ty::Region, b: ty::Region) -> cres { + fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region> { debug!("{}.regions({}, {})", self.tag(), a.repr(self.fields.infcx.tcx), @@ -114,19 +114,21 @@ impl<'f, 'tcx> Combine<'tcx> for Glb<'f, 'tcx> { } fn contraregions(&self, a: ty::Region, b: ty::Region) - -> cres { + -> cres<'tcx, ty::Region> { self.lub().regions(a, b) } - fn tys(&self, a: ty::t, b: ty::t) -> cres { + fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> { super_lattice_tys(self, a, b) } - fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres { + fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) + -> cres<'tcx, ty::FnSig<'tcx>> { self.higher_ranked_glb(a, b) } - fn trait_refs(&self, a: &ty::TraitRef, b: &ty::TraitRef) -> cres { + fn trait_refs(&self, a: &ty::TraitRef<'tcx>, b: &ty::TraitRef<'tcx>) + -> cres<'tcx, ty::TraitRef<'tcx>> { self.higher_ranked_glb(a, b) } } diff --git a/src/librustc/middle/typeck/infer/higher_ranked/mod.rs b/src/librustc/middle/typeck/infer/higher_ranked/mod.rs index 09f0bbb2254ad..812aa5c555728 100644 --- a/src/librustc/middle/typeck/infer/higher_ranked/mod.rs +++ b/src/librustc/middle/typeck/infer/higher_ranked/mod.rs @@ -13,8 +13,7 @@ * the end of the file for details. */ -use middle::ty; -use middle::ty::replace_late_bound_regions; +use middle::ty::{mod, Ty, replace_late_bound_regions}; use middle::typeck::infer::{mod, combine, cres, InferCtxt}; use middle::typeck::infer::combine::Combine; use middle::typeck::infer::region_inference::{RegionMark}; @@ -23,26 +22,27 @@ use syntax::codemap::Span; use util::nodemap::FnvHashMap; use util::ppaux::{bound_region_to_string, Repr}; -pub trait HigherRankedCombineable : HigherRankedFoldable + TypeFoldable + Repr { - fn super_combine<'tcx,C:Combine<'tcx>>(combiner: &C, a: &Self, b: &Self) -> cres; +pub trait HigherRankedCombineable<'tcx>: HigherRankedFoldable<'tcx> + + TypeFoldable<'tcx> + Repr<'tcx> { + fn super_combine>(combiner: &C, a: &Self, b: &Self) -> cres<'tcx, Self>; } -pub trait HigherRankedRelations { - fn higher_ranked_sub(&self, a: &T, b: &T) -> cres - where T : HigherRankedCombineable; +pub trait HigherRankedRelations<'tcx> { + fn higher_ranked_sub(&self, a: &T, b: &T) -> cres<'tcx, T> + where T : HigherRankedCombineable<'tcx>; - fn higher_ranked_lub(&self, a: &T, b: &T) -> cres - where T : HigherRankedCombineable; + fn higher_ranked_lub(&self, a: &T, b: &T) -> cres<'tcx, T> + where T : HigherRankedCombineable<'tcx>; - fn higher_ranked_glb(&self, a: &T, b: &T) -> cres - where T : HigherRankedCombineable; + fn higher_ranked_glb(&self, a: &T, b: &T) -> cres<'tcx, T> + where T : HigherRankedCombineable<'tcx>; } -impl<'tcx,C> HigherRankedRelations for C +impl<'tcx,C> HigherRankedRelations<'tcx> for C where C : Combine<'tcx> { - fn higher_ranked_sub(&self, a: &T, b: &T) -> cres - where T : HigherRankedCombineable + fn higher_ranked_sub(&self, a: &T, b: &T) -> cres<'tcx, T> + where T : HigherRankedCombineable<'tcx> { debug!("higher_ranked_sub(a={}, b={})", a.repr(self.tcx()), b.repr(self.tcx())); @@ -122,8 +122,8 @@ impl<'tcx,C> HigherRankedRelations for C return Ok(result); } - fn higher_ranked_lub(&self, a: &T, b: &T) -> cres - where T : HigherRankedCombineable + fn higher_ranked_lub(&self, a: &T, b: &T) -> cres<'tcx, T> + where T : HigherRankedCombineable<'tcx> { // Make a mark so we can examine "all bindings that were // created as part of this type comparison". @@ -210,8 +210,8 @@ impl<'tcx,C> HigherRankedRelations for C } } - fn higher_ranked_glb(&self, a: &T, b: &T) -> cres - where T : HigherRankedCombineable + fn higher_ranked_glb(&self, a: &T, b: &T) -> cres<'tcx, T> + where T : HigherRankedCombineable<'tcx> { debug!("{}.higher_ranked_glb({}, {})", self.tag(), a.repr(self.tcx()), b.repr(self.tcx())); @@ -346,9 +346,9 @@ impl<'tcx,C> HigherRankedRelations for C } } -impl HigherRankedCombineable for ty::FnSig { - fn super_combine<'tcx,C:Combine<'tcx>>(combiner: &C, a: &ty::FnSig, b: &ty::FnSig) - -> cres +impl<'tcx> HigherRankedCombineable<'tcx> for ty::FnSig<'tcx> { + fn super_combine>(combiner: &C, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) + -> cres<'tcx, ty::FnSig<'tcx>> { if a.variadic != b.variadic { return Err(ty::terr_variadic_mismatch( @@ -375,9 +375,9 @@ impl HigherRankedCombineable for ty::FnSig { fn argvecs<'tcx, C: Combine<'tcx>>(combiner: &C, - a_args: &[ty::t], - b_args: &[ty::t]) - -> cres> + a_args: &[Ty<'tcx>], + b_args: &[Ty<'tcx>]) + -> cres<'tcx, Vec>> { if a_args.len() == b_args.len() { a_args.iter().zip(b_args.iter()) @@ -389,9 +389,11 @@ impl HigherRankedCombineable for ty::FnSig { } } -impl HigherRankedCombineable for ty::TraitRef { - fn super_combine<'tcx,C:Combine<'tcx>>(combiner: &C, a: &ty::TraitRef, b: &ty::TraitRef) - -> cres +impl<'tcx> HigherRankedCombineable<'tcx> for ty::TraitRef<'tcx> { + fn super_combine>(combiner: &C, + a: &ty::TraitRef<'tcx>, + b: &ty::TraitRef<'tcx>) + -> cres<'tcx, ty::TraitRef<'tcx>> { // Different traits cannot be related if a.def_id != b.def_id { @@ -425,10 +427,11 @@ fn is_var_in_set(new_vars: &[ty::RegionVid], r: ty::Region) -> bool { } } -fn fold_regions_in(tcx: &ty::ctxt, - value: &T, - fldr: |ty::Region, ty::DebruijnIndex| -> ty::Region) - -> T +fn fold_regions_in<'tcx, T>(tcx: &ty::ctxt<'tcx>, + value: &T, + fldr: |ty::Region, ty::DebruijnIndex| -> ty::Region) + -> T + where T: HigherRankedFoldable<'tcx> { value.fold_contents(&mut ty_fold::RegionFolder::new(tcx, |region, current_depth| { // we should only be encountering "escaping" late-bound regions here, diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index f7e6cef99af93..6e6c631f00749 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -32,21 +32,21 @@ */ use middle::ty::{TyVar}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::infer::*; use middle::typeck::infer::combine::*; use middle::typeck::infer::glb::Glb; use middle::typeck::infer::lub::Lub; use util::ppaux::Repr; -pub trait LatticeDir { +pub trait LatticeDir<'tcx> { // Relates the type `v` to `a` and `b` such that `v` represents // the LUB/GLB of `a` and `b` as appropriate. - fn relate_bound<'a>(&'a self, v: ty::t, a: ty::t, b: ty::t) -> cres<()>; + fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, ()>; } -impl<'a, 'tcx> LatticeDir for Lub<'a, 'tcx> { - fn relate_bound<'a>(&'a self, v: ty::t, a: ty::t, b: ty::t) -> cres<()> { +impl<'a, 'tcx> LatticeDir<'tcx> for Lub<'a, 'tcx> { + fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, ()> { let sub = self.sub(); try!(sub.tys(a, v)); try!(sub.tys(b, v)); @@ -54,8 +54,8 @@ impl<'a, 'tcx> LatticeDir for Lub<'a, 'tcx> { } } -impl<'a, 'tcx> LatticeDir for Glb<'a, 'tcx> { - fn relate_bound<'a>(&'a self, v: ty::t, a: ty::t, b: ty::t) -> cres<()> { +impl<'a, 'tcx> LatticeDir<'tcx> for Glb<'a, 'tcx> { + fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, ()> { let sub = self.sub(); try!(sub.tys(v, a)); try!(sub.tys(v, b)); @@ -63,10 +63,10 @@ impl<'a, 'tcx> LatticeDir for Glb<'a, 'tcx> { } } -pub fn super_lattice_tys<'tcx, L:LatticeDir+Combine<'tcx>>(this: &L, - a: ty::t, - b: ty::t) - -> cres +pub fn super_lattice_tys<'tcx, L:LatticeDir<'tcx>+Combine<'tcx>>(this: &L, + a: Ty<'tcx>, + b: Ty<'tcx>) + -> cres<'tcx, Ty<'tcx>> { debug!("{}.lattice_tys({}, {})", this.tag(), @@ -80,7 +80,7 @@ pub fn super_lattice_tys<'tcx, L:LatticeDir+Combine<'tcx>>(this: &L, let infcx = this.infcx(); let a = infcx.type_variables.borrow().replace_if_possible(a); let b = infcx.type_variables.borrow().replace_if_possible(b); - match (&ty::get(a).sty, &ty::get(b).sty) { + match (&a.sty, &b.sty) { (&ty::ty_infer(TyVar(..)), &ty::ty_infer(TyVar(..))) if infcx.type_var_diverges(a) && infcx.type_var_diverges(b) => { let v = infcx.next_diverging_ty_var(); diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index 8856f42d1f5ab..e7bd1f3716c12 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -9,7 +9,7 @@ // except according to those terms. use middle::ty::{BuiltinBounds}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::infer::combine::*; use middle::typeck::infer::equate::Equate; use middle::typeck::infer::glb::Glb; @@ -39,14 +39,14 @@ impl<'f, 'tcx> Combine<'tcx> for Lub<'f, 'tcx> { fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx> { self.fields.infcx } fn tag(&self) -> String { "lub".to_string() } fn a_is_expected(&self) -> bool { self.fields.a_is_expected } - fn trace(&self) -> TypeTrace { self.fields.trace.clone() } + fn trace(&self) -> TypeTrace<'tcx> { self.fields.trace.clone() } fn equate<'a>(&'a self) -> Equate<'a, 'tcx> { Equate(self.fields.clone()) } fn sub<'a>(&'a self) -> Sub<'a, 'tcx> { Sub(self.fields.clone()) } fn lub<'a>(&'a self) -> Lub<'a, 'tcx> { Lub(self.fields.clone()) } fn glb<'a>(&'a self) -> Glb<'a, 'tcx> { Glb(self.fields.clone()) } - fn mts(&self, a: &ty::mt, b: &ty::mt) -> cres { + fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> { let tcx = self.tcx(); debug!("{}.mts({}, {})", @@ -72,18 +72,18 @@ impl<'f, 'tcx> Combine<'tcx> for Lub<'f, 'tcx> { } } - fn contratys(&self, a: ty::t, b: ty::t) -> cres { + fn contratys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> { self.glb().tys(a, b) } - fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres { + fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> { match (a, b) { (UnsafeFn, _) | (_, UnsafeFn) => Ok(UnsafeFn), (NormalFn, NormalFn) => Ok(NormalFn), } } - fn oncenesses(&self, a: Onceness, b: Onceness) -> cres { + fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<'tcx, Onceness> { match (a, b) { (Once, _) | (_, Once) => Ok(Once), (Many, Many) => Ok(Many) @@ -93,18 +93,18 @@ impl<'f, 'tcx> Combine<'tcx> for Lub<'f, 'tcx> { fn builtin_bounds(&self, a: ty::BuiltinBounds, b: ty::BuiltinBounds) - -> cres { + -> cres<'tcx, ty::BuiltinBounds> { // More bounds is a subtype of fewer bounds, so // the LUB (mutual supertype) is the intersection. Ok(a.intersection(b)) } fn contraregions(&self, a: ty::Region, b: ty::Region) - -> cres { + -> cres<'tcx, ty::Region> { self.glb().regions(a, b) } - fn regions(&self, a: ty::Region, b: ty::Region) -> cres { + fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region> { debug!("{}.regions({}, {})", self.tag(), a.repr(self.tcx()), @@ -113,15 +113,17 @@ impl<'f, 'tcx> Combine<'tcx> for Lub<'f, 'tcx> { Ok(self.infcx().region_vars.lub_regions(Subtype(self.trace()), a, b)) } - fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres { + fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) + -> cres<'tcx, ty::FnSig<'tcx>> { self.higher_ranked_lub(a, b) } - fn tys(&self, a: ty::t, b: ty::t) -> cres { + fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> { super_lattice_tys(self, a, b) } - fn trait_refs(&self, a: &ty::TraitRef, b: &ty::TraitRef) -> cres { + fn trait_refs(&self, a: &ty::TraitRef<'tcx>, b: &ty::TraitRef<'tcx>) + -> cres<'tcx, ty::TraitRef<'tcx>> { self.higher_ranked_lub(a, b) } } diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index e69bd2157662e..93c11693091c2 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -32,7 +32,7 @@ use middle::subst; use middle::subst::Substs; use middle::ty::{TyVid, IntVid, FloatVid, RegionVid}; use middle::ty::replace_late_bound_regions; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty_fold::{HigherRankedFoldable, TypeFolder, TypeFoldable}; use std::cell::{RefCell}; use std::rc::Rc; @@ -72,18 +72,18 @@ pub mod unify; pub type Bound = Option; -pub type cres = Result; // "combine result" -pub type ures = cres<()>; // "unify result" +pub type cres<'tcx, T> = Result>; // "combine result" +pub type ures<'tcx> = cres<'tcx, ()>; // "unify result" pub type fres = Result; // "fixup result" -pub type CoerceResult = cres>; +pub type CoerceResult<'tcx> = cres<'tcx, Option>>; pub struct InferCtxt<'a, 'tcx: 'a> { pub tcx: &'a ty::ctxt<'tcx>, - // We instantiate UnificationTable with bounds because the + // We instantiate UnificationTable with bounds because the // types that might instantiate a general type variable have an // order, represented by its upper and lower bounds. - type_variables: RefCell, + type_variables: RefCell>, // Map from integral variable to the kind of integer it represents int_unification_table: @@ -134,9 +134,9 @@ pub enum TypeOrigin { /// See `error_reporting.rs` for more details #[deriving(Clone, Show)] -pub enum ValuePairs { - Types(ty::expected_found), - TraitRefs(ty::expected_found>), +pub enum ValuePairs<'tcx> { + Types(ty::expected_found>), + TraitRefs(ty::expected_found>>), } /// The trace designates the path through inference that we took to @@ -144,18 +144,18 @@ pub enum ValuePairs { /// /// See `error_reporting.rs` for more details. #[deriving(Clone, Show)] -pub struct TypeTrace { +pub struct TypeTrace<'tcx> { origin: TypeOrigin, - values: ValuePairs, + values: ValuePairs<'tcx>, } /// The origin of a `r1 <= r2` constraint. /// /// See `error_reporting.rs` for more details #[deriving(Clone, Show)] -pub enum SubregionOrigin { +pub enum SubregionOrigin<'tcx> { // Arose from a subtyping relation - Subtype(TypeTrace), + Subtype(TypeTrace<'tcx>), // Stack-allocated closures cannot outlive innermost loop // or function so as to ensure we only require finite stack @@ -182,11 +182,11 @@ pub enum SubregionOrigin { // When closing over a variable in a closure/proc, ensure that the // type of the variable outlives the lifetime bound. - RelateProcBound(Span, ast::NodeId, ty::t), + RelateProcBound(Span, ast::NodeId, Ty<'tcx>), // Some type parameter was instantiated with the given type, // and that type must outlive some region. - RelateParamBound(Span, ty::t), + RelateParamBound(Span, Ty<'tcx>), // The given region parameter was instantiated with a region // that must outlive some other region. @@ -194,7 +194,7 @@ pub enum SubregionOrigin { // A bound placed on type parameters that states that must outlive // the moment of their instantiation. - RelateDefaultParamBound(Span, ty::t), + RelateDefaultParamBound(Span, Ty<'tcx>), // Creating a pointer `b` to contents of another reference Reborrow(Span), @@ -203,10 +203,10 @@ pub enum SubregionOrigin { ReborrowUpvar(Span, ty::UpvarId), // (&'a &'b T) where a >= b - ReferenceOutlivesReferent(ty::t, Span), + ReferenceOutlivesReferent(Ty<'tcx>, Span), // The type T of an expression E must outlive the lifetime for E. - ExprTypeIsNotInScope(ty::t, Span), + ExprTypeIsNotInScope(Ty<'tcx>, Span), // A `ref b` whose region does not enclose the decl site BindingTypeIsNotValidAtDecl(Span), @@ -241,7 +241,7 @@ pub enum LateBoundRegionConversionTime { /// /// See `error_reporting.rs` for more details #[deriving(Clone, Show)] -pub enum RegionVariableOrigin { +pub enum RegionVariableOrigin<'tcx> { // Region variables created for ill-categorized reasons, // mostly indicates places in need of refactoring MiscVariable(Span), @@ -259,7 +259,7 @@ pub enum RegionVariableOrigin { Autoref(Span), // Regions created as part of an automatic coercion - Coercion(TypeTrace), + Coercion(TypeTrace<'tcx>), // Region variables created as the values for early-bound regions EarlyBoundRegion(Span, ast::Name), @@ -305,12 +305,12 @@ pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>) } } -pub fn common_supertype(cx: &InferCtxt, - origin: TypeOrigin, - a_is_expected: bool, - a: ty::t, - b: ty::t) - -> ty::t +pub fn common_supertype<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, + origin: TypeOrigin, + a_is_expected: bool, + a: Ty<'tcx>, + b: Ty<'tcx>) + -> Ty<'tcx> { /*! * Computes the least upper-bound of `a` and `b`. If this is @@ -336,12 +336,12 @@ pub fn common_supertype(cx: &InferCtxt, } } -pub fn mk_subty(cx: &InferCtxt, - a_is_expected: bool, - origin: TypeOrigin, - a: ty::t, - b: ty::t) - -> ures +pub fn mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, + a_is_expected: bool, + origin: TypeOrigin, + a: Ty<'tcx>, + b: Ty<'tcx>) + -> ures<'tcx> { debug!("mk_subty({} <: {})", a.repr(cx.tcx), b.repr(cx.tcx)); cx.commit_if_ok(|| { @@ -349,7 +349,10 @@ pub fn mk_subty(cx: &InferCtxt, }) } -pub fn can_mk_subty(cx: &InferCtxt, a: ty::t, b: ty::t) -> ures { +pub fn can_mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, + a: Ty<'tcx>, + b: Ty<'tcx>) + -> ures<'tcx> { debug!("can_mk_subty({} <: {})", a.repr(cx.tcx), b.repr(cx.tcx)); cx.probe(|| { let trace = TypeTrace { @@ -360,7 +363,9 @@ pub fn can_mk_subty(cx: &InferCtxt, a: ty::t, b: ty::t) -> ures { }) } -pub fn can_mk_eqty(cx: &InferCtxt, a: ty::t, b: ty::t) -> ures { +pub fn can_mk_eqty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, + a: Ty<'tcx>, b: Ty<'tcx>) + -> ures<'tcx> { debug!("can_mk_subty({} <: {})", a.repr(cx.tcx), b.repr(cx.tcx)); cx.probe(|| { let trace = TypeTrace { @@ -371,21 +376,21 @@ pub fn can_mk_eqty(cx: &InferCtxt, a: ty::t, b: ty::t) -> ures { }).to_ures() } -pub fn mk_subr(cx: &InferCtxt, - origin: SubregionOrigin, - a: ty::Region, - b: ty::Region) { +pub fn mk_subr<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, + origin: SubregionOrigin<'tcx>, + a: ty::Region, + b: ty::Region) { debug!("mk_subr({} <: {})", a.repr(cx.tcx), b.repr(cx.tcx)); let snapshot = cx.region_vars.start_snapshot(); cx.region_vars.make_subregion(origin, a, b); cx.region_vars.commit(snapshot); } -pub fn verify_param_bound(cx: &InferCtxt, - origin: SubregionOrigin, - param_ty: ty::ParamTy, - a: ty::Region, - bs: Vec) { +pub fn verify_param_bound<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, + origin: SubregionOrigin<'tcx>, + param_ty: ty::ParamTy, + a: ty::Region, + bs: Vec) { debug!("verify_param_bound({}, {} <: {})", param_ty.repr(cx.tcx), a.repr(cx.tcx), @@ -394,24 +399,24 @@ pub fn verify_param_bound(cx: &InferCtxt, cx.region_vars.verify_param_bound(origin, param_ty, a, bs); } -pub fn mk_eqty(cx: &InferCtxt, - a_is_expected: bool, - origin: TypeOrigin, - a: ty::t, - b: ty::t) - -> ures +pub fn mk_eqty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, + a_is_expected: bool, + origin: TypeOrigin, + a: Ty<'tcx>, + b: Ty<'tcx>) + -> ures<'tcx> { debug!("mk_eqty({} <: {})", a.repr(cx.tcx), b.repr(cx.tcx)); cx.commit_if_ok( || cx.eq_types(a_is_expected, origin, a, b)) } -pub fn mk_sub_trait_refs(cx: &InferCtxt, - a_is_expected: bool, - origin: TypeOrigin, - a: Rc, - b: Rc) - -> ures +pub fn mk_sub_trait_refs<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, + a_is_expected: bool, + origin: TypeOrigin, + a: Rc>, + b: Rc>) + -> ures<'tcx> { debug!("mk_sub_trait_refs({} <: {})", a.repr(cx.tcx), b.repr(cx.tcx)); @@ -431,12 +436,12 @@ fn expected_found(a_is_expected: bool, } } -pub fn mk_coercety(cx: &InferCtxt, - a_is_expected: bool, - origin: TypeOrigin, - a: ty::t, - b: ty::t) - -> CoerceResult { +pub fn mk_coercety<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, + a_is_expected: bool, + origin: TypeOrigin, + a: Ty<'tcx>, + b: Ty<'tcx>) + -> CoerceResult<'tcx> { debug!("mk_coercety({} -> {})", a.repr(cx.tcx), b.repr(cx.tcx)); indent(|| { cx.commit_if_ok(|| { @@ -450,11 +455,11 @@ pub fn mk_coercety(cx: &InferCtxt, } // See comment on the type `resolve_state` below -pub fn resolve_type(cx: &InferCtxt, - span: Option, - a: ty::t, - modes: uint) - -> fres { +pub fn resolve_type<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, + span: Option, + a: Ty<'tcx>, + modes: uint) + -> fres> { let mut resolver = resolver(cx, modes, span); cx.commit_unconditionally(|| resolver.resolve_type_chk(a)) } @@ -465,24 +470,24 @@ pub fn resolve_region(cx: &InferCtxt, r: ty::Region, modes: uint) resolver.resolve_region_chk(r) } -trait then { - fn then(&self, f: || -> Result) - -> Result; +trait then<'tcx> { + fn then(&self, f: || -> Result>) + -> Result>; } -impl then for ures { - fn then(&self, f: || -> Result) - -> Result { +impl<'tcx> then<'tcx> for ures<'tcx> { + fn then(&self, f: || -> Result>) + -> Result> { self.and_then(|_i| f()) } } -trait ToUres { - fn to_ures(&self) -> ures; +trait ToUres<'tcx> { + fn to_ures(&self) -> ures<'tcx>; } -impl ToUres for cres { - fn to_ures(&self) -> ures { +impl<'tcx, T> ToUres<'tcx> for cres<'tcx, T> { + fn to_ures(&self) -> ures<'tcx> { match *self { Ok(ref _v) => Ok(()), Err(ref e) => Err((*e)) @@ -490,12 +495,12 @@ impl ToUres for cres { } } -trait CresCompare { - fn compare(&self, t: T, f: || -> ty::type_err) -> cres; +trait CresCompare<'tcx, T> { + fn compare(&self, t: T, f: || -> ty::type_err<'tcx>) -> cres<'tcx, T>; } -impl CresCompare for cres { - fn compare(&self, t: T, f: || -> ty::type_err) -> cres { +impl<'tcx, T:Clone + PartialEq> CresCompare<'tcx, T> for cres<'tcx, T> { + fn compare(&self, t: T, f: || -> ty::type_err<'tcx>) -> cres<'tcx, T> { (*self).clone().and_then(|s| { if s == t { (*self).clone() @@ -506,7 +511,7 @@ impl CresCompare for cres { } } -pub fn uok() -> ures { +pub fn uok<'tcx>() -> ures<'tcx> { Ok(()) } @@ -518,12 +523,12 @@ pub struct CombinedSnapshot { } impl<'a, 'tcx> InferCtxt<'a, 'tcx> { - pub fn skolemize(&self, t: T) -> T { + pub fn skolemize>(&self, t: T) -> T { t.fold_with(&mut self.skolemizer()) } - pub fn type_var_diverges(&'a self, ty: ty::t) -> bool { - match ty::get(ty).sty { + pub fn type_var_diverges(&'a self, ty: Ty) -> bool { + match ty.sty { ty::ty_infer(ty::TyVar(vid)) => self.type_variables.borrow().var_diverges(vid), _ => false } @@ -533,22 +538,25 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { skolemize::TypeSkolemizer::new(self) } - pub fn combine_fields<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) + pub fn combine_fields<'a>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>) -> CombineFields<'a, 'tcx> { CombineFields {infcx: self, a_is_expected: a_is_expected, trace: trace} } - pub fn equate<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) -> Equate<'a, 'tcx> { + pub fn equate<'a>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>) + -> Equate<'a, 'tcx> { Equate(self.combine_fields(a_is_expected, trace)) } - pub fn sub<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) -> Sub<'a, 'tcx> { + pub fn sub<'a>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>) + -> Sub<'a, 'tcx> { Sub(self.combine_fields(a_is_expected, trace)) } - pub fn lub<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) -> Lub<'a, 'tcx> { + pub fn lub<'a>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>) + -> Lub<'a, 'tcx> { Lub(self.combine_fields(a_is_expected, trace)) } @@ -651,9 +659,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn sub_types(&self, a_is_expected: bool, origin: TypeOrigin, - a: ty::t, - b: ty::t) - -> ures + a: Ty<'tcx>, + b: Ty<'tcx>) + -> ures<'tcx> { debug!("sub_types({} <: {})", a.repr(self.tcx), b.repr(self.tcx)); self.commit_if_ok(|| { @@ -668,9 +676,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn eq_types(&self, a_is_expected: bool, origin: TypeOrigin, - a: ty::t, - b: ty::t) - -> ures + a: Ty<'tcx>, + b: Ty<'tcx>) + -> ures<'tcx> { self.commit_if_ok(|| { let trace = TypeTrace { @@ -684,9 +692,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn sub_trait_refs(&self, a_is_expected: bool, origin: TypeOrigin, - a: Rc, - b: Rc) - -> ures + a: Rc>, + b: Rc>) + -> ures<'tcx> { debug!("sub_trait_refs({} <: {})", a.repr(self.tcx), @@ -709,15 +717,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { .new_var(diverging) } - pub fn next_ty_var(&self) -> ty::t { + pub fn next_ty_var(&self) -> Ty<'tcx> { ty::mk_var(self.tcx, self.next_ty_var_id(false)) } - pub fn next_diverging_ty_var(&self) -> ty::t { + pub fn next_diverging_ty_var(&self) -> Ty<'tcx> { ty::mk_var(self.tcx, self.next_ty_var_id(true)) } - pub fn next_ty_vars(&self, n: uint) -> Vec { + pub fn next_ty_vars(&self, n: uint) -> Vec> { Vec::from_fn(n, |_i| self.next_ty_var()) } @@ -733,7 +741,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { .new_key(None) } - pub fn next_region_var(&self, origin: RegionVariableOrigin) -> ty::Region { + pub fn next_region_var(&self, origin: RegionVariableOrigin<'tcx>) -> ty::Region { ty::ReInfer(ty::ReVar(self.region_vars.new_region_var(origin))) } @@ -748,8 +756,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn fresh_substs_for_generics(&self, span: Span, - generics: &ty::Generics) - -> subst::Substs + generics: &ty::Generics<'tcx>) + -> subst::Substs<'tcx> { /*! * Given a set of generics defined on a type or impl, returns @@ -768,9 +776,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn fresh_substs_for_trait(&self, span: Span, - generics: &ty::Generics, - self_ty: ty::t) - -> subst::Substs + generics: &ty::Generics<'tcx>, + self_ty: Ty<'tcx>) + -> subst::Substs<'tcx> { /*! * Given a set of generics defined on a trait, returns a @@ -805,22 +813,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { self.report_region_errors(&errors); // see error_reporting.rs } - pub fn ty_to_string(&self, t: ty::t) -> String { + pub fn ty_to_string(&self, t: Ty<'tcx>) -> String { ty_to_string(self.tcx, self.resolve_type_vars_if_possible(t)) } - pub fn tys_to_string(&self, ts: &[ty::t]) -> String { + pub fn tys_to_string(&self, ts: &[Ty<'tcx>]) -> String { let tstrs: Vec = ts.iter().map(|t| self.ty_to_string(*t)).collect(); format!("({})", tstrs.connect(", ")) } - pub fn trait_ref_to_string(&self, t: &Rc) -> String { + pub fn trait_ref_to_string(&self, t: &Rc>) -> String { let t = self.resolve_type_vars_in_trait_ref_if_possible(&**t); trait_ref_to_string(self.tcx, &t) } - pub fn contains_unbound_type_variables(&self, typ: ty::t) -> ty::t { + pub fn contains_unbound_type_variables(&self, typ: Ty<'tcx>) -> Ty<'tcx> { match resolve_type(self, None, typ, resolve_nested_tvar | resolve_ivar) { @@ -829,8 +837,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } } - pub fn shallow_resolve(&self, typ: ty::t) -> ty::t { - match ty::get(typ).sty { + pub fn shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'tcx> { + match typ.sty { ty::ty_infer(ty::TyVar(v)) => { self.type_variables.borrow() .probe(v) @@ -853,7 +861,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } } - pub fn resolve_type_vars_if_possible(&self, typ: ty::t) -> ty::t { + pub fn resolve_type_vars_if_possible(&self, typ: Ty<'tcx>) -> Ty<'tcx> { match resolve_type(self, None, typ, resolve_nested_tvar | resolve_ivar) { @@ -863,14 +871,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } pub fn resolve_type_vars_in_trait_ref_if_possible(&self, - trait_ref: &ty::TraitRef) - -> ty::TraitRef { + trait_ref: &ty::TraitRef<'tcx>) + -> ty::TraitRef<'tcx> { // make up a dummy type just to reuse/abuse the resolve machinery let dummy0 = ty::mk_trait(self.tcx, (*trait_ref).clone(), ty::region_existential_bound(ty::ReStatic)); let dummy1 = self.resolve_type_vars_if_possible(dummy0); - match ty::get(dummy1).sty { + match dummy1.sty { ty::ty_trait(box ty::TyTrait { ref principal, .. }) => { (*principal).clone() } @@ -899,7 +907,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { sp: Span, mk_msg: |Option, String| -> String, actual_ty: String, - err: Option<&ty::type_err>) { + err: Option<&ty::type_err<'tcx>>) { self.type_error_message_str_with_expected(sp, mk_msg, None, actual_ty, err) } @@ -908,9 +916,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { mk_msg: |Option, String| -> String, - expected_ty: Option, + expected_ty: Option>, actual_ty: String, - err: Option<&ty::type_err>) { + err: Option<&ty::type_err<'tcx>>) { debug!("hi! expected_ty = {}, actual_ty = {}", expected_ty, actual_ty); let resolved_expected = expected_ty.map(|e_ty| { @@ -938,8 +946,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn type_error_message(&self, sp: Span, mk_msg: |String| -> String, - actual_ty: ty::t, - err: Option<&ty::type_err>) { + actual_ty: Ty<'tcx>, + err: Option<&ty::type_err<'tcx>>) { let actual_ty = self.resolve_type_vars_if_possible(actual_ty); // Don't report an error if actual type is ty_err. @@ -952,9 +960,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn report_mismatched_types(&self, span: Span, - expected: ty::t, - actual: ty::t, - err: &ty::type_err) { + expected: Ty<'tcx>, + actual: Ty<'tcx>, + err: &ty::type_err<'tcx>) { let trace = TypeTrace { origin: Misc(span), values: Types(ty::expected_found { @@ -971,7 +979,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { lbrct: LateBoundRegionConversionTime, value: &T) -> (T, FnvHashMap) - where T : HigherRankedFoldable + where T : HigherRankedFoldable<'tcx> { ty::replace_late_bound_regions( self.tcx, @@ -980,12 +988,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } } -impl TypeTrace { +impl<'tcx> TypeTrace<'tcx> { pub fn span(&self) -> Span { self.origin.span() } - pub fn dummy() -> TypeTrace { + pub fn dummy() -> TypeTrace<'tcx> { TypeTrace { origin: Misc(codemap::DUMMY_SP), values: Types(ty::expected_found { @@ -996,7 +1004,7 @@ impl TypeTrace { } } -impl Repr for TypeTrace { +impl<'tcx> Repr<'tcx> for TypeTrace<'tcx> { fn repr(&self, tcx: &ty::ctxt) -> String { format!("TypeTrace({})", self.origin.repr(tcx)) } @@ -1018,7 +1026,7 @@ impl TypeOrigin { } } -impl Repr for TypeOrigin { +impl<'tcx> Repr<'tcx> for TypeOrigin { fn repr(&self, tcx: &ty::ctxt) -> String { match *self { MethodCompatCheck(a) => { @@ -1050,7 +1058,7 @@ impl Repr for TypeOrigin { } } -impl SubregionOrigin { +impl<'tcx> SubregionOrigin<'tcx> { pub fn span(&self) -> Span { match *self { Subtype(ref a) => a.span(), @@ -1079,8 +1087,8 @@ impl SubregionOrigin { } } -impl Repr for SubregionOrigin { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for SubregionOrigin<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { Subtype(ref a) => { format!("Subtype({})", a.repr(tcx)) @@ -1150,7 +1158,7 @@ impl Repr for SubregionOrigin { } } -impl RegionVariableOrigin { +impl<'tcx> RegionVariableOrigin<'tcx> { pub fn span(&self) -> Span { match *self { MiscVariable(a) => a, @@ -1167,8 +1175,8 @@ impl RegionVariableOrigin { } } -impl Repr for RegionVariableOrigin { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for RegionVariableOrigin<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { MiscVariable(a) => { format!("MiscVariable({})", a.repr(tcx)) diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index 54fb7872f3b03..5452a99127fc4 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -52,17 +52,17 @@ pub enum Constraint { // Something we have to verify after region inference is done, but // which does not directly influence the inference process -pub enum Verify { +pub enum Verify<'tcx> { // VerifyRegSubReg(a, b): Verify that `a <= b`. Neither `a` nor // `b` are inference variables. - VerifyRegSubReg(SubregionOrigin, Region, Region), + VerifyRegSubReg(SubregionOrigin<'tcx>, Region, Region), // VerifyParamBound(T, _, R, RS): The parameter type `T` must // outlive the region `R`. `T` is known to outlive `RS`. Therefore // verify that `R <= RS[i]` for some `i`. Inference variables may // be involved (but this verification step doesn't influence // inference). - VerifyParamBound(ty::ParamTy, SubregionOrigin, Region, Vec), + VerifyParamBound(ty::ParamTy, SubregionOrigin<'tcx>, Region, Vec), } #[deriving(PartialEq, Eq, Hash)] @@ -89,43 +89,43 @@ pub enum CombineMapType { } #[deriving(Clone, Show)] -pub enum RegionResolutionError { +pub enum RegionResolutionError<'tcx> { /// `ConcreteFailure(o, a, b)`: /// /// `o` requires that `a <= b`, but this does not hold - ConcreteFailure(SubregionOrigin, Region, Region), + ConcreteFailure(SubregionOrigin<'tcx>, Region, Region), /// `ParamBoundFailure(p, s, a, bs) /// /// The parameter type `p` must be known to outlive the lifetime /// `a`, but it is only known to outlive `bs` (and none of the /// regions in `bs` outlive `a`). - ParamBoundFailure(SubregionOrigin, ty::ParamTy, Region, Vec), + ParamBoundFailure(SubregionOrigin<'tcx>, ty::ParamTy, Region, Vec), /// `SubSupConflict(v, sub_origin, sub_r, sup_origin, sup_r)`: /// /// Could not infer a value for `v` because `sub_r <= v` (due to /// `sub_origin`) but `v <= sup_r` (due to `sup_origin`) and /// `sub_r <= sup_r` does not hold. - SubSupConflict(RegionVariableOrigin, - SubregionOrigin, Region, - SubregionOrigin, Region), + SubSupConflict(RegionVariableOrigin<'tcx>, + SubregionOrigin<'tcx>, Region, + SubregionOrigin<'tcx>, Region), /// `SupSupConflict(v, origin1, r1, origin2, r2)`: /// /// Could not infer a value for `v` because `v <= r1` (due to /// `origin1`) and `v <= r2` (due to `origin2`) and /// `r1` and `r2` have no intersection. - SupSupConflict(RegionVariableOrigin, - SubregionOrigin, Region, - SubregionOrigin, Region), + SupSupConflict(RegionVariableOrigin<'tcx>, + SubregionOrigin<'tcx>, Region, + SubregionOrigin<'tcx>, Region), /// For subsets of `ConcreteFailure` and `SubSupConflict`, we can derive /// more specific errors message by suggesting to the user where they /// should put a lifetime. In those cases we process and put those errors /// into `ProcessedErrors` before we do any reporting. - ProcessedErrors(Vec, - Vec<(TypeTrace, ty::type_err)>, + ProcessedErrors(Vec>, + Vec<(TypeTrace<'tcx>, ty::type_err<'tcx>)>, Vec), } @@ -160,19 +160,19 @@ pub type CombineMap = FnvHashMap; pub struct RegionVarBindings<'a, 'tcx: 'a> { tcx: &'a ty::ctxt<'tcx>, - var_origins: RefCell>, + var_origins: RefCell>>, // Constraints of the form `A <= B` introduced by the region // checker. Here at least one of `A` and `B` must be a region // variable. - constraints: RefCell>, + constraints: RefCell>>, // A "verify" is something that we need to verify after inference is // done, but which does not directly affect inference in any way. // // An example is a `A <= B` where neither `A` nor `B` are // inference variables. - verifys: RefCell>, + verifys: RefCell>>, // A "given" is a relationship that is known to hold. In particular, // we often know from closure fn signatures that a particular free @@ -314,7 +314,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { self.var_origins.borrow().len() } - pub fn new_region_var(&self, origin: RegionVariableOrigin) -> RegionVid { + pub fn new_region_var(&self, origin: RegionVariableOrigin<'tcx>) -> RegionVid { let id = self.num_vars(); self.var_origins.borrow_mut().push(origin.clone()); let vid = RegionVid { index: id }; @@ -367,7 +367,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { fn add_constraint(&self, constraint: Constraint, - origin: SubregionOrigin) { + origin: SubregionOrigin<'tcx>) { // cannot add constraints once regions are resolved assert!(self.values_are_none()); @@ -382,7 +382,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { } fn add_verify(&self, - verify: Verify) { + verify: Verify<'tcx>) { // cannot add verifys once regions are resolved assert!(self.values_are_none()); @@ -414,7 +414,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { } pub fn make_eqregion(&self, - origin: SubregionOrigin, + origin: SubregionOrigin<'tcx>, sub: Region, sup: Region) { if sub != sup { @@ -426,7 +426,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { } pub fn make_subregion(&self, - origin: SubregionOrigin, + origin: SubregionOrigin<'tcx>, sub: Region, sup: Region) { // cannot add constraints once regions are resolved @@ -474,7 +474,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { } pub fn verify_param_bound(&self, - origin: SubregionOrigin, + origin: SubregionOrigin<'tcx>, param_ty: ty::ParamTy, sub: Region, sups: Vec) { @@ -482,7 +482,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { } pub fn lub_regions(&self, - origin: SubregionOrigin, + origin: SubregionOrigin<'tcx>, a: Region, b: Region) -> Region { @@ -507,7 +507,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { } pub fn glb_regions(&self, - origin: SubregionOrigin, + origin: SubregionOrigin<'tcx>, a: Region, b: Region) -> Region { @@ -560,8 +560,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { t: CombineMapType, a: Region, b: Region, - origin: SubregionOrigin, - relate: |this: &RegionVarBindings, + origin: SubregionOrigin<'tcx>, + relate: |this: &RegionVarBindings<'a, 'tcx>, old_r: Region, new_r: Region|) -> Region { @@ -700,7 +700,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { constraints, assuming such values can be found; if they cannot, errors are reported. */ - pub fn resolve_regions(&self) -> Vec { + pub fn resolve_regions(&self) -> Vec> { debug!("RegionVarBindings: resolve_regions()"); let mut errors = vec!(); let v = self.infer_variable_values(&mut errors); @@ -815,7 +815,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { fn glb_concrete_regions(&self, a: Region, b: Region) - -> cres { + -> cres<'tcx, Region> { debug!("glb_concrete_regions({}, {})", a, b); match (a, b) { (ReLateBound(..), _) | @@ -885,7 +885,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { fn glb_free_regions(&self, a: &FreeRegion, - b: &FreeRegion) -> cres + b: &FreeRegion) -> cres<'tcx, ty::Region> { /*! * Computes a region that is enclosed by both free region arguments, @@ -899,9 +899,9 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { Equal => Ok(ty::ReFree(*a)) }; - fn helper(this: &RegionVarBindings, - a: &FreeRegion, - b: &FreeRegion) -> cres + fn helper<'a, 'tcx>(this: &RegionVarBindings<'a, 'tcx>, + a: &FreeRegion, + b: &FreeRegion) -> cres<'tcx, ty::Region> { if this.tcx.region_maps.sub_free_region(*a, *b) { Ok(ty::ReFree(*a)) @@ -918,7 +918,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { region_a: ty::Region, region_b: ty::Region, scope_a: ast::NodeId, - scope_b: ast::NodeId) -> cres + scope_b: ast::NodeId) -> cres<'tcx, Region> { // We want to generate the intersection of two // scopes or two free regions. So, if one of @@ -946,16 +946,16 @@ struct VarData { value: VarValue, } -struct RegionAndOrigin { +struct RegionAndOrigin<'tcx> { region: Region, - origin: SubregionOrigin, + origin: SubregionOrigin<'tcx>, } type RegionGraph = graph::Graph<(), Constraint>; impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { fn infer_variable_values(&self, - errors: &mut Vec) + errors: &mut Vec>) -> Vec { let mut var_data = self.construct_var_data(); @@ -1188,7 +1188,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { fn collect_concrete_region_errors(&self, values: &Vec, - errors: &mut Vec) + errors: &mut Vec>) { let mut reg_reg_dups = FnvHashSet::new(); for verify in self.verifys.borrow().iter() { @@ -1230,7 +1230,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { fn extract_values_and_collect_conflicts( &self, var_data: &[VarData], - errors: &mut Vec) + errors: &mut Vec>) -> Vec { debug!("extract_values_and_collect_conflicts()"); @@ -1353,7 +1353,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { var_data: &[VarData], dup_vec: &mut [uint], node_idx: RegionVid, - errors: &mut Vec) + errors: &mut Vec>) { // Errors in expanding nodes result from a lower-bound that is // not contained by an upper-bound. @@ -1414,7 +1414,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { var_data: &[VarData], dup_vec: &mut [uint], node_idx: RegionVid, - errors: &mut Vec) + errors: &mut Vec>) { // Errors in contracting nodes result from two upper-bounds // that have no intersection. @@ -1458,11 +1458,11 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { orig_node_idx: RegionVid, dir: Direction, dup_vec: &mut [uint]) - -> (Vec , bool) { - struct WalkState { + -> (Vec>, bool) { + struct WalkState<'tcx> { set: FnvHashSet, - stack: Vec , - result: Vec , + stack: Vec, + result: Vec>, dup_found: bool } let mut state = WalkState { @@ -1505,8 +1505,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { let WalkState {result, dup_found, ..} = state; return (result, dup_found); - fn process_edges(this: &RegionVarBindings, - state: &mut WalkState, + fn process_edges<'a, 'tcx>(this: &RegionVarBindings<'a, 'tcx>, + state: &mut WalkState<'tcx>, graph: &RegionGraph, source_vid: RegionVid, dir: Direction) { @@ -1559,7 +1559,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { } -impl Repr for Constraint { +impl<'tcx> Repr<'tcx> for Constraint { fn repr(&self, tcx: &ty::ctxt) -> String { match *self { ConstrainVarSubVar(a, b) => { @@ -1575,8 +1575,8 @@ impl Repr for Constraint { } } -impl Repr for Verify { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for Verify<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { VerifyRegSubReg(_, ref a, ref b) => { format!("VerifyRegSubReg({}, {})", a.repr(tcx), b.repr(tcx)) @@ -1604,7 +1604,7 @@ fn lookup(values: &Vec, rid: ty::RegionVid) -> ty::Region { } } -impl Repr for VarValue { +impl<'tcx> Repr<'tcx> for VarValue { fn repr(&self, tcx: &ty::ctxt) -> String { match *self { NoValue => format!("NoValue"), @@ -1614,8 +1614,8 @@ impl Repr for VarValue { } } -impl Repr for RegionAndOrigin { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for RegionAndOrigin<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { format!("RegionAndOrigin({},{})", self.region.repr(tcx), self.origin.repr(tcx)) diff --git a/src/librustc/middle/typeck/infer/resolve.rs b/src/librustc/middle/typeck/infer/resolve.rs index 73f595dbedc2e..cf5efd188ed96 100644 --- a/src/librustc/middle/typeck/infer/resolve.rs +++ b/src/librustc/middle/typeck/infer/resolve.rs @@ -50,7 +50,7 @@ use middle::ty::{FloatVar, FloatVid, IntVar, IntVid, RegionVid, TyVar, TyVid}; use middle::ty::{IntType, UintType}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty_fold; use middle::typeck::infer::{fixup_err, fres, InferCtxt}; use middle::typeck::infer::{unresolved_int_ty,unresolved_float_ty,unresolved_ty}; @@ -98,7 +98,7 @@ impl<'a, 'tcx> ty_fold::TypeFolder<'tcx> for ResolveState<'a, 'tcx> { self.infcx.tcx } - fn fold_ty(&mut self, t: ty::t) -> ty::t { + fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { self.resolve_type(t) } @@ -112,10 +112,7 @@ impl<'a, 'tcx> ResolveState<'a, 'tcx> { (self.modes & mode) == mode } - pub fn resolve_type_chk(&mut self, - typ: ty::t) - -> fres - { + pub fn resolve_type_chk(&mut self, typ: Ty<'tcx>) -> fres> { self.err = None; debug!("Resolving {} (modes={:x})", @@ -151,7 +148,7 @@ impl<'a, 'tcx> ResolveState<'a, 'tcx> { } } - pub fn resolve_type(&mut self, typ: ty::t) -> ty::t { + pub fn resolve_type(&mut self, typ: Ty<'tcx>) -> Ty<'tcx> { debug!("resolve_type({})", typ.repr(self.infcx.tcx)); if !ty::type_needs_infer(typ) { @@ -162,7 +159,7 @@ impl<'a, 'tcx> ResolveState<'a, 'tcx> { return typ; } - match ty::get(typ).sty { + match typ.sty { ty::ty_infer(TyVar(vid)) => { self.resolve_ty_var(vid) } @@ -203,7 +200,7 @@ impl<'a, 'tcx> ResolveState<'a, 'tcx> { self.infcx.region_vars.resolve_var(rid) } - pub fn resolve_ty_var(&mut self, vid: TyVid) -> ty::t { + pub fn resolve_ty_var(&mut self, vid: TyVid) -> Ty<'tcx> { let tcx = self.infcx.tcx; let tv = self.infcx.type_variables.borrow(); match tv.probe(vid) { @@ -219,7 +216,7 @@ impl<'a, 'tcx> ResolveState<'a, 'tcx> { } } - pub fn resolve_int_var(&mut self, vid: IntVid) -> ty::t { + pub fn resolve_int_var(&mut self, vid: IntVid) -> Ty<'tcx> { if !self.should(resolve_ivar) { return ty::mk_int_var(self.infcx.tcx, vid); } @@ -240,7 +237,7 @@ impl<'a, 'tcx> ResolveState<'a, 'tcx> { } } - pub fn resolve_float_var(&mut self, vid: FloatVid) -> ty::t { + pub fn resolve_float_var(&mut self, vid: FloatVid) -> Ty<'tcx> { if !self.should(resolve_fvar) { return ty::mk_float_var(self.infcx.tcx, vid); } diff --git a/src/librustc/middle/typeck/infer/skolemize.rs b/src/librustc/middle/typeck/infer/skolemize.rs index 9458960156ea0..5907a2bb9b61d 100644 --- a/src/librustc/middle/typeck/infer/skolemize.rs +++ b/src/librustc/middle/typeck/infer/skolemize.rs @@ -40,7 +40,7 @@ * it is reasonable to ask what the type inferencer knows "so far". */ -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty_fold; use middle::ty_fold::TypeFoldable; use middle::ty_fold::TypeFolder; @@ -52,7 +52,7 @@ use super::unify::InferCtxtMethodsForSimplyUnifiableTypes; pub struct TypeSkolemizer<'a, 'tcx:'a> { infcx: &'a InferCtxt<'a, 'tcx>, skolemization_count: uint, - skolemization_map: hash_map::HashMap, + skolemization_map: hash_map::HashMap>, } impl<'a, 'tcx> TypeSkolemizer<'a, 'tcx> { @@ -65,10 +65,10 @@ impl<'a, 'tcx> TypeSkolemizer<'a, 'tcx> { } fn skolemize(&mut self, - opt_ty: Option, + opt_ty: Option>, key: ty::InferTy, skolemizer: |uint| -> ty::InferTy) - -> ty::t + -> Ty<'tcx> { match opt_ty { Some(ty) => { return ty.fold_with(self); } @@ -112,8 +112,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeSkolemizer<'a, 'tcx> { } } - fn fold_ty(&mut self, t: ty::t) -> ty::t { - match ty::get(t).sty { + fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { + match t.sty { ty::ty_infer(ty::TyVar(v)) => { self.skolemize(self.infcx.type_variables.borrow().probe(v), ty::TyVar(v), diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index f85cb85ff21a2..65d2a5133936c 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -10,7 +10,7 @@ use middle::ty::{BuiltinBounds}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty::TyVar; use middle::typeck::infer::combine::*; use middle::typeck::infer::{cres, CresCompare}; @@ -40,19 +40,19 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> { fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx> { self.fields.infcx } fn tag(&self) -> String { "sub".to_string() } fn a_is_expected(&self) -> bool { self.fields.a_is_expected } - fn trace(&self) -> TypeTrace { self.fields.trace.clone() } + fn trace(&self) -> TypeTrace<'tcx> { self.fields.trace.clone() } fn equate<'a>(&'a self) -> Equate<'a, 'tcx> { Equate(self.fields.clone()) } fn sub<'a>(&'a self) -> Sub<'a, 'tcx> { Sub(self.fields.clone()) } fn lub<'a>(&'a self) -> Lub<'a, 'tcx> { Lub(self.fields.clone()) } fn glb<'a>(&'a self) -> Glb<'a, 'tcx> { Glb(self.fields.clone()) } - fn contratys(&self, a: ty::t, b: ty::t) -> cres { + fn contratys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> { Sub(self.fields.switch_expected()).tys(b, a) } fn contraregions(&self, a: ty::Region, b: ty::Region) - -> cres { + -> cres<'tcx, ty::Region> { let opp = CombineFields { a_is_expected: !self.fields.a_is_expected, ..self.fields.clone() @@ -60,7 +60,7 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> { Sub(opp).regions(b, a) } - fn regions(&self, a: ty::Region, b: ty::Region) -> cres { + fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region> { debug!("{}.regions({}, {})", self.tag(), a.repr(self.tcx()), @@ -69,7 +69,7 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> { Ok(a) } - fn mts(&self, a: &ty::mt, b: &ty::mt) -> cres { + fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> { debug!("mts({} <: {})", a.repr(self.tcx()), b.repr(self.tcx())); @@ -93,20 +93,20 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> { Ok(*a) // return is meaningless in sub, just return *a } - fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres { + fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> { self.lub().fn_styles(a, b).compare(b, || { ty::terr_fn_style_mismatch(expected_found(self, a, b)) }) } - fn oncenesses(&self, a: Onceness, b: Onceness) -> cres { + fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<'tcx, Onceness> { self.lub().oncenesses(a, b).compare(b, || { ty::terr_onceness_mismatch(expected_found(self, a, b)) }) } fn builtin_bounds(&self, a: BuiltinBounds, b: BuiltinBounds) - -> cres { + -> cres<'tcx, BuiltinBounds> { // More bounds is a subtype of fewer bounds. // // e.g., fn:Copy() <: fn(), because the former is a function @@ -119,7 +119,7 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> { } } - fn tys(&self, a: ty::t, b: ty::t) -> cres { + fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> { debug!("{}.tys({}, {})", self.tag(), a.repr(self.tcx()), b.repr(self.tcx())); if a == b { return Ok(a); } @@ -127,7 +127,7 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> { let infcx = self.fields.infcx; let a = infcx.type_variables.borrow().replace_if_possible(a); let b = infcx.type_variables.borrow().replace_if_possible(b); - match (&ty::get(a).sty, &ty::get(b).sty) { + match (&a.sty, &b.sty) { (&ty::ty_infer(TyVar(a_id)), &ty::ty_infer(TyVar(b_id))) => { infcx.type_variables .borrow_mut() @@ -155,11 +155,13 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> { } } - fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres { + fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) + -> cres<'tcx, ty::FnSig<'tcx>> { self.higher_ranked_sub(a, b) } - fn trait_refs(&self, a: &ty::TraitRef, b: &ty::TraitRef) -> cres { + fn trait_refs(&self, a: &ty::TraitRef<'tcx>, b: &ty::TraitRef<'tcx>) + -> cres<'tcx, ty::TraitRef<'tcx>> { self.higher_ranked_sub(a, b) } } diff --git a/src/librustc/middle/typeck/infer/type_variable.rs b/src/librustc/middle/typeck/infer/type_variable.rs index 4bb2cc2ca5cf4..f7f7389602f82 100644 --- a/src/librustc/middle/typeck/infer/type_variable.rs +++ b/src/librustc/middle/typeck/infer/type_variable.rs @@ -12,21 +12,21 @@ pub use self::RelationDir::*; use self::TypeVariableValue::*; use self::UndoEntry::*; -use middle::ty; +use middle::ty::{mod, Ty}; use std::mem; use util::snapshot_vec as sv; -pub struct TypeVariableTable { - values: sv::SnapshotVec, +pub struct TypeVariableTable<'tcx> { + values: sv::SnapshotVec,UndoEntry,Delegate>, } -struct TypeVariableData { - value: TypeVariableValue, +struct TypeVariableData<'tcx> { + value: TypeVariableValue<'tcx>, diverging: bool } -enum TypeVariableValue { - Known(ty::t), +enum TypeVariableValue<'tcx> { + Known(Ty<'tcx>), Bounded(Vec), } @@ -59,8 +59,8 @@ impl RelationDir { } } -impl TypeVariableTable { - pub fn new() -> TypeVariableTable { +impl<'tcx> TypeVariableTable<'tcx> { + pub fn new() -> TypeVariableTable<'tcx> { TypeVariableTable { values: sv::SnapshotVec::new(Delegate) } } @@ -89,8 +89,8 @@ impl TypeVariableTable { pub fn instantiate_and_push( &mut self, vid: ty::TyVid, - ty: ty::t, - stack: &mut Vec<(ty::t, RelationDir, ty::TyVid)>) + ty: Ty<'tcx>, + stack: &mut Vec<(Ty<'tcx>, RelationDir, ty::TyVid)>) { /*! * Instantiates `vid` with the type `ty` and then pushes an @@ -125,15 +125,15 @@ impl TypeVariableTable { ty::TyVid { index: index } } - pub fn probe(&self, vid: ty::TyVid) -> Option { + pub fn probe(&self, vid: ty::TyVid) -> Option> { match self.values.get(vid.index).value { Bounded(..) => None, Known(t) => Some(t) } } - pub fn replace_if_possible(&self, t: ty::t) -> ty::t { - match ty::get(t).sty { + pub fn replace_if_possible(&self, t: Ty<'tcx>) -> Ty<'tcx> { + match t.sty { ty::ty_infer(ty::TyVar(v)) => { match self.probe(v) { None => t, @@ -157,7 +157,7 @@ impl TypeVariableTable { } } -impl sv::SnapshotVecDelegate for Delegate { +impl<'tcx> sv::SnapshotVecDelegate,UndoEntry> for Delegate { fn reverse(&mut self, values: &mut Vec, action: UndoEntry) { diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/typeck/infer/unify.rs index eaf1d2805b01e..fcf042b3f8b80 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/typeck/infer/unify.rs @@ -13,7 +13,7 @@ pub use self::VarValue::*; use std::kinds::marker; use middle::ty::{expected_found, IntVarValue}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::infer::{uok, ures}; use middle::typeck::infer::InferCtxt; use std::cell::RefCell; @@ -34,7 +34,7 @@ use util::snapshot_vec as sv; * * Implementations of this trait are at the end of this file. */ -pub trait UnifyKey : Clone + Show + PartialEq + Repr { +pub trait UnifyKey<'tcx, V> : Clone + Show + PartialEq + Repr<'tcx> { fn index(&self) -> uint; fn from_index(u: uint) -> Self; @@ -57,7 +57,7 @@ pub trait UnifyKey : Clone + Show + PartialEq + Repr { * * Implementations of this trait are at the end of this file. */ -pub trait UnifyValue : Clone + Repr + PartialEq { +pub trait UnifyValue<'tcx> : Clone + Repr<'tcx> + PartialEq { } /** @@ -114,7 +114,7 @@ pub struct Delegate; // other type parameter U, and we have no way to say // Option:LatticeValue. -impl> UnificationTable { +impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable { pub fn new() -> UnificationTable { UnificationTable { values: sv::SnapshotVec::new(Delegate), @@ -189,7 +189,7 @@ impl> UnificationTable { } pub fn set(&mut self, - tcx: &ty::ctxt, + tcx: &ty::ctxt<'tcx>, key: K, new_value: VarValue) { @@ -208,7 +208,7 @@ impl> UnificationTable { } pub fn unify(&mut self, - tcx: &ty::ctxt, + tcx: &ty::ctxt<'tcx>, node_a: &Node, node_b: &Node) -> (K, uint) @@ -259,15 +259,15 @@ impl sv::SnapshotVecDelegate,()> for Delegate { * Indicates a type that does not have any kind of subtyping * relationship. */ -pub trait SimplyUnifiable : Clone + PartialEq + Repr { - fn to_type(&self) -> ty::t; - fn to_type_err(expected_found) -> ty::type_err; +pub trait SimplyUnifiable<'tcx> : Clone + PartialEq + Repr<'tcx> { + fn to_type(&self) -> Ty<'tcx>; + fn to_type_err(expected_found) -> ty::type_err<'tcx>; } -pub fn err(a_is_expected: bool, - a_t: V, - b_t: V) - -> ures { +pub fn err<'tcx, V:SimplyUnifiable<'tcx>>(a_is_expected: bool, + a_t: V, + b_t: V) + -> ures<'tcx> { if a_is_expected { Err(SimplyUnifiable::to_type_err( ty::expected_found {expected: a_t, found: b_t})) @@ -277,29 +277,29 @@ pub fn err(a_is_expected: bool, } } -pub trait InferCtxtMethodsForSimplyUnifiableTypes>> { +pub trait InferCtxtMethodsForSimplyUnifiableTypes<'tcx, V:SimplyUnifiable<'tcx>, + K:UnifyKey<'tcx, Option>> { fn simple_vars(&self, a_is_expected: bool, a_id: K, b_id: K) - -> ures; + -> ures<'tcx>; fn simple_var_t(&self, a_is_expected: bool, a_id: K, b: V) - -> ures; - fn probe_var(&self, a_id: K) -> Option; + -> ures<'tcx>; + fn probe_var(&self, a_id: K) -> Option>; } -impl<'a,'tcx,V:SimplyUnifiable,K:UnifyKey>> - InferCtxtMethodsForSimplyUnifiableTypes for InferCtxt<'a, 'tcx> +impl<'a,'tcx,V:SimplyUnifiable<'tcx>,K:UnifyKey<'tcx, Option>> + InferCtxtMethodsForSimplyUnifiableTypes<'tcx, V, K> for InferCtxt<'a, 'tcx> { fn simple_vars(&self, a_is_expected: bool, a_id: K, b_id: K) - -> ures + -> ures<'tcx> { /*! * Unifies two simple keys. Because simple keys do @@ -345,7 +345,7 @@ impl<'a,'tcx,V:SimplyUnifiable,K:UnifyKey>> a_is_expected: bool, a_id: K, b: V) - -> ures + -> ures<'tcx> { /*! * Sets the value of the key `a_id` to `b`. Because @@ -375,7 +375,7 @@ impl<'a,'tcx,V:SimplyUnifiable,K:UnifyKey>> } } - fn probe_var(&self, a_id: K) -> Option { + fn probe_var(&self, a_id: K) -> Option> { let tcx = self.tcx; let table = UnifyKey::unification_table(self); let node_a = table.borrow_mut().get(tcx, a_id); @@ -390,7 +390,7 @@ impl<'a,'tcx,V:SimplyUnifiable,K:UnifyKey>> // Integral type keys -impl UnifyKey> for ty::IntVid { +impl<'tcx> UnifyKey<'tcx, Option> for ty::IntVid { fn index(&self) -> uint { self.index } fn from_index(i: uint) -> ty::IntVid { ty::IntVid { index: i } } @@ -406,24 +406,24 @@ impl UnifyKey> for ty::IntVid { } } -impl SimplyUnifiable for IntVarValue { - fn to_type(&self) -> ty::t { +impl<'tcx> SimplyUnifiable<'tcx> for IntVarValue { + fn to_type(&self) -> Ty<'tcx> { match *self { ty::IntType(i) => ty::mk_mach_int(i), ty::UintType(i) => ty::mk_mach_uint(i), } } - fn to_type_err(err: expected_found) -> ty::type_err { + fn to_type_err(err: expected_found) -> ty::type_err<'tcx> { return ty::terr_int_mismatch(err); } } -impl UnifyValue for Option { } +impl<'tcx> UnifyValue<'tcx> for Option { } // Floating point type keys -impl UnifyKey> for ty::FloatVid { +impl<'tcx> UnifyKey<'tcx, Option> for ty::FloatVid { fn index(&self) -> uint { self.index } fn from_index(i: uint) -> ty::FloatVid { ty::FloatVid { index: i } } @@ -439,21 +439,21 @@ impl UnifyKey> for ty::FloatVid { } } -impl UnifyValue for Option { +impl<'tcx> UnifyValue<'tcx> for Option { } -impl SimplyUnifiable for ast::FloatTy { - fn to_type(&self) -> ty::t { +impl<'tcx> SimplyUnifiable<'tcx> for ast::FloatTy { + fn to_type(&self) -> Ty<'tcx> { ty::mk_mach_float(*self) } - fn to_type_err(err: expected_found) -> ty::type_err { - return ty::terr_float_mismatch(err); + fn to_type_err(err: expected_found) -> ty::type_err<'tcx> { + ty::terr_float_mismatch(err) } } -impl Repr for VarValue { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx, K:Repr<'tcx>, V:Repr<'tcx>> Repr<'tcx> for VarValue { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { Redirect(ref k) => format!("Redirect({})", k.repr(tcx)), Root(ref v, r) => format!("Root({}, {})", v.repr(tcx), r) diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 24d11b25a60f2..ad64537e1533e 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -69,7 +69,7 @@ use middle::def; use middle::resolve; use middle::subst; use middle::subst::VecPerParamSpace; -use middle::ty; +use middle::ty::{mod, Ty}; use session::config; use util::common::time; use util::ppaux::Repr; @@ -97,7 +97,7 @@ pub struct param_index { } #[deriving(Clone, Show)] -pub enum MethodOrigin { +pub enum MethodOrigin<'tcx> { // fully statically resolved method MethodStatic(ast::DefId), @@ -105,20 +105,20 @@ pub enum MethodOrigin { MethodStaticUnboxedClosure(ast::DefId), // method invoked on a type parameter with a bounded trait - MethodTypeParam(MethodParam), + MethodTypeParam(MethodParam<'tcx>), // method invoked on a trait instance - MethodTraitObject(MethodObject), + MethodTraitObject(MethodObject<'tcx>), } // details for a method invoked with a receiver whose type is a type parameter // with a bounded trait. #[deriving(Clone, Show)] -pub struct MethodParam { +pub struct MethodParam<'tcx> { // the precise trait reference that occurs as a bound -- this may // be a supertrait of what the user actually typed. - pub trait_ref: Rc, + pub trait_ref: Rc>, // index of uint in the list of methods for the trait pub method_num: uint, @@ -126,9 +126,9 @@ pub struct MethodParam { // details for a method invoked with a receiver whose type is an object #[deriving(Clone, Show)] -pub struct MethodObject { +pub struct MethodObject<'tcx> { // the (super)trait containing the method to be invoked - pub trait_ref: Rc, + pub trait_ref: Rc>, // the actual base trait id of the object pub object_trait_id: ast::DefId, @@ -144,10 +144,10 @@ pub struct MethodObject { } #[deriving(Clone)] -pub struct MethodCallee { - pub origin: MethodOrigin, - pub ty: ty::t, - pub substs: subst::Substs +pub struct MethodCallee<'tcx> { + pub origin: MethodOrigin<'tcx>, + pub ty: Ty<'tcx>, + pub substs: subst::Substs<'tcx> } /** @@ -177,9 +177,9 @@ pub enum ExprAdjustment { AutoObject } -pub struct TypeAndSubsts { - pub substs: subst::Substs, - pub ty: ty::t, +pub struct TypeAndSubsts<'tcx> { + pub substs: subst::Substs<'tcx>, + pub ty: Ty<'tcx>, } impl MethodCall { @@ -207,21 +207,21 @@ impl MethodCall { // maps from an expression id that corresponds to a method call to the details // of the method to be invoked -pub type MethodMap = RefCell>; +pub type MethodMap<'tcx> = RefCell>>; -pub type vtable_param_res = Vec; +pub type vtable_param_res<'tcx> = Vec>; // Resolutions for bounds of all parameters, left to right, for a given path. -pub type vtable_res = VecPerParamSpace; +pub type vtable_res<'tcx> = VecPerParamSpace>; #[deriving(Clone)] -pub enum vtable_origin { +pub enum vtable_origin<'tcx> { /* Statically known vtable. def_id gives the impl item from whence comes the vtable, and tys are the type substs. vtable_res is the vtable itself. */ - vtable_static(ast::DefId, subst::Substs, vtable_res), + vtable_static(ast::DefId, subst::Substs<'tcx>, vtable_res<'tcx>), /* Dynamic vtable, comes from a parameter that has a bound on it: @@ -248,8 +248,8 @@ pub enum vtable_origin { vtable_error, } -impl Repr for vtable_origin { - fn repr(&self, tcx: &ty::ctxt) -> String { +impl<'tcx> Repr<'tcx> for vtable_origin<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { match *self { vtable_static(def_id, ref tys, ref vtable_res) => { format!("vtable_static({}:{}, {}, {})", @@ -276,7 +276,7 @@ impl Repr for vtable_origin { // For every explicit cast into an object type, maps from the cast // expr to the associated trait ref. -pub type ObjectCastMap = RefCell>>; +pub type ObjectCastMap<'tcx> = RefCell>>>; pub struct CrateCtxt<'a, 'tcx: 'a> { // A mapping from method call sites to traits that have that method. @@ -285,15 +285,15 @@ pub struct CrateCtxt<'a, 'tcx: 'a> { } // Functions that write types into the node type table -pub fn write_ty_to_tcx(tcx: &ty::ctxt, node_id: ast::NodeId, ty: ty::t) { +pub fn write_ty_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>, node_id: ast::NodeId, ty: Ty<'tcx>) { debug!("write_ty_to_tcx({}, {})", node_id, ppaux::ty_to_string(tcx, ty)); assert!(!ty::type_needs_infer(ty)); tcx.node_types.borrow_mut().insert(node_id, ty); } -pub fn write_substs_to_tcx(tcx: &ty::ctxt, - node_id: ast::NodeId, - item_substs: ty::ItemSubsts) { +pub fn write_substs_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>, + node_id: ast::NodeId, + item_substs: ty::ItemSubsts<'tcx>) { if !item_substs.is_noop() { debug!("write_substs_to_tcx({}, {})", node_id, @@ -318,7 +318,7 @@ pub fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId) lookup_def_tcx(ccx.tcx, sp, id) } -pub fn no_params(t: ty::t) -> ty::Polytype { +pub fn no_params<'tcx>(t: Ty<'tcx>) -> ty::Polytype<'tcx> { ty::Polytype { generics: ty::Generics {types: VecPerParamSpace::empty(), regions: VecPerParamSpace::empty()}, @@ -326,14 +326,14 @@ pub fn no_params(t: ty::t) -> ty::Polytype { } } -pub fn require_same_types(tcx: &ty::ctxt, - maybe_infcx: Option<&infer::InferCtxt>, - t1_is_expected: bool, - span: Span, - t1: ty::t, - t2: ty::t, - msg: || -> String) - -> bool { +pub fn require_same_types<'a, 'tcx>(tcx: &ty::ctxt<'tcx>, + maybe_infcx: Option<&infer::InferCtxt<'a, 'tcx>>, + t1_is_expected: bool, + span: Span, + t1: Ty<'tcx>, + t2: Ty<'tcx>, + msg: || -> String) + -> bool { let result = match maybe_infcx { None => { let infcx = infer::new_infer_ctxt(tcx); @@ -363,7 +363,7 @@ fn check_main_fn_ty(ccx: &CrateCtxt, main_span: Span) { let tcx = ccx.tcx; let main_t = ty::node_id_to_type(tcx, main_id); - match ty::get(main_t).sty { + match main_t.sty { ty::ty_bare_fn(..) => { match tcx.map.find(main_id) { Some(ast_map::NodeItem(it)) => { @@ -410,7 +410,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt, start_span: Span) { let tcx = ccx.tcx; let start_t = ty::node_id_to_type(tcx, start_id); - match ty::get(start_t).sty { + match start_t.sty { ty::ty_bare_fn(_) => { match tcx.map.find(start_id) { Some(ast_map::NodeItem(it)) => { diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index 76250d44baf6e..b20ab0b054880 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -199,7 +199,7 @@ use arena::Arena; use middle::resolve_lifetime as rl; use middle::subst; use middle::subst::{ParamSpace, FnSpace, TypeSpace, SelfSpace, VecPerParamSpace}; -use middle::ty; +use middle::ty::{mod, Ty}; use std::fmt; use std::rc::Rc; use syntax::ast; @@ -725,11 +725,11 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { /// Adds constraints appropriate for an instance of `ty` appearing /// in a context with ambient variance `variance` fn add_constraints_from_ty(&mut self, - ty: ty::t, + ty: Ty<'tcx>, variance: VarianceTermPtr<'a>) { debug!("add_constraints_from_ty(ty={})", ty.repr(self.tcx())); - match ty::get(ty).sty { + match ty.sty { ty::ty_bool | ty::ty_char | ty::ty_int(_) | ty::ty_uint(_) | ty::ty_float(_) | ty::ty_str => { @@ -854,9 +854,9 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { /// object, etc) appearing in a context with ambient variance `variance` fn add_constraints_from_substs(&mut self, def_id: ast::DefId, - type_param_defs: &[ty::TypeParameterDef], + type_param_defs: &[ty::TypeParameterDef<'tcx>], region_param_defs: &[ty::RegionParameterDef], - substs: &subst::Substs, + substs: &subst::Substs<'tcx>, variance: VarianceTermPtr<'a>) { debug!("add_constraints_from_substs(def_id={})", def_id); @@ -882,7 +882,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { /// Adds constraints appropriate for a function with signature /// `sig` appearing in a context with ambient variance `variance` fn add_constraints_from_sig(&mut self, - sig: &ty::FnSig, + sig: &ty::FnSig<'tcx>, variance: VarianceTermPtr<'a>) { let contra = self.contravariant(variance); for &input in sig.inputs.iter() { @@ -929,7 +929,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { /// Adds constraints appropriate for a mutability-type pair /// appearing in a context with ambient variance `variance` fn add_constraints_from_mt(&mut self, - mt: &ty::mt, + mt: &ty::mt<'tcx>, variance: VarianceTermPtr<'a>) { match mt.mutbl { ast::MutMutable => { diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 4ce783b37b737..76055372a6149 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -16,7 +16,7 @@ use middle::ty::{BoundRegion, BrAnon, BrNamed}; use middle::ty::{ReEarlyBound, BrFresh, ctxt}; use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region, ReEmpty}; use middle::ty::{ReSkolemized, ReVar, BrEnv}; -use middle::ty::{mt, t, ParamTy}; +use middle::ty::{mt, Ty, ParamTy}; use middle::ty::{ty_bool, ty_char, ty_struct, ty_enum}; use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn, ty_closure}; use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup, ty_open}; @@ -37,13 +37,13 @@ use syntax::{ast, ast_util}; use syntax::owned_slice::OwnedSlice; /// Produces a string suitable for debugging output. -pub trait Repr for Sized? { - fn repr(&self, tcx: &ctxt) -> String; +pub trait Repr<'tcx> for Sized? { + fn repr(&self, tcx: &ctxt<'tcx>) -> String; } /// Produces a string suitable for showing to the user. -pub trait UserString { - fn user_string(&self, tcx: &ctxt) -> String; +pub trait UserString<'tcx> { + fn user_string(&self, tcx: &ctxt<'tcx>) -> String; } pub fn note_and_explain_region(cx: &ctxt, @@ -231,7 +231,7 @@ pub fn mutability_to_string(m: ast::Mutability) -> String { } } -pub fn mt_to_string(cx: &ctxt, m: &mt) -> String { +pub fn mt_to_string<'tcx>(cx: &ctxt<'tcx>, m: &mt<'tcx>) -> String { format!("{}{}", mutability_to_string(m.mutbl), ty_to_string(cx, m.ty)) @@ -251,21 +251,22 @@ pub fn vec_map_to_string(ts: &[T], f: |t: &T| -> String) -> String { format!("[{}]", tstrs.connect(", ")) } -pub fn fn_sig_to_string(cx: &ctxt, typ: &ty::FnSig) -> String { +pub fn fn_sig_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::FnSig<'tcx>) -> String { format!("fn{} -> {}", typ.inputs.repr(cx), typ.output.repr(cx)) } -pub fn trait_ref_to_string(cx: &ctxt, trait_ref: &ty::TraitRef) -> String { +pub fn trait_ref_to_string<'tcx>(cx: &ctxt<'tcx>, + trait_ref: &ty::TraitRef<'tcx>) -> String { trait_ref.user_string(cx).to_string() } -pub fn ty_to_string(cx: &ctxt, typ: t) -> String { - fn bare_fn_to_string(cx: &ctxt, - fn_style: ast::FnStyle, - abi: abi::Abi, - ident: Option, - sig: &ty::FnSig) - -> String { +pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String { + fn bare_fn_to_string<'tcx>(cx: &ctxt<'tcx>, + fn_style: ast::FnStyle, + abi: abi::Abi, + ident: Option, + sig: &ty::FnSig<'tcx>) + -> String { let mut s = String::new(); match fn_style { ast::NormalFn => {} @@ -294,7 +295,7 @@ pub fn ty_to_string(cx: &ctxt, typ: t) -> String { s } - fn closure_to_string(cx: &ctxt, cty: &ty::ClosureTy) -> String { + fn closure_to_string<'tcx>(cx: &ctxt<'tcx>, cty: &ty::ClosureTy<'tcx>) -> String { let mut s = String::new(); match cty.store { @@ -334,12 +335,12 @@ pub fn ty_to_string(cx: &ctxt, typ: t) -> String { s } - fn push_sig_to_string(cx: &ctxt, - s: &mut String, - bra: char, - ket: char, - sig: &ty::FnSig, - bounds: &str) { + fn push_sig_to_string<'tcx>(cx: &ctxt<'tcx>, + s: &mut String, + bra: char, + ket: char, + sig: &ty::FnSig<'tcx>, + bounds: &str) { s.push(bra); let strs = sig.inputs .iter() @@ -382,7 +383,7 @@ pub fn ty_to_string(cx: &ctxt, typ: t) -> String { } // pretty print the structural type representation: - match ty::get(typ).sty { + match typ.sty { ty_bool => "bool".to_string(), ty_char => "char".to_string(), ty_int(t) => ast_util::int_ty_to_string(t, None).to_string(), @@ -476,11 +477,11 @@ pub fn explicit_self_category_to_str(category: &ty::ExplicitSelfCategory) } } -pub fn parameterized(cx: &ctxt, - base: &str, - substs: &subst::Substs, - generics: &ty::Generics) - -> String +pub fn parameterized<'tcx>(cx: &ctxt<'tcx>, + base: &str, + substs: &subst::Substs<'tcx>, + generics: &ty::Generics<'tcx>) + -> String { if cx.sess.verbose() { if substs.is_noop() { @@ -539,7 +540,7 @@ pub fn parameterized(cx: &ctxt, } } -pub fn ty_to_short_str(cx: &ctxt, typ: t) -> String { +pub fn ty_to_short_str<'tcx>(cx: &ctxt<'tcx>, typ: Ty<'tcx>) -> String { let mut s = typ.repr(cx).to_string(); if s.len() >= 32u { s = s.as_slice().slice(0u, 32u).to_string(); @@ -547,8 +548,8 @@ pub fn ty_to_short_str(cx: &ctxt, typ: t) -> String { return s; } -impl Repr for Option { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Option { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { match self { &None => "None".to_string(), &Some(ref t) => t.repr(tcx), @@ -556,14 +557,14 @@ impl Repr for Option { } } -impl Repr for P { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for P { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { (*self).repr(tcx) } } -impl Repr for Result { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx,T:Repr<'tcx>,U:Repr<'tcx>> Repr<'tcx> for Result { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { match self { &Ok(ref t) => t.repr(tcx), &Err(ref u) => format!("Err({})", u.repr(tcx)) @@ -571,70 +572,70 @@ impl Repr for Result { } } -impl Repr for () { +impl<'tcx> Repr<'tcx> for () { fn repr(&self, _tcx: &ctxt) -> String { "()".to_string() } } -impl<'a, Sized? T:Repr> Repr for &'a T { - fn repr(&self, tcx: &ctxt) -> String { +impl<'a, 'tcx, Sized? T:Repr<'tcx>> Repr<'tcx> for &'a T { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { Repr::repr(*self, tcx) } } -impl Repr for Rc { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Rc { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { (&**self).repr(tcx) } } -impl Repr for Box { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Box { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { (&**self).repr(tcx) } } -fn repr_vec(tcx: &ctxt, v: &[T]) -> String { +fn repr_vec<'tcx, T:Repr<'tcx>>(tcx: &ctxt<'tcx>, v: &[T]) -> String { vec_map_to_string(v, |t| t.repr(tcx)) } -impl Repr for [T] { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for [T] { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { repr_vec(tcx, self) } } -impl Repr for OwnedSlice { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for OwnedSlice { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { repr_vec(tcx, self.as_slice()) } } // This is necessary to handle types like Option<~[T]>, for which // autoderef cannot convert the &[T] handler -impl Repr for Vec { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Vec { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { repr_vec(tcx, self.as_slice()) } } -impl UserString for Vec { - fn user_string(&self, tcx: &ctxt) -> String { +impl<'tcx, T:UserString<'tcx>> UserString<'tcx> for Vec { + fn user_string(&self, tcx: &ctxt<'tcx>) -> String { let strs: Vec = self.iter().map(|t| t.user_string(tcx)).collect(); strs.connect(", ") } } -impl Repr for def::Def { +impl<'tcx> Repr<'tcx> for def::Def { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", *self) } } -impl Repr for ty::TypeParameterDef { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::TypeParameterDef<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("TypeParameterDef({}, {}, {}/{})", self.def_id, self.bounds.repr(tcx), @@ -643,7 +644,7 @@ impl Repr for ty::TypeParameterDef { } } -impl Repr for ty::RegionParameterDef { +impl<'tcx> Repr<'tcx> for ty::RegionParameterDef { fn repr(&self, tcx: &ctxt) -> String { format!("RegionParameterDef(name={}, def_id={}, bounds={})", token::get_name(self.name), @@ -652,28 +653,28 @@ impl Repr for ty::RegionParameterDef { } } -impl Repr for ty::t { - fn repr(&self, tcx: &ctxt) -> String { - ty_to_string(tcx, *self) +impl<'tcx> Repr<'tcx> for ty::TyS<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { + ty_to_string(tcx, self) } } -impl Repr for ty::mt { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::mt<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { mt_to_string(tcx, self) } } -impl Repr for subst::Substs { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for subst::Substs<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("Substs[types={}, regions={}]", self.types.repr(tcx), self.regions.repr(tcx)) } } -impl Repr for subst::VecPerParamSpace { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for subst::VecPerParamSpace { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("[{};{};{};{}]", self.get_slice(subst::TypeSpace).repr(tcx), self.get_slice(subst::SelfSpace).repr(tcx), @@ -682,13 +683,13 @@ impl Repr for subst::VecPerParamSpace { } } -impl Repr for ty::ItemSubsts { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::ItemSubsts<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("ItemSubsts({})", self.substs.repr(tcx)) } } -impl Repr for subst::RegionSubsts { +impl<'tcx> Repr<'tcx> for subst::RegionSubsts { fn repr(&self, tcx: &ctxt) -> String { match *self { subst::ErasedRegions => "erased".to_string(), @@ -697,7 +698,7 @@ impl Repr for subst::RegionSubsts { } } -impl Repr for ty::BuiltinBounds { +impl<'tcx> Repr<'tcx> for ty::BuiltinBounds { fn repr(&self, _tcx: &ctxt) -> String { let mut res = Vec::new(); for b in self.iter() { @@ -712,14 +713,14 @@ impl Repr for ty::BuiltinBounds { } } -impl Repr for ty::ExistentialBounds { +impl<'tcx> Repr<'tcx> for ty::ExistentialBounds { fn repr(&self, tcx: &ctxt) -> String { self.user_string(tcx) } } -impl Repr for ty::ParamBounds { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::ParamBounds<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { let mut res = Vec::new(); res.push(self.builtin_bounds.repr(tcx)); for t in self.trait_bounds.iter() { @@ -729,8 +730,8 @@ impl Repr for ty::ParamBounds { } } -impl Repr for ty::TraitRef { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::TraitRef<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { // when printing out the debug representation, we don't need // to enumerate the `for<...>` etc because the debruijn index // tells you everything you need to know. @@ -742,8 +743,8 @@ impl Repr for ty::TraitRef { } } -impl Repr for ty::TraitDef { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::TraitDef<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("TraitDef(generics={}, bounds={}, trait_ref={})", self.generics.repr(tcx), self.bounds.repr(tcx), @@ -751,7 +752,7 @@ impl Repr for ty::TraitDef { } } -impl Repr for ast::TraitItem { +impl<'tcx> Repr<'tcx> for ast::TraitItem { fn repr(&self, _tcx: &ctxt) -> String { match *self { ast::RequiredMethod(ref data) => format!("RequiredMethod({}, id={})", @@ -764,43 +765,43 @@ impl Repr for ast::TraitItem { } } -impl Repr for ast::Expr { +impl<'tcx> Repr<'tcx> for ast::Expr { fn repr(&self, _tcx: &ctxt) -> String { format!("expr({}: {})", self.id, pprust::expr_to_string(self)) } } -impl Repr for ast::Path { +impl<'tcx> Repr<'tcx> for ast::Path { fn repr(&self, _tcx: &ctxt) -> String { format!("path({})", pprust::path_to_string(self)) } } -impl UserString for ast::Path { +impl<'tcx> UserString<'tcx> for ast::Path { fn user_string(&self, _tcx: &ctxt) -> String { pprust::path_to_string(self) } } -impl Repr for ast::Ty { +impl<'tcx> Repr<'tcx> for ast::Ty { fn repr(&self, _tcx: &ctxt) -> String { format!("type({})", pprust::ty_to_string(self)) } } -impl Repr for ast::Item { +impl<'tcx> Repr<'tcx> for ast::Item { fn repr(&self, tcx: &ctxt) -> String { format!("item({})", tcx.map.node_to_string(self.id)) } } -impl Repr for ast::Lifetime { +impl<'tcx> Repr<'tcx> for ast::Lifetime { fn repr(&self, _tcx: &ctxt) -> String { format!("lifetime({}: {})", self.id, pprust::lifetime_to_string(self)) } } -impl Repr for ast::Stmt { +impl<'tcx> Repr<'tcx> for ast::Stmt { fn repr(&self, _tcx: &ctxt) -> String { format!("stmt({}: {})", ast_util::stmt_id(self), @@ -808,13 +809,13 @@ impl Repr for ast::Stmt { } } -impl Repr for ast::Pat { +impl<'tcx> Repr<'tcx> for ast::Pat { fn repr(&self, _tcx: &ctxt) -> String { format!("pat({}: {})", self.id, pprust::pat_to_string(self)) } } -impl Repr for ty::BoundRegion { +impl<'tcx> Repr<'tcx> for ty::BoundRegion { fn repr(&self, tcx: &ctxt) -> String { match *self { ty::BrAnon(id) => format!("BrAnon({})", id), @@ -827,7 +828,7 @@ impl Repr for ty::BoundRegion { } } -impl Repr for ty::Region { +impl<'tcx> Repr<'tcx> for ty::Region { fn repr(&self, tcx: &ctxt) -> String { match *self { ty::ReEarlyBound(id, space, index, name) => { @@ -869,13 +870,13 @@ impl Repr for ty::Region { } } -impl UserString for ty::Region { +impl<'tcx> UserString<'tcx> for ty::Region { fn user_string(&self, tcx: &ctxt) -> String { region_to_string(tcx, "", false, *self) } } -impl Repr for ty::FreeRegion { +impl<'tcx> Repr<'tcx> for ty::FreeRegion { fn repr(&self, tcx: &ctxt) -> String { format!("ReFree({}, {})", self.scope_id, @@ -883,7 +884,7 @@ impl Repr for ty::FreeRegion { } } -impl Repr for ast::DefId { +impl<'tcx> Repr<'tcx> for ast::DefId { fn repr(&self, tcx: &ctxt) -> String { // Unfortunately, there seems to be no way to attempt to print // a path for a def-id, so I'll just make a best effort for now @@ -908,31 +909,31 @@ impl Repr for ast::DefId { } } -impl Repr for ty::Polytype { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::Polytype<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("Polytype {{generics: {}, ty: {}}}", self.generics.repr(tcx), self.ty.repr(tcx)) } } -impl Repr for ty::Generics { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::Generics<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("Generics(types: {}, regions: {})", self.types.repr(tcx), self.regions.repr(tcx)) } } -impl Repr for ty::GenericBounds { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::GenericBounds<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("GenericBounds(types: {}, regions: {})", self.types.repr(tcx), self.regions.repr(tcx)) } } -impl Repr for ty::ItemVariances { +impl<'tcx> Repr<'tcx> for ty::ItemVariances { fn repr(&self, tcx: &ctxt) -> String { format!("ItemVariances(types={}, \ regions={})", @@ -941,7 +942,7 @@ impl Repr for ty::ItemVariances { } } -impl Repr for ty::Variance { +impl<'tcx> Repr<'tcx> for ty::Variance { fn repr(&self, _: &ctxt) -> String { // The first `.to_string()` returns a &'static str (it is not an implementation // of the ToString trait). Because of that, we need to call `.to_string()` again @@ -951,8 +952,8 @@ impl Repr for ty::Variance { } } -impl Repr for ty::Method { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::Method<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("method(name: {}, generics: {}, fty: {}, \ explicit_self: {}, vis: {}, def_id: {})", self.name.repr(tcx), @@ -964,38 +965,38 @@ impl Repr for ty::Method { } } -impl Repr for ast::Name { +impl<'tcx> Repr<'tcx> for ast::Name { fn repr(&self, _tcx: &ctxt) -> String { token::get_name(*self).get().to_string() } } -impl UserString for ast::Name { +impl<'tcx> UserString<'tcx> for ast::Name { fn user_string(&self, _tcx: &ctxt) -> String { token::get_name(*self).get().to_string() } } -impl Repr for ast::Ident { +impl<'tcx> Repr<'tcx> for ast::Ident { fn repr(&self, _tcx: &ctxt) -> String { token::get_ident(*self).get().to_string() } } -impl Repr for ast::ExplicitSelf_ { +impl<'tcx> Repr<'tcx> for ast::ExplicitSelf_ { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", *self) } } -impl Repr for ast::Visibility { +impl<'tcx> Repr<'tcx> for ast::Visibility { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", *self) } } -impl Repr for ty::BareFnTy { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::BareFnTy<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("BareFnTy {{fn_style: {}, abi: {}, sig: {}}}", self.fn_style, self.abi.to_string(), @@ -1003,14 +1004,14 @@ impl Repr for ty::BareFnTy { } } -impl Repr for ty::FnSig { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::FnSig<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { fn_sig_to_string(tcx, self) } } -impl Repr for ty::FnOutput { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for ty::FnOutput<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { match *self { ty::FnConverging(ty) => format!("FnConverging({0})", ty.repr(tcx)), @@ -1020,8 +1021,8 @@ impl Repr for ty::FnOutput { } } -impl Repr for typeck::MethodCallee { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for typeck::MethodCallee<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("MethodCallee {{origin: {}, ty: {}, {}}}", self.origin.repr(tcx), self.ty.repr(tcx), @@ -1029,8 +1030,8 @@ impl Repr for typeck::MethodCallee { } } -impl Repr for typeck::MethodOrigin { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for typeck::MethodOrigin<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { match self { &typeck::MethodStatic(def_id) => { format!("MethodStatic({})", def_id.repr(tcx)) @@ -1048,16 +1049,16 @@ impl Repr for typeck::MethodOrigin { } } -impl Repr for typeck::MethodParam { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for typeck::MethodParam<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("MethodParam({},{})", self.trait_ref.repr(tcx), self.method_num) } } -impl Repr for typeck::MethodObject { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx> Repr<'tcx> for typeck::MethodObject<'tcx> { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("MethodObject({},{},{})", self.trait_ref.repr(tcx), self.method_num, @@ -1065,19 +1066,19 @@ impl Repr for typeck::MethodObject { } } -impl Repr for ty::TraitStore { +impl<'tcx> Repr<'tcx> for ty::TraitStore { fn repr(&self, tcx: &ctxt) -> String { trait_store_to_string(tcx, *self) } } -impl Repr for ty::BuiltinBound { +impl<'tcx> Repr<'tcx> for ty::BuiltinBound { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", *self) } } -impl UserString for ty::BuiltinBound { +impl<'tcx> UserString<'tcx> for ty::BuiltinBound { fn user_string(&self, _tcx: &ctxt) -> String { match *self { ty::BoundSend => "Send".to_string(), @@ -1088,21 +1089,21 @@ impl UserString for ty::BuiltinBound { } } -impl Repr for Span { +impl<'tcx> Repr<'tcx> for Span { fn repr(&self, tcx: &ctxt) -> String { tcx.sess.codemap().span_to_string(*self).to_string() } } -impl UserString for Rc { - fn user_string(&self, tcx: &ctxt) -> String { +impl<'tcx, A:UserString<'tcx>> UserString<'tcx> for Rc { + fn user_string(&self, tcx: &ctxt<'tcx>) -> String { let this: &A = &**self; this.user_string(tcx) } } -impl UserString for ty::ParamBounds { - fn user_string(&self, tcx: &ctxt) -> String { +impl<'tcx> UserString<'tcx> for ty::ParamBounds<'tcx> { + fn user_string(&self, tcx: &ctxt<'tcx>) -> String { let mut result = Vec::new(); let s = self.builtin_bounds.user_string(tcx); if !s.is_empty() { @@ -1115,7 +1116,7 @@ impl UserString for ty::ParamBounds { } } -impl UserString for ty::ExistentialBounds { +impl<'tcx> UserString<'tcx> for ty::ExistentialBounds { fn user_string(&self, tcx: &ctxt) -> String { if self.builtin_bounds.contains(&ty::BoundSend) && self.region_bound == ty::ReStatic @@ -1138,7 +1139,7 @@ impl UserString for ty::ExistentialBounds { } } -impl UserString for ty::BuiltinBounds { +impl<'tcx> UserString<'tcx> for ty::BuiltinBounds { fn user_string(&self, tcx: &ctxt) -> String { self.iter() .map(|bb| bb.user_string(tcx)) @@ -1148,8 +1149,8 @@ impl UserString for ty::BuiltinBounds { } } -impl UserString for ty::TraitRef { - fn user_string(&self, tcx: &ctxt) -> String { +impl<'tcx> UserString<'tcx> for ty::TraitRef<'tcx> { + fn user_string(&self, tcx: &ctxt<'tcx>) -> String { // Replace any anonymous late-bound regions with named // variants, using gensym'd identifiers, so that we can // clearly differentiate between named and unnamed regions in @@ -1188,31 +1189,31 @@ impl UserString for ty::TraitRef { } } -impl UserString for ty::t { - fn user_string(&self, tcx: &ctxt) -> String { +impl<'tcx> UserString<'tcx> for Ty<'tcx> { + fn user_string(&self, tcx: &ctxt<'tcx>) -> String { ty_to_string(tcx, *self) } } -impl UserString for ast::Ident { +impl<'tcx> UserString<'tcx> for ast::Ident { fn user_string(&self, _tcx: &ctxt) -> String { token::get_name(self.name).get().to_string() } } -impl Repr for abi::Abi { +impl<'tcx> Repr<'tcx> for abi::Abi { fn repr(&self, _tcx: &ctxt) -> String { self.to_string() } } -impl UserString for abi::Abi { +impl<'tcx> UserString<'tcx> for abi::Abi { fn user_string(&self, _tcx: &ctxt) -> String { self.to_string() } } -impl Repr for ty::UpvarId { +impl<'tcx> Repr<'tcx> for ty::UpvarId { fn repr(&self, tcx: &ctxt) -> String { format!("UpvarId({};`{}`;{})", self.var_id, @@ -1221,19 +1222,19 @@ impl Repr for ty::UpvarId { } } -impl Repr for ast::Mutability { +impl<'tcx> Repr<'tcx> for ast::Mutability { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", *self) } } -impl Repr for ty::BorrowKind { +impl<'tcx> Repr<'tcx> for ty::BorrowKind { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", *self) } } -impl Repr for ty::UpvarBorrow { +impl<'tcx> Repr<'tcx> for ty::UpvarBorrow { fn repr(&self, tcx: &ctxt) -> String { format!("UpvarBorrow({}, {})", self.kind.repr(tcx), @@ -1241,62 +1242,62 @@ impl Repr for ty::UpvarBorrow { } } -impl Repr for ty::IntVid { +impl<'tcx> Repr<'tcx> for ty::IntVid { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", self) } } -impl Repr for ty::FloatVid { +impl<'tcx> Repr<'tcx> for ty::FloatVid { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", self) } } -impl Repr for ty::RegionVid { +impl<'tcx> Repr<'tcx> for ty::RegionVid { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", self) } } -impl Repr for ty::TyVid { +impl<'tcx> Repr<'tcx> for ty::TyVid { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", self) } } -impl Repr for ty::IntVarValue { +impl<'tcx> Repr<'tcx> for ty::IntVarValue { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", *self) } } -impl Repr for ast::IntTy { +impl<'tcx> Repr<'tcx> for ast::IntTy { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", *self) } } -impl Repr for ast::UintTy { +impl<'tcx> Repr<'tcx> for ast::UintTy { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", *self) } } -impl Repr for ast::FloatTy { +impl<'tcx> Repr<'tcx> for ast::FloatTy { fn repr(&self, _tcx: &ctxt) -> String { format!("{}", *self) } } -impl Repr for ty::ExplicitSelfCategory { +impl<'tcx> Repr<'tcx> for ty::ExplicitSelfCategory { fn repr(&self, _: &ctxt) -> String { explicit_self_category_to_str(self).to_string() } } -impl Repr for regionmanip::WfConstraint { +impl<'tcx> Repr<'tcx> for regionmanip::WfConstraint<'tcx> { fn repr(&self, tcx: &ctxt) -> String { match *self { regionmanip::RegionSubRegionConstraint(_, r_a, r_b) => { @@ -1314,7 +1315,7 @@ impl Repr for regionmanip::WfConstraint { } } -impl UserString for ParamTy { +impl<'tcx> UserString<'tcx> for ParamTy { fn user_string(&self, tcx: &ctxt) -> String { let id = self.idx; let did = self.def_id; @@ -1329,22 +1330,22 @@ impl UserString for ParamTy { } } -impl Repr for ParamTy { +impl<'tcx> Repr<'tcx> for ParamTy { fn repr(&self, tcx: &ctxt) -> String { let ident = self.user_string(tcx); format!("{}/{}.{}", ident, self.space, self.idx) } } -impl Repr for (A,B) { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx, A:Repr<'tcx>, B:Repr<'tcx>> Repr<'tcx> for (A,B) { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { let &(ref a, ref b) = self; format!("({},{})", a.repr(tcx), b.repr(tcx)) } } -impl Repr for ty::Binder { - fn repr(&self, tcx: &ctxt) -> String { +impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for ty::Binder { + fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("Binder({})", self.value.repr(tcx)) } } diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index d5d488e8965a3..d27a338b308c7 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -22,7 +22,7 @@ use metadata::common::LinkMeta; use metadata::{encoder, cstore, filesearch, csearch, creader}; use trans::context::CrateContext; use trans::common::gensym_name; -use middle::ty; +use middle::ty::{mod, Ty}; use util::common::time; use util::ppaux; use util::sha2::{Digest, Sha256}; @@ -196,11 +196,11 @@ fn truncated_hash_result(symbol_hasher: &mut Sha256) -> String { // This calculates STH for a symbol, as defined above -fn symbol_hash(tcx: &ty::ctxt, - symbol_hasher: &mut Sha256, - t: ty::t, - link_meta: &LinkMeta) - -> String { +fn symbol_hash<'tcx>(tcx: &ty::ctxt<'tcx>, + symbol_hasher: &mut Sha256, + t: Ty<'tcx>, + link_meta: &LinkMeta) + -> String { // NB: do *not* use abbrevs here as we want the symbol names // to be independent of one another in the crate. @@ -219,7 +219,7 @@ fn symbol_hash(tcx: &ty::ctxt, hash } -fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> String { +fn get_symbol_hash<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> String { match ccx.type_hashcodes().borrow().get(&t) { Some(h) => return h.to_string(), None => {} @@ -320,8 +320,8 @@ pub fn exported_name(path: PathElems, hash: &str) -> String { mangle(path, Some(hash)) } -pub fn mangle_exported_name(ccx: &CrateContext, path: PathElems, - t: ty::t, id: ast::NodeId) -> String { +pub fn mangle_exported_name<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, path: PathElems, + t: Ty<'tcx>, id: ast::NodeId) -> String { let mut hash = get_symbol_hash(ccx, t); // Paths can be completely identical for different nodes, @@ -345,9 +345,9 @@ pub fn mangle_exported_name(ccx: &CrateContext, path: PathElems, exported_name(path, hash.as_slice()) } -pub fn mangle_internal_name_by_type_and_seq(ccx: &CrateContext, - t: ty::t, - name: &str) -> String { +pub fn mangle_internal_name_by_type_and_seq<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>, + name: &str) -> String { let s = ppaux::ty_to_string(ccx.tcx(), t); let path = [PathName(token::intern(s.as_slice())), gensym_name(name)]; diff --git a/src/librustc_trans/driver/driver.rs b/src/librustc_trans/driver/driver.rs index a0e2bf07b830f..98cf779fcd2a2 100644 --- a/src/librustc_trans/driver/driver.rs +++ b/src/librustc_trans/driver/driver.rs @@ -358,7 +358,7 @@ pub struct CrateAnalysis<'tcx> { /// structures carrying the results of the analysis. pub fn phase_3_run_analysis_passes<'tcx>(sess: Session, ast_map: ast_map::Map<'tcx>, - type_arena: &'tcx TypedArena, + type_arena: &'tcx TypedArena>, name: String) -> CrateAnalysis<'tcx> { let time_passes = sess.time_passes(); let krate = ast_map.krate(); diff --git a/src/librustc_trans/driver/pretty.rs b/src/librustc_trans/driver/pretty.rs index c20f2e097f31f..aa6ac6564e205 100644 --- a/src/librustc_trans/driver/pretty.rs +++ b/src/librustc_trans/driver/pretty.rs @@ -98,7 +98,7 @@ impl PpSourceMode { fn call_with_pp_support<'tcx, A, B>(&self, sess: Session, ast_map: Option>, - type_arena: &'tcx TypedArena, + type_arena: &'tcx TypedArena>, id: String, payload: B, f: |&PrinterSupport, B| -> A) -> A { diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index c9410d753ae6a..2591051e9b90a 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -31,7 +31,7 @@ use driver::driver::CrateAnalysis; use session::Session; use middle::def; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck; use std::cell::Cell; @@ -1300,9 +1300,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { self.visit_expr(&**sub_ex); - let t = ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex); - let t_box = ty::get(t); - match t_box.sty { + match ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex).sty { ty::ty_struct(def_id, _) => { let fields = ty::lookup_struct_fields(&self.analysis.ty_cx, def_id); for f in fields.iter() { @@ -1328,9 +1326,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { self.visit_expr(&**sub_ex); - let t = ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex); - let t_box = ty::get(t); - match t_box.sty { + match ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex).sty { ty::ty_struct(def_id, _) => { let fields = ty::lookup_struct_fields(&self.analysis.ty_cx, def_id); for (i, f) in fields.iter().enumerate() { diff --git a/src/librustc_trans/test.rs b/src/librustc_trans/test.rs index a17702ac1dcaa..984c1f99720ea 100644 --- a/src/librustc_trans/test.rs +++ b/src/librustc_trans/test.rs @@ -24,7 +24,7 @@ use middle::resolve_lifetime; use middle::stability; use middle::subst; use middle::subst::Subst; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::infer::combine::Combine; use middle::typeck::infer; use middle::typeck::infer::lub::Lub; @@ -215,7 +215,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> { } } - pub fn make_subtype(&self, a: ty::t, b: ty::t) -> bool { + pub fn make_subtype(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> bool { match infer::mk_subty(self.infcx, true, infer::Misc(DUMMY_SP), a, b) { Ok(_) => true, Err(ref e) => panic!("Encountered error: {}", @@ -223,14 +223,14 @@ impl<'a, 'tcx> Env<'a, 'tcx> { } } - pub fn is_subtype(&self, a: ty::t, b: ty::t) -> bool { + pub fn is_subtype(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> bool { match infer::can_mk_subty(self.infcx, a, b) { Ok(_) => true, Err(_) => false } } - pub fn assert_subtype(&self, a: ty::t, b: ty::t) { + pub fn assert_subtype(&self, a: Ty<'tcx>, b: Ty<'tcx>) { if !self.is_subtype(a, b) { panic!("{} is not a subtype of {}, but it should be", self.ty_to_string(a), @@ -238,37 +238,36 @@ impl<'a, 'tcx> Env<'a, 'tcx> { } } - pub fn assert_eq(&self, a: ty::t, b: ty::t) { + pub fn assert_eq(&self, a: Ty<'tcx>, b: Ty<'tcx>) { self.assert_subtype(a, b); self.assert_subtype(b, a); } - pub fn ty_to_string(&self, a: ty::t) -> String { + pub fn ty_to_string(&self, a: Ty<'tcx>) -> String { ty_to_string(self.infcx.tcx, a) } pub fn t_fn(&self, - input_tys: &[ty::t], - output_ty: ty::t) - -> ty::t + input_tys: &[Ty<'tcx>], + output_ty: Ty<'tcx>) + -> Ty<'tcx> { ty::mk_ctor_fn(self.infcx.tcx, input_tys, output_ty) } - pub fn t_nil(&self) -> ty::t { + pub fn t_nil(&self) -> Ty<'tcx> { ty::mk_nil(self.infcx.tcx) } - pub fn t_pair(&self, ty1: ty::t, ty2: ty::t) -> ty::t - { + pub fn t_pair(&self, ty1: Ty<'tcx>, ty2: Ty<'tcx>) -> Ty<'tcx> { ty::mk_tup(self.infcx.tcx, vec![ty1, ty2]) } pub fn t_closure(&self, - input_tys: &[ty::t], - output_ty: ty::t, + input_tys: &[Ty<'tcx>], + output_ty: Ty<'tcx>, region_bound: ty::Region) - -> ty::t + -> Ty<'tcx> { ty::mk_closure(self.infcx.tcx, ty::ClosureTy { fn_style: ast::NormalFn, @@ -284,7 +283,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> { }) } - pub fn t_param(&self, space: subst::ParamSpace, index: uint) -> ty::t { + pub fn t_param(&self, space: subst::ParamSpace, index: uint) -> Ty<'tcx> { ty::mk_param(self.infcx.tcx, space, index, ast_util::local_def(ast::DUMMY_NODE_ID)) } @@ -302,23 +301,26 @@ impl<'a, 'tcx> Env<'a, 'tcx> { ty::ReLateBound(debruijn, ty::BrAnon(id)) } - pub fn t_rptr(&self, r: ty::Region) -> ty::t { + pub fn t_rptr(&self, r: ty::Region) -> Ty<'tcx> { ty::mk_imm_rptr(self.infcx.tcx, r, ty::mk_int()) } - pub fn t_rptr_late_bound(&self, id: uint) -> ty::t { + pub fn t_rptr_late_bound(&self, id: uint) -> Ty<'tcx> { ty::mk_imm_rptr(self.infcx.tcx, self.re_late_bound_with_debruijn(id, ty::DebruijnIndex::new(1)), ty::mk_int()) } - pub fn t_rptr_late_bound_with_debruijn(&self, id: uint, debruijn: ty::DebruijnIndex) -> ty::t { + pub fn t_rptr_late_bound_with_debruijn(&self, + id: uint, + debruijn: ty::DebruijnIndex) + -> Ty<'tcx> { ty::mk_imm_rptr(self.infcx.tcx, self.re_late_bound_with_debruijn(id, debruijn), ty::mk_int()) } - pub fn t_rptr_scope(&self, id: ast::NodeId) -> ty::t { + pub fn t_rptr_scope(&self, id: ast::NodeId) -> Ty<'tcx> { ty::mk_imm_rptr(self.infcx.tcx, ty::ReScope(id), ty::mk_int()) } @@ -327,15 +329,15 @@ impl<'a, 'tcx> Env<'a, 'tcx> { bound_region: ty::BrAnon(id)}) } - pub fn t_rptr_free(&self, nid: ast::NodeId, id: uint) -> ty::t { + pub fn t_rptr_free(&self, nid: ast::NodeId, id: uint) -> Ty<'tcx> { ty::mk_imm_rptr(self.infcx.tcx, self.re_free(nid, id), ty::mk_int()) } - pub fn t_rptr_static(&self) -> ty::t { + pub fn t_rptr_static(&self) -> Ty<'tcx> { ty::mk_imm_rptr(self.infcx.tcx, ty::ReStatic, ty::mk_int()) } - pub fn dummy_type_trace(&self) -> infer::TypeTrace { + pub fn dummy_type_trace(&self) -> infer::TypeTrace<'tcx> { infer::TypeTrace::dummy() } @@ -349,7 +351,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> { Glb(self.infcx.combine_fields(true, trace)) } - pub fn make_lub_ty(&self, t1: ty::t, t2: ty::t) -> ty::t { + pub fn make_lub_ty(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> Ty<'tcx> { match self.lub().tys(t1, t2) { Ok(t) => t, Err(ref e) => panic!("unexpected error computing LUB: {}", @@ -358,7 +360,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> { } /// Checks that `LUB(t1,t2) == t_lub` - pub fn check_lub(&self, t1: ty::t, t2: ty::t, t_lub: ty::t) { + pub fn check_lub(&self, t1: Ty<'tcx>, t2: Ty<'tcx>, t_lub: Ty<'tcx>) { match self.lub().tys(t1, t2) { Ok(t) => { self.assert_eq(t, t_lub); @@ -371,7 +373,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> { } /// Checks that `GLB(t1,t2) == t_glb` - pub fn check_glb(&self, t1: ty::t, t2: ty::t, t_glb: ty::t) { + pub fn check_glb(&self, t1: Ty<'tcx>, t2: Ty<'tcx>, t_glb: Ty<'tcx>) { debug!("check_glb(t1={}, t2={}, t_glb={})", self.ty_to_string(t1), self.ty_to_string(t2), diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index 001a3a4dca0e9..de406cff6e741 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -217,7 +217,7 @@ use trans::expr::{mod, Dest}; use trans::tvec; use trans::type_of; use trans::debuginfo; -use middle::ty; +use middle::ty::{mod, Ty}; use session::config::FullDebugInfo; use util::common::indenter; use util::nodemap::FnvHashMap; @@ -248,16 +248,16 @@ impl<'a> ConstantExpr<'a> { // An option identifying a branch (either a literal, an enum variant or a range) #[deriving(Show)] -enum Opt<'a> { +enum Opt<'a, 'tcx> { ConstantValue(ConstantExpr<'a>), ConstantRange(ConstantExpr<'a>, ConstantExpr<'a>), - Variant(ty::Disr, Rc, ast::DefId), + Variant(ty::Disr, Rc>, ast::DefId), SliceLengthEqual(uint), SliceLengthGreaterOrEqual(/* prefix length */ uint, /* suffix length */ uint), } -impl<'a> Opt<'a> { - fn eq(&self, other: &Opt<'a>, tcx: &ty::ctxt) -> bool { +impl<'a, 'tcx> Opt<'a, 'tcx> { + fn eq(&self, other: &Opt<'a, 'tcx>, tcx: &ty::ctxt<'tcx>) -> bool { match (self, other) { (&ConstantValue(a), &ConstantValue(b)) => a.eq(b, tcx), (&ConstantRange(a1, a2), &ConstantRange(b1, b2)) => { @@ -274,7 +274,7 @@ impl<'a> Opt<'a> { } } - fn trans<'blk, 'tcx>(&self, mut bcx: Block<'blk, 'tcx>) -> OptResult<'blk, 'tcx> { + fn trans<'blk>(&self, mut bcx: Block<'blk, 'tcx>) -> OptResult<'blk, 'tcx> { let _icx = push_ctxt("match::trans_opt"); let ccx = bcx.ccx(); match *self { @@ -334,20 +334,20 @@ pub enum TransBindingMode { * - `id` is the node id of the binding * - `ty` is the Rust type of the binding */ #[deriving(Clone)] -pub struct BindingInfo { +pub struct BindingInfo<'tcx> { pub llmatch: ValueRef, pub trmode: TransBindingMode, pub id: ast::NodeId, pub span: Span, - pub ty: ty::t, + pub ty: Ty<'tcx>, } -type BindingsMap = FnvHashMap; +type BindingsMap<'tcx> = FnvHashMap>; struct ArmData<'p, 'blk, 'tcx: 'blk> { bodycx: Block<'blk, 'tcx>, arm: &'p ast::Arm, - bindings_map: BindingsMap + bindings_map: BindingsMap<'tcx> } /** @@ -362,7 +362,7 @@ struct Match<'a, 'p: 'a, 'blk: 'a, 'tcx: 'blk> { bound_ptrs: Vec<(Ident, ValueRef)>, } -impl<'a, 'p, 'blk, 'tcx> Repr for Match<'a, 'p, 'blk, 'tcx> { +impl<'a, 'p, 'blk, 'tcx> Repr<'tcx> for Match<'a, 'p, 'blk, 'tcx> { fn repr(&self, tcx: &ty::ctxt) -> String { if tcx.sess.verbose() { // for many programs, this just take too long to serialize @@ -564,7 +564,7 @@ fn enter_opt<'a, 'p, 'blk, 'tcx>( // on a set of enum variants or a literal. fn get_branches<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, m: &[Match<'a, 'p, 'blk, 'tcx>], col: uint) - -> Vec> { + -> Vec> { let tcx = bcx.tcx(); let mut found: Vec = vec![]; @@ -608,7 +608,7 @@ struct ExtractedBlock<'blk, 'tcx: 'blk> { } fn extract_variant_args<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - repr: &adt::Repr, + repr: &adt::Repr<'tcx>, disr_val: ty::Disr, val: ValueRef) -> ExtractedBlock<'blk, 'tcx> { @@ -620,7 +620,7 @@ fn extract_variant_args<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ExtractedBlock { vals: args, bcx: bcx } } -fn match_datum(val: ValueRef, left_ty: ty::t) -> Datum { +fn match_datum<'tcx>(val: ValueRef, left_ty: Ty<'tcx>) -> Datum<'tcx, Lvalue> { /*! * Helper for converting from the ValueRef that we pass around in * the match code, which is always an lvalue, into a Datum. Eventually @@ -655,7 +655,7 @@ fn bind_subslice_pat(bcx: Block, } fn extract_vec_elems<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - left_ty: ty::t, + left_ty: Ty, before: uint, after: uint, val: ValueRef) @@ -790,12 +790,12 @@ fn pick_column_to_specialize(def_map: &DefMap, m: &[Match]) -> Option { fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>, lhs: ValueRef, rhs: ValueRef, - rhs_t: ty::t) + rhs_t: Ty<'tcx>) -> Result<'blk, 'tcx> { fn compare_str<'blk, 'tcx>(cx: Block<'blk, 'tcx>, lhs: ValueRef, rhs: ValueRef, - rhs_t: ty::t) + rhs_t: Ty<'tcx>) -> Result<'blk, 'tcx> { let did = langcall(cx, None, @@ -811,10 +811,10 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>, return Result::new(rs.bcx, rs.val); } - match ty::get(rhs_t).sty { - ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty { + match rhs_t.sty { + ty::ty_rptr(_, mt) => match mt.ty.sty { ty::ty_str => compare_str(cx, lhs, rhs, rhs_t), - ty::ty_vec(ty, _) => match ty::get(ty).sty { + ty::ty_vec(ty, _) => match ty.sty { ty::ty_uint(ast::TyU8) => { // NOTE: cast &[u8] to &str and abuse the str_eq lang item, // which calls memcmp(). @@ -832,7 +832,7 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>, } fn insert_lllocals<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, - bindings_map: &BindingsMap, + bindings_map: &BindingsMap<'tcx>, cs: Option) -> Block<'blk, 'tcx> { /*! @@ -889,7 +889,7 @@ fn insert_lllocals<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, fn compile_guard<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, guard_expr: &ast::Expr, - data: &ArmData, + data: &ArmData<'p, 'blk, 'tcx>, m: &[Match<'a, 'p, 'blk, 'tcx>], vals: &[ValueRef], chk: &FailureHandler, @@ -1034,7 +1034,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, } else if any_uniq_pat(m, col) || any_region_pat(m, col) { Some(vec!(Load(bcx, val))) } else { - match ty::get(left_ty).sty { + match left_ty.sty { ty::ty_vec(_, Some(n)) => { let args = extract_vec_elems(bcx, left_ty, n, 0, val); Some(args.vals) @@ -1272,7 +1272,7 @@ struct ReassignmentChecker { reassigned: bool } -impl euv::Delegate for ReassignmentChecker { +impl<'tcx> euv::Delegate<'tcx> for ReassignmentChecker { fn consume(&mut self, _: ast::NodeId, _: Span, _: mc::cmt, _: euv::ConsumeMode) {} fn consume_pat(&mut self, _: &ast::Pat, _: mc::cmt, _: euv::ConsumeMode) {} fn borrow(&mut self, _: ast::NodeId, _: Span, _: mc::cmt, _: ty::Region, @@ -1288,8 +1288,9 @@ impl euv::Delegate for ReassignmentChecker { } } -fn create_bindings_map(bcx: Block, pat: &ast::Pat, - discr: &ast::Expr, body: &ast::Expr) -> BindingsMap { +fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &ast::Pat, + discr: &ast::Expr, body: &ast::Expr) + -> BindingsMap<'tcx> { // Create the bindings map, which is a mapping from each binding name // to an alloca() that will be the value for that local variable. // Note that we use the names because each binding will have many ids @@ -1482,7 +1483,7 @@ pub fn store_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pub fn store_arg<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, pat: &ast::Pat, - arg: Datum, + arg: Datum<'tcx, Rvalue>, arg_scope: cleanup::ScopeId) -> Block<'blk, 'tcx> { /*! @@ -1560,7 +1561,7 @@ fn mk_binding_alloca<'blk, 'tcx, A>(bcx: Block<'blk, 'tcx>, ident: &ast::Ident, cleanup_scope: cleanup::ScopeId, arg: A, - populate: |A, Block<'blk, 'tcx>, ValueRef, ty::t| + populate: |A, Block<'blk, 'tcx>, ValueRef, Ty<'tcx>| -> Block<'blk, 'tcx>) -> Block<'blk, 'tcx> { let var_ty = node_id_type(bcx, p_id); diff --git a/src/librustc_trans/trans/adt.rs b/src/librustc_trans/trans/adt.rs index 806c4a68ba281..c5f66cf0c542f 100644 --- a/src/librustc_trans/trans/adt.rs +++ b/src/librustc_trans/trans/adt.rs @@ -64,7 +64,7 @@ use trans::datum; use trans::machine; use trans::type_::Type; use trans::type_of; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty::Disr; use syntax::ast; use syntax::attr; @@ -76,7 +76,7 @@ type Hint = attr::ReprAttr; /// Representations. #[deriving(Eq, PartialEq, Show)] -pub enum Repr { +pub enum Repr<'tcx> { /// C-like enums; basically an int. CEnum(IntType, Disr, Disr), // discriminant range (signedness based on the IntType) /** @@ -86,7 +86,7 @@ pub enum Repr { * avoid running the destructor too many times; this is included * in the `Struct` if present. */ - Univariant(Struct, bool), + Univariant(Struct<'tcx>, bool), /** * General-case enums: for each case there is a struct, and they * all start with a field for the discriminant. @@ -95,7 +95,7 @@ pub enum Repr { * avoid running the destructor too many times; the last argument * indicates whether such a flag is present. */ - General(IntType, Vec, bool), + General(IntType, Vec>, bool), /** * Two cases distinguished by a nullable pointer: the case with discriminant * `nndiscr` must have single field which is known to be nonnull due to its type. @@ -105,8 +105,8 @@ pub enum Repr { */ RawNullablePointer { nndiscr: Disr, - nnty: ty::t, - nullfields: Vec + nnty: Ty<'tcx>, + nullfields: Vec> }, /** * Two cases distinguished by a nullable pointer: the case with discriminant @@ -120,36 +120,38 @@ pub enum Repr { * identity function. */ StructWrappedNullablePointer { - nonnull: Struct, + nonnull: Struct<'tcx>, nndiscr: Disr, ptrfield: PointerField, - nullfields: Vec, + nullfields: Vec>, } } /// For structs, and struct-like parts of anything fancier. #[deriving(Eq, PartialEq, Show)] -pub struct Struct { +pub struct Struct<'tcx> { // If the struct is DST, then the size and alignment do not take into // account the unsized fields of the struct. pub size: u64, pub align: u32, pub sized: bool, pub packed: bool, - pub fields: Vec + pub fields: Vec> } /** * Convenience for `represent_type`. There should probably be more or - * these, for places in trans where the `ty::t` isn't directly + * these, for places in trans where the `Ty` isn't directly * available. */ -pub fn represent_node(bcx: Block, node: ast::NodeId) -> Rc { +pub fn represent_node<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + node: ast::NodeId) -> Rc> { represent_type(bcx.ccx(), node_id_type(bcx, node)) } /// Decides how to represent a given type. -pub fn represent_type(cx: &CrateContext, t: ty::t) -> Rc { +pub fn represent_type<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>) -> Rc> { debug!("Representing: {}", ty_to_string(cx.tcx(), t)); match cx.adt_reprs().borrow().get(&t) { Some(repr) => return repr.clone(), @@ -162,10 +164,11 @@ pub fn represent_type(cx: &CrateContext, t: ty::t) -> Rc { repr } -fn represent_type_uncached(cx: &CrateContext, t: ty::t) -> Repr { - match ty::get(t).sty { +fn represent_type_uncached<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>) -> Repr<'tcx> { + match t.sty { ty::ty_tup(ref elems) => { - return Univariant(mk_struct(cx, elems.as_slice(), false, t), false) + Univariant(mk_struct(cx, elems.as_slice(), false, t), false) } ty::ty_struct(def_id, ref substs) => { let fields = ty::lookup_struct_fields(cx.tcx(), def_id); @@ -176,13 +179,12 @@ fn represent_type_uncached(cx: &CrateContext, t: ty::t) -> Repr { let dtor = ty::ty_dtor(cx.tcx(), def_id).has_drop_flag(); if dtor { ftys.push(ty::mk_bool()); } - return Univariant(mk_struct(cx, ftys.as_slice(), packed, t), dtor) + Univariant(mk_struct(cx, ftys.as_slice(), packed, t), dtor) } ty::ty_unboxed_closure(def_id, _, ref substs) => { let upvars = ty::unboxed_closure_upvars(cx.tcx(), def_id, substs); let upvar_types = upvars.iter().map(|u| u.ty).collect::>(); - return Univariant(mk_struct(cx, upvar_types.as_slice(), false, t), - false) + Univariant(mk_struct(cx, upvar_types.as_slice(), false, t), false) } ty::ty_enum(def_id, ref substs) => { let cases = get_cases(cx.tcx(), def_id, substs); @@ -285,9 +287,9 @@ fn represent_type_uncached(cx: &CrateContext, t: ty::t) -> Repr { } // this should probably all be in ty -struct Case { +struct Case<'tcx> { discr: Disr, - tys: Vec + tys: Vec> } @@ -297,16 +299,16 @@ pub enum PointerField { FatPointer(uint) } -impl Case { - fn is_zerolen(&self, cx: &CrateContext, scapegoat: ty::t) -> bool { +impl<'tcx> Case<'tcx> { + fn is_zerolen<'a>(&self, cx: &CrateContext<'a, 'tcx>, scapegoat: Ty<'tcx>) -> bool { mk_struct(cx, self.tys.as_slice(), false, scapegoat).size == 0 } - fn find_ptr(&self, cx: &CrateContext) -> Option { + fn find_ptr<'a>(&self, cx: &CrateContext<'a, 'tcx>) -> Option { for (i, &ty) in self.tys.iter().enumerate() { - match ty::get(ty).sty { + match ty.sty { // &T/&mut T/Box could either be a thin or fat pointer depending on T - ty::ty_rptr(_, ty::mt { ty, .. }) | ty::ty_uniq(ty) => match ty::get(ty).sty { + ty::ty_rptr(_, ty::mt { ty, .. }) | ty::ty_uniq(ty) => match ty.sty { // &[T] and &str are a pointer and length pair ty::ty_vec(_, None) | ty::ty_str => return Some(FatPointer(i)), @@ -336,7 +338,10 @@ impl Case { } } -fn get_cases(tcx: &ty::ctxt, def_id: ast::DefId, substs: &subst::Substs) -> Vec { +fn get_cases<'tcx>(tcx: &ty::ctxt<'tcx>, + def_id: ast::DefId, + substs: &subst::Substs<'tcx>) + -> Vec> { ty::enum_variants(tcx, def_id).iter().map(|vi| { let arg_tys = vi.args.iter().map(|&raw_ty| { raw_ty.subst(tcx, substs) @@ -345,7 +350,10 @@ fn get_cases(tcx: &ty::ctxt, def_id: ast::DefId, substs: &subst::Substs) -> Vec< }).collect() } -fn mk_struct(cx: &CrateContext, tys: &[ty::t], packed: bool, scapegoat: ty::t) -> Struct { +fn mk_struct<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + tys: &[Ty<'tcx>], packed: bool, + scapegoat: Ty<'tcx>) + -> Struct<'tcx> { let sized = tys.iter().all(|&ty| ty::type_is_sized(cx.tcx(), ty)); let lltys : Vec = if sized { tys.iter() @@ -375,7 +383,9 @@ struct IntBounds { uhi: u64 } -fn mk_cenum(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> Repr { +fn mk_cenum<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + hint: Hint, bounds: &IntBounds) + -> Repr<'tcx> { let it = range_to_inttype(cx, hint, bounds); match it { attr::SignedInt(_) => CEnum(it, bounds.slo as Disr, bounds.shi as Disr), @@ -450,7 +460,8 @@ fn bounds_usable(cx: &CrateContext, ity: IntType, bounds: &IntBounds) -> bool { } } -pub fn ty_of_inttype(ity: IntType) -> ty::t { +// FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx. +pub fn ty_of_inttype<'tcx>(ity: IntType) -> Ty<'tcx> { match ity { attr::SignedInt(t) => ty::mk_mach_int(t), attr::UnsignedInt(t) => ty::mk_mach_uint(t) @@ -458,10 +469,10 @@ pub fn ty_of_inttype(ity: IntType) -> ty::t { } // LLVM doesn't like types that don't fit in the address space -fn ensure_struct_fits_in_address_space(ccx: &CrateContext, - fields: &[Type], - packed: bool, - scapegoat: ty::t) { +fn ensure_struct_fits_in_address_space<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + fields: &[Type], + packed: bool, + scapegoat: Ty<'tcx>) { let mut offset = 0; for &llty in fields.iter() { // Invariant: offset < ccx.max_obj_size() <= 1<<61 @@ -486,10 +497,10 @@ fn union_size_and_align(sts: &[Struct]) -> (machine::llsize, machine::llalign) { (size, most_aligned.align) } -fn ensure_enum_fits_in_address_space(ccx: &CrateContext, - discr: IntType, - fields: &[Struct], - scapegoat: ty::t) { +fn ensure_enum_fits_in_address_space<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + discr: IntType, + fields: &[Struct], + scapegoat: Ty<'tcx>) { let discr_size = machine::llsize_of_alloc(ccx, ll_inttype(ccx, discr)); let (field_size, field_align) = union_size_and_align(fields); @@ -513,19 +524,22 @@ fn ensure_enum_fits_in_address_space(ccx: &CrateContext, * and fill in the actual contents in a second pass to prevent * unbounded recursion; see also the comments in `trans::type_of`. */ -pub fn type_of(cx: &CrateContext, r: &Repr) -> Type { +pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, r: &Repr<'tcx>) -> Type { generic_type_of(cx, r, None, false, false) } // Pass dst=true if the type you are passing is a DST. Yes, we could figure // this out, but if you call this on an unsized type without realising it, you // are going to get the wrong type (it will not include the unsized parts of it). -pub fn sizing_type_of(cx: &CrateContext, r: &Repr, dst: bool) -> Type { +pub fn sizing_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + r: &Repr<'tcx>, dst: bool) -> Type { generic_type_of(cx, r, None, true, dst) } -pub fn incomplete_type_of(cx: &CrateContext, r: &Repr, name: &str) -> Type { +pub fn incomplete_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + r: &Repr<'tcx>, name: &str) -> Type { generic_type_of(cx, r, Some(name), false, false) } -pub fn finish_type_of(cx: &CrateContext, r: &Repr, llty: &mut Type) { +pub fn finish_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + r: &Repr<'tcx>, llty: &mut Type) { match *r { CEnum(..) | General(..) | RawNullablePointer { .. } => { } Univariant(ref st, _) | StructWrappedNullablePointer { nonnull: ref st, .. } => @@ -534,11 +548,11 @@ pub fn finish_type_of(cx: &CrateContext, r: &Repr, llty: &mut Type) { } } -fn generic_type_of(cx: &CrateContext, - r: &Repr, - name: Option<&str>, - sizing: bool, - dst: bool) -> Type { +fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + r: &Repr<'tcx>, + name: Option<&str>, + sizing: bool, + dst: bool) -> Type { match *r { CEnum(ity, _, _) => ll_inttype(cx, ity), RawNullablePointer { nnty, .. } => type_of::sizing_type_of(cx, nnty), @@ -596,7 +610,8 @@ fn generic_type_of(cx: &CrateContext, } } -fn struct_llfields(cx: &CrateContext, st: &Struct, sizing: bool, dst: bool) -> Vec { +fn struct_llfields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, st: &Struct<'tcx>, + sizing: bool, dst: bool) -> Vec { if sizing { st.fields.iter().filter(|&ty| !dst || ty::type_is_sized(cx.tcx(), *ty)) .map(|&ty| type_of::sizing_type_of(cx, ty)).collect() @@ -611,8 +626,9 @@ fn struct_llfields(cx: &CrateContext, st: &Struct, sizing: bool, dst: bool) -> V * * This should ideally be less tightly tied to `_match`. */ -pub fn trans_switch(bcx: Block, r: &Repr, scrutinee: ValueRef) - -> (_match::BranchKind, Option) { +pub fn trans_switch<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + r: &Repr<'tcx>, scrutinee: ValueRef) + -> (_match::BranchKind, Option) { match *r { CEnum(..) | General(..) | RawNullablePointer { .. } | StructWrappedNullablePointer { .. } => { @@ -627,7 +643,8 @@ pub fn trans_switch(bcx: Block, r: &Repr, scrutinee: ValueRef) /// Obtain the actual discriminant of a value. -pub fn trans_get_discr(bcx: Block, r: &Repr, scrutinee: ValueRef, cast_to: Option) +pub fn trans_get_discr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>, + scrutinee: ValueRef, cast_to: Option) -> ValueRef { let signed; let val; @@ -728,7 +745,8 @@ pub fn trans_case<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr, discr: Disr) * Set the discriminant for a new value of the given case of the given * representation. */ -pub fn trans_set_discr(bcx: Block, r: &Repr, val: ValueRef, discr: Disr) { +pub fn trans_set_discr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>, + val: ValueRef, discr: Disr) { match *r { CEnum(ity, min, max) => { assert_discr_in_range(ity, min, max, discr); @@ -806,8 +824,8 @@ pub fn num_args(r: &Repr, discr: Disr) -> uint { } /// Access a field, at a point when the value's case is known. -pub fn trans_field_ptr(bcx: Block, r: &Repr, val: ValueRef, discr: Disr, - ix: uint) -> ValueRef { +pub fn trans_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>, + val: ValueRef, discr: Disr, ix: uint) -> ValueRef { // Note: if this ever needs to generate conditionals (e.g., if we // decide to do some kind of cdr-coding-like non-unique repr // someday), it will need to return a possibly-new bcx as well. @@ -845,8 +863,8 @@ pub fn trans_field_ptr(bcx: Block, r: &Repr, val: ValueRef, discr: Disr, } } -pub fn struct_field_ptr(bcx: Block, st: &Struct, val: ValueRef, - ix: uint, needs_cast: bool) -> ValueRef { +pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, val: ValueRef, + ix: uint, needs_cast: bool) -> ValueRef { let val = if needs_cast { let ccx = bcx.ccx(); let fields = st.fields.iter().map(|&ty| type_of::type_of(ccx, ty)).collect::>(); @@ -860,8 +878,8 @@ pub fn struct_field_ptr(bcx: Block, st: &Struct, val: ValueRef, } pub fn fold_variants<'blk, 'tcx>( - bcx: Block<'blk, 'tcx>, r: &Repr, value: ValueRef, - f: |Block<'blk, 'tcx>, &Struct, ValueRef| -> Block<'blk, 'tcx>) + bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>, value: ValueRef, + f: |Block<'blk, 'tcx>, &Struct<'tcx>, ValueRef| -> Block<'blk, 'tcx>) -> Block<'blk, 'tcx> { let fcx = bcx.fcx; match *r { @@ -900,7 +918,7 @@ pub fn fold_variants<'blk, 'tcx>( } /// Access the struct drop flag, if present. -pub fn trans_drop_flag_ptr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, r: &Repr, val: ValueRef) +pub fn trans_drop_flag_ptr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>, val: ValueRef) -> datum::DatumBlock<'blk, 'tcx, datum::Expr> { let ptr_ty = ty::mk_imm_ptr(bcx.tcx(), ty::mk_bool()); match *r { @@ -949,8 +967,8 @@ pub fn trans_drop_flag_ptr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, r: &Repr, val * this could be changed in the future to avoid allocating unnecessary * space after values of shorter-than-maximum cases. */ -pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr, - vals: &[ValueRef]) -> ValueRef { +pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, r: &Repr<'tcx>, discr: Disr, + vals: &[ValueRef]) -> ValueRef { match *r { CEnum(ity, min, max) => { assert_eq!(vals.len(), 0); @@ -1004,7 +1022,8 @@ pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr, /** * Compute struct field offsets relative to struct begin. */ -fn compute_struct_field_offsets(ccx: &CrateContext, st: &Struct) -> Vec { +fn compute_struct_field_offsets<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + st: &Struct<'tcx>) -> Vec { let mut offsets = vec!(); let mut offset = 0; @@ -1031,8 +1050,9 @@ fn compute_struct_field_offsets(ccx: &CrateContext, st: &Struct) -> Vec { * a two-element struct will locate it at offset 4, and accesses to it * will read the wrong memory. */ -fn build_const_struct(ccx: &CrateContext, st: &Struct, vals: &[ValueRef]) - -> Vec { +fn build_const_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + st: &Struct<'tcx>, vals: &[ValueRef]) + -> Vec { assert_eq!(vals.len(), st.fields.len()); let target_offsets = compute_struct_field_offsets(ccx, st); diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 9c4a532790dde..b3f64e3fd798c 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -17,15 +17,14 @@ // // Hopefully useful general knowledge about trans: // -// * There's no way to find out the ty::t type of a ValueRef. Doing so +// * There's no way to find out the Ty type of a ValueRef. Doing so // would be "trying to get the eggs out of an omelette" (credit: // pcwalton). You can, instead, find out its TypeRef by calling val_ty, -// but one TypeRef corresponds to many `ty::t`s; for instance, tup(int, int, +// but one TypeRef corresponds to many `Ty`s; for instance, tup(int, int, // int) and rec(x=int, y=int, z=int) will have the same TypeRef. #![allow(non_camel_case_types)] -pub use self::IsUnboxedClosureFlag::*; pub use self::ValueOrigin::*; pub use self::scalar_type::*; @@ -40,8 +39,8 @@ use middle::astencode; use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem}; use middle::subst; use middle::weak_lang_items; -use middle::subst::Subst; -use middle::ty; +use middle::subst::{Subst, Substs}; +use middle::ty::{mod, Ty}; use session::config::{mod, NoDebugInfo, FullDebugInfo}; use session::Session; use trans::_match; @@ -49,13 +48,14 @@ use trans::adt; use trans::build::*; use trans::builder::{Builder, noname}; use trans::callee; -use trans::cleanup::{CleanupMethods, ScopeId}; +use trans::cleanup::CleanupMethods; use trans::cleanup; +use trans::closure; use trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral}; use trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_uint, C_undef}; use trans::common::{CrateContext, ExternMap, FunctionContext}; -use trans::common::{NodeInfo, Result, SubstP}; -use trans::common::{node_id_type, param_substs, return_type_is_void}; +use trans::common::{NodeInfo, Result}; +use trans::common::{node_id_type, return_type_is_void}; use trans::common::{tydesc_info, type_is_immediate}; use trans::common::{type_is_zero_size, val_ty}; use trans::common; @@ -170,7 +170,7 @@ impl<'a, 'tcx> Drop for StatRecorder<'a, 'tcx> { // only use this for foreign function ABIs and glue, use `decl_rust_fn` for Rust functions pub fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv, - ty: Type, output: ty::FnOutput) -> ValueRef { + ty: Type, output: ty::FnOutput) -> ValueRef { let llfn: ValueRef = name.with_c_str(|buf| { unsafe { @@ -203,7 +203,7 @@ pub fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv, pub fn decl_cdecl_fn(ccx: &CrateContext, name: &str, ty: Type, - output: ty::t) -> ValueRef { + output: Ty) -> ValueRef { decl_fn(ccx, name, llvm::CCallConv, ty, ty::FnConverging(output)) } @@ -213,7 +213,7 @@ pub fn get_extern_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv, ty: Type, - output: ty::t) + output: Ty) -> ValueRef { match externs.get(name) { Some(n) => return *n, @@ -224,7 +224,8 @@ pub fn get_extern_fn(ccx: &CrateContext, f } -fn get_extern_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str, did: ast::DefId) -> ValueRef { +fn get_extern_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<'tcx>, + name: &str, did: ast::DefId) -> ValueRef { match ccx.externs().borrow().get(name) { Some(n) => return *n, None => () @@ -240,10 +241,10 @@ fn get_extern_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str, did: ast::De f } -pub fn self_type_for_unboxed_closure(ccx: &CrateContext, +pub fn self_type_for_unboxed_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, closure_id: ast::DefId, - fn_ty: ty::t) - -> ty::t { + fn_ty: Ty<'tcx>) + -> Ty<'tcx> { let unboxed_closures = ccx.tcx().unboxed_closures.borrow(); let unboxed_closure = &(*unboxed_closures)[closure_id]; match unboxed_closure.kind { @@ -263,8 +264,9 @@ pub fn kind_for_unboxed_closure(ccx: &CrateContext, closure_id: ast::DefId) (*unboxed_closures)[closure_id].kind } -pub fn decl_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str) -> ValueRef { - let (inputs, output, abi, env) = match ty::get(fn_ty).sty { +pub fn decl_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + fn_ty: Ty<'tcx>, name: &str) -> ValueRef { + let (inputs, output, abi, env) = match fn_ty.sty { ty::ty_bare_fn(ref f) => { (f.sig.inputs.clone(), f.sig.output, f.abi, None) } @@ -297,14 +299,15 @@ pub fn decl_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str) -> ValueRef { llfn } -pub fn decl_internal_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str) -> ValueRef { +pub fn decl_internal_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + fn_ty: Ty<'tcx>, name: &str) -> ValueRef { let llfn = decl_rust_fn(ccx, fn_ty, name); llvm::SetLinkage(llfn, llvm::InternalLinkage); llfn } -pub fn get_extern_const(ccx: &CrateContext, did: ast::DefId, - t: ty::t) -> ValueRef { +pub fn get_extern_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, did: ast::DefId, + t: Ty<'tcx>) -> ValueRef { let name = csearch::get_symbol(&ccx.sess().cstore, did); let ty = type_of(ccx, t); match ccx.externs().borrow_mut().get(&name) { @@ -335,7 +338,8 @@ pub fn get_extern_const(ccx: &CrateContext, did: ast::DefId, // Returns a pointer to the body for the box. The box may be an opaque // box. The result will be casted to the type of body_t, if it is statically // known. -pub fn at_box_body(bcx: Block, body_t: ty::t, boxptr: ValueRef) -> ValueRef { +pub fn at_box_body<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + body_t: Ty<'tcx>, boxptr: ValueRef) -> ValueRef { let _icx = push_ctxt("at_box_body"); let ccx = bcx.ccx(); let ty = Type::at_box(ccx, type_of(ccx, body_t)); @@ -343,7 +347,8 @@ pub fn at_box_body(bcx: Block, body_t: ty::t, boxptr: ValueRef) -> ValueRef { GEPi(bcx, boxptr, &[0u, abi::box_field_body]) } -fn require_alloc_fn(bcx: Block, info_ty: ty::t, it: LangItem) -> ast::DefId { +fn require_alloc_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + info_ty: Ty<'tcx>, it: LangItem) -> ast::DefId { match bcx.tcx().lang_items.require(it) { Ok(id) => id, Err(s) => { @@ -359,7 +364,7 @@ fn require_alloc_fn(bcx: Block, info_ty: ty::t, it: LangItem) -> ast::DefId { pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, llty_ptr: Type, - info_ty: ty::t, + info_ty: Ty<'tcx>, size: ValueRef, align: ValueRef) -> Result<'blk, 'tcx> { @@ -374,7 +379,8 @@ pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr)) } -pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: ty::t) -> Result<'blk, 'tcx> { +pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>) + -> Result<'blk, 'tcx> { let _icx = push_ctxt("malloc_raw_dyn_proc"); let ccx = bcx.ccx(); @@ -399,7 +405,8 @@ pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: ty::t) -> Resu // Type descriptor and type glue stuff -pub fn get_tydesc(ccx: &CrateContext, t: ty::t) -> Rc { +pub fn get_tydesc<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>) -> Rc> { match ccx.tydescs().borrow().get(&t) { Some(inf) => return inf.clone(), _ => { } @@ -494,12 +501,12 @@ pub fn note_unique_llvm_symbol(ccx: &CrateContext, sym: String) { } -pub fn get_res_dtor(ccx: &CrateContext, - did: ast::DefId, - t: ty::t, - parent_id: ast::DefId, - substs: &subst::Substs) - -> ValueRef { +pub fn get_res_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + did: ast::DefId, + t: Ty<'tcx>, + parent_id: ast::DefId, + substs: &subst::Substs<'tcx>) + -> ValueRef { let _icx = push_ctxt("trans_res_dtor"); let did = inline::maybe_instantiate_inline(ccx, did); @@ -549,12 +556,12 @@ pub enum scalar_type { nil_type, signed_int, unsigned_int, floating_point, } pub fn compare_scalar_types<'blk, 'tcx>(cx: Block<'blk, 'tcx>, lhs: ValueRef, rhs: ValueRef, - t: ty::t, + t: Ty<'tcx>, op: ast::BinOp) -> Result<'blk, 'tcx> { let f = |a| Result::new(cx, compare_scalar_values(cx, lhs, rhs, a, op)); - match ty::get(t).sty { + match t.sty { ty::ty_tup(ref tys) if tys.is_empty() => f(nil_type), ty::ty_bool | ty::ty_uint(_) | ty::ty_char => f(unsigned_int), ty::ty_ptr(mt) if ty::type_is_sized(cx.tcx(), mt.ty) => f(unsigned_int), @@ -627,15 +634,15 @@ pub fn compare_scalar_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>, } } -pub fn compare_simd_types( - cx: Block, +pub fn compare_simd_types<'blk, 'tcx>( + cx: Block<'blk, 'tcx>, lhs: ValueRef, rhs: ValueRef, - t: ty::t, + t: Ty<'tcx>, size: uint, op: ast::BinOp) -> ValueRef { - match ty::get(t).sty { + match t.sty { ty::ty_float(_) => { // The comparison operators for floating point vectors are challenging. // LLVM outputs a `< size x i1 >`, but if we perform a sign extension @@ -666,21 +673,21 @@ pub fn compare_simd_types( } pub type val_and_ty_fn<'a, 'blk, 'tcx> = - |Block<'blk, 'tcx>, ValueRef, ty::t|: 'a -> Block<'blk, 'tcx>; + |Block<'blk, 'tcx>, ValueRef, Ty<'tcx>|: 'a -> Block<'blk, 'tcx>; // Iterates through the elements of a structural type. pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, av: ValueRef, - t: ty::t, + t: Ty<'tcx>, f: val_and_ty_fn<'a, 'blk, 'tcx>) -> Block<'blk, 'tcx> { let _icx = push_ctxt("iter_structural_ty"); fn iter_variant<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, - repr: &adt::Repr, + repr: &adt::Repr<'tcx>, av: ValueRef, - variant: &ty::VariantInfo, - substs: &subst::Substs, + variant: &ty::VariantInfo<'tcx>, + substs: &subst::Substs<'tcx>, f: val_and_ty_fn<'a, 'blk, 'tcx>) -> Block<'blk, 'tcx> { let _icx = push_ctxt("iter_variant"); @@ -704,7 +711,7 @@ pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, }; let mut cx = cx; - match ty::get(t).sty { + match t.sty { ty::ty_struct(..) => { let repr = adt::represent_type(cx.ccx(), t); expr::with_field_tys(cx.tcx(), t, None, |discr, field_tys| { @@ -855,7 +862,7 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>( divrem: ast::BinOp, lhs: ValueRef, rhs: ValueRef, - rhs_t: ty::t) + rhs_t: Ty<'tcx>) -> Block<'blk, 'tcx> { let (zero_text, overflow_text) = if divrem == ast::BiDiv { ("attempted to divide by zero", @@ -864,7 +871,7 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>( ("attempted remainder with a divisor of zero", "attempted remainder with overflow") }; - let (is_zero, is_signed) = match ty::get(rhs_t).sty { + let (is_zero, is_signed) = match rhs_t.sty { ty::ty_int(t) => { let zero = C_integral(Type::int_from_ty(cx.ccx(), t), 0u64, false); (ICmp(cx, llvm::IntEQ, rhs, zero), true) @@ -892,7 +899,7 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>( // signed division/remainder which would trigger overflow. For unsigned // integers, no action beyond checking for zero need be taken. if is_signed { - let (llty, min) = match ty::get(rhs_t).sty { + let (llty, min) = match rhs_t.sty { ty::ty_int(t) => { let llty = Type::int_from_ty(cx.ccx(), t); let min = match t { @@ -922,9 +929,10 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>( } } -pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> ValueRef { +pub fn trans_external_path<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + did: ast::DefId, t: Ty<'tcx>) -> ValueRef { let name = csearch::get_symbol(&ccx.sess().cstore, did); - match ty::get(t).sty { + match t.sty { ty::ty_bare_fn(ref fn_ty) => { match ccx.sess().target.target.adjust_abi(fn_ty.abi) { Rust | RustCall => { @@ -951,7 +959,7 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val pub fn invoke<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, llfn: ValueRef, llargs: Vec , - fn_ty: ty::t, + fn_ty: Ty<'tcx>, call_info: Option, // FIXME(15064) is_lang_item is a horrible hack, please remove it // at the soonest opportunity. @@ -1028,13 +1036,15 @@ pub fn need_invoke(bcx: Block) -> bool { bcx.fcx.needs_invoke() } -pub fn load_if_immediate(cx: Block, v: ValueRef, t: ty::t) -> ValueRef { +pub fn load_if_immediate<'blk, 'tcx>(cx: Block<'blk, 'tcx>, + v: ValueRef, t: Ty<'tcx>) -> ValueRef { let _icx = push_ctxt("load_if_immediate"); if type_is_immediate(cx.ccx(), t) { return load_ty(cx, v, t); } return v; } -pub fn load_ty(cx: Block, ptr: ValueRef, t: ty::t) -> ValueRef { +pub fn load_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>, + ptr: ValueRef, t: Ty<'tcx>) -> ValueRef { /*! * Helper for loading values from memory. Does the necessary conversion if * the in-memory type differs from the type used for SSA values. Also @@ -1054,7 +1064,7 @@ pub fn load_ty(cx: Block, ptr: ValueRef, t: ty::t) -> ValueRef { } } -pub fn store_ty(cx: Block, v: ValueRef, dst: ValueRef, t: ty::t) { +pub fn store_ty(cx: Block, v: ValueRef, dst: ValueRef, t: Ty) { /*! * Helper for storing values in memory. Does the necessary conversion if * the in-memory type differs from the type used for SSA values. @@ -1148,7 +1158,9 @@ pub fn call_memcpy(cx: Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, a Call(cx, memcpy, &[dst_ptr, src_ptr, size, align, volatile], None); } -pub fn memcpy_ty(bcx: Block, dst: ValueRef, src: ValueRef, t: ty::t) { +pub fn memcpy_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + dst: ValueRef, src: ValueRef, + t: Ty<'tcx>) { let _icx = push_ctxt("memcpy_ty"); let ccx = bcx.ccx(); if ty::type_is_structural(t) { @@ -1161,7 +1173,7 @@ pub fn memcpy_ty(bcx: Block, dst: ValueRef, src: ValueRef, t: ty::t) { } } -pub fn zero_mem(cx: Block, llptr: ValueRef, t: ty::t) { +pub fn zero_mem<'blk, 'tcx>(cx: Block<'blk, 'tcx>, llptr: ValueRef, t: Ty<'tcx>) { if cx.unreachable.get() { return; } let _icx = push_ctxt("zero_mem"); let bcx = cx; @@ -1173,7 +1185,7 @@ pub fn zero_mem(cx: Block, llptr: ValueRef, t: ty::t) { // allocation for large data structures, and the generated code will be // awful. (A telltale sign of this is large quantities of // `mov [byte ptr foo],0` in the generated code.) -fn memzero(b: &Builder, llptr: ValueRef, ty: ty::t) { +fn memzero<'a, 'tcx>(b: &Builder<'a, 'tcx>, llptr: ValueRef, ty: Ty<'tcx>) { let _icx = push_ctxt("memzero"); let ccx = b.ccx; @@ -1194,7 +1206,7 @@ fn memzero(b: &Builder, llptr: ValueRef, ty: ty::t) { b.call(llintrinsicfn, &[llptr, llzeroval, size, align, volatile], None); } -pub fn alloc_ty(bcx: Block, t: ty::t, name: &str) -> ValueRef { +pub fn alloc_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, name: &str) -> ValueRef { let _icx = push_ctxt("alloc_ty"); let ccx = bcx.ccx(); let ty = type_of::type_of(ccx, t); @@ -1220,7 +1232,8 @@ pub fn alloca_no_lifetime(cx: Block, ty: Type, name: &str) -> ValueRef { Alloca(cx, ty, name) } -pub fn alloca_zeroed(cx: Block, ty: ty::t, name: &str) -> ValueRef { +pub fn alloca_zeroed<'blk, 'tcx>(cx: Block<'blk, 'tcx>, ty: Ty<'tcx>, + name: &str) -> ValueRef { let llty = type_of::type_of(cx.ccx(), ty); if cx.unreachable.get() { unsafe { @@ -1248,7 +1261,8 @@ pub fn arrayalloca(cx: Block, ty: Type, v: ValueRef) -> ValueRef { } // Creates the alloca slot which holds the pointer to the slot for the final return value -pub fn make_return_slot_pointer(fcx: &FunctionContext, output_type: ty::t) -> ValueRef { +pub fn make_return_slot_pointer<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>, + output_type: Ty<'tcx>) -> ValueRef { let lloutputtype = type_of::type_of(fcx.ccx, output_type); // We create an alloca to hold a pointer of type `output_type` @@ -1407,12 +1421,12 @@ pub fn new_fn_ctxt<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>, llfndecl: ValueRef, id: ast::NodeId, has_env: bool, - output_type: ty::FnOutput, - param_substs: &'a param_substs, + output_type: ty::FnOutput<'tcx>, + param_substs: &'a Substs<'tcx>, sp: Option, block_arena: &'a TypedArena>) -> FunctionContext<'a, 'tcx> { - param_substs.validate(); + common::validate_substs(param_substs); debug!("new_fn_ctxt(path={}, id={}, param_substs={})", if id == -1 { @@ -1424,7 +1438,7 @@ pub fn new_fn_ctxt<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>, let uses_outptr = match output_type { ty::FnConverging(output_type) => { - let substd_output_type = output_type.substp(ccx.tcx(), param_substs); + let substd_output_type = output_type.subst(ccx.tcx(), param_substs); type_of::return_uses_outptr(ccx, substd_output_type) } ty::FnDiverging => false @@ -1463,7 +1477,8 @@ pub fn new_fn_ctxt<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>, /// and allocating space for the return pointer. pub fn init_function<'a, 'tcx>(fcx: &'a FunctionContext<'a, 'tcx>, skip_retptr: bool, - output: ty::FnOutput) -> Block<'a, 'tcx> { + output: ty::FnOutput<'tcx>) + -> Block<'a, 'tcx> { let entry_bcx = fcx.new_temp_block("entry-block"); // Use a dummy instruction as the insertion point for all allocas. @@ -1476,7 +1491,7 @@ pub fn init_function<'a, 'tcx>(fcx: &'a FunctionContext<'a, 'tcx>, if let ty::FnConverging(output_type) = output { // This shouldn't need to recompute the return type, // as new_fn_ctxt did it already. - let substd_output_type = output_type.substp(fcx.ccx.tcx(), fcx.param_substs); + let substd_output_type = output_type.subst(fcx.ccx.tcx(), fcx.param_substs); if !return_type_is_void(fcx.ccx, substd_output_type) { // If the function returns nil/bot, there is no real return // value, so do not set `llretslotptr`. @@ -1499,7 +1514,8 @@ pub fn init_function<'a, 'tcx>(fcx: &'a FunctionContext<'a, 'tcx>, // - new_fn_ctxt // - trans_args -pub fn arg_kind(cx: &FunctionContext, t: ty::t) -> datum::Rvalue { +pub fn arg_kind<'a, 'tcx>(cx: &FunctionContext<'a, 'tcx>, t: Ty<'tcx>) + -> datum::Rvalue { use trans::datum::{ByRef, ByValue}; datum::Rvalue { @@ -1508,15 +1524,15 @@ pub fn arg_kind(cx: &FunctionContext, t: ty::t) -> datum::Rvalue { } // work around bizarre resolve errors -pub type RvalueDatum = datum::Datum; -pub type LvalueDatum = datum::Datum; +pub type RvalueDatum<'tcx> = datum::Datum<'tcx, datum::Rvalue>; +pub type LvalueDatum<'tcx> = datum::Datum<'tcx, datum::Lvalue>; // create_datums_for_fn_args: creates rvalue datums for each of the // incoming function arguments. These will later be stored into // appropriate lvalue datums. -pub fn create_datums_for_fn_args(fcx: &FunctionContext, - arg_tys: &[ty::t]) - -> Vec { +pub fn create_datums_for_fn_args<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>, + arg_tys: &[Ty<'tcx>]) + -> Vec> { let _icx = push_ctxt("create_datums_for_fn_args"); // Return an array wrapping the ValueRefs that we get from `get_param` for @@ -1532,11 +1548,11 @@ pub fn create_datums_for_fn_args(fcx: &FunctionContext, /// datums. /// /// FIXME(pcwalton): Reduce the amount of code bloat this is responsible for. -fn create_datums_for_fn_args_under_call_abi( - mut bcx: Block, +fn create_datums_for_fn_args_under_call_abi<'blk, 'tcx>( + mut bcx: Block<'blk, 'tcx>, arg_scope: cleanup::CustomScopeIndex, - arg_tys: &[ty::t]) - -> Vec { + arg_tys: &[Ty<'tcx>]) + -> Vec> { let mut result = Vec::new(); for (i, &arg_ty) in arg_tys.iter().enumerate() { if i < arg_tys.len() - 1 { @@ -1548,7 +1564,7 @@ fn create_datums_for_fn_args_under_call_abi( } // This is the last argument. Tuple it. - match ty::get(arg_ty).sty { + match arg_ty.sty { ty::ty_tup(ref tupled_arg_tys) => { let tuple_args_scope_id = cleanup::CustomScope(arg_scope); let tuple = @@ -1597,7 +1613,7 @@ fn copy_args_to_allocas<'blk, 'tcx>(fcx: &FunctionContext<'blk, 'tcx>, arg_scope: cleanup::CustomScopeIndex, bcx: Block<'blk, 'tcx>, args: &[ast::Arg], - arg_datums: Vec ) + arg_datums: Vec>) -> Block<'blk, 'tcx> { debug!("copy_args_to_allocas"); @@ -1629,8 +1645,8 @@ fn copy_unboxed_closure_args_to_allocas<'blk, 'tcx>( mut bcx: Block<'blk, 'tcx>, arg_scope: cleanup::CustomScopeIndex, args: &[ast::Arg], - arg_datums: Vec, - monomorphized_arg_types: &[ty::t]) + arg_datums: Vec>, + monomorphized_arg_types: &[Ty<'tcx>]) -> Block<'blk, 'tcx> { let _icx = push_ctxt("copy_unboxed_closure_args_to_allocas"); let arg_scope_id = cleanup::CustomScope(arg_scope); @@ -1645,7 +1661,7 @@ fn copy_unboxed_closure_args_to_allocas<'blk, 'tcx>( arg_datum.to_lvalue_datum_in_scope(bcx, "argtuple", arg_scope_id)); - let untupled_arg_types = match ty::get(monomorphized_arg_types[0]).sty { + let untupled_arg_types = match monomorphized_arg_types[0].sty { ty::ty_tup(ref types) => types.as_slice(), _ => { bcx.tcx().sess.span_bug(args[0].pat.span, @@ -1681,7 +1697,7 @@ fn copy_unboxed_closure_args_to_allocas<'blk, 'tcx>( // and builds the return block. pub fn finish_fn<'blk, 'tcx>(fcx: &'blk FunctionContext<'blk, 'tcx>, last_bcx: Block<'blk, 'tcx>, - retty: ty::FnOutput) { + retty: ty::FnOutput<'tcx>) { let _icx = push_ctxt("finish_fn"); let ret_cx = match fcx.llreturn.get() { @@ -1696,7 +1712,7 @@ pub fn finish_fn<'blk, 'tcx>(fcx: &'blk FunctionContext<'blk, 'tcx>, // This shouldn't need to recompute the return type, // as new_fn_ctxt did it already. - let substd_retty = retty.substp(fcx.ccx.tcx(), fcx.param_substs); + let substd_retty = retty.subst(fcx.ccx.tcx(), fcx.param_substs); build_return_block(fcx, ret_cx, substd_retty); debuginfo::clear_source_location(fcx); @@ -1704,7 +1720,9 @@ pub fn finish_fn<'blk, 'tcx>(fcx: &'blk FunctionContext<'blk, 'tcx>, } // Builds the return block for a function. -pub fn build_return_block(fcx: &FunctionContext, ret_cx: Block, retty: ty::FnOutput) { +pub fn build_return_block<'blk, 'tcx>(fcx: &FunctionContext<'blk, 'tcx>, + ret_cx: Block<'blk, 'tcx>, + retty: ty::FnOutput<'tcx>) { if fcx.llretslotptr.get().is_none() || (!fcx.needs_ret_allocas && fcx.caller_expects_out_pointer) { return RetVoid(ret_cx); @@ -1763,28 +1781,19 @@ pub fn build_return_block(fcx: &FunctionContext, ret_cx: Block, retty: ty::FnOut } } -#[deriving(Clone, Eq, PartialEq)] -pub enum IsUnboxedClosureFlag { - NotUnboxedClosure, - IsUnboxedClosure, -} - // trans_closure: Builds an LLVM function out of a source function. // If the function closes over its environment a closure will be // returned. -pub fn trans_closure(ccx: &CrateContext, - decl: &ast::FnDecl, - body: &ast::Block, - llfndecl: ValueRef, - param_substs: ¶m_substs, - fn_ast_id: ast::NodeId, - _attributes: &[ast::Attribute], - output_type: ty::FnOutput, - abi: Abi, - has_env: bool, - is_unboxed_closure: IsUnboxedClosureFlag, - maybe_load_env: for<'blk, 'tcx> |Block<'blk, 'tcx>, ScopeId| - -> Block<'blk, 'tcx>) { +pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + decl: &ast::FnDecl, + body: &ast::Block, + llfndecl: ValueRef, + param_substs: &Substs<'tcx>, + fn_ast_id: ast::NodeId, + _attributes: &[ast::Attribute], + output_type: ty::FnOutput<'tcx>, + abi: Abi, + closure_env: closure::ClosureEnv<'b, 'tcx>) { ccx.stats().n_closures.set(ccx.stats().n_closures.get() + 1); let _icx = push_ctxt("trans_closure"); @@ -1797,7 +1806,7 @@ pub fn trans_closure(ccx: &CrateContext, let fcx = new_fn_ctxt(ccx, llfndecl, fn_ast_id, - has_env, + closure_env.kind != closure::NotClosure, output_type, param_substs, Some(body.span), @@ -1816,11 +1825,15 @@ pub fn trans_closure(ccx: &CrateContext, decl.inputs.iter() .map(|arg| node_id_type(bcx, arg.id)) .collect::>(); - let monomorphized_arg_types = match is_unboxed_closure { - NotUnboxedClosure => monomorphized_arg_types, + let monomorphized_arg_types = match closure_env.kind { + closure::NotClosure | closure::BoxedClosure(..) => { + monomorphized_arg_types + } // Tuple up closure argument types for the "rust-call" ABI. - IsUnboxedClosure => vec![ty::mk_tup(ccx.tcx(), monomorphized_arg_types)] + closure::UnboxedClosure(..) => { + vec![ty::mk_tup(ccx.tcx(), monomorphized_arg_types)] + } }; for monomorphized_arg_type in monomorphized_arg_types.iter() { debug!("trans_closure: monomorphized_arg_type: {}", @@ -1839,15 +1852,15 @@ pub fn trans_closure(ccx: &CrateContext, monomorphized_arg_types.as_slice()) }; - bcx = match is_unboxed_closure { - NotUnboxedClosure => { + bcx = match closure_env.kind { + closure::NotClosure | closure::BoxedClosure(..) => { copy_args_to_allocas(&fcx, arg_scope, bcx, decl.inputs.as_slice(), arg_datums) } - IsUnboxedClosure => { + closure::UnboxedClosure(..) => { copy_unboxed_closure_args_to_allocas( bcx, arg_scope, @@ -1857,7 +1870,7 @@ pub fn trans_closure(ccx: &CrateContext, } }; - bcx = maybe_load_env(bcx, cleanup::CustomScope(arg_scope)); + bcx = closure_env.load(bcx, cleanup::CustomScope(arg_scope)); // Up until here, IR instructions for this function have explicitly not been annotated with // source code location, so we don't step into call setup code. From here on, source location @@ -1912,13 +1925,13 @@ pub fn trans_closure(ccx: &CrateContext, // trans_fn: creates an LLVM function corresponding to a source language // function. -pub fn trans_fn(ccx: &CrateContext, - decl: &ast::FnDecl, - body: &ast::Block, - llfndecl: ValueRef, - param_substs: ¶m_substs, - id: ast::NodeId, - attrs: &[ast::Attribute]) { +pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + decl: &ast::FnDecl, + body: &ast::Block, + llfndecl: ValueRef, + param_substs: &Substs<'tcx>, + id: ast::NodeId, + attrs: &[ast::Attribute]) { let _s = StatRecorder::new(ccx, ccx.tcx().map.path_to_string(id).to_string()); debug!("trans_fn(param_substs={})", param_substs.repr(ccx.tcx())); let _icx = push_ctxt("trans_fn"); @@ -1934,18 +1947,16 @@ pub fn trans_fn(ccx: &CrateContext, attrs, output_type, abi, - false, - NotUnboxedClosure, - |bcx, _| bcx); -} - -pub fn trans_enum_variant(ccx: &CrateContext, - _enum_id: ast::NodeId, - variant: &ast::Variant, - _args: &[ast::VariantArg], - disr: ty::Disr, - param_substs: ¶m_substs, - llfndecl: ValueRef) { + closure::ClosureEnv::new(&[], closure::NotClosure)); +} + +pub fn trans_enum_variant<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + _enum_id: ast::NodeId, + variant: &ast::Variant, + _args: &[ast::VariantArg], + disr: ty::Disr, + param_substs: &Substs<'tcx>, + llfndecl: ValueRef) { let _icx = push_ctxt("trans_enum_variant"); trans_enum_variant_or_tuple_like_struct( @@ -1957,7 +1968,7 @@ pub fn trans_enum_variant(ccx: &CrateContext, } pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, - ctor_ty: ty::t, + ctor_ty: Ty<'tcx>, disr: ty::Disr, args: callee::CallArgs, dest: expr::Dest, @@ -1967,7 +1978,7 @@ pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, let ccx = bcx.fcx.ccx; let tcx = ccx.tcx(); - let result_ty = match ty::get(ctor_ty).sty { + let result_ty = match ctor_ty.sty { ty::ty_bare_fn(ref bft) => bft.sig.output.unwrap(), _ => ccx.sess().bug( format!("trans_enum_variant_constructor: \ @@ -2016,11 +2027,11 @@ pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, Result::new(bcx, llresult) } -pub fn trans_tuple_struct(ccx: &CrateContext, - _fields: &[ast::StructField], - ctor_id: ast::NodeId, - param_substs: ¶m_substs, - llfndecl: ValueRef) { +pub fn trans_tuple_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + _fields: &[ast::StructField], + ctor_id: ast::NodeId, + param_substs: &Substs<'tcx>, + llfndecl: ValueRef) { let _icx = push_ctxt("trans_tuple_struct"); trans_enum_variant_or_tuple_like_struct( @@ -2031,15 +2042,15 @@ pub fn trans_tuple_struct(ccx: &CrateContext, llfndecl); } -fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext, - ctor_id: ast::NodeId, - disr: ty::Disr, - param_substs: ¶m_substs, - llfndecl: ValueRef) { +fn trans_enum_variant_or_tuple_like_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + ctor_id: ast::NodeId, + disr: ty::Disr, + param_substs: &Substs<'tcx>, + llfndecl: ValueRef) { let ctor_ty = ty::node_id_to_type(ccx.tcx(), ctor_id); - let ctor_ty = ctor_ty.substp(ccx.tcx(), param_substs); + let ctor_ty = ctor_ty.subst(ccx.tcx(), param_substs); - let result_ty = match ty::get(ctor_ty).sty { + let result_ty = match ctor_ty.sty { ty::ty_bare_fn(ref bft) => bft.sig.output, _ => ccx.sess().bug( format!("trans_enum_variant_or_tuple_like_struct: \ @@ -2253,7 +2264,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) { &**body, item.attrs.as_slice(), llfn, - ¶m_substs::empty(), + &Substs::trans_empty(), item.id, None); } else { @@ -2261,7 +2272,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) { &**decl, &**body, llfn, - ¶m_substs::empty(), + &Substs::trans_empty(), item.id, item.attrs.as_slice()); } @@ -2370,13 +2381,13 @@ fn finish_register_fn(ccx: &CrateContext, sp: Span, sym: String, node_id: ast::N } } -fn register_fn(ccx: &CrateContext, - sp: Span, - sym: String, - node_id: ast::NodeId, - node_type: ty::t) - -> ValueRef { - match ty::get(node_type).sty { +fn register_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + sp: Span, + sym: String, + node_id: ast::NodeId, + node_type: Ty<'tcx>) + -> ValueRef { + match node_type.sty { ty::ty_bare_fn(ref f) => { assert!(f.abi == Rust || f.abi == RustCall); } @@ -2388,11 +2399,11 @@ fn register_fn(ccx: &CrateContext, llfn } -pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) - -> llvm::AttrBuilder { +pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<'tcx>) + -> llvm::AttrBuilder { use middle::ty::{BrAnon, ReLateBound}; - let (fn_sig, abi, has_env) = match ty::get(fn_ty).sty { + let (fn_sig, abi, has_env) = match fn_ty.sty { ty::ty_closure(ref f) => (f.sig.clone(), f.abi, true), ty::ty_bare_fn(ref f) => (f.sig.clone(), f.abi, false), ty::ty_unboxed_closure(closure_did, _, ref substs) => { @@ -2414,11 +2425,11 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) // These have an odd calling convention, so we need to manually // unpack the input ty's - let input_tys = match ty::get(fn_ty).sty { + let input_tys = match fn_ty.sty { ty::ty_unboxed_closure(_, _, _) => { assert!(abi == RustCall); - match ty::get(fn_sig.inputs[0]).sty { + match fn_sig.inputs[0].sty { ty::ty_tup(ref inputs) => inputs.clone(), _ => ccx.sess().bug("expected tuple'd inputs") } @@ -2426,7 +2437,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) ty::ty_bare_fn(_) if abi == RustCall => { let mut inputs = vec![fn_sig.inputs[0]]; - match ty::get(fn_sig.inputs[1]).sty { + match fn_sig.inputs[1].sty { ty::ty_tup(ref t_in) => { inputs.push_all(t_in.as_slice()); inputs @@ -2458,7 +2469,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) } else { // The `noalias` attribute on the return value is useful to a // function ptr caller. - match ty::get(ret_ty).sty { + match ret_ty.sty { // `~` pointer return values never alias because ownership // is transferred ty::ty_uniq(it) if !ty::type_is_sized(ccx.tcx(), it) => {} @@ -2469,7 +2480,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) } // We can also mark the return value as `dereferenceable` in certain cases - match ty::get(ret_ty).sty { + match ret_ty.sty { // These are not really pointers but pairs, (pointer, len) ty::ty_uniq(it) | ty::ty_rptr(_, ty::mt { ty: it, .. }) if !ty::type_is_sized(ccx.tcx(), it) => {} @@ -2480,7 +2491,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) _ => {} } - match ty::get(ret_ty).sty { + match ret_ty.sty { ty::ty_bool => { attrs.ret(llvm::ZExtAttribute); } @@ -2490,7 +2501,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) } for (idx, &t) in input_tys.iter().enumerate().map(|(i, v)| (i + first_arg_offset, v)) { - match ty::get(t).sty { + match t.sty { // this needs to be first to prevent fat pointers from falling through _ if !type_is_immediate(ccx, t) => { let llarg_sz = llsize_of_real(ccx, type_of::type_of(ccx, t)); @@ -2664,8 +2675,8 @@ pub fn create_entry_wrapper(ccx: &CrateContext, } } -fn exported_name(ccx: &CrateContext, id: ast::NodeId, - ty: ty::t, attrs: &[ast::Attribute]) -> String { +fn exported_name<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, id: ast::NodeId, + ty: Ty<'tcx>, attrs: &[ast::Attribute]) -> String { match ccx.external_srcs().borrow().get(&id) { Some(&did) => { let sym = csearch::get_symbol(&ccx.sess().cstore, did); diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index de49754fe7f9d..bf7adbbecef1a 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -29,7 +29,7 @@ use llvm; use metadata::csearch; use middle::def; use middle::subst; -use middle::subst::{Subst}; +use middle::subst::{Subst, Substs}; use trans::adt; use trans::base; use trans::base::*; @@ -50,7 +50,7 @@ use trans::meth; use trans::monomorphize; use trans::type_::Type; use trans::type_of; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck::coherence::make_substs_for_receiver_types; use middle::typeck::MethodCall; use util::ppaux::Repr; @@ -66,26 +66,26 @@ pub struct MethodData { pub llself: ValueRef, } -pub enum CalleeData { - Closure(Datum), +pub enum CalleeData<'tcx> { + Closure(Datum<'tcx, Lvalue>), // Constructor for enum variant/tuple-like-struct // i.e. Some, Ok - NamedTupleConstructor(subst::Substs, ty::Disr), + NamedTupleConstructor(subst::Substs<'tcx>, ty::Disr), // Represents a (possibly monomorphized) top-level fn item or method // item. Note that this is just the fn-ptr and is not a Rust closure // value (which is a pair). Fn(/* llfn */ ValueRef), - Intrinsic(ast::NodeId, subst::Substs), + Intrinsic(ast::NodeId, subst::Substs<'tcx>), TraitItem(MethodData) } pub struct Callee<'blk, 'tcx: 'blk> { pub bcx: Block<'blk, 'tcx>, - pub data: CalleeData, + pub data: CalleeData<'tcx>, } fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) @@ -107,7 +107,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) fn datum_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) -> Callee<'blk, 'tcx> { let DatumBlock {mut bcx, datum} = expr::trans(bcx, expr); - match ty::get(datum.ty).sty { + match datum.ty.sty { ty::ty_bare_fn(..) => { let llval = datum.to_llscalarish(bcx); return Callee { @@ -163,7 +163,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) data: NamedTupleConstructor(substs, 0) } } - def::DefFn(did, _) if match ty::get(expr_ty).sty { + def::DefFn(did, _) if match expr_ty.sty { ty::ty_bare_fn(ref f) => f.abi == synabi::RustIntrinsic, _ => false } => { @@ -240,7 +240,7 @@ pub fn trans_fn_ref(bcx: Block, def_id: ast::DefId, node: ExprOrMethodCall) -> V fn trans_fn_ref_with_substs_to_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, def_id: ast::DefId, ref_id: ast::NodeId, - substs: subst::Substs) + substs: subst::Substs<'tcx>) -> Callee<'blk, 'tcx> { Callee { bcx: bcx, @@ -253,12 +253,12 @@ fn trans_fn_ref_with_substs_to_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, /// Translates the adapter that deconstructs a `Box` object into /// `Trait` so that a by-value self method can be called. -pub fn trans_unboxing_shim(bcx: Block, - llshimmedfn: ValueRef, - fty: &ty::BareFnTy, - method_id: ast::DefId, - substs: &subst::Substs) - -> ValueRef { +pub fn trans_unboxing_shim<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + llshimmedfn: ValueRef, + fty: &ty::BareFnTy<'tcx>, + method_id: ast::DefId, + substs: &subst::Substs<'tcx>) + -> ValueRef { let _icx = push_ctxt("trans_unboxing_shim"); let ccx = bcx.ccx(); let tcx = bcx.tcx(); @@ -319,7 +319,7 @@ pub fn trans_unboxing_shim(bcx: Block, function_name.as_slice()); let block_arena = TypedArena::new(); - let empty_param_substs = param_substs::empty(); + let empty_param_substs = Substs::trans_empty(); let return_type = ty::ty_fn_ret(boxed_function_type); let fcx = new_fn_ctxt(ccx, llfn, @@ -334,8 +334,7 @@ pub fn trans_unboxing_shim(bcx: Block, // Create the substituted versions of the self type. let arg_scope = fcx.push_custom_cleanup_scope(); let arg_scope_id = cleanup::CustomScope(arg_scope); - let boxed_arg_types = ty::ty_fn_args(boxed_function_type); - let boxed_self_type = boxed_arg_types[0]; + let boxed_self_type = ty::ty_fn_args(boxed_function_type)[0]; let arg_types = ty::ty_fn_args(function_type); let self_type = arg_types[0]; let boxed_self_kind = arg_kind(&fcx, boxed_self_type); @@ -399,11 +398,11 @@ pub fn trans_unboxing_shim(bcx: Block, llfn } -pub fn trans_fn_ref_with_substs( - bcx: Block, // +pub fn trans_fn_ref_with_substs<'blk, 'tcx>( + bcx: Block<'blk, 'tcx>, // def_id: ast::DefId, // def id of fn node: ExprOrMethodCall, // node id of use of fn; may be zero if N/A - substs: subst::Substs) // vtables for the call + substs: subst::Substs<'tcx>) // vtables for the call -> ValueRef { /*! @@ -610,12 +609,12 @@ pub fn trans_fn_ref_with_substs( // ______________________________________________________________________ // Translating calls -pub fn trans_call<'blk, 'tcx>(in_cx: Block<'blk, 'tcx>, - call_ex: &ast::Expr, - f: &ast::Expr, - args: CallArgs, - dest: expr::Dest) - -> Block<'blk, 'tcx> { +pub fn trans_call<'a, 'blk, 'tcx>(in_cx: Block<'blk, 'tcx>, + call_ex: &ast::Expr, + f: &ast::Expr, + args: CallArgs<'a, 'tcx>, + dest: expr::Dest) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_call"); trans_call_inner(in_cx, Some(common::expr_info(call_ex)), @@ -625,12 +624,12 @@ pub fn trans_call<'blk, 'tcx>(in_cx: Block<'blk, 'tcx>, Some(dest)).bcx } -pub fn trans_method_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - call_ex: &ast::Expr, - rcvr: &ast::Expr, - args: CallArgs, - dest: expr::Dest) - -> Block<'blk, 'tcx> { +pub fn trans_method_call<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + call_ex: &ast::Expr, + rcvr: &ast::Expr, + args: CallArgs<'a, 'tcx>, + dest: expr::Dest) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_method_call"); debug!("trans_method_call(call_ex={})", call_ex.repr(bcx.tcx())); let method_call = MethodCall::expr(call_ex.id); @@ -669,15 +668,15 @@ pub fn trans_lang_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, dest) } -pub fn trans_call_inner<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - call_info: Option, - callee_ty: ty::t, - get_callee: |bcx: Block<'blk, 'tcx>, - arg_cleanup_scope: cleanup::ScopeId| - -> Callee<'blk, 'tcx>, - args: CallArgs, - dest: Option) - -> Result<'blk, 'tcx> { +pub fn trans_call_inner<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + call_info: Option, + callee_ty: Ty<'tcx>, + get_callee: |bcx: Block<'blk, 'tcx>, + arg_cleanup_scope: cleanup::ScopeId| + -> Callee<'blk, 'tcx>, + args: CallArgs<'a, 'tcx>, + dest: Option) + -> Result<'blk, 'tcx> { /*! * This behemoth of a function translates function calls. * Unfortunately, in order to generate more efficient LLVM @@ -708,7 +707,7 @@ pub fn trans_call_inner<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let callee = get_callee(bcx, cleanup::CustomScope(arg_cleanup_scope)); let mut bcx = callee.bcx; - let (abi, ret_ty) = match ty::get(callee_ty).sty { + let (abi, ret_ty) = match callee_ty.sty { ty::ty_bare_fn(ref f) => (f.abi, f.sig.output), ty::ty_closure(ref f) => (f.abi, f.sig.output), _ => panic!("expected bare rust fn or closure in trans_call_inner") @@ -890,7 +889,7 @@ pub fn trans_call_inner<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, Result::new(bcx, llresult) } -pub enum CallArgs<'a> { +pub enum CallArgs<'a, 'tcx> { // Supply value of arguments as a list of expressions that must be // translated. This is used in the common case of `foo(bar, qux)`. ArgExprs(&'a [P]), @@ -903,7 +902,7 @@ pub enum CallArgs<'a> { // For overloaded operators: `(lhs, Vec(rhs, rhs_id))`. `lhs` // is the left-hand-side and `rhs/rhs_id` is the datum/expr-id of // the right-hand-side arguments (if any). - ArgOverloadedOp(Datum, Vec<(Datum, ast::NodeId)>), + ArgOverloadedOp(Datum<'tcx, Expr>, Vec<(Datum<'tcx, Expr>, ast::NodeId)>), // Supply value of arguments as a list of expressions that must be // translated, for overloaded call operators. @@ -913,18 +912,17 @@ pub enum CallArgs<'a> { fn trans_args_under_call_abi<'blk, 'tcx>( mut bcx: Block<'blk, 'tcx>, arg_exprs: &[P], - fn_ty: ty::t, + fn_ty: Ty<'tcx>, llargs: &mut Vec, arg_cleanup_scope: cleanup::ScopeId, ignore_self: bool) -> Block<'blk, 'tcx> { // Translate the `self` argument first. - let arg_tys = ty::ty_fn_args(fn_ty); if !ignore_self { let arg_datum = unpack_datum!(bcx, expr::trans(bcx, &*arg_exprs[0])); llargs.push(unpack_result!(bcx, { trans_arg_datum(bcx, - arg_tys[0], + ty::ty_fn_args(fn_ty)[0], arg_datum, arg_cleanup_scope, DontAutorefArg) @@ -935,7 +933,7 @@ fn trans_args_under_call_abi<'blk, 'tcx>( let tuple_expr = &arg_exprs[1]; let tuple_type = node_id_type(bcx, tuple_expr.id); - match ty::get(tuple_type).sty { + match tuple_type.sty { ty::ty_tup(ref field_types) => { let tuple_datum = unpack_datum!(bcx, expr::trans(bcx, &**tuple_expr)); @@ -973,7 +971,7 @@ fn trans_args_under_call_abi<'blk, 'tcx>( fn trans_overloaded_call_args<'blk, 'tcx>( mut bcx: Block<'blk, 'tcx>, arg_exprs: Vec<&ast::Expr>, - fn_ty: ty::t, + fn_ty: Ty<'tcx>, llargs: &mut Vec, arg_cleanup_scope: cleanup::ScopeId, ignore_self: bool) @@ -993,7 +991,7 @@ fn trans_overloaded_call_args<'blk, 'tcx>( // Now untuple the rest of the arguments. let tuple_type = arg_tys[1]; - match ty::get(tuple_type).sty { + match tuple_type.sty { ty::ty_tup(ref field_types) => { for (i, &field_type) in field_types.iter().enumerate() { let arg_datum = @@ -1016,14 +1014,14 @@ fn trans_overloaded_call_args<'blk, 'tcx>( bcx } -pub fn trans_args<'blk, 'tcx>(cx: Block<'blk, 'tcx>, - args: CallArgs, - fn_ty: ty::t, - llargs: &mut Vec , - arg_cleanup_scope: cleanup::ScopeId, - ignore_self: bool, - abi: synabi::Abi) - -> Block<'blk, 'tcx> { +pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, + args: CallArgs<'a, 'tcx>, + fn_ty: Ty<'tcx>, + llargs: &mut Vec, + arg_cleanup_scope: cleanup::ScopeId, + ignore_self: bool, + abi: synabi::Abi) + -> Block<'blk, 'tcx> { debug!("trans_args(abi={})", abi); let _icx = push_ctxt("trans_args"); @@ -1108,8 +1106,8 @@ pub enum AutorefArg { } pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - formal_arg_ty: ty::t, - arg_datum: Datum, + formal_arg_ty: Ty<'tcx>, + arg_datum: Datum<'tcx, Expr>, arg_cleanup_scope: cleanup::ScopeId, autoref_arg: AutorefArg) -> Result<'blk, 'tcx> { diff --git a/src/librustc_trans/trans/cleanup.rs b/src/librustc_trans/trans/cleanup.rs index 02909b0e3a921..0a26922e18468 100644 --- a/src/librustc_trans/trans/cleanup.rs +++ b/src/librustc_trans/trans/cleanup.rs @@ -27,7 +27,7 @@ use trans::common::{Block, FunctionContext, ExprId, NodeInfo}; use trans::debuginfo; use trans::glue; use trans::type_::Type; -use middle::ty; +use middle::ty::{mod, Ty}; use std::fmt; use syntax::ast; use util::ppaux::Repr; @@ -41,7 +41,7 @@ pub struct CleanupScope<'blk, 'tcx: 'blk> { kind: CleanupScopeKind<'blk, 'tcx>, // Cleanups to run upon scope exit. - cleanups: Vec, + cleanups: Vec>, // The debug location any drop calls generated for this scope will be // associated with. @@ -94,17 +94,17 @@ pub struct CachedEarlyExit { cleanup_block: BasicBlockRef, } -pub trait Cleanup { +pub trait Cleanup<'tcx> { fn must_unwind(&self) -> bool; fn clean_on_unwind(&self) -> bool; fn is_lifetime_end(&self) -> bool; - fn trans<'blk, 'tcx>(&self, - bcx: Block<'blk, 'tcx>, - debug_loc: Option) - -> Block<'blk, 'tcx>; + fn trans<'blk>(&self, + bcx: Block<'blk, 'tcx>, + debug_loc: Option) + -> Block<'blk, 'tcx>; } -pub type CleanupObj = Box; +pub type CleanupObj<'tcx> = Box+'tcx>; #[deriving(Show)] pub enum ScopeId { @@ -307,7 +307,7 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { fn schedule_drop_mem(&self, cleanup_scope: ScopeId, val: ValueRef, - ty: ty::t) { + ty: Ty<'tcx>) { /*! * Schedules a (deep) drop of `val`, which is a pointer to an * instance of `ty` @@ -333,7 +333,7 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { fn schedule_drop_and_zero_mem(&self, cleanup_scope: ScopeId, val: ValueRef, - ty: ty::t) { + ty: Ty<'tcx>) { /*! * Schedules a (deep) drop and zero-ing of `val`, which is a pointer * to an instance of `ty` @@ -360,7 +360,7 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { fn schedule_drop_immediate(&self, cleanup_scope: ScopeId, val: ValueRef, - ty: ty::t) { + ty: Ty<'tcx>) { /*! * Schedules a (deep) drop of `val`, which is an instance of `ty` */ @@ -386,7 +386,7 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { cleanup_scope: ScopeId, val: ValueRef, heap: Heap, - content_ty: ty::t) { + content_ty: Ty<'tcx>) { /*! * Schedules a call to `free(val)`. Note that this is a shallow * operation. @@ -425,7 +425,7 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { fn schedule_clean(&self, cleanup_scope: ScopeId, - cleanup: CleanupObj) { + cleanup: CleanupObj<'tcx>) { match cleanup_scope { AstScope(id) => self.schedule_clean_in_ast_scope(id, cleanup), CustomScope(id) => self.schedule_clean_in_custom_scope(id, cleanup), @@ -434,7 +434,7 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { fn schedule_clean_in_ast_scope(&self, cleanup_scope: ast::NodeId, - cleanup: CleanupObj) { + cleanup: CleanupObj<'tcx>) { /*! * Schedules a cleanup to occur upon exit from `cleanup_scope`. * If `cleanup_scope` is not provided, then the cleanup is scheduled @@ -462,7 +462,7 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { fn schedule_clean_in_custom_scope(&self, custom_scope: CustomScopeIndex, - cleanup: CleanupObj) { + cleanup: CleanupObj<'tcx>) { /*! * Schedules a cleanup to occur in the top-most scope, * which must be a temporary scope. @@ -559,7 +559,7 @@ impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx fn trans_scope_cleanups(&self, // cannot borrow self, will recurse bcx: Block<'blk, 'tcx>, - scope: &CleanupScope) -> Block<'blk, 'tcx> { + scope: &CleanupScope<'blk, 'tcx>) -> Block<'blk, 'tcx> { /*! Generates the cleanups for `scope` into `bcx` */ let mut bcx = bcx; @@ -955,15 +955,15 @@ impl EarlyExitLabel { /////////////////////////////////////////////////////////////////////////// // Cleanup types -pub struct DropValue { +pub struct DropValue<'tcx> { is_immediate: bool, must_unwind: bool, val: ValueRef, - ty: ty::t, + ty: Ty<'tcx>, zero: bool } -impl Cleanup for DropValue { +impl<'tcx> Cleanup<'tcx> for DropValue<'tcx> { fn must_unwind(&self) -> bool { self.must_unwind } @@ -976,10 +976,10 @@ impl Cleanup for DropValue { false } - fn trans<'blk, 'tcx>(&self, - bcx: Block<'blk, 'tcx>, - debug_loc: Option) - -> Block<'blk, 'tcx> { + fn trans<'blk>(&self, + bcx: Block<'blk, 'tcx>, + debug_loc: Option) + -> Block<'blk, 'tcx> { let bcx = if self.is_immediate { glue::drop_ty_immediate(bcx, self.val, self.ty, debug_loc) } else { @@ -997,13 +997,13 @@ pub enum Heap { HeapExchange } -pub struct FreeValue { +pub struct FreeValue<'tcx> { ptr: ValueRef, heap: Heap, - content_ty: ty::t + content_ty: Ty<'tcx> } -impl Cleanup for FreeValue { +impl<'tcx> Cleanup<'tcx> for FreeValue<'tcx> { fn must_unwind(&self) -> bool { true } @@ -1016,10 +1016,10 @@ impl Cleanup for FreeValue { false } - fn trans<'blk, 'tcx>(&self, - bcx: Block<'blk, 'tcx>, - debug_loc: Option) - -> Block<'blk, 'tcx> { + fn trans<'blk>(&self, + bcx: Block<'blk, 'tcx>, + debug_loc: Option) + -> Block<'blk, 'tcx> { apply_debug_loc(bcx.fcx, debug_loc); match self.heap { @@ -1037,7 +1037,7 @@ pub struct FreeSlice { heap: Heap, } -impl Cleanup for FreeSlice { +impl<'tcx> Cleanup<'tcx> for FreeSlice { fn must_unwind(&self) -> bool { true } @@ -1068,7 +1068,7 @@ pub struct LifetimeEnd { ptr: ValueRef, } -impl Cleanup for LifetimeEnd { +impl<'tcx> Cleanup<'tcx> for LifetimeEnd { fn must_unwind(&self) -> bool { false } @@ -1166,20 +1166,20 @@ pub trait CleanupMethods<'blk, 'tcx> { fn schedule_drop_mem(&self, cleanup_scope: ScopeId, val: ValueRef, - ty: ty::t); + ty: Ty<'tcx>); fn schedule_drop_and_zero_mem(&self, cleanup_scope: ScopeId, val: ValueRef, - ty: ty::t); + ty: Ty<'tcx>); fn schedule_drop_immediate(&self, cleanup_scope: ScopeId, val: ValueRef, - ty: ty::t); + ty: Ty<'tcx>); fn schedule_free_value(&self, cleanup_scope: ScopeId, val: ValueRef, heap: Heap, - content_ty: ty::t); + content_ty: Ty<'tcx>); fn schedule_free_slice(&self, cleanup_scope: ScopeId, val: ValueRef, @@ -1188,13 +1188,13 @@ pub trait CleanupMethods<'blk, 'tcx> { heap: Heap); fn schedule_clean(&self, cleanup_scope: ScopeId, - cleanup: CleanupObj); + cleanup: CleanupObj<'tcx>); fn schedule_clean_in_ast_scope(&self, cleanup_scope: ast::NodeId, - cleanup: CleanupObj); + cleanup: CleanupObj<'tcx>); fn schedule_clean_in_custom_scope(&self, custom_scope: CustomScopeIndex, - cleanup: CleanupObj); + cleanup: CleanupObj<'tcx>); fn needs_invoke(&self) -> bool; fn get_landing_pad(&'blk self) -> BasicBlockRef; } diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index 3cb823aec34c1..d4c93be7eafca 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +pub use self::ClosureKind::*; use back::abi; use back::link::mangle_internal_name_by_path_and_seq; @@ -25,7 +26,7 @@ use trans::expr; use trans::monomorphize::MonoId; use trans::type_of::*; use trans::type_::Type; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::subst::{Subst, Substs}; use session::config::FullDebugInfo; use util::ppaux::Repr; @@ -101,21 +102,21 @@ use syntax::ast_util; // // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -pub struct EnvValue { +pub struct EnvValue<'tcx> { action: ast::CaptureClause, - datum: Datum + datum: Datum<'tcx, Lvalue> } -impl EnvValue { - pub fn to_string(&self, ccx: &CrateContext) -> String { +impl<'tcx> EnvValue<'tcx> { + pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String { format!("{}({})", self.action, self.datum.to_string(ccx)) } } // Given a closure ty, emits a corresponding tuple ty -pub fn mk_closure_tys(tcx: &ty::ctxt, - bound_values: &[EnvValue]) - -> ty::t { +pub fn mk_closure_tys<'tcx>(tcx: &ty::ctxt<'tcx>, + bound_values: &[EnvValue<'tcx>]) + -> Ty<'tcx> { // determine the types of the values in the env. Note that this // is the actual types that will be stored in the map, not the // logical types as the user sees them, so by-ref upvars must be @@ -131,14 +132,14 @@ pub fn mk_closure_tys(tcx: &ty::ctxt, return cdata_ty; } -fn tuplify_box_ty(tcx: &ty::ctxt, t: ty::t) -> ty::t { +fn tuplify_box_ty<'tcx>(tcx: &ty::ctxt<'tcx>, t: Ty<'tcx>) -> Ty<'tcx> { let ptr = ty::mk_imm_ptr(tcx, ty::mk_i8()); ty::mk_tup(tcx, vec!(ty::mk_uint(), ty::mk_nil_ptr(tcx), ptr, ptr, t)) } fn allocate_cbox<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, store: ty::TraitStore, - cdata_ty: ty::t) + cdata_ty: Ty<'tcx>) -> Result<'blk, 'tcx> { let _icx = push_ctxt("closure::allocate_cbox"); let tcx = bcx.tcx(); @@ -157,8 +158,8 @@ fn allocate_cbox<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } pub struct ClosureResult<'blk, 'tcx: 'blk> { - llbox: ValueRef, // llvalue of ptr to closure - cdata_ty: ty::t, // type of the closure data + llbox: ValueRef, // llvalue of ptr to closure + cdata_ty: Ty<'tcx>, // type of the closure data bcx: Block<'blk, 'tcx> // final bcx } @@ -167,7 +168,7 @@ pub struct ClosureResult<'blk, 'tcx: 'blk> { // heap allocated closure that copies the upvars into environment. // Otherwise, it is stack allocated and copies pointers to the upvars. pub fn store_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - bound_values: Vec , + bound_values: Vec> , store: ty::TraitStore) -> ClosureResult<'blk, 'tcx> { let _icx = push_ctxt("closure::store_environment"); @@ -248,17 +249,12 @@ fn build_closure<'blk, 'tcx>(bcx0: Block<'blk, 'tcx>, // and a list of upvars, generate code to load and populate the environment // with the upvars and type descriptors. fn load_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - cdata_ty: ty::t, - freevars: &Vec, + cdata_ty: Ty<'tcx>, + freevars: &[ty::Freevar], store: ty::TraitStore) -> Block<'blk, 'tcx> { let _icx = push_ctxt("closure::load_environment"); - // Don't bother to create the block if there's nothing to load - if freevars.len() == 0 { - return bcx; - } - // Load a pointer to the closure data, skipping over the box header: let llcdata = at_box_body(bcx, cdata_ty, bcx.fcx.llenv.unwrap()); @@ -304,16 +300,12 @@ fn load_unboxed_closure_environment<'blk, 'tcx>( bcx: Block<'blk, 'tcx>, arg_scope_id: ScopeId, freevar_mode: ast::CaptureClause, - freevars: &Vec, - closure_id: ast::DefId) + freevars: &[ty::Freevar]) -> Block<'blk, 'tcx> { let _icx = push_ctxt("closure::load_environment"); - if freevars.len() == 0 { - return bcx - } - // Special case for small by-value selfs. + let closure_id = ast_util::local_def(bcx.fcx.id); let self_type = self_type_for_unboxed_closure(bcx.ccx(), closure_id, node_id_type(bcx, closure_id.node)); let kind = kind_for_unboxed_closure(bcx.ccx(), closure_id); @@ -352,6 +344,48 @@ fn fill_fn_pair(bcx: Block, pair: ValueRef, llfn: ValueRef, llenvptr: ValueRef) Store(bcx, llenvptr, GEPi(bcx, pair, &[0u, abi::fn_field_box])); } +#[deriving(PartialEq)] +pub enum ClosureKind<'tcx> { + NotClosure, + // See load_environment. + BoxedClosure(Ty<'tcx>, ty::TraitStore), + // See load_unboxed_closure_environment. + UnboxedClosure(ast::CaptureClause) +} + +pub struct ClosureEnv<'a, 'tcx> { + freevars: &'a [ty::Freevar], + pub kind: ClosureKind<'tcx> +} + +impl<'a, 'tcx> ClosureEnv<'a, 'tcx> { + pub fn new(freevars: &'a [ty::Freevar], kind: ClosureKind<'tcx>) + -> ClosureEnv<'a, 'tcx> { + ClosureEnv { + freevars: freevars, + kind: kind + } + } + + pub fn load<'blk>(self, bcx: Block<'blk, 'tcx>, arg_scope: ScopeId) + -> Block<'blk, 'tcx> { + // Don't bother to create the block if there's nothing to load + if self.freevars.is_empty() { + return bcx; + } + + match self.kind { + NotClosure => bcx, + BoxedClosure(cdata_ty, store) => { + load_environment(bcx, cdata_ty, self.freevars, store) + } + UnboxedClosure(freevar_mode) => { + load_unboxed_closure_environment(bcx, arg_scope, freevar_mode, self.freevars) + } + } + } +} + pub fn trans_expr_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, store: ty::TraitStore, decl: &ast::FnDecl, @@ -401,6 +435,7 @@ pub fn trans_expr_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, cdata_ty, bcx } = build_closure(bcx, freevar_mode, &freevars, store); + trans_closure(ccx, decl, body, @@ -410,9 +445,8 @@ pub fn trans_expr_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, &[], ty::ty_fn_ret(fty), ty::ty_fn_abi(fty), - true, - NotUnboxedClosure, - |bcx, _| load_environment(bcx, cdata_ty, &freevars, store)); + ClosureEnv::new(freevars.as_slice(), + BoxedClosure(cdata_ty, store))); fill_fn_pair(bcx, dest_addr, llfn, llbox); bcx } @@ -421,7 +455,7 @@ pub fn trans_expr_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, /// if necessary. If the ID does not correspond to a closure ID, returns None. pub fn get_or_create_declaration_if_unboxed_closure<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, closure_id: ast::DefId, - substs: &Substs) + substs: &Substs<'tcx>) -> Option { let ccx = bcx.ccx(); if !ccx.tcx().unboxed_closures.borrow().contains_key(&closure_id) { @@ -435,7 +469,7 @@ pub fn get_or_create_declaration_if_unboxed_closure<'blk, 'tcx>(bcx: Block<'blk, // Normalize type so differences in regions and typedefs don't cause // duplicate declarations let function_type = ty::normalize_ty(bcx.tcx(), function_type); - let params = match ty::get(function_type).sty { + let params = match function_type.sty { ty::ty_unboxed_closure(_, _, ref substs) => substs.types.clone(), _ => unreachable!() }; @@ -486,7 +520,7 @@ pub fn trans_unboxed_closure<'blk, 'tcx>( let llfn = get_or_create_declaration_if_unboxed_closure( bcx, closure_id, - bcx.fcx.param_substs.substs()).unwrap(); + bcx.fcx.param_substs).unwrap(); let function_type = (*bcx.tcx().unboxed_closures.borrow())[closure_id] .closure_type @@ -495,7 +529,6 @@ pub fn trans_unboxed_closure<'blk, 'tcx>( let freevars: Vec = ty::with_freevars(bcx.tcx(), id, |fv| fv.iter().map(|&fv| fv).collect()); - let freevars_ptr = &freevars; let freevar_mode = bcx.tcx().capture_mode(id); trans_closure(bcx.ccx(), @@ -507,15 +540,8 @@ pub fn trans_unboxed_closure<'blk, 'tcx>( &[], ty::ty_fn_ret(function_type), ty::ty_fn_abi(function_type), - true, - IsUnboxedClosure, - |bcx, arg_scope| { - load_unboxed_closure_environment(bcx, - arg_scope, - freevar_mode, - freevars_ptr, - closure_id) - }); + ClosureEnv::new(freevars.as_slice(), + UnboxedClosure(freevar_mode))); // Don't hoist this to the top of the function. It's perfectly legitimate // to have a zero-size unboxed closure (in which case dest will be @@ -531,7 +557,7 @@ pub fn trans_unboxed_closure<'blk, 'tcx>( let repr = adt::represent_type(bcx.ccx(), node_id_type(bcx, id)); // Create the closure. - for (i, freevar) in freevars_ptr.iter().enumerate() { + for (i, freevar) in freevars.iter().enumerate() { let datum = expr::trans_local_var(bcx, freevar.def); let upvar_slot_dest = adt::trans_field_ptr(bcx, &*repr, @@ -552,11 +578,11 @@ pub fn trans_unboxed_closure<'blk, 'tcx>( bcx } -pub fn get_wrapper_for_bare_fn(ccx: &CrateContext, - closure_ty: ty::t, - def: def::Def, - fn_ptr: ValueRef, - is_local: bool) -> ValueRef { +pub fn get_wrapper_for_bare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + closure_ty: Ty<'tcx>, + def: def::Def, + fn_ptr: ValueRef, + is_local: bool) -> ValueRef { let def_id = match def { def::DefFn(did, _) | def::DefStaticMethod(did, _) | @@ -578,7 +604,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext, debug!("get_wrapper_for_bare_fn(closure_ty={})", closure_ty.repr(tcx)); - let f = match ty::get(closure_ty).sty { + let f = match closure_ty.sty { ty::ty_closure(ref f) => f, _ => { ccx.sess().bug(format!("get_wrapper_for_bare_fn: \ @@ -607,7 +633,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext, let _icx = push_ctxt("closure::get_wrapper_for_bare_fn"); let arena = TypedArena::new(); - let empty_param_substs = param_substs::empty(); + let empty_param_substs = Substs::trans_empty(); let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, true, f.sig.output, &empty_param_substs, None, &arena); let bcx = init_function(&fcx, true, f.sig.output); @@ -647,7 +673,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext, } pub fn make_closure_from_bare_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - closure_ty: ty::t, + closure_ty: Ty<'tcx>, def: def::Def, fn_ptr: ValueRef) -> DatumBlock<'blk, 'tcx, Expr> { diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index 21cf313866144..9cd249f1e005d 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -22,7 +22,7 @@ use middle::def; use middle::lang_items::LangItem; use middle::mem_categorization as mc; use middle::subst; -use middle::subst::Subst; +use middle::subst::{Subst, Substs}; use trans::base; use trans::build; use trans::cleanup; @@ -32,7 +32,7 @@ use trans::machine; use trans::type_::Type; use trans::type_of; use middle::traits; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::ty_fold; use middle::ty_fold::TypeFoldable; use middle::typeck; @@ -55,8 +55,9 @@ use syntax::parse::token; pub use trans::context::CrateContext; -fn type_is_newtype_immediate(ccx: &CrateContext, ty: ty::t) -> bool { - match ty::get(ty).sty { +fn type_is_newtype_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + ty: Ty<'tcx>) -> bool { + match ty.sty { ty::ty_struct(def_id, ref substs) => { let fields = ty::struct_fields(ccx.tcx(), def_id, substs); fields.len() == 1 && @@ -68,7 +69,7 @@ fn type_is_newtype_immediate(ccx: &CrateContext, ty: ty::t) -> bool { } } -pub fn type_is_immediate(ccx: &CrateContext, ty: ty::t) -> bool { +pub fn type_is_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { use trans::machine::llsize_of_alloc; use trans::type_of::sizing_type_of; @@ -83,7 +84,7 @@ pub fn type_is_immediate(ccx: &CrateContext, ty: ty::t) -> bool { if !ty::type_is_sized(tcx, ty) { return false; } - match ty::get(ty).sty { + match ty.sty { ty::ty_struct(..) | ty::ty_enum(..) | ty::ty_tup(..) | ty::ty_unboxed_closure(..) => { let llty = sizing_type_of(ccx, ty); @@ -93,7 +94,7 @@ pub fn type_is_immediate(ccx: &CrateContext, ty: ty::t) -> bool { } } -pub fn type_is_zero_size(ccx: &CrateContext, ty: ty::t) -> bool { +pub fn type_is_zero_size<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { /*! * Identify types which have size zero at runtime. */ @@ -104,7 +105,7 @@ pub fn type_is_zero_size(ccx: &CrateContext, ty: ty::t) -> bool { llsize_of_alloc(ccx, llty) == 0 } -pub fn return_type_is_void(ccx: &CrateContext, ty: ty::t) -> bool { +pub fn return_type_is_void(ccx: &CrateContext, ty: Ty) -> bool { /*! * Identifies types which we declare to be equivalent to `void` * in C for the purpose of function return types. These are @@ -125,8 +126,8 @@ pub fn gensym_name(name: &str) -> PathElem { PathName(token::gensym(format!("{}:{}", name, num).as_slice())) } -pub struct tydesc_info { - pub ty: ty::t, +pub struct tydesc_info<'tcx> { + pub ty: Ty<'tcx>, pub tydesc: ValueRef, pub size: ValueRef, pub align: ValueRef, @@ -188,55 +189,13 @@ pub fn BuilderRef_res(b: BuilderRef) -> BuilderRef_res { pub type ExternMap = FnvHashMap; -// Here `self_ty` is the real type of the self parameter to this method. It -// will only be set in the case of default methods. -pub struct param_substs { - substs: subst::Substs, -} - -impl param_substs { - pub fn new(substs: subst::Substs) -> param_substs { - assert!(substs.types.all(|t| !ty::type_needs_infer(*t))); - assert!(substs.types.all(|t| !ty::type_has_params(*t))); - assert!(substs.types.all(|t| !ty::type_has_escaping_regions(*t))); - param_substs { substs: substs.erase_regions() } - } - - pub fn substs(&self) -> &subst::Substs { - &self.substs - } - - pub fn empty() -> param_substs { - param_substs { - substs: subst::Substs::trans_empty(), - } - } - - pub fn validate(&self) { - assert!(self.substs.types.all(|t| !ty::type_needs_infer(*t))); - } -} - -impl Repr for param_substs { - fn repr(&self, tcx: &ty::ctxt) -> String { - self.substs.repr(tcx) - } -} - -pub trait SubstP { - fn substp(&self, tcx: &ty::ctxt, param_substs: ¶m_substs) - -> Self; -} - -impl SubstP for T { - fn substp(&self, tcx: &ty::ctxt, substs: ¶m_substs) -> T { - self.subst(tcx, &substs.substs) - } +pub fn validate_substs(substs: &Substs) { + assert!(substs.types.all(|t| !ty::type_needs_infer(*t))); } // work around bizarre resolve errors -pub type RvalueDatum = datum::Datum; -pub type LvalueDatum = datum::Datum; +pub type RvalueDatum<'tcx> = datum::Datum<'tcx, datum::Rvalue>; +pub type LvalueDatum<'tcx> = datum::Datum<'tcx, datum::Lvalue>; // Function context. Every LLVM function we create will have one of // these. @@ -280,7 +239,7 @@ pub struct FunctionContext<'a, 'tcx: 'a> { // Maps the DefId's for local variables to the allocas created for // them in llallocas. - pub lllocals: RefCell>, + pub lllocals: RefCell>>, // Same as above, but for closure upvars pub llupvars: RefCell>, @@ -291,7 +250,7 @@ pub struct FunctionContext<'a, 'tcx: 'a> { // If this function is being monomorphized, this contains the type // substitutions used. - pub param_substs: &'a param_substs, + pub param_substs: &'a Substs<'tcx>, // The source span and nesting context where this function comes from, for // error reporting and symbol generation. @@ -354,7 +313,9 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> { self.llreturn.get().unwrap() } - pub fn get_ret_slot(&self, bcx: Block, output: ty::FnOutput, name: &str) -> ValueRef { + pub fn get_ret_slot(&self, bcx: Block<'a, 'tcx>, + output: ty::FnOutput<'tcx>, + name: &str) -> ValueRef { if self.needs_ret_allocas { base::alloca_no_lifetime(bcx, match output { ty::FnConverging(output_type) => type_of::type_of(bcx.ccx(), output_type), @@ -495,7 +456,7 @@ impl<'blk, 'tcx> BlockS<'blk, 'tcx> { self.ccx().tn().type_to_string(ty) } - pub fn ty_to_string(&self, t: ty::t) -> String { + pub fn ty_to_string(&self, t: Ty<'tcx>) -> String { t.repr(self.tcx()) } @@ -509,11 +470,11 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> { self.tcx() } - fn node_ty(&self, id: ast::NodeId) -> mc::McResult { + fn node_ty(&self, id: ast::NodeId) -> mc::McResult> { Ok(node_id_type(self, id)) } - fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option { + fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option> { self.tcx() .method_map .borrow() @@ -521,7 +482,7 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> { .map(|method| monomorphize_type(self, method.ty)) } - fn adjustments<'a>(&'a self) -> &'a RefCell> { + fn adjustments<'a>(&'a self) -> &'a RefCell>> { &self.tcx().adjustments } @@ -534,7 +495,7 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> { } fn unboxed_closures<'a>(&'a self) - -> &'a RefCell> { + -> &'a RefCell>> { &self.tcx().unboxed_closures } @@ -788,28 +749,28 @@ pub fn is_null(val: ValueRef) -> bool { } } -pub fn monomorphize_type(bcx: &BlockS, t: ty::t) -> ty::t { - t.subst(bcx.tcx(), &bcx.fcx.param_substs.substs) +pub fn monomorphize_type<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, t: Ty<'tcx>) -> Ty<'tcx> { + t.subst(bcx.tcx(), bcx.fcx.param_substs) } -pub fn node_id_type(bcx: &BlockS, id: ast::NodeId) -> ty::t { +pub fn node_id_type<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, id: ast::NodeId) -> Ty<'tcx> { let tcx = bcx.tcx(); let t = ty::node_id_to_type(tcx, id); monomorphize_type(bcx, t) } -pub fn expr_ty(bcx: Block, ex: &ast::Expr) -> ty::t { +pub fn expr_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ex: &ast::Expr) -> Ty<'tcx> { node_id_type(bcx, ex.id) } -pub fn expr_ty_adjusted(bcx: Block, ex: &ast::Expr) -> ty::t { +pub fn expr_ty_adjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ex: &ast::Expr) -> Ty<'tcx> { monomorphize_type(bcx, ty::expr_ty_adjusted(bcx.tcx(), ex)) } -pub fn fulfill_obligation(ccx: &CrateContext, - span: Span, - trait_ref: Rc) - -> traits::Vtable<()> +pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + span: Span, + trait_ref: Rc>) + -> traits::Vtable<'tcx, ()> { /*! * Attempts to resolve an obligation. The result is a shallow @@ -923,9 +884,9 @@ pub enum ExprOrMethodCall { MethodCall(typeck::MethodCall) } -pub fn node_id_substs(bcx: Block, - node: ExprOrMethodCall) - -> subst::Substs +pub fn node_id_substs<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + node: ExprOrMethodCall) + -> subst::Substs<'tcx> { let tcx = bcx.tcx(); @@ -947,7 +908,7 @@ pub fn node_id_substs(bcx: Block, } let substs = substs.erase_regions(); - substs.substp(tcx, bcx.fcx.param_substs) + substs.subst(tcx, bcx.fcx.param_substs) } pub fn langcall(bcx: Block, diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 545b12d2267e1..4213e9417276c 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -29,7 +29,7 @@ use trans::machine; use trans::type_::Type; use trans::type_of; use trans::debuginfo; -use middle::ty; +use middle::ty::{mod, Ty}; use util::ppaux::{Repr, ty_to_string}; use std::c_str::ToCStr; @@ -52,7 +52,7 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: &ast::Lit) } ast::LitInt(i, ast::UnsuffixedIntLit(_)) => { let lit_int_ty = ty::node_id_to_type(cx.tcx(), e.id); - match ty::get(lit_int_ty).sty { + match lit_int_ty.sty { ty::ty_int(t) => { C_integral(Type::int_from_ty(cx, t), i as u64, true) } @@ -70,7 +70,7 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: &ast::Lit) } ast::LitFloatUnsuffixed(ref fs) => { let lit_float_ty = ty::node_id_to_type(cx.tcx(), e.id); - match ty::get(lit_float_ty).sty { + match lit_float_ty.sty { ty::ty_float(t) => { C_floating(fs.get(), Type::float_from_ty(cx, t)) } @@ -133,17 +133,18 @@ fn const_deref_ptr(cx: &CrateContext, v: ValueRef) -> ValueRef { } } -fn const_deref_newtype(cx: &CrateContext, v: ValueRef, t: ty::t) +fn const_deref_newtype<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, v: ValueRef, t: Ty<'tcx>) -> ValueRef { let repr = adt::represent_type(cx, t); adt::const_get_field(cx, &*repr, v, 0, 0) } -fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool) - -> (ValueRef, ty::t) { +fn const_deref<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, v: ValueRef, + t: Ty<'tcx>, explicit: bool) + -> (ValueRef, Ty<'tcx>) { match ty::deref(t, explicit) { Some(ref mt) => { - match ty::get(t).sty { + match t.sty { ty::ty_ptr(mt) | ty::ty_rptr(_, mt) => { if ty::type_is_sized(cx.tcx(), mt.ty) { (const_deref_ptr(cx, v), mt.ty) @@ -187,7 +188,8 @@ pub fn get_const_val(cx: &CrateContext, cx.const_values().borrow()[def_id.node].clone() } -pub fn const_expr(cx: &CrateContext, e: &ast::Expr) -> (ValueRef, ty::t) { +pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, e: &ast::Expr) + -> (ValueRef, Ty<'tcx>) { let llconst = const_expr_unadjusted(cx, e); let mut llconst = llconst; let ety = ty::expr_ty(cx.tcx(), e); @@ -258,7 +260,7 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr) -> (ValueRef, ty::t) { llconst = const_addr_of(cx, llconst, ast::MutImmutable) } - match ty::get(ty).sty { + match ty.sty { ty::ty_vec(unit_ty, Some(len)) => { let llunitty = type_of::type_of(cx, unit_ty); let llptr = const_ptrcast(cx, llconst, llunitty); @@ -440,9 +442,9 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef { _ => cx.sess().span_bug(index.span, "index is not an integer-constant expression") }; - let (arr, len) = match ty::get(bt).sty { + let (arr, len) = match bt.sty { ty::ty_vec(_, Some(u)) => (bv, C_uint(cx, u)), - ty::ty_open(ty) => match ty::get(ty).sty { + ty::ty_open(ty) => match ty.sty { ty::ty_vec(_, None) | ty::ty_str => { let e1 = const_get_elt(cx, bv, &[0]); (const_deref_ptr(cx, e1), const_get_elt(cx, bv, &[1])) @@ -452,7 +454,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef { or string type, found {}", ty_to_string(cx.tcx(), bt)).as_slice()) }, - ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty { + ty::ty_rptr(_, mt) => match mt.ty.sty { ty::ty_vec(_, Some(u)) => { (const_deref_ptr(cx, bv), C_uint(cx, u)) }, @@ -468,8 +470,8 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef { }; let len = llvm::LLVMConstIntGetZExtValue(len) as u64; - let len = match ty::get(bt).sty { - ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty { + let len = match bt.sty { + ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty.sty { ty::ty_str => { assert!(len > 0); len - 1 @@ -725,7 +727,8 @@ pub fn trans_static(ccx: &CrateContext, m: ast::Mutability, id: ast::NodeId) { } } -fn get_static_val(ccx: &CrateContext, did: ast::DefId, ty: ty::t) -> ValueRef { +fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, did: ast::DefId, + ty: Ty<'tcx>) -> ValueRef { if ast_util::is_local(did) { return base::get_item_val(ccx, did.node) } base::trans_external_path(ccx, did, ty) } diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs index c2c1f8bb5f5ac..4822299d14886 100644 --- a/src/librustc_trans/trans/context.rs +++ b/src/librustc_trans/trans/context.rs @@ -22,7 +22,7 @@ use trans::common::{ExternMap,tydesc_info,BuilderRef_res}; use trans::debuginfo; use trans::monomorphize::MonoId; use trans::type_::{Type, TypeNames}; -use middle::ty; +use middle::ty::{mod, Ty}; use session::config::NoDebugInfo; use session::Session; use util::ppaux::Repr; @@ -56,7 +56,7 @@ pub struct Stats { /// crate, so it must not contain references to any LLVM data structures /// (aside from metadata-related ones). pub struct SharedCrateContext<'tcx> { - local_ccxs: Vec, + local_ccxs: Vec>, metadata_llmod: ModuleRef, metadata_llcx: ContextRef, @@ -70,22 +70,22 @@ pub struct SharedCrateContext<'tcx> { stats: Stats, available_monomorphizations: RefCell>, - available_drop_glues: RefCell>, + available_drop_glues: RefCell, String>>, } /// The local portion of a `CrateContext`. There is one `LocalCrateContext` /// per compilation unit. Each one has its own LLVM `ContextRef` so that /// several compilation units may be optimized in parallel. All other LLVM /// data structures in the `LocalCrateContext` are tied to that `ContextRef`. -pub struct LocalCrateContext { +pub struct LocalCrateContext<'tcx> { llmod: ModuleRef, llcx: ContextRef, td: TargetData, tn: TypeNames, externs: RefCell, item_vals: RefCell>, - drop_glues: RefCell>, - tydescs: RefCell>>, + drop_glues: RefCell, ValueRef>>, + tydescs: RefCell, Rc>>>, /// Set when running emit_tydescs to enforce that no more tydescs are /// created. finished_tydescs: Cell, @@ -95,10 +95,10 @@ pub struct LocalCrateContext { /// came from) external_srcs: RefCell>, /// Cache instances of monomorphized functions - monomorphized: RefCell>, + monomorphized: RefCell, ValueRef>>, monomorphizing: RefCell>, /// Cache generated vtables - vtables: RefCell), ValueRef>>, + vtables: RefCell, Rc>), ValueRef>>, /// Cache of constant strings, const_cstr_cache: RefCell>, @@ -126,19 +126,19 @@ pub struct LocalCrateContext { /// Cache of closure wrappers for bare fn's. closure_bare_wrapper_cache: RefCell>, - lltypes: RefCell>, - llsizingtypes: RefCell>, - adt_reprs: RefCell>>, - type_hashcodes: RefCell>, + lltypes: RefCell, Type>>, + llsizingtypes: RefCell, Type>>, + adt_reprs: RefCell, Rc>>>, + type_hashcodes: RefCell, String>>, all_llvm_symbols: RefCell>, int_type: Type, opaque_vec_type: Type, builder: BuilderRef_res, /// Holds the LLVM values for closure IDs. - unboxed_closure_vals: RefCell>, + unboxed_closure_vals: RefCell, ValueRef>>, - dbg_cx: Option, + dbg_cx: Option>, eh_personality: RefCell>, @@ -149,13 +149,13 @@ pub struct LocalCrateContext { /// contexts around the same size. n_llvm_insns: Cell, - trait_cache: RefCell, - traits::Vtable<()>>>, + trait_cache: RefCell>, + traits::Vtable<'tcx, ()>>>, } pub struct CrateContext<'a, 'tcx: 'a> { shared: &'a SharedCrateContext<'tcx>, - local: &'a LocalCrateContext, + local: &'a LocalCrateContext<'tcx>, /// The index of `local` in `shared.local_ccxs`. This is used in /// `maybe_iter(true)` to identify the original `LocalCrateContext`. index: uint, @@ -367,10 +367,10 @@ impl<'tcx> SharedCrateContext<'tcx> { } } -impl LocalCrateContext { - fn new(shared: &SharedCrateContext, +impl<'tcx> LocalCrateContext<'tcx> { + fn new(shared: &SharedCrateContext<'tcx>, name: &str) - -> LocalCrateContext { + -> LocalCrateContext<'tcx> { unsafe { let (llcx, llmod) = create_context_and_module(&shared.tcx.sess, name); @@ -456,8 +456,8 @@ impl LocalCrateContext { /// This is used in the `LocalCrateContext` constructor to allow calling /// functions that expect a complete `CrateContext`, even before the local /// portion is fully initialized and attached to the `SharedCrateContext`. - fn dummy_ccx<'a, 'tcx>(&'a self, shared: &'a SharedCrateContext<'tcx>) - -> CrateContext<'a, 'tcx> { + fn dummy_ccx<'a>(&'a self, shared: &'a SharedCrateContext<'tcx>) + -> CrateContext<'a, 'tcx> { CrateContext { shared: shared, local: self, @@ -471,7 +471,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { self.shared } - pub fn local(&self) -> &'b LocalCrateContext { + pub fn local(&self) -> &'b LocalCrateContext<'tcx> { self.local } @@ -574,11 +574,11 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { &self.shared.link_meta } - pub fn drop_glues<'a>(&'a self) -> &'a RefCell> { + pub fn drop_glues<'a>(&'a self) -> &'a RefCell, ValueRef>> { &self.local.drop_glues } - pub fn tydescs<'a>(&'a self) -> &'a RefCell>> { + pub fn tydescs<'a>(&'a self) -> &'a RefCell, Rc>>> { &self.local.tydescs } @@ -594,7 +594,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { &self.local.external_srcs } - pub fn monomorphized<'a>(&'a self) -> &'a RefCell> { + pub fn monomorphized<'a>(&'a self) -> &'a RefCell, ValueRef>> { &self.local.monomorphized } @@ -602,7 +602,8 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { &self.local.monomorphizing } - pub fn vtables<'a>(&'a self) -> &'a RefCell), ValueRef>> { + pub fn vtables<'a>(&'a self) -> &'a RefCell, Rc>), + ValueRef>> { &self.local.vtables } @@ -635,15 +636,15 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { &self.local.closure_bare_wrapper_cache } - pub fn lltypes<'a>(&'a self) -> &'a RefCell> { + pub fn lltypes<'a>(&'a self) -> &'a RefCell, Type>> { &self.local.lltypes } - pub fn llsizingtypes<'a>(&'a self) -> &'a RefCell> { + pub fn llsizingtypes<'a>(&'a self) -> &'a RefCell, Type>> { &self.local.llsizingtypes } - pub fn adt_reprs<'a>(&'a self) -> &'a RefCell>> { + pub fn adt_reprs<'a>(&'a self) -> &'a RefCell, Rc>>> { &self.local.adt_reprs } @@ -651,7 +652,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { &self.shared.symbol_hasher } - pub fn type_hashcodes<'a>(&'a self) -> &'a RefCell> { + pub fn type_hashcodes<'a>(&'a self) -> &'a RefCell, String>> { &self.local.type_hashcodes } @@ -667,7 +668,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { &self.shared.available_monomorphizations } - pub fn available_drop_glues<'a>(&'a self) -> &'a RefCell> { + pub fn available_drop_glues<'a>(&'a self) -> &'a RefCell, String>> { &self.shared.available_drop_glues } @@ -679,11 +680,11 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { self.local.opaque_vec_type } - pub fn unboxed_closure_vals<'a>(&'a self) -> &'a RefCell> { + pub fn unboxed_closure_vals<'a>(&'a self) -> &'a RefCell,ValueRef>> { &self.local.unboxed_closure_vals } - pub fn dbg_cx<'a>(&'a self) -> &'a Option { + pub fn dbg_cx<'a>(&'a self) -> &'a Option> { &self.local.dbg_cx } @@ -699,7 +700,8 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { self.local.n_llvm_insns.set(self.local.n_llvm_insns.get() + 1); } - pub fn trait_cache(&self) -> &RefCell, traits::Vtable<()>>> { + pub fn trait_cache(&self) -> &RefCell>, + traits::Vtable<'tcx, ()>>> { &self.local.trait_cache } @@ -707,7 +709,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { 1<<31 /* FIXME #18069: select based on architecture */ } - pub fn report_overbig_object(&self, obj: ty::t) -> ! { + pub fn report_overbig_object(&self, obj: Ty<'tcx>) -> ! { self.sess().fatal( format!("the type `{}` is too big for the current architecture", obj.repr(self.tcx())).as_slice()) diff --git a/src/librustc_trans/trans/datum.rs b/src/librustc_trans/trans/datum.rs index c4be6bf27b800..354a607220715 100644 --- a/src/librustc_trans/trans/datum.rs +++ b/src/librustc_trans/trans/datum.rs @@ -25,7 +25,7 @@ use trans::cleanup::CleanupMethods; use trans::expr; use trans::tvec; use trans::type_of; -use middle::ty; +use middle::ty::{mod, Ty}; use util::ppaux::{ty_to_string}; use std::fmt; @@ -38,13 +38,13 @@ use syntax::ast; * the section on datums in `doc.rs` for more details. */ #[deriving(Clone)] -pub struct Datum { +pub struct Datum<'tcx, K> { /// The llvm value. This is either a pointer to the Rust value or /// the value itself, depending on `kind` below. pub val: ValueRef, /// The rust type of the value. - pub ty: ty::t, + pub ty: Ty<'tcx>, /// Indicates whether this is by-ref or by-value. pub kind: K, @@ -52,7 +52,7 @@ pub struct Datum { pub struct DatumBlock<'blk, 'tcx: 'blk, K> { pub bcx: Block<'blk, 'tcx>, - pub datum: Datum, + pub datum: Datum<'tcx, K>, } #[deriving(Show)] @@ -95,20 +95,20 @@ pub enum RvalueMode { ByValue, } -pub fn immediate_rvalue(val: ValueRef, ty: ty::t) -> Datum { +pub fn immediate_rvalue<'tcx>(val: ValueRef, ty: Ty<'tcx>) -> Datum<'tcx, Rvalue> { return Datum::new(val, ty, Rvalue::new(ByValue)); } pub fn immediate_rvalue_bcx<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, val: ValueRef, - ty: ty::t) + ty: Ty<'tcx>) -> DatumBlock<'blk, 'tcx, Rvalue> { return DatumBlock::new(bcx, immediate_rvalue(val, ty)) } pub fn lvalue_scratch_datum<'blk, 'tcx, A>(bcx: Block<'blk, 'tcx>, - ty: ty::t, + ty: Ty<'tcx>, name: &str, zero: bool, scope: cleanup::ScopeId, @@ -140,10 +140,10 @@ pub fn lvalue_scratch_datum<'blk, 'tcx, A>(bcx: Block<'blk, 'tcx>, DatumBlock::new(bcx, Datum::new(scratch, ty, Lvalue)) } -pub fn rvalue_scratch_datum(bcx: Block, - ty: ty::t, - name: &str) - -> Datum { +pub fn rvalue_scratch_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + ty: Ty<'tcx>, + name: &str) + -> Datum<'tcx, Rvalue> { /*! * Allocates temporary space on the stack using alloca() and * returns a by-ref Datum pointing to it. If `zero` is true, the @@ -159,7 +159,8 @@ pub fn rvalue_scratch_datum(bcx: Block, Datum::new(scratch, ty, Rvalue::new(ByRef)) } -pub fn appropriate_rvalue_mode(ccx: &CrateContext, ty: ty::t) -> RvalueMode { +pub fn appropriate_rvalue_mode<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + ty: Ty<'tcx>) -> RvalueMode { /*! * Indicates the "appropriate" mode for this value, * which is either by ref or by value, depending @@ -173,11 +174,11 @@ pub fn appropriate_rvalue_mode(ccx: &CrateContext, ty: ty::t) -> RvalueMode { } } -fn add_rvalue_clean(mode: RvalueMode, - fcx: &FunctionContext, - scope: cleanup::ScopeId, - val: ValueRef, - ty: ty::t) { +fn add_rvalue_clean<'a, 'tcx>(mode: RvalueMode, + fcx: &FunctionContext<'a, 'tcx>, + scope: cleanup::ScopeId, + val: ValueRef, + ty: Ty<'tcx>) { match mode { ByValue => { fcx.schedule_drop_immediate(scope, val, ty); } ByRef => { @@ -196,7 +197,7 @@ pub trait KindOps { fn post_store<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>, val: ValueRef, - ty: ty::t) + ty: Ty<'tcx>) -> Block<'blk, 'tcx>; /** @@ -216,7 +217,7 @@ impl KindOps for Rvalue { fn post_store<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>, _val: ValueRef, - _ty: ty::t) + _ty: Ty<'tcx>) -> Block<'blk, 'tcx> { // No cleanup is scheduled for an rvalue, so we don't have // to do anything after a move to cancel or duplicate it. @@ -236,7 +237,7 @@ impl KindOps for Lvalue { fn post_store<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>, val: ValueRef, - ty: ty::t) + ty: Ty<'tcx>) -> Block<'blk, 'tcx> { /*! * If an lvalue is moved, we must zero out the memory in which @@ -266,7 +267,7 @@ impl KindOps for Expr { fn post_store<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>, val: ValueRef, - ty: ty::t) + ty: Ty<'tcx>) -> Block<'blk, 'tcx> { match *self { LvalueExpr => Lvalue.post_store(bcx, val, ty), @@ -286,11 +287,11 @@ impl KindOps for Expr { } } -impl Datum { - pub fn add_clean(self, - fcx: &FunctionContext, - scope: cleanup::ScopeId) - -> ValueRef { +impl<'tcx> Datum<'tcx, Rvalue> { + pub fn add_clean<'a>(self, + fcx: &FunctionContext<'a, 'tcx>, + scope: cleanup::ScopeId) + -> ValueRef { /*! * Schedules a cleanup for this datum in the given scope. * That means that this datum is no longer an rvalue datum; @@ -302,11 +303,11 @@ impl Datum { self.val } - pub fn to_lvalue_datum_in_scope<'blk, 'tcx>(self, - bcx: Block<'blk, 'tcx>, - name: &str, - scope: cleanup::ScopeId) - -> DatumBlock<'blk, 'tcx, Lvalue> { + pub fn to_lvalue_datum_in_scope<'blk>(self, + bcx: Block<'blk, 'tcx>, + name: &str, + scope: cleanup::ScopeId) + -> DatumBlock<'blk, 'tcx, Lvalue> { /*! * Returns an lvalue datum (that is, a by ref datum with * cleanup scheduled). If `self` is not already an lvalue, @@ -328,8 +329,8 @@ impl Datum { } } - pub fn to_ref_datum<'blk, 'tcx>(self, bcx: Block<'blk, 'tcx>) - -> DatumBlock<'blk, 'tcx, Rvalue> { + pub fn to_ref_datum<'blk>(self, bcx: Block<'blk, 'tcx>) + -> DatumBlock<'blk, 'tcx, Rvalue> { let mut bcx = bcx; match self.kind.mode { ByRef => DatumBlock::new(bcx, self), @@ -341,9 +342,8 @@ impl Datum { } } - pub fn to_appropriate_datum<'blk, 'tcx>(self, - bcx: Block<'blk, 'tcx>) - -> DatumBlock<'blk, 'tcx, Rvalue> { + pub fn to_appropriate_datum<'blk>(self, bcx: Block<'blk, 'tcx>) + -> DatumBlock<'blk, 'tcx, Rvalue> { match self.appropriate_rvalue_mode(bcx.ccx()) { ByRef => { self.to_ref_datum(bcx) @@ -369,10 +369,10 @@ impl Datum { * here since we can `match self.kind` rather than having to implement * generic methods in `KindOps`.) */ -impl Datum { +impl<'tcx> Datum<'tcx, Expr> { fn match_kind(self, - if_lvalue: |Datum| -> R, - if_rvalue: |Datum| -> R) + if_lvalue: |Datum<'tcx, Lvalue>| -> R, + if_rvalue: |Datum<'tcx, Rvalue>| -> R) -> R { let Datum { val, ty, kind } = self; match kind { @@ -382,7 +382,7 @@ impl Datum { } #[allow(dead_code)] // potentially useful - pub fn assert_lvalue(self, bcx: Block) -> Datum { + pub fn assert_lvalue(self, bcx: Block) -> Datum<'tcx, Lvalue> { /*! * Asserts that this datum *is* an lvalue and returns it. */ @@ -392,7 +392,7 @@ impl Datum { |_| bcx.sess().bug("assert_lvalue given rvalue")) } - pub fn assert_rvalue(self, bcx: Block) -> Datum { + pub fn assert_rvalue(self, bcx: Block) -> Datum<'tcx, Rvalue> { /*! * Asserts that this datum *is* an lvalue and returns it. */ @@ -402,11 +402,11 @@ impl Datum { |r| r) } - pub fn store_to_dest<'blk, 'tcx>(self, - bcx: Block<'blk, 'tcx>, - dest: expr::Dest, - expr_id: ast::NodeId) - -> Block<'blk, 'tcx> { + pub fn store_to_dest<'blk>(self, + bcx: Block<'blk, 'tcx>, + dest: expr::Dest, + expr_id: ast::NodeId) + -> Block<'blk, 'tcx> { match dest { expr::Ignore => { self.add_clean_if_rvalue(bcx, expr_id); @@ -418,9 +418,9 @@ impl Datum { } } - pub fn add_clean_if_rvalue<'blk, 'tcx>(self, - bcx: Block<'blk, 'tcx>, - expr_id: ast::NodeId) { + pub fn add_clean_if_rvalue<'blk>(self, + bcx: Block<'blk, 'tcx>, + expr_id: ast::NodeId) { /*! * Arranges cleanup for `self` if it is an rvalue. Use when * you are done working with a value that may need drop. @@ -434,11 +434,11 @@ impl Datum { }) } - pub fn clean<'blk, 'tcx>(self, - bcx: Block<'blk, 'tcx>, - name: &'static str, - expr_id: ast::NodeId) - -> Block<'blk, 'tcx> { + pub fn clean<'blk>(self, + bcx: Block<'blk, 'tcx>, + name: &'static str, + expr_id: ast::NodeId) + -> Block<'blk, 'tcx> { /*! * Ensures that `self` will get cleaned up, if it is not an lvalue * already. @@ -447,11 +447,11 @@ impl Datum { self.to_lvalue_datum(bcx, name, expr_id).bcx } - pub fn to_lvalue_datum<'blk, 'tcx>(self, - bcx: Block<'blk, 'tcx>, - name: &str, - expr_id: ast::NodeId) - -> DatumBlock<'blk, 'tcx, Lvalue> { + pub fn to_lvalue_datum<'blk>(self, + bcx: Block<'blk, 'tcx>, + name: &str, + expr_id: ast::NodeId) + -> DatumBlock<'blk, 'tcx, Lvalue> { debug!("to_lvalue_datum self: {}", self.to_string(bcx.ccx())); assert!(ty::lltype_is_sized(bcx.tcx(), self.ty), @@ -464,10 +464,10 @@ impl Datum { }) } - pub fn to_rvalue_datum<'blk, 'tcx>(self, - bcx: Block<'blk, 'tcx>, - name: &'static str) - -> DatumBlock<'blk, 'tcx, Rvalue> { + pub fn to_rvalue_datum<'blk>(self, + bcx: Block<'blk, 'tcx>, + name: &'static str) + -> DatumBlock<'blk, 'tcx, Rvalue> { /*! * Ensures that we have an rvalue datum (that is, a datum with * no cleanup scheduled). @@ -500,7 +500,7 @@ impl Datum { * such as extracting the field from a struct or a particular element * from an array. */ -impl Datum { +impl<'tcx> Datum<'tcx, Lvalue> { pub fn to_llref(self) -> ValueRef { /*! * Converts a datum into a by-ref value. The datum type must @@ -515,10 +515,10 @@ impl Datum { // datum may also be unsized _without the size information_. It is the // callers responsibility to package the result in some way to make a valid // datum in that case (e.g., by making a fat pointer or opened pair). - pub fn get_element(&self, bcx: Block, ty: ty::t, - gep: |ValueRef| -> ValueRef) - -> Datum { - let val = match ty::get(self.ty).sty { + pub fn get_element<'blk>(&self, bcx: Block<'blk, 'tcx>, ty: Ty<'tcx>, + gep: |ValueRef| -> ValueRef) + -> Datum<'tcx, Lvalue> { + let val = match self.ty.sty { _ if ty::type_is_sized(bcx.tcx(), self.ty) => gep(self.val), ty::ty_open(_) => { let base = Load(bcx, expr::get_dataptr(bcx, self.val)); @@ -545,20 +545,20 @@ impl Datum { /** * Generic methods applicable to any sort of datum. */ -impl Datum { - pub fn new(val: ValueRef, ty: ty::t, kind: K) -> Datum { +impl<'tcx, K: KindOps + fmt::Show> Datum<'tcx, K> { + pub fn new(val: ValueRef, ty: Ty<'tcx>, kind: K) -> Datum<'tcx, K> { Datum { val: val, ty: ty, kind: kind } } - pub fn to_expr_datum(self) -> Datum { + pub fn to_expr_datum(self) -> Datum<'tcx, Expr> { let Datum { val, ty, kind } = self; Datum { val: val, ty: ty, kind: kind.to_expr_kind() } } - pub fn store_to<'blk, 'tcx>(self, - bcx: Block<'blk, 'tcx>, - dst: ValueRef) - -> Block<'blk, 'tcx> { + pub fn store_to<'blk>(self, + bcx: Block<'blk, 'tcx>, + dst: ValueRef) + -> Block<'blk, 'tcx> { /*! * Moves or copies this value into a new home, as appropriate * depending on the type of the datum. This method consumes @@ -572,10 +572,10 @@ impl Datum { self.kind.post_store(bcx, self.val, self.ty) } - fn shallow_copy_raw<'blk, 'tcx>(&self, - bcx: Block<'blk, 'tcx>, - dst: ValueRef) - -> Block<'blk, 'tcx> { + fn shallow_copy_raw<'blk>(&self, + bcx: Block<'blk, 'tcx>, + dst: ValueRef) + -> Block<'blk, 'tcx> { /*! * Helper function that performs a shallow copy of this value * into `dst`, which should be a pointer to a memory location @@ -604,10 +604,10 @@ impl Datum { return bcx; } - pub fn shallow_copy<'blk, 'tcx>(&self, - bcx: Block<'blk, 'tcx>, - dst: ValueRef) - -> Block<'blk, 'tcx> { + pub fn shallow_copy<'blk>(&self, + bcx: Block<'blk, 'tcx>, + dst: ValueRef) + -> Block<'blk, 'tcx> { /*! * Copies the value into a new location. This function always * preserves the existing datum as a valid value. Therefore, @@ -620,20 +620,21 @@ impl Datum { } #[allow(dead_code)] // useful for debugging - pub fn to_string(&self, ccx: &CrateContext) -> String { + pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String { format!("Datum({}, {}, {})", ccx.tn().val_to_string(self.val), ty_to_string(ccx.tcx(), self.ty), self.kind) } - pub fn appropriate_rvalue_mode(&self, ccx: &CrateContext) -> RvalueMode { + pub fn appropriate_rvalue_mode<'a>(&self, ccx: &CrateContext<'a, 'tcx>) + -> RvalueMode { /*! See the `appropriate_rvalue_mode()` function */ appropriate_rvalue_mode(ccx, self.ty) } - pub fn to_llscalarish(self, bcx: Block) -> ValueRef { + pub fn to_llscalarish<'blk>(self, bcx: Block<'blk, 'tcx>) -> ValueRef { /*! * Converts `self` into a by-value `ValueRef`. Consumes this * datum (i.e., absolves you of responsibility to cleanup the @@ -652,14 +653,15 @@ impl Datum { } } - pub fn to_llbool(self, bcx: Block) -> ValueRef { + pub fn to_llbool<'blk>(self, bcx: Block<'blk, 'tcx>) -> ValueRef { assert!(ty::type_is_bool(self.ty)) self.to_llscalarish(bcx) } } impl<'blk, 'tcx, K> DatumBlock<'blk, 'tcx, K> { - pub fn new(bcx: Block<'blk, 'tcx>, datum: Datum) -> DatumBlock<'blk, 'tcx, K> { + pub fn new(bcx: Block<'blk, 'tcx>, datum: Datum<'tcx, K>) + -> DatumBlock<'blk, 'tcx, K> { DatumBlock { bcx: bcx, datum: datum } } } diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 65fd95667608a..7b3f619f41f1a 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -172,9 +172,9 @@ to always map crate and node IDs back to the original crate context. As a side-effect these unique type IDs also help to solve a problem arising from lifetime parameters. Since lifetime parameters are completely omitted in -debuginfo, more than one `ty::t` instance may map to the same debuginfo type +debuginfo, more than one `Ty` instance may map to the same debuginfo type metadata, that is, some struct `Struct<'a>` may have N instantiations with -different concrete substitutions for `'a`, and thus there will be N `ty::t` +different concrete substitutions for `'a`, and thus there will be N `Ty` instances for the type `Struct<'a>` even though it is not generic otherwise. Unfortunately this means that we cannot use `ty::type_id()` as cheap identifier for type metadata---we have done this in the past, but it led to unnecessary @@ -196,7 +196,7 @@ use llvm; use llvm::{ModuleRef, ContextRef, ValueRef}; use llvm::debuginfo::*; use metadata::csearch; -use middle::subst::{mod, Subst}; +use middle::subst::{mod, Subst, Substs}; use trans::adt; use trans::common::*; use trans::machine; @@ -204,7 +204,7 @@ use trans::_match::{BindingInfo, TrByCopy, TrByMove, TrByRef}; use trans::type_of; use trans::type_::Type; use trans; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::pat_util; use session::config::{mod, FullDebugInfo, LimitedDebugInfo, NoDebugInfo}; use util::nodemap::{DefIdMap, NodeMap, FnvHashMap, FnvHashSet}; @@ -258,22 +258,22 @@ struct UniqueTypeId(ast::Name); // The TypeMap is where the CrateDebugContext holds the type metadata nodes // created so far. The metadata nodes are indexed by UniqueTypeId, and, for -// faster lookup, also by ty::t. The TypeMap is responsible for creating +// faster lookup, also by Ty. The TypeMap is responsible for creating // UniqueTypeIds. -struct TypeMap { +struct TypeMap<'tcx> { // The UniqueTypeIds created so far unique_id_interner: Interner>, // A map from UniqueTypeId to debuginfo metadata for that type. This is a 1:1 mapping. unique_id_to_metadata: FnvHashMap, // A map from types to debuginfo metadata. This is a N:1 mapping. - type_to_metadata: FnvHashMap, + type_to_metadata: FnvHashMap, DIType>, // A map from types to UniqueTypeId. This is a N:1 mapping. - type_to_unique_id: FnvHashMap + type_to_unique_id: FnvHashMap, UniqueTypeId> } -impl TypeMap { +impl<'tcx> TypeMap<'tcx> { - fn new() -> TypeMap { + fn new() -> TypeMap<'tcx> { TypeMap { unique_id_interner: Interner::new(), type_to_metadata: FnvHashMap::new(), @@ -282,14 +282,14 @@ impl TypeMap { } } - // Adds a ty::t to metadata mapping to the TypeMap. The method will fail if + // Adds a Ty to metadata mapping to the TypeMap. The method will fail if // the mapping already exists. - fn register_type_with_metadata(&mut self, - cx: &CrateContext, - type_: ty::t, - metadata: DIType) { + fn register_type_with_metadata<'a>(&mut self, + cx: &CrateContext<'a, 'tcx>, + type_: Ty<'tcx>, + metadata: DIType) { if self.type_to_metadata.insert(type_, metadata).is_some() { - cx.sess().bug(format!("Type metadata for ty::t '{}' is already in the TypeMap!", + cx.sess().bug(format!("Type metadata for Ty '{}' is already in the TypeMap!", ppaux::ty_to_string(cx.tcx(), type_)).as_slice()); } } @@ -307,7 +307,7 @@ impl TypeMap { } } - fn find_metadata_for_type(&self, type_: ty::t) -> Option { + fn find_metadata_for_type(&self, type_: Ty<'tcx>) -> Option { self.type_to_metadata.get(&type_).cloned() } @@ -325,7 +325,8 @@ impl TypeMap { // Get the UniqueTypeId for the given type. If the UniqueTypeId for the given // type has been requested before, this is just a table lookup. Otherwise an // ID will be generated and stored for later lookup. - fn get_unique_type_id_of_type(&mut self, cx: &CrateContext, type_: ty::t) -> UniqueTypeId { + fn get_unique_type_id_of_type<'a>(&mut self, cx: &CrateContext<'a, 'tcx>, + type_: Ty<'tcx>) -> UniqueTypeId { // basic type -> {:name of the type:} // tuple -> {tuple_(:param-uid:)*} @@ -356,7 +357,7 @@ impl TypeMap { let mut unique_type_id = String::with_capacity(256); unique_type_id.push('{'); - match ty::get(type_).sty { + match type_.sty { ty::ty_bool | ty::ty_char | ty::ty_str | @@ -484,7 +485,7 @@ impl TypeMap { _ => { cx.sess().bug(format!("get_unique_type_id_of_type() - unexpected type: {}, {}", ppaux::ty_to_string(cx.tcx(), type_).as_slice(), - ty::get(type_).sty).as_slice()) + type_.sty).as_slice()) } }; @@ -498,11 +499,11 @@ impl TypeMap { return UniqueTypeId(key); - fn from_def_id_and_substs(type_map: &mut TypeMap, - cx: &CrateContext, - def_id: ast::DefId, - substs: &subst::Substs, - output: &mut String) { + fn from_def_id_and_substs<'a, 'tcx>(type_map: &mut TypeMap<'tcx>, + cx: &CrateContext<'a, 'tcx>, + def_id: ast::DefId, + substs: &subst::Substs<'tcx>, + output: &mut String) { // First, find out the 'real' def_id of the type. Items inlined from // other crates have to be mapped back to their source. let source_def_id = if def_id.krate == ast::LOCAL_CRATE { @@ -549,10 +550,10 @@ impl TypeMap { } } - fn get_unique_type_id_of_closure_type(&mut self, - cx: &CrateContext, - closure_ty: ty::ClosureTy, - unique_type_id: &mut String) { + fn get_unique_type_id_of_closure_type<'a>(&mut self, + cx: &CrateContext<'a, 'tcx>, + closure_ty: ty::ClosureTy<'tcx>, + unique_type_id: &mut String) { let ty::ClosureTy { fn_style, onceness, store, @@ -619,11 +620,11 @@ impl TypeMap { // Get the UniqueTypeId for an enum variant. Enum variants are not really // types of their own, so they need special handling. We still need a // UniqueTypeId for them, since to debuginfo they *are* real types. - fn get_unique_type_id_of_enum_variant(&mut self, - cx: &CrateContext, - enum_type: ty::t, - variant_name: &str) - -> UniqueTypeId { + fn get_unique_type_id_of_enum_variant<'a>(&mut self, + cx: &CrateContext<'a, 'tcx>, + enum_type: Ty<'tcx>, + variant_name: &str) + -> UniqueTypeId { let enum_type_id = self.get_unique_type_id_of_type(cx, enum_type); let enum_variant_type_id = format!("{}::{}", self.get_unique_type_id_as_string(enum_type_id) @@ -649,14 +650,14 @@ macro_rules! return_if_metadata_created_in_meantime( /// A context object for maintaining all state needed by the debuginfo module. -pub struct CrateDebugContext { +pub struct CrateDebugContext<'tcx> { llcontext: ContextRef, builder: DIBuilderRef, current_debug_location: Cell, created_files: RefCell>, created_enum_disr_types: RefCell>, - type_map: RefCell, + type_map: RefCell>, namespace_map: RefCell, Rc>>, // This collection is used to assert that composite types (structs, enums, @@ -664,8 +665,8 @@ pub struct CrateDebugContext { composite_types_completed: RefCell>, } -impl CrateDebugContext { - pub fn new(llmod: ModuleRef) -> CrateDebugContext { +impl<'tcx> CrateDebugContext<'tcx> { + pub fn new(llmod: ModuleRef) -> CrateDebugContext<'tcx> { debug!("CrateDebugContext::new"); let builder = unsafe { llvm::LLVMDIBuilderCreate(llmod) }; // DIBuilder inherits context from the module, so we'd better use the same one @@ -884,13 +885,13 @@ pub fn create_local_var_metadata(bcx: Block, local: &ast::Local) { /// Creates debug information for a variable captured in a closure. /// /// Adds the created metadata nodes directly to the crate's IR. -pub fn create_captured_var_metadata(bcx: Block, - node_id: ast::NodeId, - env_data_type: ty::t, - env_pointer: ValueRef, - env_index: uint, - closure_store: ty::TraitStore, - span: Span) { +pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + node_id: ast::NodeId, + env_data_type: Ty<'tcx>, + env_pointer: ValueRef, + env_index: uint, + closure_store: ty::TraitStore, + span: Span) { if fn_should_be_ignored(bcx.fcx) { return; } @@ -971,9 +972,9 @@ pub fn create_captured_var_metadata(bcx: Block, /// match-statement arm. /// /// Adds the created metadata nodes directly to the crate's IR. -pub fn create_match_binding_metadata(bcx: Block, - variable_ident: ast::Ident, - binding: BindingInfo) { +pub fn create_match_binding_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + variable_ident: ast::Ident, + binding: BindingInfo<'tcx>) { if fn_should_be_ignored(bcx.fcx) { return; } @@ -1168,10 +1169,10 @@ pub fn start_emitting_source_locations(fcx: &FunctionContext) { /// for debug info creation. The function may also return another variant of the /// FunctionDebugContext enum which indicates why no debuginfo should be created /// for the function. -pub fn create_function_debug_context(cx: &CrateContext, - fn_ast_id: ast::NodeId, - param_substs: ¶m_substs, - llfn: ValueRef) -> FunctionDebugContext { +pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + fn_ast_id: ast::NodeId, + param_substs: &Substs<'tcx>, + llfn: ValueRef) -> FunctionDebugContext { if cx.sess().opts.debuginfo == NoDebugInfo { return FunctionDebugContext { repr: DebugInfoDisabled }; } @@ -1369,11 +1370,11 @@ pub fn create_function_debug_context(cx: &CrateContext, return FunctionDebugContext { repr: DebugInfo(fn_debug_context) }; - fn get_function_signature(cx: &CrateContext, - fn_ast_id: ast::NodeId, - fn_decl: &ast::FnDecl, - param_substs: ¶m_substs, - error_reporting_span: Span) -> DIArray { + fn get_function_signature<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + fn_ast_id: ast::NodeId, + fn_decl: &ast::FnDecl, + param_substs: &Substs<'tcx>, + error_reporting_span: Span) -> DIArray { if cx.sess().opts.debuginfo == LimitedDebugInfo { return create_DIArray(DIB(cx), &[]); } @@ -1388,7 +1389,7 @@ pub fn create_function_debug_context(cx: &CrateContext, assert_type_for_node_id(cx, fn_ast_id, error_reporting_span); let return_type = ty::node_id_to_type(cx.tcx(), fn_ast_id); - let return_type = return_type.substp(cx.tcx(), param_substs); + let return_type = return_type.subst(cx.tcx(), param_substs); signature.push(type_metadata(cx, return_type, codemap::DUMMY_SP)); } } @@ -1397,20 +1398,20 @@ pub fn create_function_debug_context(cx: &CrateContext, for arg in fn_decl.inputs.iter() { assert_type_for_node_id(cx, arg.pat.id, arg.pat.span); let arg_type = ty::node_id_to_type(cx.tcx(), arg.pat.id); - let arg_type = arg_type.substp(cx.tcx(), param_substs); + let arg_type = arg_type.subst(cx.tcx(), param_substs); signature.push(type_metadata(cx, arg_type, codemap::DUMMY_SP)); } return create_DIArray(DIB(cx), signature.as_slice()); } - fn get_template_parameters(cx: &CrateContext, - generics: &ast::Generics, - param_substs: ¶m_substs, - file_metadata: DIFile, - name_to_append_suffix_to: &mut String) - -> DIArray { - let self_type = param_substs.substs().self_ty(); + fn get_template_parameters<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + generics: &ast::Generics, + param_substs: &Substs<'tcx>, + file_metadata: DIFile, + name_to_append_suffix_to: &mut String) + -> DIArray { + let self_type = param_substs.self_ty(); // Only true for static default methods: let has_self_type = self_type.is_some(); @@ -1467,7 +1468,7 @@ pub fn create_function_debug_context(cx: &CrateContext, } // Handle other generic parameters - let actual_types = param_substs.substs().types.get_slice(subst::FnSpace); + let actual_types = param_substs.types.get_slice(subst::FnSpace); for (index, &ast::TyParam{ ident, .. }) in generics.ty_params.iter().enumerate() { let actual_type = actual_types[index]; // Add actual type name to <...> clause of function name @@ -1590,13 +1591,13 @@ fn compile_unit_metadata(cx: &CrateContext) { } } -fn declare_local(bcx: Block, - variable_ident: ast::Ident, - variable_type: ty::t, - scope_metadata: DIScope, - variable_access: VariableAccess, - variable_kind: VariableKind, - span: Span) { +fn declare_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + variable_ident: ast::Ident, + variable_type: Ty<'tcx>, + scope_metadata: DIScope, + variable_access: VariableAccess, + variable_kind: VariableKind, + span: Span) { let cx: &CrateContext = bcx.ccx(); let filename = span_start(cx, span).file.name.clone(); @@ -1739,11 +1740,12 @@ fn diverging_type_metadata(cx: &CrateContext) -> DIType { }) } -fn basic_type_metadata(cx: &CrateContext, t: ty::t) -> DIType { +fn basic_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>) -> DIType { - debug!("basic_type_metadata: {}", ty::get(t)); + debug!("basic_type_metadata: {}", t); - let (name, encoding) = match ty::get(t).sty { + let (name, encoding) = match t.sty { ty::ty_tup(ref elements) if elements.is_empty() => ("()".to_string(), DW_ATE_unsigned), ty::ty_bool => ("bool".to_string(), DW_ATE_boolean), @@ -1785,10 +1787,10 @@ fn basic_type_metadata(cx: &CrateContext, t: ty::t) -> DIType { return ty_metadata; } -fn pointer_type_metadata(cx: &CrateContext, - pointer_type: ty::t, - pointee_type_metadata: DIType) - -> DIType { +fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + pointer_type: Ty<'tcx>, + pointee_type_metadata: DIType) + -> DIType { let pointer_llvm_type = type_of::type_of(cx, pointer_type); let (pointer_size, pointer_align) = size_and_align_of(cx, pointer_llvm_type); let name = compute_debuginfo_type_name(cx, pointer_type, false); @@ -1829,15 +1831,16 @@ struct MemberDescription { // for some record-like type. MemberDescriptionFactories are used to defer the // creation of type member descriptions in order to break cycles arising from // recursive type definitions. -enum MemberDescriptionFactory { - StructMDF(StructMemberDescriptionFactory), - TupleMDF(TupleMemberDescriptionFactory), - EnumMDF(EnumMemberDescriptionFactory), - VariantMDF(VariantMemberDescriptionFactory) +enum MemberDescriptionFactory<'tcx> { + StructMDF(StructMemberDescriptionFactory<'tcx>), + TupleMDF(TupleMemberDescriptionFactory<'tcx>), + EnumMDF(EnumMemberDescriptionFactory<'tcx>), + VariantMDF(VariantMemberDescriptionFactory<'tcx>) } -impl MemberDescriptionFactory { - fn create_member_descriptions(&self, cx: &CrateContext) -> Vec { +impl<'tcx> MemberDescriptionFactory<'tcx> { + fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>) + -> Vec { match *self { StructMDF(ref this) => { this.create_member_descriptions(cx) @@ -1859,25 +1862,25 @@ impl MemberDescriptionFactory { // with FinalMetadata) or it is not yet finished, but contains all information // needed to generate the missing parts of the description. See the documentation // section on Recursive Types at the top of this file for more information. -enum RecursiveTypeDescription { +enum RecursiveTypeDescription<'tcx> { UnfinishedMetadata { - unfinished_type: ty::t, + unfinished_type: Ty<'tcx>, unique_type_id: UniqueTypeId, metadata_stub: DICompositeType, llvm_type: Type, - member_description_factory: MemberDescriptionFactory, + member_description_factory: MemberDescriptionFactory<'tcx>, }, FinalMetadata(DICompositeType) } -fn create_and_register_recursive_type_forward_declaration( - cx: &CrateContext, - unfinished_type: ty::t, +fn create_and_register_recursive_type_forward_declaration<'a, 'tcx>( + cx: &CrateContext<'a, 'tcx>, + unfinished_type: Ty<'tcx>, unique_type_id: UniqueTypeId, metadata_stub: DICompositeType, llvm_type: Type, - member_description_factory: MemberDescriptionFactory) - -> RecursiveTypeDescription { + member_description_factory: MemberDescriptionFactory<'tcx>) + -> RecursiveTypeDescription<'tcx> { // Insert the stub into the TypeMap in order to allow for recursive references let mut type_map = debug_context(cx).type_map.borrow_mut(); @@ -1893,10 +1896,10 @@ fn create_and_register_recursive_type_forward_declaration( } } -impl RecursiveTypeDescription { +impl<'tcx> RecursiveTypeDescription<'tcx> { // Finishes up the description of the type in question (mostly by providing // descriptions of the fields of the given type) and returns the final type metadata. - fn finalize(&self, cx: &CrateContext) -> MetadataCreationResult { + fn finalize<'a>(&self, cx: &CrateContext<'a, 'tcx>) -> MetadataCreationResult { match *self { FinalMetadata(metadata) => MetadataCreationResult::new(metadata, false), UnfinishedMetadata { @@ -1944,14 +1947,15 @@ impl RecursiveTypeDescription { //=----------------------------------------------------------------------------- // Creates MemberDescriptions for the fields of a struct -struct StructMemberDescriptionFactory { - fields: Vec, +struct StructMemberDescriptionFactory<'tcx> { + fields: Vec>, is_simd: bool, span: Span, } -impl StructMemberDescriptionFactory { - fn create_member_descriptions(&self, cx: &CrateContext) -> Vec { +impl<'tcx> StructMemberDescriptionFactory<'tcx> { + fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>) + -> Vec { if self.fields.len() == 0 { return Vec::new(); } @@ -1988,13 +1992,13 @@ impl StructMemberDescriptionFactory { } -fn prepare_struct_metadata(cx: &CrateContext, - struct_type: ty::t, - def_id: ast::DefId, - substs: &subst::Substs, - unique_type_id: UniqueTypeId, - span: Span) - -> RecursiveTypeDescription { +fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + struct_type: Ty<'tcx>, + def_id: ast::DefId, + substs: &subst::Substs<'tcx>, + unique_type_id: UniqueTypeId, + span: Span) + -> RecursiveTypeDescription<'tcx> { let struct_name = compute_debuginfo_type_name(cx, struct_type, false); let struct_llvm_type = type_of::type_of(cx, struct_type); @@ -2028,14 +2032,14 @@ fn prepare_struct_metadata(cx: &CrateContext, //=----------------------------------------------------------------------------- // Creates MemberDescriptions for the fields of a tuple -struct TupleMemberDescriptionFactory { - component_types: Vec , +struct TupleMemberDescriptionFactory<'tcx> { + component_types: Vec>, span: Span, } -impl TupleMemberDescriptionFactory { - fn create_member_descriptions(&self, cx: &CrateContext) - -> Vec { +impl<'tcx> TupleMemberDescriptionFactory<'tcx> { + fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>) + -> Vec { self.component_types.iter().map(|&component_type| { MemberDescription { name: "".to_string(), @@ -2048,12 +2052,12 @@ impl TupleMemberDescriptionFactory { } } -fn prepare_tuple_metadata(cx: &CrateContext, - tuple_type: ty::t, - component_types: &[ty::t], - unique_type_id: UniqueTypeId, - span: Span) - -> RecursiveTypeDescription { +fn prepare_tuple_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + tuple_type: Ty<'tcx>, + component_types: &[Ty<'tcx>], + unique_type_id: UniqueTypeId, + span: Span) + -> RecursiveTypeDescription<'tcx> { let tuple_name = compute_debuginfo_type_name(cx, tuple_type, false); let tuple_llvm_type = type_of::type_of(cx, tuple_type); @@ -2084,18 +2088,19 @@ fn prepare_tuple_metadata(cx: &CrateContext, // the members of this union; so for every variant of the given enum, this factory // will produce one MemberDescription (all with no name and a fixed offset of // zero bytes). -struct EnumMemberDescriptionFactory { - enum_type: ty::t, - type_rep: Rc, - variants: Rc>>, +struct EnumMemberDescriptionFactory<'tcx> { + enum_type: Ty<'tcx>, + type_rep: Rc>, + variants: Rc>>>, discriminant_type_metadata: Option, containing_scope: DIScope, file_metadata: DIFile, span: Span, } -impl EnumMemberDescriptionFactory { - fn create_member_descriptions(&self, cx: &CrateContext) -> Vec { +impl<'tcx> EnumMemberDescriptionFactory<'tcx> { + fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>) + -> Vec { match *self.type_rep { adt::General(_, ref struct_defs, _) => { let discriminant_info = RegularDiscriminant(self.discriminant_type_metadata @@ -2286,14 +2291,15 @@ impl EnumMemberDescriptionFactory { } // Creates MemberDescriptions for the fields of a single enum variant. -struct VariantMemberDescriptionFactory { - args: Vec<(String, ty::t)> , +struct VariantMemberDescriptionFactory<'tcx> { + args: Vec<(String, Ty<'tcx>)>, discriminant_type_metadata: Option, span: Span, } -impl VariantMemberDescriptionFactory { - fn create_member_descriptions(&self, cx: &CrateContext) -> Vec { +impl<'tcx> VariantMemberDescriptionFactory<'tcx> { + fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>) + -> Vec { self.args.iter().enumerate().map(|(i, &(ref name, ty))| { MemberDescription { name: name.to_string(), @@ -2319,14 +2325,14 @@ enum EnumDiscriminantInfo { // of the variant, and (3) a MemberDescriptionFactory for producing the // descriptions of the fields of the variant. This is a rudimentary version of a // full RecursiveTypeDescription. -fn describe_enum_variant(cx: &CrateContext, - enum_type: ty::t, - struct_def: &adt::Struct, - variant_info: &ty::VariantInfo, - discriminant_info: EnumDiscriminantInfo, - containing_scope: DIScope, - span: Span) - -> (DICompositeType, Type, MemberDescriptionFactory) { +fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + enum_type: Ty<'tcx>, + struct_def: &adt::Struct<'tcx>, + variant_info: &ty::VariantInfo<'tcx>, + discriminant_info: EnumDiscriminantInfo, + containing_scope: DIScope, + span: Span) + -> (DICompositeType, Type, MemberDescriptionFactory<'tcx>) { let variant_llvm_type = Type::struct_(cx, struct_def.fields .iter() @@ -2369,7 +2375,7 @@ fn describe_enum_variant(cx: &CrateContext, }; // Build an array of (field name, field type) pairs to be captured in the factory closure. - let args: Vec<(String, ty::t)> = arg_names.iter() + let args: Vec<(String, Ty)> = arg_names.iter() .zip(struct_def.fields.iter()) .map(|(s, &t)| (s.to_string(), t)) .collect(); @@ -2389,12 +2395,12 @@ fn describe_enum_variant(cx: &CrateContext, (metadata_stub, variant_llvm_type, member_description_factory) } -fn prepare_enum_metadata(cx: &CrateContext, - enum_type: ty::t, - enum_def_id: ast::DefId, - unique_type_id: UniqueTypeId, - span: Span) - -> RecursiveTypeDescription { +fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + enum_type: Ty<'tcx>, + enum_def_id: ast::DefId, + unique_type_id: UniqueTypeId, + span: Span) + -> RecursiveTypeDescription<'tcx> { let enum_name = compute_debuginfo_type_name(cx, enum_type, false); let (containing_scope, definition_span) = get_namespace_and_span_for_item(cx, enum_def_id); @@ -2675,12 +2681,12 @@ fn create_struct_stub(cx: &CrateContext, return metadata_stub; } -fn fixed_vec_metadata(cx: &CrateContext, - unique_type_id: UniqueTypeId, - element_type: ty::t, - len: uint, - span: Span) - -> MetadataCreationResult { +fn fixed_vec_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + unique_type_id: UniqueTypeId, + element_type: Ty<'tcx>, + len: uint, + span: Span) + -> MetadataCreationResult { let element_type_metadata = type_metadata(cx, element_type, span); return_if_metadata_created_in_meantime!(cx, unique_type_id); @@ -2708,12 +2714,12 @@ fn fixed_vec_metadata(cx: &CrateContext, return MetadataCreationResult::new(metadata, false); } -fn vec_slice_metadata(cx: &CrateContext, - vec_type: ty::t, - element_type: ty::t, - unique_type_id: UniqueTypeId, - span: Span) - -> MetadataCreationResult { +fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + vec_type: Ty<'tcx>, + element_type: Ty<'tcx>, + unique_type_id: UniqueTypeId, + span: Span) + -> MetadataCreationResult { let data_ptr_type = ty::mk_ptr(cx.tcx(), ty::mt { ty: element_type, mutbl: ast::MutImmutable @@ -2762,26 +2768,26 @@ fn vec_slice_metadata(cx: &CrateContext, span); return MetadataCreationResult::new(metadata, false); - fn slice_layout_is_correct(cx: &CrateContext, - member_llvm_types: &[Type], - element_type: ty::t) - -> bool { + fn slice_layout_is_correct<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + member_llvm_types: &[Type], + element_type: Ty<'tcx>) + -> bool { member_llvm_types.len() == 2 && member_llvm_types[0] == type_of::type_of(cx, element_type).ptr_to() && member_llvm_types[1] == cx.int_type() } } -fn subroutine_type_metadata(cx: &CrateContext, - unique_type_id: UniqueTypeId, - signature: &ty::FnSig, - span: Span) - -> MetadataCreationResult { +fn subroutine_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + unique_type_id: UniqueTypeId, + signature: &ty::FnSig<'tcx>, + span: Span) + -> MetadataCreationResult { let mut signature_metadata: Vec = Vec::with_capacity(signature.inputs.len() + 1); // return type signature_metadata.push(match signature.output { - ty::FnConverging(ret_ty) => match ty::get(ret_ty).sty { + ty::FnConverging(ret_ty) => match ret_ty.sty { ty::ty_tup(ref tys) if tys.is_empty() => ptr::null_mut(), _ => type_metadata(cx, ret_ty, span) }, @@ -2811,16 +2817,16 @@ fn subroutine_type_metadata(cx: &CrateContext, // trait_type should be the actual trait (e.g., Trait). Where the trait is part // of a DST struct, there is no trait_object_type and the results of this // function will be a little bit weird. -fn trait_pointer_metadata(cx: &CrateContext, - trait_type: ty::t, - trait_object_type: Option, - unique_type_id: UniqueTypeId) - -> DIType { +fn trait_pointer_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + trait_type: Ty<'tcx>, + trait_object_type: Option>, + unique_type_id: UniqueTypeId) + -> DIType { // The implementation provided here is a stub. It makes sure that the trait // type is assigned the correct name, size, namespace, and source location. // But it does not describe the trait's methods. - let def_id = match ty::get(trait_type).sty { + let def_id = match trait_type.sty { ty::ty_trait(box ty::TyTrait { ref principal, .. }) => principal.def_id, _ => { let pp_type_name = ppaux::ty_to_string(cx.tcx(), trait_type); @@ -2848,10 +2854,10 @@ fn trait_pointer_metadata(cx: &CrateContext, codemap::DUMMY_SP) } -fn type_metadata(cx: &CrateContext, - t: ty::t, - usage_site_span: Span) - -> DIType { +fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>, + usage_site_span: Span) + -> DIType { // Get the unique type id of this type. let unique_type_id = { let mut type_map = debug_context(cx).type_map.borrow_mut(); @@ -2862,7 +2868,7 @@ fn type_metadata(cx: &CrateContext, return metadata; }, None => { - // The ty::t is not in the TypeMap but maybe we have already seen + // The Ty is not in the TypeMap but maybe we have already seen // an equivalent type (e.g. only differing in region arguments). // In order to find out, generate the unique type id and look // that up. @@ -2870,7 +2876,7 @@ fn type_metadata(cx: &CrateContext, match type_map.find_metadata_for_unique_id(unique_type_id) { Some(metadata) => { // There is already an equivalent type in the TypeMap. - // Register this ty::t as an alias in the cache and + // Register this Ty as an alias in the cache and // return the cached metadata. type_map.register_type_with_metadata(cx, t, metadata); return metadata; @@ -2885,9 +2891,9 @@ fn type_metadata(cx: &CrateContext, } }; - debug!("type_metadata: {}", ty::get(t)); + debug!("type_metadata: {}", t); - let sty = &ty::get(t).sty; + let sty = &t.sty; let MetadataCreationResult { metadata, already_stored_in_typemap } = match *sty { ty::ty_bool | ty::ty_char | @@ -2914,7 +2920,7 @@ fn type_metadata(cx: &CrateContext, false) } ty::ty_uniq(ty) | ty::ty_ptr(ty::mt{ty, ..}) | ty::ty_rptr(_, ty::mt{ty, ..}) => { - match ty::get(ty).sty { + match ty.sty { ty::ty_vec(typ, None) => { vec_slice_metadata(cx, t, typ, unique_type_id, usage_site_span) } @@ -2986,7 +2992,7 @@ fn type_metadata(cx: &CrateContext, let error_message = format!("Expected type metadata for unique \ type id '{}' to already be in \ the debuginfo::TypeMap but it \ - was not. (ty::t = {})", + was not. (Ty = {})", unique_type_id_str.as_slice(), ppaux::ty_to_string(cx.tcx(), t)); cx.sess().span_bug(usage_site_span, error_message.as_slice()); @@ -2998,10 +3004,10 @@ fn type_metadata(cx: &CrateContext, if metadata != metadata_for_uid { let unique_type_id_str = type_map.get_unique_type_id_as_string(unique_type_id); - let error_message = format!("Mismatch between ty::t and \ + let error_message = format!("Mismatch between Ty and \ UniqueTypeId maps in \ debuginfo::TypeMap. \ - UniqueTypeId={}, ty::t={}", + UniqueTypeId={}, Ty={}", unique_type_id_str.as_slice(), ppaux::ty_to_string(cx.tcx(), t)); cx.sess().span_bug(usage_site_span, error_message.as_slice()); @@ -3111,8 +3117,9 @@ fn bytes_to_bits(bytes: u64) -> u64 { } #[inline] -fn debug_context<'a>(cx: &'a CrateContext) -> &'a CrateDebugContext { - let debug_context: &'a CrateDebugContext = cx.dbg_cx().as_ref().unwrap(); +fn debug_context<'a, 'tcx>(cx: &'a CrateContext<'a, 'tcx>) + -> &'a CrateDebugContext<'tcx> { + let debug_context: &'a CrateDebugContext<'tcx> = cx.dbg_cx().as_ref().unwrap(); debug_context } @@ -3666,10 +3673,10 @@ fn populate_scope_map(cx: &CrateContext, // any caching, i.e. calling the function twice with the same type will also do // the work twice. The `qualified` parameter only affects the first level of the // type name, further levels (i.e. type parameters) are always fully qualified. -fn compute_debuginfo_type_name(cx: &CrateContext, - t: ty::t, - qualified: bool) - -> String { +fn compute_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>, + qualified: bool) + -> String { let mut result = String::with_capacity(64); push_debuginfo_type_name(cx, t, qualified, &mut result); result @@ -3677,11 +3684,11 @@ fn compute_debuginfo_type_name(cx: &CrateContext, // Pushes the name of the type as it should be stored in debuginfo on the // `output` String. See also compute_debuginfo_type_name(). -fn push_debuginfo_type_name(cx: &CrateContext, - t: ty::t, - qualified: bool, - output: &mut String) { - match ty::get(t).sty { +fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>, + qualified: bool, + output: &mut String) { + match t.sty { ty::ty_bool => output.push_str("bool"), ty::ty_char => output.push_str("char"), ty::ty_str => output.push_str("str"), @@ -3907,9 +3914,9 @@ fn push_debuginfo_type_name(cx: &CrateContext, // reconstructed for items from non-local crates. For local crates, this // would be possible but with inlining and LTO we have to use the least // common denominator - otherwise we would run into conflicts. - fn push_type_params(cx: &CrateContext, - substs: &subst::Substs, - output: &mut String) { + fn push_type_params<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + substs: &subst::Substs<'tcx>, + output: &mut String) { if substs.types.is_empty() { return; } diff --git a/src/librustc_trans/trans/doc.rs b/src/librustc_trans/trans/doc.rs index 013483d0003c3..a5281e582f136 100644 --- a/src/librustc_trans/trans/doc.rs +++ b/src/librustc_trans/trans/doc.rs @@ -40,7 +40,7 @@ up expressions into: ## The Datum module A `Datum` encapsulates the result of evaluating a Rust expression. It -contains a `ValueRef` indicating the result, a `ty::t` describing +contains a `ValueRef` indicating the result, a `Ty` describing the Rust type, but also a *kind*. The kind indicates whether the datum has cleanup scheduled (lvalue) or not (rvalue) and -- in the case of rvalues -- whether or not the value is "by ref" or "by value". diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 40a4d6047aa53..8ccc59831993a 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -68,7 +68,7 @@ use trans::type_of; use middle::ty::{struct_fields, tup_fields}; use middle::ty::{AdjustDerefRef, AdjustAddEnv, AutoUnsafe}; use middle::ty::{AutoPtr}; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck; use middle::typeck::MethodCall; use util::common::indenter; @@ -179,7 +179,7 @@ pub fn get_dataptr(bcx: Block, fat_ptr: ValueRef) -> ValueRef { fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum) + datum: Datum<'tcx, Expr>) -> DatumBlock<'blk, 'tcx, Expr> { /*! * Helper for trans that apply adjustments from `expr` to `datum`, @@ -212,7 +212,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // also be just in case we need to unsize. But if there are no nested // adjustments then it should be a no-op). Some(ty::AutoPtr(_, _, None)) if adj.autoderefs == 1 => { - match ty::get(datum.ty).sty { + match datum.ty.sty { // Don't skip a conversion from Box to &T, etc. ty::ty_rptr(..) => { let method_call = MethodCall::autoderef(expr.id, adj.autoderefs-1); @@ -253,10 +253,10 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, debug!("after adjustments, datum={}", datum.to_string(bcx.ccx())); return DatumBlock::new(bcx, datum); - fn apply_autoref<'blk, 'tcx>(autoref: &ty::AutoRef, + fn apply_autoref<'blk, 'tcx>(autoref: &ty::AutoRef<'tcx>, bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum) + datum: Datum<'tcx, Expr>) -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; let mut datum = datum; @@ -291,7 +291,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn ref_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum) + datum: Datum<'tcx, Expr>) -> DatumBlock<'blk, 'tcx, Expr> { if !ty::type_is_sized(bcx.tcx(), datum.ty) { debug!("Taking address of unsized type {}", @@ -312,13 +312,13 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // then mk_ty should make a Box pointer (T -> Box), if we want a // borrowed reference then it should be T -> &T. fn unsized_info<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - kind: &ty::UnsizeKind, + kind: &ty::UnsizeKind<'tcx>, id: ast::NodeId, - unsized_ty: ty::t, - mk_ty: |ty::t| -> ty::t) -> ValueRef { + unsized_ty: Ty<'tcx>, + mk_ty: |Ty<'tcx>| -> Ty<'tcx>) -> ValueRef { match kind { &ty::UnsizeLength(len) => C_uint(bcx.ccx(), len), - &ty::UnsizeStruct(box ref k, tp_index) => match ty::get(unsized_ty).sty { + &ty::UnsizeStruct(box ref k, tp_index) => match unsized_ty.sty { ty::ty_struct(_, ref substs) => { let ty_substs = substs.types.get_slice(subst::TypeSpace); // The dtor for a field treats it like a value, so mk_ty @@ -333,8 +333,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let trait_ref = Rc::new(ty::TraitRef { def_id: principal.def_id, substs: substs }); - let trait_ref = - trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs.substs()); + let trait_ref = trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs); let box_ty = mk_ty(unsized_ty); PointerCast(bcx, meth::get_vtable(bcx, box_ty, trait_ref), @@ -345,8 +344,8 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn unsize_expr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum, - k: &ty::UnsizeKind) + datum: Datum<'tcx, Expr>, + k: &ty::UnsizeKind<'tcx>) -> DatumBlock<'blk, 'tcx, Expr> { let tcx = bcx.tcx(); let datum_ty = datum.ty; @@ -379,7 +378,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn ref_fat_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum) + datum: Datum<'tcx, Expr>) -> DatumBlock<'blk, 'tcx, Expr> { let tcx = bcx.tcx(); let dest_ty = ty::close_type(tcx, datum.ty); @@ -390,8 +389,8 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn into_fat_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum, - dest_ty: ty::t, + datum: Datum<'tcx, Expr>, + dest_ty: Ty<'tcx>, base: |Block<'blk, 'tcx>, ValueRef| -> ValueRef, info: |Block<'blk, 'tcx>, ValueRef| -> ValueRef) -> DatumBlock<'blk, 'tcx, Expr> { @@ -412,7 +411,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn unsize_unique_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum, + datum: Datum<'tcx, Expr>, len: uint) -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; @@ -440,14 +439,14 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn unsize_unique_expr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum, - k: &ty::UnsizeKind) + datum: Datum<'tcx, Expr>, + k: &ty::UnsizeKind<'tcx>) -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; let tcx = bcx.tcx(); let datum_ty = datum.ty; - let unboxed_ty = match ty::get(datum_ty).sty { + let unboxed_ty = match datum_ty.sty { ty::ty_uniq(t) => t, _ => bcx.sess().bug(format!("Expected ty_uniq, found {}", bcx.ty_to_string(datum_ty)).as_slice()) @@ -475,7 +474,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn add_env<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum) + datum: Datum<'tcx, Expr>) -> DatumBlock<'blk, 'tcx, Expr> { // This is not the most efficient thing possible; since closures // are two words it'd be better if this were compiled in @@ -566,7 +565,7 @@ fn trans_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } }; - fn nil<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ty: ty::t) + fn nil<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ty: Ty<'tcx>) -> DatumBlock<'blk, 'tcx, Expr> { let llval = C_undef(type_of::type_of(bcx.ccx(), ty)); let datum = immediate_rvalue(llval, ty); @@ -629,7 +628,7 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Special case for `Box` let box_ty = expr_ty(bcx, expr); let contents_ty = expr_ty(bcx, &**contents); - match ty::get(box_ty).sty { + match box_ty.sty { ty::ty_uniq(..) => { trans_uniq_expr(bcx, box_ty, &**contents, contents_ty) } @@ -678,7 +677,7 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn trans_field<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, base: &ast::Expr, - get_idx: |&'blk ty::ctxt<'tcx>, &[ty::field]| -> uint) + get_idx: |&'blk ty::ctxt<'tcx>, &[ty::field<'tcx>]| -> uint) -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; let _icx = push_ctxt("trans_rec_field"); @@ -858,7 +857,7 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let const_ty = expr_ty(bcx, ref_expr); fn get_val<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, did: ast::DefId, - const_ty: ty::t) -> ValueRef { + const_ty: Ty<'tcx>) -> ValueRef { // For external constants, we don't inline. if did.krate == ast::LOCAL_CRATE { // Case 1. @@ -1121,8 +1120,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, .get(&expr.id) .map(|t| (*t).clone()) .unwrap(); - let trait_ref = - trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs.substs()); + let trait_ref = trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs); let datum = unpack_datum!(bcx, trans(bcx, &**val)); meth::trans_trait_cast(bcx, datum, expr.id, trait_ref, dest) @@ -1175,7 +1173,7 @@ fn trans_def_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } def::DefStruct(_) => { let ty = expr_ty(bcx, ref_expr); - match ty::get(ty).sty { + match ty.sty { ty::ty_struct(did, _) if ty::has_dtor(bcx.tcx(), did) => { let repr = adt::represent_type(bcx.ccx(), ty); adt::trans_set_discr(bcx, &*repr, lldest, 0); @@ -1224,7 +1222,7 @@ fn trans_def_fn_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, def: def::Def) - -> Datum { + -> Datum<'tcx, Lvalue> { /*! * Translates a reference to a local variable or argument. * This always results in an lvalue datum. @@ -1266,11 +1264,11 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } } -pub fn with_field_tys(tcx: &ty::ctxt, - ty: ty::t, - node_id_opt: Option, - op: |ty::Disr, (&[ty::field])| -> R) - -> R { +pub fn with_field_tys<'tcx, R>(tcx: &ty::ctxt<'tcx>, + ty: Ty<'tcx>, + node_id_opt: Option, + op: |ty::Disr, (&[ty::field<'tcx>])| -> R) + -> R { /*! * Helper for enumerating the field types of structs, enums, or records. * The optional node ID here is the node ID of the path identifying the enum @@ -1278,7 +1276,7 @@ pub fn with_field_tys(tcx: &ty::ctxt, * is and `node_id_opt` is none, this function panics). */ - match ty::get(ty).sty { + match ty.sty { ty::ty_struct(did, ref substs) => { op(0, struct_fields(tcx, did, substs).as_slice()) } @@ -1389,11 +1387,11 @@ fn trans_struct<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, * Note that `fields` may be empty; the base expression must always be * evaluated for side-effects. */ -pub struct StructBaseInfo<'a> { +pub struct StructBaseInfo<'a, 'tcx> { /// The base expression; will be evaluated after all explicit fields. expr: &'a ast::Expr, /// The indices of fields to copy paired with their types. - fields: Vec<(uint, ty::t)> + fields: Vec<(uint, Ty<'tcx>)> } /** @@ -1406,14 +1404,14 @@ pub struct StructBaseInfo<'a> { * - `optbase` contains information on the base struct (if any) from * which remaining fields are copied; see comments on `StructBaseInfo`. */ -pub fn trans_adt<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, - ty: ty::t, - discr: ty::Disr, - fields: &[(uint, &ast::Expr)], - optbase: Option, - dest: Dest, - source_location: Option) - -> Block<'blk, 'tcx> { +pub fn trans_adt<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + ty: Ty<'tcx>, + discr: ty::Disr, + fields: &[(uint, &ast::Expr)], + optbase: Option>, + dest: Dest, + source_location: Option) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_adt"); let fcx = bcx.fcx; let repr = adt::represent_type(bcx.ccx(), ty); @@ -1572,9 +1570,9 @@ fn trans_unary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } fn trans_uniq_expr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - box_ty: ty::t, + box_ty: Ty<'tcx>, contents: &ast::Expr, - contents_ty: ty::t) + contents_ty: Ty<'tcx>) -> DatumBlock<'blk, 'tcx, Expr> { let _icx = push_ctxt("trans_uniq_expr"); let fcx = bcx.fcx; @@ -1607,7 +1605,7 @@ fn trans_addr_of<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let _icx = push_ctxt("trans_addr_of"); let mut bcx = bcx; let sub_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, subexpr, "addr_of")); - match ty::get(sub_datum.ty).sty { + match sub_datum.ty.sty { ty::ty_open(_) => { // Opened DST value, close to a fat pointer debug!("Closing fat pointer {}", bcx.ty_to_string(sub_datum.ty)); @@ -1635,11 +1633,11 @@ fn trans_addr_of<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // and the other not. fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, binop_expr: &ast::Expr, - binop_ty: ty::t, + binop_ty: Ty<'tcx>, op: ast::BinOp, - lhs_t: ty::t, + lhs_t: Ty<'tcx>, lhs: ValueRef, - rhs_t: ty::t, + rhs_t: Ty<'tcx>, rhs: ValueRef) -> DatumBlock<'blk, 'tcx, Expr> { let _icx = push_ctxt("trans_eager_binop"); @@ -1813,8 +1811,8 @@ fn trans_binary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn trans_overloaded_op<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, method_call: MethodCall, - lhs: Datum, - rhs: Vec<(Datum, ast::NodeId)>, + lhs: Datum<'tcx, Expr>, + rhs: Vec<(Datum<'tcx, Expr>, ast::NodeId)>, dest: Option) -> Result<'blk, 'tcx> { let method_ty = (*bcx.tcx().method_map.borrow())[method_call].ty; @@ -1907,8 +1905,8 @@ pub enum cast_kind { cast_other, } -pub fn cast_type_kind(tcx: &ty::ctxt, t: ty::t) -> cast_kind { - match ty::get(t).sty { +pub fn cast_type_kind<'tcx>(tcx: &ty::ctxt<'tcx>, t: Ty<'tcx>) -> cast_kind { + match t.sty { ty::ty_char => cast_integral, ty::ty_float(..) => cast_float, ty::ty_rptr(_, mt) | ty::ty_ptr(mt) => { @@ -1927,7 +1925,7 @@ pub fn cast_type_kind(tcx: &ty::ctxt, t: ty::t) -> cast_kind { } } -fn cast_is_noop(t_in: ty::t, t_out: ty::t) -> bool { +fn cast_is_noop<'tcx>(t_in: Ty<'tcx>, t_out: Ty<'tcx>) -> bool { match (ty::deref(t_in, true), ty::deref(t_out, true)) { (Some(ty::mt{ ty: t_in, .. }), Some(ty::mt{ ty: t_out, .. })) => { t_in == t_out @@ -2061,7 +2059,7 @@ fn trans_assign_op<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } fn auto_ref<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - datum: Datum, + datum: Datum<'tcx, Expr>, expr: &ast::Expr) -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; @@ -2086,7 +2084,7 @@ fn auto_ref<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn deref_multiple<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum, + datum: Datum<'tcx, Expr>, times: uint) -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; @@ -2100,7 +2098,7 @@ fn deref_multiple<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum, + datum: Datum<'tcx, Expr>, method_call: MethodCall) -> DatumBlock<'blk, 'tcx, Expr> { let ccx = bcx.ccx(); @@ -2141,7 +2139,7 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } }; - let r = match ty::get(datum.ty).sty { + let r = match datum.ty.sty { ty::ty_uniq(content_ty) => { if ty::type_is_sized(bcx.tcx(), content_ty) { deref_owned_pointer(bcx, expr, datum, content_ty) @@ -2195,8 +2193,8 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, fn deref_owned_pointer<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr, - datum: Datum, - content_ty: ty::t) + datum: Datum<'tcx, Expr>, + content_ty: Ty<'tcx>) -> DatumBlock<'blk, 'tcx, Expr> { /*! * We microoptimize derefs of owned pointers a bit here. diff --git a/src/librustc_trans/trans/foreign.rs b/src/librustc_trans/trans/foreign.rs index f86a0994bf95c..1f6aeacc86058 100644 --- a/src/librustc_trans/trans/foreign.rs +++ b/src/librustc_trans/trans/foreign.rs @@ -23,8 +23,8 @@ use trans::type_::Type; use trans::type_of::*; use trans::type_of; use middle::ty::FnSig; -use middle::ty; -use middle::subst::Subst; +use middle::ty::{mod, Ty}; +use middle::subst::{Subst, Substs}; use std::cmp; use libc::c_uint; use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi}; @@ -39,9 +39,9 @@ use util::ppaux::Repr; /////////////////////////////////////////////////////////////////////////// // Type definitions -struct ForeignTypes { +struct ForeignTypes<'tcx> { /// Rust signature of the function - fn_sig: ty::FnSig, + fn_sig: ty::FnSig<'tcx>, /// Adapter object for handling native ABI rules (trust me, you /// don't want to know) @@ -122,7 +122,7 @@ pub fn register_static(ccx: &CrateContext, "invalid linkage specified"); } }; - let llty2 = match ty::get(ty).sty { + let llty2 = match ty.sty { ty::ty_ptr(ref mt) => type_of::type_of(ccx, mt.ty), _ => { ccx.sess().span_fatal(foreign_item.span, @@ -161,8 +161,9 @@ pub fn register_static(ccx: &CrateContext, } } -pub fn register_foreign_item_fn(ccx: &CrateContext, abi: Abi, fty: ty::t, - name: &str) -> ValueRef { +pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + abi: Abi, fty: Ty<'tcx>, + name: &str) -> ValueRef { /*! * Registers a foreign function found in a library. * Just adds a LLVM global. @@ -201,11 +202,11 @@ pub fn register_foreign_item_fn(ccx: &CrateContext, abi: Abi, fty: ty::t, } pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - callee_ty: ty::t, + callee_ty: Ty<'tcx>, llfn: ValueRef, llretptr: ValueRef, llargs_rust: &[ValueRef], - passed_arg_tys: Vec ) + passed_arg_tys: Vec>) -> Block<'blk, 'tcx> { /*! * Prepares a call to a native function. This requires adapting @@ -234,7 +235,7 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ccx.tn().val_to_string(llfn), ccx.tn().val_to_string(llretptr)); - let (fn_abi, fn_sig) = match ty::get(callee_ty).sty { + let (fn_abi, fn_sig) = match callee_ty.sty { ty::ty_bare_fn(ref fn_ty) => (fn_ty.abi, fn_ty.sig.clone()), _ => ccx.sess().bug("trans_native_call called on non-function type") }; @@ -483,13 +484,13 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &ast::ForeignMod) { // inline the one into the other. Of course we could just generate the // correct code in the first place, but this is much simpler. -pub fn decl_rust_fn_with_foreign_abi(ccx: &CrateContext, - t: ty::t, - name: &str) - -> ValueRef { +pub fn decl_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>, + name: &str) + -> ValueRef { let tys = foreign_types_for_fn_ty(ccx, t); let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys); - let cconv = match ty::get(t).sty { + let cconv = match t.sty { ty::ty_bare_fn(ref fn_ty) => { llvm_calling_convention(ccx, fn_ty.abi) } @@ -512,7 +513,7 @@ pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext, let tys = foreign_types_for_id(ccx, node_id); let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys); let t = ty::node_id_to_type(ccx.tcx(), node_id); - let cconv = match ty::get(t).sty { + let cconv = match t.sty { ty::ty_bare_fn(ref fn_ty) => { llvm_calling_convention(ccx, fn_ty.abi) } @@ -525,18 +526,18 @@ pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext, llfn } -pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext, - decl: &ast::FnDecl, - body: &ast::Block, - attrs: &[ast::Attribute], - llwrapfn: ValueRef, - param_substs: ¶m_substs, - id: ast::NodeId, - hash: Option<&str>) { +pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + decl: &ast::FnDecl, + body: &ast::Block, + attrs: &[ast::Attribute], + llwrapfn: ValueRef, + param_substs: &Substs<'tcx>, + id: ast::NodeId, + hash: Option<&str>) { let _icx = push_ctxt("foreign::build_foreign_fn"); let fnty = ty::node_id_to_type(ccx.tcx(), id); - let mty = fnty.subst(ccx.tcx(), param_substs.substs()); + let mty = fnty.subst(ccx.tcx(), param_substs); let tys = foreign_types_for_fn_ty(ccx, mty); unsafe { // unsafe because we call LLVM operations @@ -547,18 +548,17 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext, return build_wrap_fn(ccx, llrustfn, llwrapfn, &tys, mty); } - fn build_rust_fn(ccx: &CrateContext, - decl: &ast::FnDecl, - body: &ast::Block, - param_substs: ¶m_substs, - attrs: &[ast::Attribute], - id: ast::NodeId, - hash: Option<&str>) - -> ValueRef { + fn build_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + decl: &ast::FnDecl, + body: &ast::Block, + param_substs: &Substs<'tcx>, + attrs: &[ast::Attribute], + id: ast::NodeId, + hash: Option<&str>) + -> ValueRef { let _icx = push_ctxt("foreign::foreign::build_rust_fn"); let tcx = ccx.tcx(); - let t = ty::node_id_to_type(tcx, id).subst( - ccx.tcx(), param_substs.substs()); + let t = ty::node_id_to_type(tcx, id).subst(ccx.tcx(), param_substs); let ps = ccx.tcx().map.with_path(id, |path| { let abi = Some(ast_map::PathName(special_idents::clownshoe_abi.name)); @@ -567,7 +567,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext, // Compute the type that the function would have if it were just a // normal Rust function. This will be the type of the wrappee fn. - match ty::get(t).sty { + match t.sty { ty::ty_bare_fn(ref f) => { assert!(f.abi != Rust && f.abi != RustIntrinsic); } @@ -589,11 +589,11 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext, llfn } - unsafe fn build_wrap_fn(ccx: &CrateContext, - llrustfn: ValueRef, - llwrapfn: ValueRef, - tys: &ForeignTypes, - t: ty::t) { + unsafe fn build_wrap_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + llrustfn: ValueRef, + llwrapfn: ValueRef, + tys: &ForeignTypes<'tcx>, + t: Ty<'tcx>) { let _icx = push_ctxt( "foreign::trans_rust_fn_with_foreign_abi::build_wrap_fn"); let tcx = ccx.tcx(); @@ -832,8 +832,9 @@ pub fn link_name(i: &ast::ForeignItem) -> InternedString { } } -fn foreign_signature(ccx: &CrateContext, fn_sig: &ty::FnSig, arg_tys: &[ty::t]) - -> LlvmSignature { +fn foreign_signature<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + fn_sig: &ty::FnSig<'tcx>, arg_tys: &[Ty<'tcx>]) + -> LlvmSignature { /*! * The ForeignSignature is the LLVM types of the arguments/return type * of a function. Note that these LLVM types are not quite the same @@ -856,14 +857,14 @@ fn foreign_signature(ccx: &CrateContext, fn_sig: &ty::FnSig, arg_tys: &[ty::t]) } } -fn foreign_types_for_id(ccx: &CrateContext, - id: ast::NodeId) -> ForeignTypes { +fn foreign_types_for_id<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + id: ast::NodeId) -> ForeignTypes<'tcx> { foreign_types_for_fn_ty(ccx, ty::node_id_to_type(ccx.tcx(), id)) } -fn foreign_types_for_fn_ty(ccx: &CrateContext, - ty: ty::t) -> ForeignTypes { - let fn_sig = match ty::get(ty).sty { +fn foreign_types_for_fn_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + ty: Ty<'tcx>) -> ForeignTypes<'tcx> { + let fn_sig = match ty.sty { ty::ty_bare_fn(ref fn_ty) => fn_ty.sig.clone(), _ => ccx.sess().bug("foreign_types_for_fn_ty called on non-function type") }; @@ -934,7 +935,8 @@ fn lltype_for_fn_from_foreign_types(ccx: &CrateContext, tys: &ForeignTypes) -> T } } -pub fn lltype_for_foreign_fn(ccx: &CrateContext, ty: ty::t) -> Type { +pub fn lltype_for_foreign_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + ty: Ty<'tcx>) -> Type { lltype_for_fn_from_foreign_types(ccx, &foreign_types_for_fn_ty(ccx, ty)) } diff --git a/src/librustc_trans/trans/glue.rs b/src/librustc_trans/trans/glue.rs index 5188ca773503a..67b3310dbdf88 100644 --- a/src/librustc_trans/trans/glue.rs +++ b/src/librustc_trans/trans/glue.rs @@ -19,7 +19,7 @@ use llvm::{ValueRef, True, get_param}; use llvm; use middle::lang_items::ExchangeFreeFnLangItem; use middle::subst; -use middle::subst::Subst; +use middle::subst::{Subst, Substs}; use trans::adt; use trans::base::*; use trans::build::*; @@ -34,7 +34,7 @@ use trans::machine::*; use trans::tvec; use trans::type_::Type; use trans::type_of::{type_of, sizing_type_of, align_of}; -use middle::ty; +use middle::ty::{mod, Ty}; use util::ppaux::{ty_to_short_str, Repr}; use util::ppaux; @@ -62,7 +62,7 @@ pub fn trans_exchange_free<'blk, 'tcx>(cx: Block<'blk, 'tcx>, v: ValueRef, } pub fn trans_exchange_free_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ptr: ValueRef, - content_ty: ty::t) -> Block<'blk, 'tcx> { + content_ty: Ty<'tcx>) -> Block<'blk, 'tcx> { assert!(ty::type_is_sized(bcx.ccx().tcx(), content_ty)); let sizing_type = sizing_type_of(bcx.ccx(), content_ty); let content_size = llsize_of_alloc(bcx.ccx(), sizing_type); @@ -76,7 +76,8 @@ pub fn trans_exchange_free_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ptr: ValueRef, } } -pub fn get_drop_glue_type(ccx: &CrateContext, t: ty::t) -> ty::t { +pub fn get_drop_glue_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>) -> Ty<'tcx> { let tcx = ccx.tcx(); // Even if there is no dtor for t, there might be one deeper down and we // might need to pass in the vtable ptr. @@ -86,7 +87,7 @@ pub fn get_drop_glue_type(ccx: &CrateContext, t: ty::t) -> ty::t { if !ty::type_needs_drop(tcx, t) { return ty::mk_i8(); } - match ty::get(t).sty { + match t.sty { ty::ty_uniq(typ) if !ty::type_needs_drop(tcx, typ) && ty::type_is_sized(tcx, typ) => { let llty = sizing_type_of(ccx, typ); @@ -103,7 +104,7 @@ pub fn get_drop_glue_type(ccx: &CrateContext, t: ty::t) -> ty::t { pub fn drop_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v: ValueRef, - t: ty::t, + t: Ty<'tcx>, source_location: Option) -> Block<'blk, 'tcx> { // NB: v is an *alias* of type t here, not a direct value. @@ -131,7 +132,7 @@ pub fn drop_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pub fn drop_ty_immediate<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v: ValueRef, - t: ty::t, + t: Ty<'tcx>, source_location: Option) -> Block<'blk, 'tcx> { let _icx = push_ctxt("drop_ty_immediate"); @@ -140,7 +141,7 @@ pub fn drop_ty_immediate<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, drop_ty(bcx, vp, t, source_location) } -pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef { +pub fn get_drop_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> ValueRef { debug!("make drop glue for {}", ppaux::ty_to_string(ccx.tcx(), t)); let t = get_drop_glue_type(ccx, t); debug!("drop glue type {}", ppaux::ty_to_string(ccx.tcx(), t)); @@ -185,11 +186,11 @@ pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef { } fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, - t: ty::t, + t: Ty<'tcx>, v0: ValueRef, dtor_did: ast::DefId, class_did: ast::DefId, - substs: &subst::Substs) + substs: &subst::Substs<'tcx>) -> Block<'blk, 'tcx> { let repr = adt::represent_type(bcx.ccx(), t); let struct_data = if ty::type_is_sized(bcx.tcx(), t) { @@ -205,11 +206,11 @@ fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, } fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - t: ty::t, + t: Ty<'tcx>, v0: ValueRef, dtor_did: ast::DefId, class_did: ast::DefId, - substs: &subst::Substs) + substs: &subst::Substs<'tcx>) -> Block<'blk, 'tcx> { let repr = adt::represent_type(bcx.ccx(), t); @@ -224,7 +225,7 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, }; let fty = ty::lookup_item_type(bcx.tcx(), dtor_did).ty.subst(bcx.tcx(), substs); - let self_ty = match ty::get(fty).sty { + let self_ty = match fty.sty { ty::ty_bare_fn(ref f) => { assert!(f.sig.inputs.len() == 1); f.sig.inputs[0] @@ -297,7 +298,8 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, }) } -fn size_and_align_of_dst(bcx: Block, t :ty::t, info: ValueRef) -> (ValueRef, ValueRef) { +fn size_and_align_of_dst<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, info: ValueRef) + -> (ValueRef, ValueRef) { debug!("calculate size of DST: {}; with lost info: {}", bcx.ty_to_string(t), bcx.val_to_string(info)); if ty::type_is_sized(bcx.tcx(), t) { @@ -306,7 +308,7 @@ fn size_and_align_of_dst(bcx: Block, t :ty::t, info: ValueRef) -> (ValueRef, Val let align = C_uint(bcx.ccx(), align_of(bcx.ccx(), t)); return (size, align); } - match ty::get(t).sty { + match t.sty { ty::ty_struct(id, ref substs) => { let ccx = bcx.ccx(); // First get the size of all statically known fields. @@ -352,13 +354,13 @@ fn size_and_align_of_dst(bcx: Block, t :ty::t, info: ValueRef) -> (ValueRef, Val } } -fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: ty::t) +fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: Ty<'tcx>) -> Block<'blk, 'tcx> { // NB: v0 is an *alias* of type t here, not a direct value. let _icx = push_ctxt("make_drop_glue"); - match ty::get(t).sty { + match t.sty { ty::ty_uniq(content_ty) => { - match ty::get(content_ty).sty { + match content_ty.sty { ty::ty_vec(ty, None) => { tvec::make_drop_glue_unboxed(bcx, v0, ty, true) } @@ -477,7 +479,8 @@ fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: ty::t) } // Generates the declaration for (but doesn't emit) a type descriptor. -pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> tydesc_info { +pub fn declare_tydesc<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) + -> tydesc_info<'tcx> { // If emit_tydescs already ran, then we shouldn't be creating any new // tydescs. assert!(!ccx.finished_tydescs().get()); @@ -514,8 +517,8 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> tydesc_info { } } -fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type, - name: &str) -> (String, ValueRef) { +fn declare_generic_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, + llfnty: Type, name: &str) -> (String, ValueRef) { let _icx = push_ctxt("declare_generic_glue"); let fn_nm = mangle_internal_name_by_type_and_seq( ccx, @@ -526,19 +529,19 @@ fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type, return (fn_nm, llfn); } -fn make_generic_glue(ccx: &CrateContext, - t: ty::t, - llfn: ValueRef, - helper: for<'blk, 'tcx> |Block<'blk, 'tcx>, ValueRef, ty::t| - -> Block<'blk, 'tcx>, - name: &str) - -> ValueRef { +fn make_generic_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>, + llfn: ValueRef, + helper: for<'blk> |Block<'blk, 'tcx>, ValueRef, Ty<'tcx>| + -> Block<'blk, 'tcx>, + name: &str) + -> ValueRef { let _icx = push_ctxt("make_generic_glue"); let glue_name = format!("glue {} {}", name, ty_to_short_str(ccx.tcx(), t)); let _s = StatRecorder::new(ccx, glue_name); let arena = TypedArena::new(); - let empty_param_substs = param_substs::empty(); + let empty_param_substs = Substs::trans_empty(); let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, false, ty::FnConverging(ty::mk_nil(ccx.tcx())), &empty_param_substs, None, &arena); diff --git a/src/librustc_trans/trans/inline.rs b/src/librustc_trans/trans/inline.rs index 51d839c3bee15..bde9051ec74d6 100644 --- a/src/librustc_trans/trans/inline.rs +++ b/src/librustc_trans/trans/inline.rs @@ -11,6 +11,7 @@ use llvm::{AvailableExternallyLinkage, InternalLinkage, SetLinkage}; use metadata::csearch; use middle::astencode; +use middle::subst::Substs; use trans::base::{push_ctxt, trans_item, get_item_val, trans_fn}; use trans::common::*; use middle::ty; @@ -164,7 +165,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId) &*mth.pe_fn_decl(), &*mth.pe_body(), llfn, - ¶m_substs::empty(), + &Substs::trans_empty(), mth.id, &[]); // Use InternalLinkage so LLVM can optimize more diff --git a/src/librustc_trans/trans/intrinsic.rs b/src/librustc_trans/trans/intrinsic.rs index 3bc6c30f8d6c0..6bdb35f8d6074 100644 --- a/src/librustc_trans/trans/intrinsic.rs +++ b/src/librustc_trans/trans/intrinsic.rs @@ -28,7 +28,7 @@ use trans::type_of; use trans::machine; use trans::machine::llsize_of; use trans::type_::Type; -use middle::ty; +use middle::ty::{mod, Ty}; use syntax::abi::RustIntrinsic; use syntax::ast; use syntax::parse::token; @@ -135,17 +135,21 @@ pub fn check_intrinsics(ccx: &CrateContext) { ccx.sess().abort_if_errors(); } -pub fn trans_intrinsic_call<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, node: ast::NodeId, - callee_ty: ty::t, cleanup_scope: cleanup::CustomScopeIndex, - args: callee::CallArgs, dest: expr::Dest, - substs: subst::Substs, call_info: NodeInfo) - -> Result<'blk, 'tcx> { +pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + node: ast::NodeId, + callee_ty: Ty<'tcx>, + cleanup_scope: cleanup::CustomScopeIndex, + args: callee::CallArgs<'a, 'tcx>, + dest: expr::Dest, + substs: subst::Substs<'tcx>, + call_info: NodeInfo) + -> Result<'blk, 'tcx> { let fcx = bcx.fcx; let ccx = fcx.ccx; let tcx = bcx.tcx(); - let ret_ty = match ty::get(callee_ty).sty { + let ret_ty = match callee_ty.sty { ty::ty_bare_fn(ref f) => f.sig.output, _ => panic!("expected bare_fn in trans_intrinsic_call") }; @@ -553,8 +557,9 @@ pub fn trans_intrinsic_call<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, node: ast::N Result::new(bcx, llresult) } -fn copy_intrinsic(bcx: Block, allow_overlap: bool, volatile: bool, - tp_ty: ty::t, dst: ValueRef, src: ValueRef, count: ValueRef) -> ValueRef { +fn copy_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + allow_overlap: bool, volatile: bool, tp_ty: Ty<'tcx>, + dst: ValueRef, src: ValueRef, count: ValueRef) -> ValueRef { let ccx = bcx.ccx(); let lltp_ty = type_of::type_of(ccx, tp_ty); let align = C_i32(ccx, type_of::align_of(ccx, tp_ty) as i32); @@ -582,8 +587,8 @@ fn copy_intrinsic(bcx: Block, allow_overlap: bool, volatile: bool, C_bool(ccx, volatile)], None) } -fn memset_intrinsic(bcx: Block, volatile: bool, tp_ty: ty::t, - dst: ValueRef, val: ValueRef, count: ValueRef) -> ValueRef { +fn memset_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, volatile: bool, tp_ty: Ty<'tcx>, + dst: ValueRef, val: ValueRef, count: ValueRef) -> ValueRef { let ccx = bcx.ccx(); let lltp_ty = type_of::type_of(ccx, tp_ty); let align = C_i32(ccx, type_of::align_of(ccx, tp_ty) as i32); @@ -607,8 +612,8 @@ fn count_zeros_intrinsic(bcx: Block, name: &'static str, val: ValueRef) -> Value Call(bcx, llfn, &[val, y], None) } -fn with_overflow_intrinsic(bcx: Block, name: &'static str, t: ty::t, - a: ValueRef, b: ValueRef) -> ValueRef { +fn with_overflow_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, name: &'static str, + t: Ty<'tcx>, a: ValueRef, b: ValueRef) -> ValueRef { let llfn = bcx.ccx().get_intrinsic(&name); // Convert `i1` to a `bool`, and write it to the out parameter diff --git a/src/librustc_trans/trans/meth.rs b/src/librustc_trans/trans/meth.rs index 90777afff7e72..0311d37c3de52 100644 --- a/src/librustc_trans/trans/meth.rs +++ b/src/librustc_trans/trans/meth.rs @@ -30,7 +30,7 @@ use trans::glue; use trans::machine; use trans::type_::Type; use trans::type_of::*; -use middle::ty; +use middle::ty::{mod, Ty}; use middle::typeck; use middle::typeck::MethodCall; use util::ppaux::Repr; @@ -87,7 +87,7 @@ pub fn trans_impl(ccx: &CrateContext, method.pe_fn_decl(), method.pe_body(), llfn, - ¶m_substs::empty(), + &Substs::trans_empty(), method.id, &[]); update_linkage(ccx, @@ -136,8 +136,7 @@ pub fn trans_method_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, method_num }) => { let trait_ref = - Rc::new(trait_ref.subst(bcx.tcx(), - bcx.fcx.param_substs.substs())); + Rc::new(trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs)); let span = bcx.tcx().map.span(method_call.expr_id); debug!("method_call={} trait_ref={}", method_call, @@ -328,7 +327,7 @@ fn trans_monomorphized_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, method_call: MethodCall, trait_id: ast::DefId, n_method: uint, - vtable: traits::Vtable<()>) + vtable: traits::Vtable<'tcx, ()>) -> Callee<'blk, 'tcx> { let _icx = push_ctxt("meth::trans_monomorphized_callee"); match vtable { @@ -378,10 +377,10 @@ fn trans_monomorphized_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } } -fn combine_impl_and_methods_tps(bcx: Block, - node: ExprOrMethodCall, - rcvr_substs: subst::Substs) - -> subst::Substs +fn combine_impl_and_methods_tps<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + node: ExprOrMethodCall, + rcvr_substs: subst::Substs<'tcx>) + -> subst::Substs<'tcx> { /*! * Creates a concatenated set of substitutions which includes @@ -424,7 +423,7 @@ fn combine_impl_and_methods_tps(bcx: Block, } fn trans_trait_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - method_ty: ty::t, + method_ty: Ty<'tcx>, n_method: uint, self_expr: &ast::Expr, arg_cleanup_scope: cleanup::ScopeId) @@ -468,7 +467,7 @@ fn trans_trait_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } pub fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - callee_ty: ty::t, + callee_ty: Ty<'tcx>, n_method: uint, llpair: ValueRef) -> Callee<'blk, 'tcx> { @@ -489,7 +488,7 @@ pub fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Load the function from the vtable and cast it to the expected type. debug!("(translating trait callee) loading method"); // Replace the self type (&Self or Box) with an opaque pointer. - let llcallee_ty = match ty::get(callee_ty).sty { + let llcallee_ty = match callee_ty.sty { ty::ty_bare_fn(ref f) if f.abi == Rust || f.abi == RustCall => { type_of_rust_fn(ccx, Some(Type::i8p(ccx)), @@ -526,10 +525,10 @@ pub fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, /// `trait_ref` would map `T:Trait`, but `box_ty` would be /// `Foo`. This `box_ty` is primarily used to encode the destructor. /// This will hopefully change now that DST is underway. -pub fn get_vtable(bcx: Block, - box_ty: ty::t, - trait_ref: Rc) - -> ValueRef +pub fn get_vtable<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + box_ty: Ty<'tcx>, + trait_ref: Rc>) + -> ValueRef { debug!("get_vtable(box_ty={}, trait_ref={})", box_ty.repr(bcx.tcx()), @@ -586,12 +585,10 @@ pub fn get_vtable(bcx: Block, unboxed closure"); if closure_info.kind == ty::FnOnceUnboxedClosureKind { // Untuple the arguments and create an unboxing shim. - let (new_inputs, new_output) = match ty::get(self_ty).sty { + let (new_inputs, new_output) = match self_ty.sty { ty::ty_unboxed_closure(_, _, ref substs) => { let mut new_inputs = vec![self_ty.clone()]; - match ty::get(closure_info.closure_type - .sig - .inputs[0]).sty { + match closure_info.closure_type.sig.inputs[0].sty { ty::ty_tup(ref elements) => { for element in elements.iter() { new_inputs.push(element.subst(bcx.tcx(), substs)); @@ -677,10 +674,10 @@ pub fn make_vtable>(ccx: &CrateContext, } } -fn emit_vtable_methods(bcx: Block, - impl_id: ast::DefId, - substs: subst::Substs) - -> Vec { +fn emit_vtable_methods<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + impl_id: ast::DefId, + substs: subst::Substs<'tcx>) + -> Vec { let ccx = bcx.ccx(); let tcx = ccx.tcx(); @@ -735,9 +732,9 @@ fn emit_vtable_methods(bcx: Block, } pub fn trans_trait_cast<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - datum: Datum, + datum: Datum<'tcx, Expr>, id: ast::NodeId, - trait_ref: Rc, + trait_ref: Rc>, dest: expr::Dest) -> Block<'blk, 'tcx> { /*! diff --git a/src/librustc_trans/trans/monomorphize.rs b/src/librustc_trans/trans/monomorphize.rs index 52aa81fa427da..bf7d560fdaa59 100644 --- a/src/librustc_trans/trans/monomorphize.rs +++ b/src/librustc_trans/trans/monomorphize.rs @@ -20,7 +20,7 @@ use trans::base::{trans_fn, decl_internal_rust_fn}; use trans::base; use trans::common::*; use trans::foreign; -use middle::ty; +use middle::ty::{mod, Ty}; use util::ppaux::Repr; use syntax::abi; @@ -30,20 +30,20 @@ use syntax::ast_util::{local_def, PostExpansionMethod}; use syntax::attr; use std::hash::{sip, Hash}; -pub fn monomorphic_fn(ccx: &CrateContext, - fn_id: ast::DefId, - real_substs: &subst::Substs, - ref_id: Option) +pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + fn_id: ast::DefId, + psubsts: &subst::Substs<'tcx>, + ref_id: Option) -> (ValueRef, bool) { debug!("monomorphic_fn(\ fn_id={}, \ real_substs={}, \ ref_id={})", fn_id.repr(ccx.tcx()), - real_substs.repr(ccx.tcx()), + psubsts.repr(ccx.tcx()), ref_id); - assert!(real_substs.types.all(|t| { + assert!(psubsts.types.all(|t| { !ty::type_needs_infer(*t) && !ty::type_has_params(*t) })); @@ -51,7 +51,7 @@ pub fn monomorphic_fn(ccx: &CrateContext, let hash_id = MonoId { def: fn_id, - params: real_substs.types.clone() + params: psubsts.types.clone() }; match ccx.monomorphized().borrow().get(&hash_id) { @@ -63,9 +63,6 @@ pub fn monomorphic_fn(ccx: &CrateContext, None => () } - debug!("creating param_substs with real_substs={}", real_substs.repr(ccx.tcx())); - let psubsts = param_substs::new((*real_substs).clone()); - debug!("monomorphic_fn(\ fn_id={}, \ psubsts={}, \ @@ -98,7 +95,7 @@ pub fn monomorphic_fn(ccx: &CrateContext, } debug!("monomorphic_fn about to subst into {}", llitem_ty.repr(ccx.tcx())); - let mono_ty = llitem_ty.subst(ccx.tcx(), real_substs); + let mono_ty = llitem_ty.subst(ccx.tcx(), psubsts); ccx.stats().n_monos.set(ccx.stats().n_monos.get() + 1); @@ -178,10 +175,10 @@ pub fn monomorphic_fn(ccx: &CrateContext, if needs_body { if abi != abi::Rust { foreign::trans_rust_fn_with_foreign_abi( - ccx, &**decl, &**body, &[], d, &psubsts, fn_id.node, + ccx, &**decl, &**body, &[], d, psubsts, fn_id.node, Some(hash.as_slice())); } else { - trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, &[]); + trans_fn(ccx, &**decl, &**body, d, psubsts, fn_id.node, &[]); } } @@ -205,7 +202,7 @@ pub fn monomorphic_fn(ccx: &CrateContext, &*v, args.as_slice(), this_tv.disr_val, - &psubsts, + psubsts, d); } ast::StructVariantKind(_) => @@ -223,7 +220,7 @@ pub fn monomorphic_fn(ccx: &CrateContext, mth.pe_fn_decl(), mth.pe_body(), d, - &psubsts, + psubsts, mth.id, &[]); } @@ -241,7 +238,7 @@ pub fn monomorphic_fn(ccx: &CrateContext, let needs_body = setup_lldecl(d, mth.attrs.as_slice()); if needs_body { trans_fn(ccx, mth.pe_fn_decl(), mth.pe_body(), d, - &psubsts, mth.id, &[]); + psubsts, mth.id, &[]); } d } @@ -258,7 +255,7 @@ pub fn monomorphic_fn(ccx: &CrateContext, struct_def.fields.as_slice(), struct_def.ctor_id.expect("ast-mapped tuple struct \ didn't have a ctor id"), - &psubsts, + psubsts, d); d } @@ -284,7 +281,7 @@ pub fn monomorphic_fn(ccx: &CrateContext, } #[deriving(PartialEq, Eq, Hash, Show)] -pub struct MonoId { +pub struct MonoId<'tcx> { pub def: ast::DefId, - pub params: subst::VecPerParamSpace + pub params: subst::VecPerParamSpace> } diff --git a/src/librustc_trans/trans/tvec.rs b/src/librustc_trans/trans/tvec.rs index 0590d7c785ad9..359f74bdbf134 100644 --- a/src/librustc_trans/trans/tvec.rs +++ b/src/librustc_trans/trans/tvec.rs @@ -27,7 +27,7 @@ use trans::machine; use trans::machine::{nonzero_llsize_of, llsize_of_alloc}; use trans::type_::Type; use trans::type_of; -use middle::ty; +use middle::ty::{mod, Ty}; use util::ppaux::ty_to_string; use syntax::ast; @@ -52,7 +52,7 @@ pub fn pointer_add_byte(bcx: Block, ptr: ValueRef, bytes: ValueRef) -> ValueRef pub fn make_drop_glue_unboxed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, vptr: ValueRef, - unit_ty: ty::t, + unit_ty: Ty<'tcx>, should_deallocate: bool) -> Block<'blk, 'tcx> { let not_null = IsNotNull(bcx, vptr); @@ -89,15 +89,15 @@ pub fn make_drop_glue_unboxed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, }) } -pub struct VecTypes { - pub unit_ty: ty::t, +pub struct VecTypes<'tcx> { + pub unit_ty: Ty<'tcx>, pub llunit_ty: Type, pub llunit_size: ValueRef, pub llunit_alloc_size: u64 } -impl VecTypes { - pub fn to_string(&self, ccx: &CrateContext) -> String { +impl<'tcx> VecTypes<'tcx> { + pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String { format!("VecTypes {{unit_ty={}, llunit_ty={}, \ llunit_size={}, llunit_alloc_size={}}}", ty_to_string(ccx.tcx(), self.unit_ty), @@ -240,7 +240,7 @@ pub fn trans_lit_str<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } pub fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - vt: &VecTypes, + vt: &VecTypes<'tcx>, vstore_expr: &ast::Expr, content_expr: &ast::Expr, dest: Dest) @@ -337,12 +337,16 @@ pub fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } } -pub fn vec_types_from_expr(bcx: Block, vec_expr: &ast::Expr) -> VecTypes { +pub fn vec_types_from_expr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + vec_expr: &ast::Expr) + -> VecTypes<'tcx> { let vec_ty = node_id_type(bcx, vec_expr.id); vec_types(bcx, ty::sequence_element_type(bcx.tcx(), vec_ty)) } -pub fn vec_types(bcx: Block, unit_ty: ty::t) -> VecTypes { +pub fn vec_types<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + unit_ty: Ty<'tcx>) + -> VecTypes<'tcx> { let ccx = bcx.ccx(); let llunit_ty = type_of::type_of(ccx, unit_ty); let llunit_size = nonzero_llsize_of(ccx, llunit_ty); @@ -404,7 +408,7 @@ fn get_slice_base_and_len(bcx: Block, pub fn get_base_and_len(bcx: Block, llval: ValueRef, - vec_ty: ty::t) + vec_ty: Ty) -> (ValueRef, ValueRef) { /*! * Converts a vector into the slice pair. The vector should be @@ -416,15 +420,15 @@ pub fn get_base_and_len(bcx: Block, let ccx = bcx.ccx(); - match ty::get(vec_ty).sty { + match vec_ty.sty { ty::ty_vec(_, Some(n)) => get_fixed_base_and_len(bcx, llval, n), - ty::ty_open(ty) => match ty::get(ty).sty { + ty::ty_open(ty) => match ty.sty { ty::ty_vec(_, None) | ty::ty_str => get_slice_base_and_len(bcx, llval), _ => ccx.sess().bug("unexpected type in get_base_and_len") }, // Only used for pattern matching. - ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty { + ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty.sty { ty::ty_vec(_, None) | ty::ty_str => get_slice_base_and_len(bcx, llval), ty::ty_vec(_, Some(n)) => { let base = GEPi(bcx, Load(bcx, llval), &[0u, 0u]); @@ -437,11 +441,11 @@ pub fn get_base_and_len(bcx: Block, } pub type iter_vec_block<'a, 'blk, 'tcx> = - |Block<'blk, 'tcx>, ValueRef, ty::t|: 'a -> Block<'blk, 'tcx>; + |Block<'blk, 'tcx>, ValueRef, Ty<'tcx>|: 'a -> Block<'blk, 'tcx>; pub fn iter_vec_loop<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, data_ptr: ValueRef, - vt: &VecTypes, + vt: &VecTypes<'tcx>, count: ValueRef, f: iter_vec_block<'a, 'blk, 'tcx>) -> Block<'blk, 'tcx> { @@ -497,7 +501,7 @@ pub fn iter_vec_loop<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pub fn iter_vec_raw<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, data_ptr: ValueRef, - unit_ty: ty::t, + unit_ty: Ty<'tcx>, len: ValueRef, f: iter_vec_block<'a, 'blk, 'tcx>) -> Block<'blk, 'tcx> { diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index 5fa2198463793..31e8130dd7513 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -17,7 +17,7 @@ use trans::adt; use trans::common::*; use trans::foreign; use trans::machine; -use middle::ty; +use middle::ty::{mod, Ty}; use util::ppaux; use util::ppaux::Repr; @@ -28,10 +28,10 @@ use syntax::abi; use syntax::ast; // LLVM doesn't like objects that are too big. Issue #17913 -fn ensure_array_fits_in_address_space(ccx: &CrateContext, - llet: Type, - size: machine::llsize, - scapegoat: ty::t) { +fn ensure_array_fits_in_address_space<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + llet: Type, + size: machine::llsize, + scapegoat: Ty<'tcx>) { let esz = machine::llsize_of_alloc(ccx, llet); match esz.checked_mul(size) { Some(n) if n < ccx.max_obj_size() => {} @@ -39,15 +39,18 @@ fn ensure_array_fits_in_address_space(ccx: &CrateContext, } } -pub fn arg_is_indirect(ccx: &CrateContext, arg_ty: ty::t) -> bool { +pub fn arg_is_indirect<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + arg_ty: Ty<'tcx>) -> bool { !type_is_immediate(ccx, arg_ty) } -pub fn return_uses_outptr(ccx: &CrateContext, ty: ty::t) -> bool { +pub fn return_uses_outptr<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + ty: Ty<'tcx>) -> bool { !type_is_immediate(ccx, ty) } -pub fn type_of_explicit_arg(ccx: &CrateContext, arg_ty: ty::t) -> Type { +pub fn type_of_explicit_arg<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + arg_ty: Ty<'tcx>) -> Type { let llty = arg_type_of(ccx, arg_ty); if arg_is_indirect(ccx, arg_ty) { llty.ptr_to() @@ -59,10 +62,10 @@ pub fn type_of_explicit_arg(ccx: &CrateContext, arg_ty: ty::t) -> Type { /// Yields the types of the "real" arguments for this function. For most /// functions, these are simply the types of the arguments. For functions with /// the `RustCall` ABI, however, this untuples the arguments of the function. -pub fn untuple_arguments_if_necessary(ccx: &CrateContext, - inputs: &[ty::t], - abi: abi::Abi) - -> Vec { +pub fn untuple_arguments_if_necessary<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + inputs: &[Ty<'tcx>], + abi: abi::Abi) + -> Vec> { if abi != abi::RustCall { return inputs.iter().map(|x| (*x).clone()).collect() } @@ -78,7 +81,7 @@ pub fn untuple_arguments_if_necessary(ccx: &CrateContext, } } - match ty::get(inputs[inputs.len() - 1]).sty { + match inputs[inputs.len() - 1].sty { ty::ty_tup(ref tupled_arguments) => { debug!("untuple_arguments_if_necessary(): untupling arguments"); for &tupled_argument in tupled_arguments.iter() { @@ -94,12 +97,12 @@ pub fn untuple_arguments_if_necessary(ccx: &CrateContext, result } -pub fn type_of_rust_fn(cx: &CrateContext, - llenvironment_type: Option, - inputs: &[ty::t], - output: ty::FnOutput, - abi: abi::Abi) - -> Type { +pub fn type_of_rust_fn<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + llenvironment_type: Option, + inputs: &[Ty<'tcx>], + output: ty::FnOutput<'tcx>, + abi: abi::Abi) + -> Type { let mut atys: Vec = Vec::new(); // First, munge the inputs, if this has the `rust-call` ABI. @@ -138,8 +141,8 @@ pub fn type_of_rust_fn(cx: &CrateContext, } // Given a function type and a count of ty params, construct an llvm type -pub fn type_of_fn_from_ty(cx: &CrateContext, fty: ty::t) -> Type { - match ty::get(fty).sty { +pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>) -> Type { + match fty.sty { ty::ty_closure(ref f) => { type_of_rust_fn(cx, Some(Type::i8p(cx)), @@ -175,13 +178,13 @@ pub fn type_of_fn_from_ty(cx: &CrateContext, fty: ty::t) -> Type { // type behind pointers. This can help prevent infinite loops for // recursive types. For example, enum types rely on this behavior. -pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type { +pub fn sizing_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type { match cx.llsizingtypes().borrow().get(&t).cloned() { Some(t) => return t, None => () } - let llsizingty = match ty::get(t).sty { + let llsizingty = match t.sty { _ if !ty::lltype_is_sized(cx.tcx(), t) => { cx.sess().bug(format!("trying to take the sizing type of {}, an unsized type", ppaux::ty_to_string(cx.tcx(), t)).as_slice()) @@ -247,7 +250,7 @@ pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type { llsizingty } -pub fn arg_type_of(cx: &CrateContext, t: ty::t) -> Type { +pub fn arg_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type { if ty::type_is_bool(t) { Type::i1(cx) } else { @@ -256,8 +259,8 @@ pub fn arg_type_of(cx: &CrateContext, t: ty::t) -> Type { } // NB: If you update this, be sure to update `sizing_type_of()` as well. -pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { - fn type_of_unsize_info(cx: &CrateContext, t: ty::t) -> Type { +pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type { + fn type_of_unsize_info<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type { // It is possible to end up here with a sized type. This happens with a // struct which might be unsized, but is monomorphised to a sized type. // In this case we'll fake a fat pointer with no unsize info (we use 0). @@ -266,7 +269,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { return Type::i8p(cx); } - match ty::get(ty::unsized_part_of_type(cx.tcx(), t)).sty { + match ty::unsized_part_of_type(cx.tcx(), t).sty { ty::ty_str | ty::ty_vec(..) => Type::uint_from_ty(cx, ast::TyU), ty::ty_trait(_) => Type::vtable_ptr(cx), _ => panic!("Unexpected type returned from unsized_part_of_type : {}", @@ -280,7 +283,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { None => () } - debug!("type_of {} {}", t.repr(cx.tcx()), ty::get(t).sty); + debug!("type_of {} {}", t.repr(cx.tcx()), t.sty); // Replace any typedef'd types with their equivalent non-typedef // type. This ensures that all LLVM nominal types that contain @@ -301,7 +304,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { return llty; } - let mut llty = match ty::get(t).sty { + let mut llty = match t.sty { ty::ty_bool => Type::bool(cx), ty::ty_char => Type::char(cx), ty::ty_int(t) => Type::int_from_ty(cx, t), @@ -330,7 +333,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { } ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) | ty::ty_ptr(ty::mt{ty, ..}) => { - match ty::get(ty).sty { + match ty.sty { ty::ty_str => { // This means we get a nicer name in the output (str is always // unsized). @@ -390,7 +393,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { } } - ty::ty_open(t) => match ty::get(t).sty { + ty::ty_open(t) => match t.sty { ty::ty_struct(..) => { let p_ty = type_of(cx, t).ptr_to(); Type::struct_(cx, &[p_ty, type_of_unsize_info(cx, t)], false) @@ -421,7 +424,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { cx.lltypes().borrow_mut().insert(t, llty); // If this was an enum or struct, fill in the type now. - match ty::get(t).sty { + match t.sty { ty::ty_enum(..) | ty::ty_struct(..) | ty::ty_unboxed_closure(..) if !ty::type_is_simd(cx.tcx(), t) => { let repr = adt::represent_type(cx, t); @@ -433,7 +436,8 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { return llty; } -pub fn align_of(cx: &CrateContext, t: ty::t) -> machine::llalign { +pub fn align_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) + -> machine::llalign { let llty = sizing_type_of(cx, t); machine::llalign_of_min(cx, llty) } @@ -445,11 +449,11 @@ pub enum named_ty { an_unboxed_closure, } -pub fn llvm_type_name(cx: &CrateContext, - what: named_ty, - did: ast::DefId, - tps: &[ty::t]) - -> String +pub fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, + what: named_ty, + did: ast::DefId, + tps: &[Ty<'tcx>]) + -> String { let name = match what { a_struct => "struct", @@ -472,7 +476,7 @@ pub fn llvm_type_name(cx: &CrateContext, } } -pub fn type_of_dtor(ccx: &CrateContext, self_ty: ty::t) -> Type { +pub fn type_of_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, self_ty: Ty<'tcx>) -> Type { let self_ty = type_of(ccx, self_ty).ptr_to(); Type::func(&[self_ty], &Type::void(ccx)) } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index bcbd09d7b119e..16edccd154302 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -169,7 +169,7 @@ pub fn build_external_trait(cx: &DocContext, tcx: &ty::ctxt, fn build_external_function(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::Function { let t = ty::lookup_item_type(tcx, did); - let (decl, style) = match ty::get(t.ty).sty { + let (decl, style) = match t.ty.sty { ty::ty_bare_fn(ref f) => ((did, &f.sig).clean(cx), f.fn_style), _ => panic!("bad function"), }; @@ -201,7 +201,7 @@ fn build_struct(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::Stru fn build_type(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEnum { let t = ty::lookup_item_type(tcx, did); - match ty::get(t.ty).sty { + match t.ty.sty { ty::ty_enum(edid, _) if !csearch::is_typedef(&tcx.sess.cstore, did) => { return clean::EnumItem(clean::Enum { generics: (&t.generics, subst::TypeSpace).clean(cx), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d622965dac772..209d8c7ca0f29 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -478,7 +478,7 @@ impl Clean for ast::TyParam { } } -impl Clean for ty::TypeParameterDef { +impl<'tcx> Clean for ty::TypeParameterDef<'tcx> { fn clean(&self, cx: &DocContext) -> TyParam { cx.external_typarams.borrow_mut().as_mut().unwrap() .insert(self.def_id, self.name.clean(cx)); @@ -567,7 +567,7 @@ impl Clean for ty::BuiltinBound { } } -impl Clean for ty::TraitRef { +impl<'tcx> Clean for ty::TraitRef<'tcx> { fn clean(&self, cx: &DocContext) -> TyParamBound { let tcx = match cx.tcx_opt() { Some(tcx) => tcx, @@ -588,7 +588,7 @@ impl Clean for ty::TraitRef { } } -impl Clean> for ty::ParamBounds { +impl<'tcx> Clean> for ty::ParamBounds<'tcx> { fn clean(&self, cx: &DocContext) -> Vec { let mut v = Vec::new(); for b in self.builtin_bounds.iter() { @@ -606,7 +606,7 @@ impl Clean> for ty::ParamBounds { } } -impl Clean>> for subst::Substs { +impl<'tcx> Clean>> for subst::Substs<'tcx> { fn clean(&self, cx: &DocContext) -> Option> { let mut v = Vec::new(); v.extend(self.regions().iter().filter_map(|r| r.clean(cx)).map(RegionBound)); @@ -698,7 +698,7 @@ impl Clean for ast::Generics { } } -impl<'a> Clean for (&'a ty::Generics, subst::ParamSpace) { +impl<'a, 'tcx> Clean for (&'a ty::Generics<'tcx>, subst::ParamSpace) { fn clean(&self, cx: &DocContext) -> Generics { let (me, space) = *self; Generics { @@ -877,7 +877,7 @@ impl Clean for ast::FnDecl { } } -impl<'a> Clean for ty::FnOutput { +impl<'tcx> Clean for ty::FnOutput<'tcx> { fn clean(&self, cx: &DocContext) -> Type { match *self { ty::FnConverging(ty) => ty.clean(cx), @@ -886,7 +886,7 @@ impl<'a> Clean for ty::FnOutput { } } -impl<'a> Clean for (ast::DefId, &'a ty::FnSig) { +impl<'a, 'tcx> Clean for (ast::DefId, &'a ty::FnSig<'tcx>) { fn clean(&self, cx: &DocContext) -> FnDecl { let (did, sig) = *self; let mut names = if did.node != 0 { @@ -1036,7 +1036,7 @@ impl Clean for ast::ImplItem { } } -impl Clean for ty::Method { +impl<'tcx> Clean for ty::Method<'tcx> { fn clean(&self, cx: &DocContext) -> Item { let (self_, sig) = match self.explicit_self { ty::StaticExplicitSelfCategory => (ast::SelfStatic.clean(cx), @@ -1049,7 +1049,7 @@ impl Clean for ty::Method { let s = match s { ty::ByValueExplicitSelfCategory => SelfValue, ty::ByReferenceExplicitSelfCategory(..) => { - match ty::get(self.fty.sig.inputs[0]).sty { + match self.fty.sig.inputs[0].sty { ty::ty_rptr(r, mt) => { SelfBorrowed(r.clean(cx), mt.mutbl.clean(cx)) } @@ -1082,7 +1082,7 @@ impl Clean for ty::Method { } } -impl Clean for ty::ImplOrTraitItem { +impl<'tcx> Clean for ty::ImplOrTraitItem<'tcx> { fn clean(&self, cx: &DocContext) -> Item { match *self { ty::MethodTraitItem(ref mti) => mti.clean(cx), @@ -1257,9 +1257,9 @@ impl Clean for ast::Ty { } } -impl Clean for ty::t { +impl<'tcx> Clean for ty::Ty<'tcx> { fn clean(&self, cx: &DocContext) -> Type { - match ty::get(*self).sty { + match self.sty { ty::ty_bool => Primitive(Bool), ty::ty_char => Primitive(Char), ty::ty_int(ast::TyI) => Primitive(Int), @@ -1321,7 +1321,7 @@ impl Clean for ty::t { let fqn: Vec = fqn.into_iter().map(|i| { i.to_string() }).collect(); - let kind = match ty::get(*self).sty { + let kind = match self.sty { ty::ty_struct(..) => TypeStruct, ty::ty_trait(..) => TypeTrait, _ => TypeEnum, @@ -1506,7 +1506,7 @@ impl Clean for doctree::Variant { } } -impl Clean for ty::VariantInfo { +impl<'tcx> Clean for ty::VariantInfo<'tcx> { fn clean(&self, cx: &DocContext) -> Item { // use syntax::parse::token::special_idents::unnamed_field; let kind = match self.arg_names.as_ref().map(|s| s.as_slice()) { @@ -2255,7 +2255,7 @@ impl Clean for ast::Typedef { } fn lang_struct(cx: &DocContext, did: Option, - t: ty::t, name: &str, + t: ty::Ty, name: &str, fallback: fn(Box) -> Type) -> Type { let did = match did { Some(did) => did,