use middle::const_eval::EvalHint::UncheckedExprHint;
use middle::subst::{Substs, FnSpace, ParamSpace, SelfSpace, TypeSpace, VecPerParamSpace};
use middle::ty::{ToPredicate, ImplContainer, ImplOrTraitItemContainer, TraitContainer};
-use middle::ty::{self, ToPolyTraitRef, Ty, TypeScheme};
+use middle::ty::{self, ToPolyTraitRef, Ty, TyCtxt, TypeScheme};
use middle::ty::{VariantKind};
use middle::ty::fold::{TypeFolder};
use middle::ty::util::IntTypeExt;
///////////////////////////////////////////////////////////////////////////
// Main entry point
-pub fn collect_item_types(tcx: &ty::ctxt) {
+pub fn collect_item_types(tcx: &TyCtxt) {
let ccx = &CrateCtxt { tcx: tcx, stack: RefCell::new(Vec::new()) };
let mut visitor = CollectItemTypesVisitor{ ccx: ccx };
ccx.tcx.visit_all_items_in_krate(DepNode::CollectItem, &mut visitor);
///////////////////////////////////////////////////////////////////////////
struct CrateCtxt<'a,'tcx:'a> {
- tcx: &'a ty::ctxt<'tcx>,
+ tcx: &'a TyCtxt<'tcx>,
// This stack is used to identify cycles in the user's source.
// Note that these cycles can cross multiple items.
}
impl<'a, 'tcx> AstConv<'tcx> for ItemCtxt<'a, 'tcx> {
- fn tcx(&self) -> &ty::ctxt<'tcx> { self.ccx.tcx }
+ fn tcx(&self) -> &TyCtxt<'tcx> { self.ccx.tcx }
fn get_item_type_scheme(&self, span: Span, id: DefId)
-> Result<ty::TypeScheme<'tcx>, ErrorReported>
/// parameter with id `param_id`. We use this so as to avoid running
/// `ast_ty_to_ty`, because we want to avoid triggering an all-out
/// conversion of the type to avoid inducing unnecessary cycles.
-fn is_param<'tcx>(tcx: &ty::ctxt<'tcx>,
+fn is_param<'tcx>(tcx: &TyCtxt<'tcx>,
ast_ty: &hir::Ty,
param_id: ast::NodeId)
-> bool
def_id,
container);
- let fty = ccx.tcx.mk_fn(Some(def_id),
- ccx.tcx.mk_bare_fn(ty_method.fty.clone()));
+ let fty = ccx.tcx.mk_fn_def(def_id, ty_method.fty.clone());
debug!("method {} (id {}) has type {:?}",
name, id, fty);
ccx.tcx.register_item_type(def_id, TypeScheme {
fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
struct_generics: &ty::Generics<'tcx>,
struct_predicates: &ty::GenericPredicates<'tcx>,
- v: &hir::StructField,
+ field: &hir::StructField,
ty_f: ty::FieldDefMaster<'tcx>)
{
- let tt = ccx.icx(struct_predicates).to_ty(&ExplicitRscope, &v.node.ty);
+ let tt = ccx.icx(struct_predicates).to_ty(&ExplicitRscope, &field.ty);
ty_f.fulfill_ty(tt);
- write_ty_to_tcx(ccx.tcx, v.node.id, tt);
+ write_ty_to_tcx(ccx.tcx, field.id, tt);
/* add the field to the tcache */
- ccx.tcx.register_item_type(ccx.tcx.map.local_def_id(v.node.id),
+ ccx.tcx.register_item_type(ccx.tcx.map.local_def_id(field.id),
ty::TypeScheme {
generics: struct_generics.clone(),
ty: tt
});
- ccx.tcx.predicates.borrow_mut().insert(ccx.tcx.map.local_def_id(v.node.id),
+ ccx.tcx.predicates.borrow_mut().insert(ccx.tcx.map.local_def_id(field.id),
struct_predicates.clone());
}
}
}
-fn convert_variant_ctor<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
+fn convert_variant_ctor<'a, 'tcx>(tcx: &TyCtxt<'tcx>,
ctor_id: ast::NodeId,
variant: ty::VariantDef<'tcx>,
scheme: ty::TypeScheme<'tcx>,
}
}
-fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
+fn convert_struct_variant<'tcx>(tcx: &TyCtxt<'tcx>,
did: DefId,
name: ast::Name,
disr_val: ty::Disr,
def: &hir::VariantData) -> ty::VariantDefData<'tcx, 'tcx> {
let mut seen_fields: FnvHashMap<ast::Name, Span> = FnvHashMap();
let fields = def.fields().iter().map(|f| {
- let fid = tcx.map.local_def_id(f.node.id);
- match f.node.kind {
- hir::NamedField(name, vis) => {
- let dup_span = seen_fields.get(&name).cloned();
- if let Some(prev_span) = dup_span {
- let mut err = struct_span_err!(tcx.sess, f.span, E0124,
- "field `{}` is already declared",
- name);
- span_note!(&mut err, prev_span, "previously declared here");
- err.emit();
- } else {
- seen_fields.insert(name, f.span);
- }
-
- ty::FieldDefData::new(fid, name, vis)
- },
- hir::UnnamedField(vis) => {
- ty::FieldDefData::new(fid, special_idents::unnamed_field.name, vis)
- }
+ let fid = tcx.map.local_def_id(f.id);
+ let dup_span = seen_fields.get(&f.name).cloned();
+ if let Some(prev_span) = dup_span {
+ let mut err = struct_span_err!(tcx.sess, f.span, E0124,
+ "field `{}` is already declared",
+ f.name);
+ span_note!(&mut err, prev_span, "previously declared here");
+ err.emit();
+ } else {
+ seen_fields.insert(f.name, f.span);
}
+
+ ty::FieldDefData::new(fid, f.name, f.vis)
}).collect();
ty::VariantDefData {
did: did,
}
}
-fn convert_struct_def<'tcx>(tcx: &ty::ctxt<'tcx>,
+fn convert_struct_def<'tcx>(tcx: &TyCtxt<'tcx>,
it: &hir::Item,
def: &hir::VariantData)
-> ty::AdtDefMaster<'tcx>
)
}
-fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>,
+fn convert_enum_def<'tcx>(tcx: &TyCtxt<'tcx>,
it: &hir::Item,
def: &hir::EnumDef)
-> ty::AdtDefMaster<'tcx>
{
- fn evaluate_disr_expr<'tcx>(tcx: &ty::ctxt<'tcx>,
+ fn evaluate_disr_expr<'tcx>(tcx: &TyCtxt<'tcx>,
repr_ty: Ty<'tcx>,
e: &hir::Expr) -> Option<ty::Disr> {
debug!("disr expr, checking {}", pprust::expr_to_string(e));
}
}
- fn report_discrim_overflow(tcx: &ty::ctxt,
+ fn report_discrim_overflow(tcx: &TyCtxt,
variant_span: Span,
variant_name: &str,
repr_type: attr::IntType,
prev_val, repr_type, variant_name, computed_value);
}
- fn next_disr(tcx: &ty::ctxt,
+ fn next_disr(tcx: &TyCtxt,
v: &hir::Variant,
repr_type: attr::IntType,
prev_disr_val: Option<ty::Disr>) -> Option<ty::Disr> {
Some(ty::INITIAL_DISCRIMINANT_VALUE)
}
}
- fn convert_enum_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
+ fn convert_enum_variant<'tcx>(tcx: &TyCtxt<'tcx>,
v: &hir::Variant,
disr: ty::Disr)
-> ty::VariantDefData<'tcx, 'tcx>
hir::ItemFn(ref decl, unsafety, _, abi, ref generics, _) => {
let ty_generics = ty_generics_for_fn(ccx, generics, &ty::Generics::empty());
let tofd = astconv::ty_of_bare_fn(&ccx.icx(generics), unsafety, abi, &decl);
- let ty = tcx.mk_fn(Some(ccx.tcx.map.local_def_id(it.id)), tcx.mk_bare_fn(tofd));
+ let ty = tcx.mk_fn_def(ccx.tcx.map.local_def_id(it.id), tofd);
ty::TypeScheme { ty: ty, generics: ty_generics }
}
hir::ItemTy(ref t, ref generics) => {
{
match it.node {
hir::ForeignItemFn(ref fn_decl, ref generics) => {
- compute_type_scheme_of_foreign_fn_decl(ccx, fn_decl, generics, abi)
+ compute_type_scheme_of_foreign_fn_decl(
+ ccx, ccx.tcx.map.local_def_id(it.id),
+ fn_decl, generics, abi)
}
hir::ForeignItemStatic(ref t, _) => {
ty::TypeScheme {
fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
ccx: &CrateCtxt<'a, 'tcx>,
+ id: DefId,
decl: &hir::FnDecl,
ast_generics: &hir::Generics,
abi: abi::Abi)
ty::FnDiverging
};
- let t_fn = ccx.tcx.mk_fn(None,
- ccx.tcx.mk_bare_fn(ty::BareFnTy {
- abi: abi,
- unsafety: hir::Unsafety::Unsafe,
- sig: ty::Binder(ty::FnSig {inputs: input_tys,
- output: output,
- variadic: decl.variadic}),
- }));
+ let t_fn = ccx.tcx.mk_fn_def(id, ty::BareFnTy {
+ abi: abi,
+ unsafety: hir::Unsafety::Unsafe,
+ sig: ty::Binder(ty::FnSig {inputs: input_tys,
+ output: output,
+ variadic: decl.variadic}),
+ });
ty::TypeScheme {
generics: ty_generics,
}
/// Checks that all the type parameters on an impl
-fn enforce_impl_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
+fn enforce_impl_params_are_constrained<'tcx>(tcx: &TyCtxt<'tcx>,
ast_generics: &hir::Generics,
impl_predicates: &mut ty::GenericPredicates<'tcx>,
impl_def_id: DefId)
}
}
-fn enforce_impl_lifetimes_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
+fn enforce_impl_lifetimes_are_constrained<'tcx>(tcx: &TyCtxt<'tcx>,
ast_generics: &hir::Generics,
impl_def_id: DefId,
impl_items: &[hir::ImplItem])
// used elsewhere are not projected back out.
}
-fn report_unused_parameter(tcx: &ty::ctxt,
+fn report_unused_parameter(tcx: &TyCtxt,
span: Span,
kind: &str,
name: &str)