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, RegionEscape, ToPolyTraitRef, Ty, TypeScheme, IntTypeExt};
+use middle::ty::{self, RegionEscape, ToPolyTraitRef, Ty, TypeScheme};
use middle::ty::{VariantKind};
-use middle::ty_fold::{self, TypeFolder, TypeFoldable};
+use middle::ty::fold::{TypeFolder, TypeFoldable};
+use middle::ty::util::IntTypeExt;
use middle::infer;
use rscope::*;
-use rustc::ast_map;
+use rustc::front::map as hir_map;
use util::common::{ErrorReported, memoized};
use util::nodemap::{FnvHashMap, FnvHashSet};
use write_ty_to_tcx;
use syntax::abi;
use syntax::ast;
-use syntax::attr;
use syntax::codemap::Span;
use syntax::parse::token::special_idents;
-use syntax::print::pprust;
use syntax::ptr::P;
-use syntax::visit;
+use rustc_front::hir;
+use rustc_front::visit;
+use rustc_front::attr;
+use rustc_front::print::pprust;
///////////////////////////////////////////////////////////////////////////
// Main entry point
/// `ItemCtxt` is parameterized by a `GetTypeParameterBounds` object
/// that it uses to satisfy `get_type_parameter_bounds` requests.
/// This object might draw the information from the AST
-/// (`ast::Generics`) or it might draw from a `ty::GenericPredicates`
+/// (`hir::Generics`) or it might draw from a `ty::GenericPredicates`
/// or both (a tuple).
struct ItemCtxt<'a,'tcx:'a> {
ccx: &'a CrateCtxt<'a,'tcx>,
}
impl<'a, 'tcx, 'v> visit::Visitor<'v> for CollectTraitDefVisitor<'a, 'tcx> {
- fn visit_item(&mut self, i: &ast::Item) {
+ fn visit_item(&mut self, i: &hir::Item) {
match i.node {
- ast::ItemTrait(..) => {
+ hir::ItemTrait(..) => {
// computing the trait def also fills in the table
let _ = trait_def_of_item(self.ccx, i);
}
}
impl<'a, 'tcx, 'v> visit::Visitor<'v> for CollectItemTypesVisitor<'a, 'tcx> {
- fn visit_item(&mut self, i: &ast::Item) {
+ fn visit_item(&mut self, i: &hir::Item) {
convert_item(self.ccx, i);
visit::walk_item(self, i);
}
- fn visit_foreign_item(&mut self, i: &ast::ForeignItem) {
+ fn visit_foreign_item(&mut self, i: &hir::ForeignItem) {
convert_foreign_item(self.ccx, i);
visit::walk_foreign_item(self, i);
}
}
let item = match tcx.map.get(trait_id.node) {
- ast_map::NodeItem(item) => item,
+ hir_map::NodeItem(item) => item,
_ => tcx.sess.bug(&format!("get_trait_def({:?}): not an item", trait_id))
};
}
impl<'a,'tcx> ItemCtxt<'a,'tcx> {
- fn to_ty<RS:RegionScope>(&self, rs: &RS, ast_ty: &ast::Ty) -> Ty<'tcx> {
+ fn to_ty<RS:RegionScope>(&self, rs: &RS, ast_ty: &hir::Ty) -> Ty<'tcx> {
ast_ty_to_ty(self, rs, ast_ty)
}
}
}
}
-/// Find bounds from ast::Generics. This requires scanning through the
+/// Find bounds from hir::Generics. This requires scanning through the
/// AST. We do this to avoid having to convert *all* the bounds, which
/// would create artificial cycles. Instead we can only convert the
/// bounds for those a type parameter `X` if `X::Foo` is used.
-impl<'tcx> GetTypeParameterBounds<'tcx> for ast::Generics {
+impl<'tcx> GetTypeParameterBounds<'tcx> for hir::Generics {
fn get_type_parameter_bounds(&self,
astconv: &AstConv<'tcx>,
_: Span,
.predicates
.iter()
.filter_map(|wp| match *wp {
- ast::WherePredicate::BoundPredicate(ref bp) => Some(bp),
+ hir::WherePredicate::BoundPredicate(ref bp) => Some(bp),
_ => None
})
.filter(|bp| is_param(astconv.tcx(), &bp.bounded_ty, node_id))
/// `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>,
- ast_ty: &ast::Ty,
+ ast_ty: &hir::Ty,
param_id: ast::NodeId)
-> bool
{
- if let ast::TyPath(None, _) = ast_ty.node {
+ if let hir::TyPath(None, _) = ast_ty.node {
let path_res = *tcx.def_map.borrow().get(&ast_ty.id).unwrap();
match path_res.base_def {
def::DefSelfTy(Some(def_id), None) => {
}
}
+
fn convert_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
container: ImplOrTraitItemContainer,
- sig: &ast::MethodSig,
+ sig: &hir::MethodSig,
id: ast::NodeId,
ident: ast::Ident,
- vis: ast::Visibility,
+ vis: hir::Visibility,
untransformed_rcvr_ty: Ty<'tcx>,
rcvr_ty_generics: &ty::Generics<'tcx>,
rcvr_ty_predicates: &ty::GenericPredicates<'tcx>) {
fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
struct_generics: &ty::Generics<'tcx>,
struct_predicates: &ty::GenericPredicates<'tcx>,
- v: &ast::StructField,
+ v: &hir::StructField,
ty_f: ty::FieldDefMaster<'tcx>)
{
let tt = ccx.icx(struct_predicates).to_ty(&ExplicitRscope, &*v.node.ty);
container: ImplOrTraitItemContainer,
ident: ast::Ident,
id: ast::NodeId,
- vis: ast::Visibility,
+ vis: hir::Visibility,
ty: ty::Ty<'tcx>,
- default: Option<&ast::Expr>)
+ default: Option<&hir::Expr>)
{
ccx.tcx.predicates.borrow_mut().insert(DefId::local(id),
ty::GenericPredicates::empty());
container: ImplOrTraitItemContainer,
ident: ast::Ident,
id: ast::NodeId,
- vis: ast::Visibility,
+ vis: hir::Visibility,
ty: Option<Ty<'tcx>>)
{
let associated_type = Rc::new(ty::AssociatedType {
untransformed_rcvr_ty: Ty<'tcx>,
rcvr_ty_generics: &ty::Generics<'tcx>,
rcvr_ty_predicates: &ty::GenericPredicates<'tcx>)
- where I: Iterator<Item=(&'i ast::MethodSig, ast::NodeId, ast::Ident, ast::Visibility, Span)>
+ where I: Iterator<Item=(&'i hir::MethodSig, ast::NodeId, ast::Ident, hir::Visibility, Span)>
{
debug!("convert_methods(untransformed_rcvr_ty={:?}, rcvr_ty_generics={:?}, \
rcvr_ty_predicates={:?})",
fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
span: Span,
- generics: &ast::Generics,
+ generics: &hir::Generics,
thing: &'static str) {
let mut warn = false;
for ty_param in generics.ty_params.iter() {
for bound in ty_param.bounds.iter() {
match *bound {
- ast::TraitTyParamBound(..) => {
+ hir::TraitTyParamBound(..) => {
warn = true;
}
- ast::RegionTyParamBound(..) => { }
+ hir::RegionTyParamBound(..) => { }
}
}
}
}
}
-fn convert_item(ccx: &CrateCtxt, it: &ast::Item) {
+fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
let tcx = ccx.tcx;
debug!("convert: item {} with id {}", it.ident, it.id);
match it.node {
// These don't define types.
- ast::ItemExternCrate(_) | ast::ItemUse(_) |
- ast::ItemForeignMod(_) | ast::ItemMod(_) | ast::ItemMac(_) => {
+ hir::ItemExternCrate(_) | hir::ItemUse(_) |
+ hir::ItemForeignMod(_) | hir::ItemMod(_) => {
}
- ast::ItemEnum(ref enum_definition, _) => {
+ hir::ItemEnum(ref enum_definition, _) => {
let (scheme, predicates) = convert_typed_item(ccx, it);
write_ty_to_tcx(tcx, it.id, scheme.ty);
convert_enum_variant_types(ccx,
predicates,
&enum_definition.variants);
},
- ast::ItemDefaultImpl(_, ref ast_trait_ref) => {
+ hir::ItemDefaultImpl(_, ref ast_trait_ref) => {
let trait_ref =
astconv::instantiate_mono_trait_ref(&ccx.icx(&()),
&ExplicitRscope,
tcx.impl_trait_refs.borrow_mut().insert(DefId::local(it.id), Some(trait_ref));
}
- ast::ItemImpl(_, _,
+ hir::ItemImpl(_, _,
ref generics,
ref opt_trait_ref,
ref selfty,
// from the trait, not the impl. Forcing the visibility to be public
// makes things sorta work.
let parent_visibility = if opt_trait_ref.is_some() {
- ast::Public
+ hir::Public
} else {
it.vis
};
for impl_item in impl_items {
let seen_items = match impl_item.node {
- ast::TypeImplItem(_) => &mut seen_type_items,
+ hir::TypeImplItem(_) => &mut seen_type_items,
_ => &mut seen_value_items,
};
if !seen_items.insert(impl_item.ident.name) {
let desc = match impl_item.node {
- ast::ConstImplItem(_, _) => "associated constant",
- ast::TypeImplItem(_) => "associated type",
- ast::MethodImplItem(ref sig, _) =>
+ hir::ConstImplItem(_, _) => "associated constant",
+ hir::TypeImplItem(_) => "associated type",
+ hir::MethodImplItem(ref sig, _) =>
match sig.explicit_self.node {
- ast::SelfStatic => "associated function",
+ hir::SelfStatic => "associated function",
_ => "method",
},
- _ => "associated item",
};
span_err!(tcx.sess, impl_item.span, E0201, "duplicate {}", desc);
}
- if let ast::ConstImplItem(ref ty, ref expr) = impl_item.node {
+ if let hir::ConstImplItem(ref ty, ref expr) = impl_item.node {
let ty = ccx.icx(&ty_predicates)
.to_ty(&ExplicitRscope, &*ty);
tcx.register_item_type(DefId::local(impl_item.id),
// Convert all the associated types.
for impl_item in impl_items {
- if let ast::TypeImplItem(ref ty) = impl_item.node {
+ if let hir::TypeImplItem(ref ty) = impl_item.node {
if opt_trait_ref.is_none() {
span_err!(tcx.sess, impl_item.span, E0202,
"associated types are not allowed in inherent impls");
}
let methods = impl_items.iter().filter_map(|ii| {
- if let ast::MethodImplItem(ref sig, _) = ii.node {
+ if let hir::MethodImplItem(ref sig, _) = ii.node {
// if the method specifies a visibility, use that, otherwise
// inherit the visibility from the impl (so `foo` in `pub impl
// { fn foo(); }` is public, but private in `impl { fn
&ty_predicates);
for impl_item in impl_items {
- if let ast::MethodImplItem(ref sig, ref body) = impl_item.node {
+ if let hir::MethodImplItem(ref sig, ref body) = impl_item.node {
let body_id = body.id;
check_method_self_type(ccx,
&BindingRscope::new(),
DefId::local(it.id),
impl_items);
},
- ast::ItemTrait(_, _, _, ref trait_items) => {
+ hir::ItemTrait(_, _, _, ref trait_items) => {
let trait_def = trait_def_of_item(ccx, it);
let _: Result<(), ErrorReported> = // any error is already reported, can ignore
ccx.ensure_super_predicates(it.span, DefId::local(it.id));
// Convert all the associated types.
for trait_item in trait_items {
match trait_item.node {
- ast::ConstTraitItem(ref ty, ref default) => {
+ hir::ConstTraitItem(ref ty, ref default) => {
let ty = ccx.icx(&trait_predicates)
.to_ty(&ExplicitRscope, ty);
tcx.register_item_type(DefId::local(trait_item.id),
});
convert_associated_const(ccx, TraitContainer(DefId::local(it.id)),
trait_item.ident, trait_item.id,
- ast::Public, ty, default.as_ref().map(|d| &**d));
+ hir::Public, ty, default.as_ref().map(|d| &**d));
}
_ => {}
}
// Convert all the associated types.
for trait_item in trait_items {
match trait_item.node {
- ast::TypeTraitItem(_, ref opt_ty) => {
+ hir::TypeTraitItem(_, ref opt_ty) => {
let typ = opt_ty.as_ref().map({
|ty| ccx.icx(&trait_predicates).to_ty(&ExplicitRscope, &ty)
});
convert_associated_type(ccx, TraitContainer(DefId::local(it.id)),
- trait_item.ident, trait_item.id, ast::Public,
+ trait_item.ident, trait_item.id, hir::Public,
typ);
}
_ => {}
let methods = trait_items.iter().filter_map(|ti| {
let sig = match ti.node {
- ast::MethodTraitItem(ref sig, _) => sig,
+ hir::MethodTraitItem(ref sig, _) => sig,
_ => return None,
};
- Some((sig, ti.id, ti.ident, ast::Inherited, ti.span))
+ Some((sig, ti.id, ti.ident, hir::Inherited, ti.span))
});
// Run convert_methods on the trait methods.
let trait_item_def_ids = Rc::new(trait_items.iter().map(|trait_item| {
let def_id = DefId::local(trait_item.id);
match trait_item.node {
- ast::ConstTraitItem(..) => {
+ hir::ConstTraitItem(..) => {
ty::ConstTraitItemId(def_id)
}
- ast::MethodTraitItem(..) => {
+ hir::MethodTraitItem(..) => {
ty::MethodTraitItemId(def_id)
}
- ast::TypeTraitItem(..) => {
+ hir::TypeTraitItem(..) => {
ty::TypeTraitItemId(def_id)
}
}
// we have a method type stored for every method.
for trait_item in trait_items {
let sig = match trait_item.node {
- ast::MethodTraitItem(ref sig, _) => sig,
+ hir::MethodTraitItem(ref sig, _) => sig,
_ => continue
};
check_method_self_type(ccx,
it.id)
}
},
- ast::ItemStruct(ref struct_def, _) => {
+ hir::ItemStruct(ref struct_def, _) => {
let (scheme, predicates) = convert_typed_item(ccx, it);
write_ty_to_tcx(tcx, it.id, scheme.ty);
convert_variant_ctor(tcx, ctor_id, variant, scheme, predicates);
}
},
- ast::ItemTy(_, ref generics) => {
+ hir::ItemTy(_, ref generics) => {
ensure_no_ty_param_bounds(ccx, it.span, generics, "type");
let (scheme, _) = convert_typed_item(ccx, it);
write_ty_to_tcx(tcx, it.id, scheme.ty);
def: ty::AdtDefMaster<'tcx>,
scheme: ty::TypeScheme<'tcx>,
predicates: ty::GenericPredicates<'tcx>,
- variants: &[P<ast::Variant>]) {
+ variants: &[P<hir::Variant>]) {
let tcx = ccx.tcx;
let icx = ccx.icx(&predicates);
// fill the field types
for (variant, ty_variant) in variants.iter().zip(def.variants.iter()) {
match variant.node.kind {
- ast::TupleVariantKind(ref args) => {
+ hir::TupleVariantKind(ref args) => {
let rs = ExplicitRscope;
let input_tys: Vec<_> = args.iter().map(|va| icx.to_ty(&rs, &*va.ty)).collect();
for (field, &ty) in ty_variant.fields.iter().zip(input_tys.iter()) {
}
}
- ast::StructVariantKind(ref struct_def) => {
+ hir::StructVariantKind(ref struct_def) => {
for (f, ty_f) in struct_def.fields.iter().zip(ty_variant.fields.iter()) {
convert_field(ccx, &scheme.generics, &predicates, f, ty_f)
}
did: DefId,
name: ast::Name,
disr_val: ty::Disr,
- def: &ast::StructDef) -> ty::VariantDefData<'tcx, 'tcx> {
+ def: &hir::StructDef) -> ty::VariantDefData<'tcx, 'tcx> {
let mut seen_fields: FnvHashMap<ast::Name, Span> = FnvHashMap();
let fields = def.fields.iter().map(|f| {
let fid = DefId::local(f.node.id);
match f.node.kind {
- ast::NamedField(ident, vis) => {
+ hir::NamedField(ident, vis) => {
let dup_span = seen_fields.get(&ident.name).cloned();
if let Some(prev_span) = dup_span {
span_err!(tcx.sess, f.span, E0124,
ty::FieldDefData::new(fid, ident.name, vis)
},
- ast::UnnamedField(vis) => {
+ hir::UnnamedField(vis) => {
ty::FieldDefData::new(fid, special_idents::unnamed_field.name, vis)
}
}
}
fn convert_struct_def<'tcx>(tcx: &ty::ctxt<'tcx>,
- it: &ast::Item,
- def: &ast::StructDef)
+ it: &hir::Item,
+ def: &hir::StructDef)
-> ty::AdtDefMaster<'tcx>
{
}
fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>,
- it: &ast::Item,
- def: &ast::EnumDef)
+ it: &hir::Item,
+ def: &hir::EnumDef)
-> ty::AdtDefMaster<'tcx>
{
fn evaluate_disr_expr<'tcx>(tcx: &ty::ctxt<'tcx>,
repr_ty: Ty<'tcx>,
- e: &ast::Expr) -> Option<ty::Disr> {
+ e: &hir::Expr) -> Option<ty::Disr> {
debug!("disr expr, checking {}", pprust::expr_to_string(e));
let hint = UncheckedExprHint(repr_ty);
}
fn next_disr(tcx: &ty::ctxt,
- v: &ast::Variant,
+ v: &hir::Variant,
repr_type: attr::IntType,
prev_disr_val: Option<ty::Disr>) -> Option<ty::Disr> {
if let Some(prev_disr_val) = prev_disr_val {
}
}
fn convert_enum_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
- v: &ast::Variant,
+ v: &hir::Variant,
disr: ty::Disr)
-> ty::VariantDefData<'tcx, 'tcx>
{
let did = DefId::local(v.node.id);
let name = v.node.name.name;
match v.node.kind {
- ast::TupleVariantKind(ref va) => {
+ hir::TupleVariantKind(ref va) => {
ty::VariantDefData {
did: did,
name: name,
disr_val: disr,
- fields: va.iter().map(|&ast::VariantArg { id, .. }| {
+ fields: va.iter().map(|&hir::VariantArg { id, .. }| {
ty::FieldDefData::new(
DefId::local(id),
special_idents::unnamed_field.name,
- ast::Visibility::Public
+ hir::Visibility::Public
)
}).collect()
}
}
- ast::StructVariantKind(ref def) => {
+ hir::StructVariantKind(ref def) => {
convert_struct_variant(tcx, did, name, disr, &def)
}
}
let trait_node_id = trait_def_id.node;
let item = match ccx.tcx.map.get(trait_node_id) {
- ast_map::NodeItem(item) => item,
+ hir_map::NodeItem(item) => item,
_ => ccx.tcx.sess.bug(&format!("trait_node_id {} is not an item", trait_node_id))
};
let (generics, bounds) = match item.node {
- ast::ItemTrait(_, ref generics, ref supertraits, _) => (generics, supertraits),
+ hir::ItemTrait(_, ref generics, ref supertraits, _) => (generics, supertraits),
_ => tcx.sess.span_bug(item.span,
"ensure_super_predicates_step invoked on non-trait"),
};
}
fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
- it: &ast::Item)
+ it: &hir::Item)
-> &'tcx ty::TraitDef<'tcx>
{
let def_id = DefId::local(it.id);
}
let (unsafety, generics, items) = match it.node {
- ast::ItemTrait(unsafety, ref generics, _, ref items) => (unsafety, generics, items),
+ hir::ItemTrait(unsafety, ref generics, _, ref items) => (unsafety, generics, items),
_ => tcx.sess.span_bug(it.span, "trait_def_of_item invoked on non-trait"),
};
let associated_type_names: Vec<_> = items.iter().filter_map(|trait_item| {
match trait_item.node {
- ast::TypeTraitItem(..) => Some(trait_item.ident.name),
+ hir::TypeTraitItem(..) => Some(trait_item.ident.name),
_ => None,
}
}).collect();
return tcx.intern_trait_def(trait_def);
fn mk_trait_substs<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
- generics: &ast::Generics)
+ generics: &hir::Generics)
-> Substs<'tcx>
{
let tcx = ccx.tcx;
-> bool
{
let item = match ccx.tcx.map.get(trait_node_id) {
- ast_map::NodeItem(item) => item,
+ hir_map::NodeItem(item) => item,
_ => ccx.tcx.sess.bug(&format!("trait_node_id {} is not an item", trait_node_id))
};
let trait_items = match item.node {
- ast::ItemTrait(_, _, _, ref trait_items) => trait_items,
+ hir::ItemTrait(_, _, _, ref trait_items) => trait_items,
_ => ccx.tcx.sess.bug(&format!("trait_node_id {} is not a trait", trait_node_id))
};
trait_items.iter().any(|trait_item| {
match trait_item.node {
- ast::TypeTraitItem(..) => trait_item.ident.name == assoc_name,
+ hir::TypeTraitItem(..) => trait_item.ident.name == assoc_name,
_ => false,
}
})
}
-fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item) {
+fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &hir::Item) {
let tcx = ccx.tcx;
let trait_def = trait_def_of_item(ccx, it);
let def_id = DefId::local(it.id);
let (generics, items) = match it.node {
- ast::ItemTrait(_, ref generics, _, ref items) => (generics, items),
+ hir::ItemTrait(_, ref generics, _, ref items) => (generics, items),
ref s => {
tcx.sess.span_bug(
it.span,
return;
fn predicates_for_associated_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
- ast_generics: &ast::Generics,
+ ast_generics: &hir::Generics,
trait_predicates: &ty::GenericPredicates<'tcx>,
self_trait_ref: ty::TraitRef<'tcx>,
- trait_items: &[P<ast::TraitItem>])
+ trait_items: &[P<hir::TraitItem>])
-> Vec<ty::Predicate<'tcx>>
{
trait_items.iter().flat_map(|trait_item| {
let bounds = match trait_item.node {
- ast::TypeTraitItem(ref bounds, _) => bounds,
+ hir::TypeTraitItem(ref bounds, _) => bounds,
_ => {
return vec!().into_iter();
}
}
match ccx.tcx.map.find(def_id.node) {
- Some(ast_map::NodeItem(item)) => {
+ Some(hir_map::NodeItem(item)) => {
type_scheme_of_item(ccx, &*item)
}
- Some(ast_map::NodeForeignItem(foreign_item)) => {
+ Some(hir_map::NodeForeignItem(foreign_item)) => {
let abi = ccx.tcx.map.get_foreign_abi(def_id.node);
type_scheme_of_foreign_item(ccx, &*foreign_item, abi)
}
}
fn type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
- it: &ast::Item)
+ it: &hir::Item)
-> ty::TypeScheme<'tcx>
{
memoized(&ccx.tcx.tcache,
}
fn compute_type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
- it: &ast::Item)
+ it: &hir::Item)
-> ty::TypeScheme<'tcx>
{
let tcx = ccx.tcx;
match it.node {
- ast::ItemStatic(ref t, _, _) | ast::ItemConst(ref t, _) => {
+ hir::ItemStatic(ref t, _, _) | hir::ItemConst(ref t, _) => {
let ty = ccx.icx(&()).to_ty(&ExplicitRscope, &**t);
ty::TypeScheme { ty: ty, generics: ty::Generics::empty() }
}
- ast::ItemFn(ref decl, unsafety, _, abi, ref generics, _) => {
+ 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(DefId::local(it.id)), tcx.mk_bare_fn(tofd));
ty::TypeScheme { ty: ty, generics: ty_generics }
}
- ast::ItemTy(ref t, ref 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);
ty::TypeScheme { ty: ty, generics: ty_generics }
}
- ast::ItemEnum(ref ei, ref generics) => {
+ hir::ItemEnum(ref ei, ref generics) => {
let ty_generics = ty_generics_for_type_or_impl(ccx, generics);
let substs = mk_item_substs(ccx, &ty_generics);
let def = convert_enum_def(tcx, it, ei);
let t = tcx.mk_enum(def, tcx.mk_substs(substs));
ty::TypeScheme { ty: t, generics: ty_generics }
}
- ast::ItemStruct(ref si, ref generics) => {
+ hir::ItemStruct(ref si, ref generics) => {
let ty_generics = ty_generics_for_type_or_impl(ccx, generics);
let substs = mk_item_substs(ccx, &ty_generics);
let def = convert_struct_def(tcx, it, si);
let t = tcx.mk_struct(def, tcx.mk_substs(substs));
ty::TypeScheme { ty: t, generics: ty_generics }
}
- ast::ItemDefaultImpl(..) |
- ast::ItemTrait(..) |
- ast::ItemImpl(..) |
- ast::ItemMod(..) |
- ast::ItemForeignMod(..) |
- ast::ItemExternCrate(..) |
- ast::ItemUse(..) |
- ast::ItemMac(..) => {
+ hir::ItemDefaultImpl(..) |
+ hir::ItemTrait(..) |
+ hir::ItemImpl(..) |
+ hir::ItemMod(..) |
+ hir::ItemForeignMod(..) |
+ hir::ItemExternCrate(..) |
+ hir::ItemUse(..) => {
tcx.sess.span_bug(
it.span,
&format!("compute_type_scheme_of_item: unexpected item type: {:?}",
}
fn convert_typed_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
- it: &ast::Item)
+ it: &hir::Item)
-> (ty::TypeScheme<'tcx>, ty::GenericPredicates<'tcx>)
{
let tcx = ccx.tcx;
let tag = type_scheme_of_item(ccx, it);
let scheme = TypeScheme { generics: tag.generics, ty: tag.ty };
let predicates = match it.node {
- ast::ItemStatic(..) | ast::ItemConst(..) => {
+ hir::ItemStatic(..) | hir::ItemConst(..) => {
ty::GenericPredicates::empty()
}
- ast::ItemFn(_, _, _, _, ref ast_generics, _) => {
+ hir::ItemFn(_, _, _, _, ref ast_generics, _) => {
ty_generic_predicates_for_fn(ccx, ast_generics, &ty::GenericPredicates::empty())
}
- ast::ItemTy(_, ref generics) => {
+ hir::ItemTy(_, ref generics) => {
ty_generic_predicates_for_type_or_impl(ccx, generics)
}
- ast::ItemEnum(_, ref generics) => {
+ hir::ItemEnum(_, ref generics) => {
ty_generic_predicates_for_type_or_impl(ccx, generics)
}
- ast::ItemStruct(_, ref generics) => {
+ hir::ItemStruct(_, ref generics) => {
ty_generic_predicates_for_type_or_impl(ccx, generics)
}
- ast::ItemDefaultImpl(..) |
- ast::ItemTrait(..) |
- ast::ItemExternCrate(..) |
- ast::ItemUse(..) |
- ast::ItemImpl(..) |
- ast::ItemMod(..) |
- ast::ItemForeignMod(..) |
- ast::ItemMac(..) => {
+ hir::ItemDefaultImpl(..) |
+ hir::ItemTrait(..) |
+ hir::ItemExternCrate(..) |
+ hir::ItemUse(..) |
+ hir::ItemImpl(..) |
+ hir::ItemMod(..) |
+ hir::ItemForeignMod(..) => {
tcx.sess.span_bug(
it.span,
&format!("compute_type_scheme_of_item: unexpected item type: {:?}",
fn type_scheme_of_foreign_item<'a, 'tcx>(
ccx: &CrateCtxt<'a, 'tcx>,
- it: &ast::ForeignItem,
+ it: &hir::ForeignItem,
abi: abi::Abi)
-> ty::TypeScheme<'tcx>
{
fn compute_type_scheme_of_foreign_item<'a, 'tcx>(
ccx: &CrateCtxt<'a, 'tcx>,
- it: &ast::ForeignItem,
+ it: &hir::ForeignItem,
abi: abi::Abi)
-> ty::TypeScheme<'tcx>
{
match it.node {
- ast::ForeignItemFn(ref fn_decl, ref generics) => {
+ hir::ForeignItemFn(ref fn_decl, ref generics) => {
compute_type_scheme_of_foreign_fn_decl(ccx, fn_decl, generics, abi)
}
- ast::ForeignItemStatic(ref t, _) => {
+ hir::ForeignItemStatic(ref t, _) => {
ty::TypeScheme {
generics: ty::Generics::empty(),
ty: ast_ty_to_ty(&ccx.icx(&()), &ExplicitRscope, t)
}
fn convert_foreign_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
- it: &ast::ForeignItem)
+ it: &hir::ForeignItem)
{
// For reasons I cannot fully articulate, I do so hate the AST
// map, and I regard each time that I use it as a personal and
write_ty_to_tcx(ccx.tcx, it.id, scheme.ty);
let predicates = match it.node {
- ast::ForeignItemFn(_, ref generics) => {
+ hir::ForeignItemFn(_, ref generics) => {
ty_generic_predicates_for_fn(ccx, generics, &ty::GenericPredicates::empty())
}
- ast::ForeignItemStatic(..) => {
+ hir::ForeignItemStatic(..) => {
ty::GenericPredicates::empty()
}
};
}
fn ty_generics_for_type_or_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
- generics: &ast::Generics)
+ generics: &hir::Generics)
-> ty::Generics<'tcx> {
ty_generics(ccx, TypeSpace, generics, &ty::Generics::empty())
}
fn ty_generic_predicates_for_type_or_impl<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
- generics: &ast::Generics)
+ generics: &hir::Generics)
-> ty::GenericPredicates<'tcx>
{
ty_generic_predicates(ccx, TypeSpace, generics, &ty::GenericPredicates::empty())
fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
trait_id: ast::NodeId,
substs: &'tcx Substs<'tcx>,
- ast_generics: &ast::Generics)
+ ast_generics: &hir::Generics)
-> ty::Generics<'tcx>
{
debug!("ty_generics_for_trait(trait_id={:?}, substs={:?})",
}
fn ty_generics_for_fn<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
- generics: &ast::Generics,
+ generics: &hir::Generics,
base_generics: &ty::Generics<'tcx>)
-> ty::Generics<'tcx>
{
}
fn ty_generic_predicates_for_fn<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
- generics: &ast::Generics,
+ generics: &hir::Generics,
base_predicates: &ty::GenericPredicates<'tcx>)
-> ty::GenericPredicates<'tcx>
{
// Add the Sized bound, unless the type parameter is marked as `?Sized`.
fn add_unsized_bound<'tcx>(astconv: &AstConv<'tcx>,
bounds: &mut ty::BuiltinBounds,
- ast_bounds: &[ast::TyParamBound],
+ ast_bounds: &[hir::TyParamBound],
span: Span)
{
let tcx = astconv.tcx();
// Try to find an unbound in bounds.
let mut unbound = None;
for ab in ast_bounds {
- if let &ast::TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = ab {
+ if let &hir::TraitTyParamBound(ref ptr, hir::TraitBoundModifier::Maybe) = ab {
if unbound.is_none() {
assert!(ptr.bound_lifetimes.is_empty());
unbound = Some(ptr.trait_ref.clone());
/// screen out those that do not appear in any where-clauses etc using
/// `resolve_lifetime::early_bound_lifetimes`.
fn early_bound_lifetimes_from_generics(space: ParamSpace,
- ast_generics: &ast::Generics)
- -> Vec<ast::LifetimeDef>
+ ast_generics: &hir::Generics)
+ -> Vec<hir::LifetimeDef>
{
match space {
SelfSpace | TypeSpace => ast_generics.lifetimes.to_vec(),
fn ty_generic_predicates<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
space: ParamSpace,
- ast_generics: &ast::Generics,
+ ast_generics: &hir::Generics,
base_predicates: &ty::GenericPredicates<'tcx>)
-> ty::GenericPredicates<'tcx>
{
let where_clause = &ast_generics.where_clause;
for predicate in &where_clause.predicates {
match predicate {
- &ast::WherePredicate::BoundPredicate(ref bound_pred) => {
+ &hir::WherePredicate::BoundPredicate(ref bound_pred) => {
let ty = ast_ty_to_ty(&ccx.icx(&(base_predicates, ast_generics)),
&ExplicitRscope,
&*bound_pred.bounded_ty);
for bound in bound_pred.bounds.iter() {
match bound {
- &ast::TyParamBound::TraitTyParamBound(ref poly_trait_ref, _) => {
+ &hir::TyParamBound::TraitTyParamBound(ref poly_trait_ref, _) => {
let mut projections = Vec::new();
let trait_ref =
}
}
- &ast::TyParamBound::RegionTyParamBound(ref lifetime) => {
+ &hir::TyParamBound::RegionTyParamBound(ref lifetime) => {
let region = ast_region_to_region(tcx, lifetime);
let pred = ty::Binder(ty::OutlivesPredicate(ty, region));
result.predicates.push(space, ty::Predicate::TypeOutlives(pred))
}
}
- &ast::WherePredicate::RegionPredicate(ref region_pred) => {
+ &hir::WherePredicate::RegionPredicate(ref region_pred) => {
let r1 = ast_region_to_region(tcx, ®ion_pred.lifetime);
for bound in ®ion_pred.bounds {
let r2 = ast_region_to_region(tcx, bound);
}
}
- &ast::WherePredicate::EqPredicate(ref eq_pred) => {
+ &hir::WherePredicate::EqPredicate(ref eq_pred) => {
// FIXME(#20041)
tcx.sess.span_bug(eq_pred.span,
"Equality constraints are not yet \
fn ty_generics<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
space: ParamSpace,
- ast_generics: &ast::Generics,
+ ast_generics: &hir::Generics,
base_generics: &ty::Generics<'tcx>)
-> ty::Generics<'tcx>
{
}
fn convert_default_type_parameter<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
- path: &P<ast::Ty>,
+ path: &P<hir::Ty>,
space: ParamSpace,
index: u32)
-> Ty<'tcx>
}
fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
- ast_generics: &ast::Generics,
+ ast_generics: &hir::Generics,
space: ParamSpace,
index: u32)
-> ty::TypeParameterDef<'tcx>
/// artificial cycles.
fn compute_object_lifetime_default<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
param_id: ast::NodeId,
- param_bounds: &[ast::TyParamBound],
- where_clause: &ast::WhereClause)
+ param_bounds: &[hir::TyParamBound],
+ where_clause: &hir::WhereClause)
-> ty::ObjectLifetimeDefault
{
let inline_bounds = from_bounds(ccx, param_bounds);
};
fn from_bounds<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
- bounds: &[ast::TyParamBound])
+ bounds: &[hir::TyParamBound])
-> Vec<ty::Region>
{
bounds.iter()
.filter_map(|bound| {
match *bound {
- ast::TraitTyParamBound(..) =>
+ hir::TraitTyParamBound(..) =>
None,
- ast::RegionTyParamBound(ref lifetime) =>
+ hir::RegionTyParamBound(ref lifetime) =>
Some(astconv::ast_region_to_region(ccx.tcx, lifetime)),
}
})
fn from_predicates<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
param_id: ast::NodeId,
- predicates: &[ast::WherePredicate])
+ predicates: &[hir::WherePredicate])
-> Vec<ty::Region>
{
predicates.iter()
.flat_map(|predicate| {
match *predicate {
- ast::WherePredicate::BoundPredicate(ref data) => {
+ hir::WherePredicate::BoundPredicate(ref data) => {
if data.bound_lifetimes.is_empty() &&
is_param(ccx.tcx, &data.bounded_ty, param_id)
{
Vec::new().into_iter()
}
}
- ast::WherePredicate::RegionPredicate(..) |
- ast::WherePredicate::EqPredicate(..) => {
+ hir::WherePredicate::RegionPredicate(..) |
+ hir::WherePredicate::EqPredicate(..) => {
Vec::new().into_iter()
}
}
/// built-in trait (formerly known as kind): Send.
fn compute_bounds<'tcx>(astconv: &AstConv<'tcx>,
param_ty: ty::Ty<'tcx>,
- ast_bounds: &[ast::TyParamBound],
+ ast_bounds: &[hir::TyParamBound],
sized_by_default: SizedByDefault,
span: Span)
-> astconv::Bounds<'tcx>
/// and `<T as Bar>::X == i32`).
fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx>,
param_ty: Ty<'tcx>,
- bound: &ast::TyParamBound)
+ bound: &hir::TyParamBound)
-> Vec<ty::Predicate<'tcx>>
{
match *bound {
- ast::TraitTyParamBound(ref tr, ast::TraitBoundModifier::None) => {
+ hir::TraitTyParamBound(ref tr, hir::TraitBoundModifier::None) => {
let mut projections = Vec::new();
let pred = conv_poly_trait_ref(astconv, param_ty, tr, &mut projections);
projections.into_iter()
.chain(Some(pred.to_predicate()))
.collect()
}
- ast::RegionTyParamBound(ref lifetime) => {
+ hir::RegionTyParamBound(ref lifetime) => {
let region = ast_region_to_region(astconv.tcx(), lifetime);
let pred = ty::Binder(ty::OutlivesPredicate(param_ty, region));
vec![ty::Predicate::TypeOutlives(pred)]
}
- ast::TraitTyParamBound(_, ast::TraitBoundModifier::Maybe) => {
+ hir::TraitTyParamBound(_, hir::TraitBoundModifier::Maybe) => {
Vec::new()
}
}
fn conv_poly_trait_ref<'tcx>(astconv: &AstConv<'tcx>,
param_ty: Ty<'tcx>,
- trait_ref: &ast::PolyTraitRef,
+ trait_ref: &hir::PolyTraitRef,
projections: &mut Vec<ty::PolyProjectionPredicate<'tcx>>)
-> ty::PolyTraitRef<'tcx>
{
fn conv_param_bounds<'a,'tcx>(astconv: &AstConv<'tcx>,
span: Span,
param_ty: ty::Ty<'tcx>,
- ast_bounds: &[ast::TyParamBound])
+ ast_bounds: &[hir::TyParamBound])
-> astconv::Bounds<'tcx>
{
let tcx = astconv.tcx();
fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
ccx: &CrateCtxt<'a, 'tcx>,
- decl: &ast::FnDecl,
- ast_generics: &ast::Generics,
+ decl: &hir::FnDecl,
+ ast_generics: &hir::Generics,
abi: abi::Abi)
-> ty::TypeScheme<'tcx>
{
for i in &decl.inputs {
match (*i).pat.node {
- ast::PatIdent(_, _, _) => (),
- ast::PatWild(ast::PatWildSingle) => (),
+ hir::PatIdent(_, _, _) => (),
+ hir::PatWild(hir::PatWildSingle) => (),
_ => {
span_err!(ccx.tcx.sess, (*i).pat.span, E0130,
"patterns aren't allowed in foreign function declarations");
.collect();
let output = match decl.output {
- ast::Return(ref ty) =>
+ hir::Return(ref ty) =>
ty::FnConverging(ast_ty_to_ty(&ccx.icx(ast_generics), &rb, &**ty)),
- ast::DefaultReturn(..) =>
+ hir::DefaultReturn(..) =>
ty::FnConverging(ccx.tcx.mk_nil()),
- ast::NoReturn(..) =>
+ hir::NoReturn(..) =>
ty::FnDiverging
};
let t_fn = ccx.tcx.mk_fn(None,
ccx.tcx.mk_bare_fn(ty::BareFnTy {
abi: abi,
- unsafety: ast::Unsafety::Unsafe,
+ unsafety: hir::Unsafety::Unsafe,
sig: ty::Binder(ty::FnSig {inputs: input_tys,
output: output,
variadic: decl.variadic}),
rs: &RS,
method_type: Rc<ty::Method<'tcx>>,
required_type: Ty<'tcx>,
- explicit_self: &ast::ExplicitSelf,
+ explicit_self: &hir::ExplicitSelf,
body_id: ast::NodeId)
{
let tcx = ccx.tcx;
- if let ast::SelfExplicit(ref ast_type, _) = explicit_self.node {
+ if let hir::SelfExplicit(ref ast_type, _) = explicit_self.node {
let typ = ccx.icx(&method_type.predicates).to_ty(rs, &**ast_type);
let base_type = match typ.sty {
ty::TyRef(_, tm) => tm.ty,
* before we really have a `ParameterEnvironment` to check.
*/
- ty_fold::fold_regions(tcx, value, &mut false, |region, _| {
+ tcx.fold_regions(value, &mut false, |region, _| {
match region {
ty::ReEarlyBound(data) => {
let def_id = DefId::local(data.param_id);
/// Checks that all the type parameters on an impl
fn enforce_impl_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
- ast_generics: &ast::Generics,
+ ast_generics: &hir::Generics,
impl_def_id: DefId,
- impl_items: &[P<ast::ImplItem>])
+ impl_items: &[P<hir::ImplItem>])
{
let impl_scheme = tcx.lookup_item_type(impl_def_id);
let impl_predicates = tcx.lookup_predicates(impl_def_id);