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;
use syntax::codemap::Span;
use syntax::parse::token::special_idents;
use syntax::ptr::P;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use rustc_front::intravisit;
use rustc_front::print::pprust;
///////////////////////////////////////////////////////////////////////////
// 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.
_ => tcx.sess.bug(&format!("get_trait_def({:?}): not an item", trait_id))
};
- trait_def_of_item(self, &*item)
+ trait_def_of_item(self, &item)
} else {
tcx.lookup_trait_def(trait_id)
}
}
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());
}
debug!("convert: impl_bounds={:?}", ty_predicates);
- let selfty = ccx.icx(&ty_predicates).to_ty(&ExplicitRscope, &**selfty);
+ let selfty = ccx.icx(&ty_predicates).to_ty(&ExplicitRscope, &selfty);
write_ty_to_tcx(tcx, it.id, selfty);
tcx.register_item_type(def_id,
if let hir::ImplItemKind::Const(ref ty, _) = impl_item.node {
let ty = ccx.icx(&ty_predicates)
- .to_ty(&ExplicitRscope, &*ty);
+ .to_ty(&ExplicitRscope, &ty);
tcx.register_item_type(ccx.tcx.map.local_def_id(impl_item.id),
TypeScheme {
generics: ty_generics.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>
if let Some(node_id) = ccx.tcx.map.as_local_node_id(def_id) {
match ccx.tcx.map.find(node_id) {
Some(hir_map::NodeItem(item)) => {
- type_scheme_of_item(ccx, &*item)
+ type_scheme_of_item(ccx, &item)
}
Some(hir_map::NodeForeignItem(foreign_item)) => {
let abi = ccx.tcx.map.get_foreign_abi(node_id);
- type_scheme_of_foreign_item(ccx, &*foreign_item, abi)
+ type_scheme_of_foreign_item(ccx, &foreign_item, abi)
}
x => {
ccx.tcx.sess.bug(&format!("unexpected sort of node \
let tcx = ccx.tcx;
match it.node {
hir::ItemStatic(ref t, _, _) | hir::ItemConst(ref t, _) => {
- let ty = ccx.icx(&()).to_ty(&ExplicitRscope, &**t);
+ let ty = ccx.icx(&()).to_ty(&ExplicitRscope, &t);
ty::TypeScheme { ty: ty, generics: ty::Generics::empty() }
}
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 tofd = astconv::ty_of_bare_fn(&ccx.icx(generics), unsafety, abi, &decl);
+ 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) => {
let ty_generics = ty_generics_for_type_or_impl(ccx, generics);
- let ty = ccx.icx(generics).to_ty(&ExplicitRscope, &**t);
+ let ty = ccx.icx(generics).to_ty(&ExplicitRscope, &t);
ty::TypeScheme { ty: ty, generics: ty_generics }
}
hir::ItemEnum(ref ei, 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 {
&hir::WherePredicate::BoundPredicate(ref bound_pred) => {
let ty = ast_ty_to_ty(&ccx.icx(&(base_predicates, ast_generics)),
&ExplicitRscope,
- &*bound_pred.bounded_ty);
+ &bound_pred.bounded_ty);
for bound in bound_pred.bounds.iter() {
match bound {
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::TypeScheme<'tcx>
{
for i in &decl.inputs {
- match (*i).pat.node {
- hir::PatIdent(_, _, _) => (),
- hir::PatWild => (),
+ match i.pat.node {
+ PatKind::Ident(_, _, _) => (),
+ PatKind::Wild => (),
_ => {
- span_err!(ccx.tcx.sess, (*i).pat.span, E0130,
+ span_err!(ccx.tcx.sess, i.pat.span, E0130,
"patterns aren't allowed in foreign function declarations");
}
}
let output = match decl.output {
hir::Return(ref ty) =>
- ty::FnConverging(ast_ty_to_ty(&ccx.icx(ast_generics), &rb, &**ty)),
+ ty::FnConverging(ast_ty_to_ty(&ccx.icx(ast_generics), &rb, &ty)),
hir::DefaultReturn(..) =>
ty::FnConverging(ccx.tcx.mk_nil()),
hir::NoReturn(..) =>
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)