Split TyBareFn into TyFnDef and TyFnPtr.
There's a lot of stuff wrong with the representation of these types: TyFnDef doesn't actually uniquely identify a function, TyFnPtr is used to represent method calls, TyFnDef in the sub-expression of a cast isn't correctly reified, and probably some other stuff I haven't discovered yet. Splitting them seems like the right first step, though.
This commit is contained in:
parent
4b868411af
commit
b423a0f9ef
73 changed files with 406 additions and 324 deletions
|
|
@ -44,7 +44,8 @@ enum RootUnsafeContext {
|
|||
|
||||
fn type_is_unsafe_function(ty: Ty) -> bool {
|
||||
match ty.sty {
|
||||
ty::TyBareFn(_, ref f) => f.unsafety == hir::Unsafety::Unsafe,
|
||||
ty::TyFnDef(_, ref f) |
|
||||
ty::TyFnPtr(ref f) => f.unsafety == hir::Unsafety::Unsafe,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -556,7 +556,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
|
|||
callee, callee_ty);
|
||||
let call_scope = self.tcx().region_maps.node_extent(call.id);
|
||||
match callee_ty.sty {
|
||||
ty::TyBareFn(..) => {
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
|
||||
self.consume_expr(callee);
|
||||
}
|
||||
ty::TyError => { }
|
||||
|
|
|
|||
|
|
@ -161,7 +161,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
|
|||
ty::TySlice(..) |
|
||||
ty::TyRawPtr(..) |
|
||||
ty::TyRef(..) |
|
||||
ty::TyBareFn(..) |
|
||||
ty::TyFnDef(..) |
|
||||
ty::TyFnPtr(_) |
|
||||
ty::TyTrait(..) |
|
||||
ty::TyStruct(..) |
|
||||
ty::TyClosure(..) |
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use dep_graph::DepNode;
|
|||
use middle::def::Def;
|
||||
use middle::def_id::DefId;
|
||||
use middle::subst::{Subst, Substs, EnumeratedItems};
|
||||
use middle::ty::{TransmuteRestriction, TyCtxt, TyBareFn};
|
||||
use middle::ty::{TransmuteRestriction, TyCtxt};
|
||||
use middle::ty::{self, Ty, TypeFoldable};
|
||||
|
||||
use std::fmt;
|
||||
|
|
@ -53,7 +53,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 self.tcx.lookup_item_type(def_id).ty.sty {
|
||||
ty::TyBareFn(_, ref bfty) => bfty.abi == RustIntrinsic,
|
||||
ty::TyFnDef(_, ref bfty) => bfty.abi == RustIntrinsic,
|
||||
_ => return false
|
||||
};
|
||||
intrinsic && self.tcx.item_name(def_id).as_str() == "transmute"
|
||||
|
|
@ -238,7 +238,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> {
|
|||
Def::Fn(did) if self.def_id_is_transmute(did) => {
|
||||
let typ = self.tcx.node_id_to_type(expr.id);
|
||||
match typ.sty {
|
||||
TyBareFn(_, ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
|
||||
ty::TyFnDef(_, ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
|
||||
if let ty::FnConverging(to) = bare_fn_ty.sig.0.output {
|
||||
let from = bare_fn_ty.sig.0.inputs[0];
|
||||
self.check_transmute(expr.span, from, to, expr.id);
|
||||
|
|
|
|||
|
|
@ -301,7 +301,8 @@ fn ty_is_local_constructor<'tcx>(tcx: &TyCtxt<'tcx>,
|
|||
ty::TyUint(..) |
|
||||
ty::TyFloat(..) |
|
||||
ty::TyStr |
|
||||
ty::TyBareFn(..) |
|
||||
ty::TyFnDef(..) |
|
||||
ty::TyFnPtr(_) |
|
||||
ty::TyArray(..) |
|
||||
ty::TySlice(..) |
|
||||
ty::TyRawPtr(..) |
|
||||
|
|
|
|||
|
|
@ -1286,7 +1286,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
// provide an impl, but only for suitable `fn` pointers
|
||||
ty::TyBareFn(_, &ty::BareFnTy {
|
||||
ty::TyFnDef(_, &ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
inputs: _,
|
||||
output: ty::FnConverging(_),
|
||||
variadic: false
|
||||
})
|
||||
}) |
|
||||
ty::TyFnPtr(&ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
|
|
@ -1646,7 +1655,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
ty::TyInt(_) |
|
||||
ty::TyBool |
|
||||
ty::TyFloat(_) |
|
||||
ty::TyBareFn(..) |
|
||||
ty::TyFnDef(..) |
|
||||
ty::TyFnPtr(_) |
|
||||
ty::TyChar => {
|
||||
// safe for everything
|
||||
ok_if(Vec::new())
|
||||
|
|
@ -1850,7 +1860,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
ty::TyInt(_) |
|
||||
ty::TyBool |
|
||||
ty::TyFloat(_) |
|
||||
ty::TyBareFn(..) |
|
||||
ty::TyFnDef(..) |
|
||||
ty::TyFnPtr(_) |
|
||||
ty::TyStr |
|
||||
ty::TyError |
|
||||
ty::TyInfer(ty::IntVar(_)) |
|
||||
|
|
|
|||
|
|
@ -155,8 +155,8 @@ impl<'tcx> ty::TyS<'tcx> {
|
|||
match *adjustment {
|
||||
AdjustReifyFnPointer => {
|
||||
match self.sty {
|
||||
ty::TyBareFn(Some(_), b) => {
|
||||
cx.mk_fn(None, b)
|
||||
ty::TyFnDef(_, b) => {
|
||||
cx.mk_ty(ty::TyFnPtr(b))
|
||||
}
|
||||
_ => {
|
||||
cx.sess.bug(
|
||||
|
|
@ -168,7 +168,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
|||
|
||||
AdjustUnsafeFnPointer => {
|
||||
match self.sty {
|
||||
ty::TyBareFn(None, b) => cx.safe_to_unsafe_fn_ty(b),
|
||||
ty::TyFnPtr(b) => cx.safe_to_unsafe_fn_ty(b),
|
||||
ref b => {
|
||||
cx.sess.bug(
|
||||
&format!("AdjustUnsafeFnPointer adjustment on non-fn-ptr: \
|
||||
|
|
|
|||
|
|
@ -69,7 +69,9 @@ impl<'tcx> CastTy<'tcx> {
|
|||
Some(CastTy::Int(IntTy::CEnum)),
|
||||
ty::TyRawPtr(ref mt) => Some(CastTy::Ptr(mt)),
|
||||
ty::TyRef(_, ref mt) => Some(CastTy::RPtr(mt)),
|
||||
ty::TyBareFn(..) => Some(CastTy::FnPtr),
|
||||
// FIXME: Treating TyFnDef as a pointer here is a bit dubious;
|
||||
// we should be coercing the operand to an actual pointer.
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(..) => Some(CastTy::FnPtr),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
|||
// Scalar and unique types are sendable, and durable
|
||||
ty::TyInfer(ty::FreshIntTy(_)) | ty::TyInfer(ty::FreshFloatTy(_)) |
|
||||
ty::TyBool | ty::TyInt(_) | ty::TyUint(_) | ty::TyFloat(_) |
|
||||
ty::TyBareFn(..) | ty::TyChar => {
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) | ty::TyChar => {
|
||||
TC::None
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -734,8 +734,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
pub fn print_debug_stats(&self) {
|
||||
sty_debug_print!(
|
||||
self,
|
||||
TyEnum, TyBox, TyArray, TySlice, TyRawPtr, TyRef, TyBareFn, TyTrait,
|
||||
TyStruct, TyClosure, TyTuple, TyParam, TyInfer, TyProjection);
|
||||
TyEnum, TyBox, TyArray, TySlice, TyRawPtr, TyRef, TyFnDef, TyFnPtr,
|
||||
TyTrait, TyStruct, TyClosure, TyTuple, TyParam, TyInfer, TyProjection);
|
||||
|
||||
println!("Substs interner: #{}", self.substs_interner.borrow().len());
|
||||
println!("BareFnTy interner: #{}", self.bare_fn_interner.borrow().len());
|
||||
|
|
@ -792,12 +792,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// Create an unsafe fn ty based on a safe fn ty.
|
||||
pub fn safe_to_unsafe_fn_ty(&self, bare_fn: &BareFnTy<'tcx>) -> Ty<'tcx> {
|
||||
assert_eq!(bare_fn.unsafety, hir::Unsafety::Normal);
|
||||
let unsafe_fn_ty_a = self.mk_bare_fn(ty::BareFnTy {
|
||||
self.mk_fn_ptr(ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Unsafe,
|
||||
abi: bare_fn.abi,
|
||||
sig: bare_fn.sig.clone()
|
||||
});
|
||||
self.mk_fn(None, unsafe_fn_ty_a)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn mk_bare_fn(&self, bare_fn: BareFnTy<'tcx>) -> &'tcx BareFnTy<'tcx> {
|
||||
|
|
@ -946,10 +945,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self.mk_ty(TyBool)
|
||||
}
|
||||
|
||||
pub fn mk_fn(&self,
|
||||
opt_def_id: Option<DefId>,
|
||||
fty: &'tcx BareFnTy<'tcx>) -> Ty<'tcx> {
|
||||
self.mk_ty(TyBareFn(opt_def_id, fty))
|
||||
pub fn mk_fn_def(&self, def_id: DefId,
|
||||
fty: BareFnTy<'tcx>) -> Ty<'tcx> {
|
||||
self.mk_ty(TyFnDef(def_id, self.mk_bare_fn(fty)))
|
||||
}
|
||||
|
||||
pub fn mk_fn_ptr(&self, fty: BareFnTy<'tcx>) -> Ty<'tcx> {
|
||||
self.mk_ty(TyFnPtr(self.mk_bare_fn(fty)))
|
||||
}
|
||||
|
||||
pub fn mk_ctor_fn(&self,
|
||||
|
|
@ -957,7 +959,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
input_tys: &[Ty<'tcx>],
|
||||
output: Ty<'tcx>) -> Ty<'tcx> {
|
||||
let input_args = input_tys.iter().cloned().collect();
|
||||
self.mk_fn(Some(def_id), self.mk_bare_fn(BareFnTy {
|
||||
self.mk_fn_def(def_id, BareFnTy {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
|
|
@ -965,7 +967,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
output: ty::FnConverging(output),
|
||||
variadic: false
|
||||
})
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn mk_trait(&self,
|
||||
|
|
|
|||
|
|
@ -223,8 +223,8 @@ impl<'tcx> ty::TyS<'tcx> {
|
|||
ty::TySlice(_) => "slice".to_string(),
|
||||
ty::TyRawPtr(_) => "*-ptr".to_string(),
|
||||
ty::TyRef(_, _) => "&-ptr".to_string(),
|
||||
ty::TyBareFn(Some(_), _) => format!("fn item"),
|
||||
ty::TyBareFn(None, _) => "fn pointer".to_string(),
|
||||
ty::TyFnDef(..) => format!("fn item"),
|
||||
ty::TyFnPtr(_) => "fn pointer".to_string(),
|
||||
ty::TyTrait(ref inner) => {
|
||||
format!("trait {}", cx.item_path_str(inner.principal_def_id()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ pub fn simplify_type(tcx: &TyCtxt,
|
|||
ty::TyTuple(ref tys) => {
|
||||
Some(TupleSimplifiedType(tys.len()))
|
||||
}
|
||||
ty::TyBareFn(_, ref f) => {
|
||||
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f) => {
|
||||
Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
|
||||
}
|
||||
ty::TyProjection(_) | ty::TyParam(_) => {
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ impl FlagComputation {
|
|||
self.add_tys(&ts[..]);
|
||||
}
|
||||
|
||||
&ty::TyBareFn(_, ref f) => {
|
||||
&ty::TyFnDef(_, ref f) | &ty::TyFnPtr(ref f) => {
|
||||
self.add_fn_sig(&f.sig);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,7 +182,8 @@ fn compute_components<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
|
|||
ty::TyRawPtr(..) | // ...
|
||||
ty::TyRef(..) | // OutlivesReference
|
||||
ty::TyTuple(..) | // ...
|
||||
ty::TyBareFn(..) | // OutlivesFunction (*)
|
||||
ty::TyFnDef(..) | // OutlivesFunction (*)
|
||||
ty::TyFnPtr(_) | // OutlivesFunction (*)
|
||||
ty::TyTrait(..) | // OutlivesObject, OutlivesFragment (*)
|
||||
ty::TyError => {
|
||||
// (*) Bare functions and traits are both binders. In the
|
||||
|
|
|
|||
|
|
@ -568,11 +568,17 @@ pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R,
|
|||
}
|
||||
}
|
||||
|
||||
(&ty::TyBareFn(a_opt_def_id, a_fty), &ty::TyBareFn(b_opt_def_id, b_fty))
|
||||
if a_opt_def_id == b_opt_def_id =>
|
||||
(&ty::TyFnDef(a_def_id, a_fty), &ty::TyFnDef(b_def_id, b_fty))
|
||||
if a_def_id == b_def_id =>
|
||||
{
|
||||
let fty = try!(relation.relate(a_fty, b_fty));
|
||||
Ok(tcx.mk_fn(a_opt_def_id, tcx.mk_bare_fn(fty)))
|
||||
Ok(tcx.mk_fn_def(a_def_id, fty))
|
||||
}
|
||||
|
||||
(&ty::TyFnPtr(a_fty), &ty::TyFnPtr(b_fty)) =>
|
||||
{
|
||||
let fty = try!(relation.relate(a_fty, b_fty));
|
||||
Ok(tcx.mk_fn_ptr(fty))
|
||||
}
|
||||
|
||||
(&ty::TyProjection(ref a_data), &ty::TyProjection(ref b_data)) =>
|
||||
|
|
|
|||
|
|
@ -282,9 +282,13 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
|||
}
|
||||
ty::TyTrait(ref trait_ty) => ty::TyTrait(trait_ty.fold_with(folder)),
|
||||
ty::TyTuple(ref ts) => ty::TyTuple(ts.fold_with(folder)),
|
||||
ty::TyBareFn(opt_def_id, ref f) => {
|
||||
ty::TyFnDef(def_id, ref f) => {
|
||||
let bfn = f.fold_with(folder);
|
||||
ty::TyBareFn(opt_def_id, folder.tcx().mk_bare_fn(bfn))
|
||||
ty::TyFnDef(def_id, folder.tcx().mk_bare_fn(bfn))
|
||||
}
|
||||
ty::TyFnPtr(ref f) => {
|
||||
let bfn = f.fold_with(folder);
|
||||
ty::TyFnPtr(folder.tcx().mk_bare_fn(bfn))
|
||||
}
|
||||
ty::TyRef(r, ref tm) => {
|
||||
let r = r.fold_with(folder);
|
||||
|
|
@ -318,7 +322,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
|||
ty::TyEnum(_tid, ref substs) => substs.visit_with(visitor),
|
||||
ty::TyTrait(ref trait_ty) => trait_ty.visit_with(visitor),
|
||||
ty::TyTuple(ref ts) => ts.visit_with(visitor),
|
||||
ty::TyBareFn(_opt_def_id, ref f) => f.visit_with(visitor),
|
||||
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f) => f.visit_with(visitor),
|
||||
ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor),
|
||||
ty::TyStruct(_did, ref substs) => substs.visit_with(visitor),
|
||||
ty::TyClosure(_did, ref substs) => substs.visit_with(visitor),
|
||||
|
|
|
|||
|
|
@ -127,14 +127,16 @@ pub enum TypeVariants<'tcx> {
|
|||
/// `&a mut T` or `&'a T`.
|
||||
TyRef(&'tcx Region, TypeAndMut<'tcx>),
|
||||
|
||||
/// If the def-id is Some(_), then this is the type of a specific
|
||||
/// fn item. Otherwise, if None(_), it is a fn pointer type.
|
||||
///
|
||||
/// FIXME: Conflating function pointers and the type of a
|
||||
/// function is probably a terrible idea; a function pointer is a
|
||||
/// value with a specific type, but a function can be polymorphic
|
||||
/// or dynamically dispatched.
|
||||
TyBareFn(Option<DefId>, &'tcx BareFnTy<'tcx>),
|
||||
/// The anonymous type of a function declaration/definition. Each
|
||||
/// function has a unique type.
|
||||
/// FIXME: Does this need to include substitutions?
|
||||
/// `g::<i32>` and `g::<u32>` should have different types.
|
||||
TyFnDef(DefId, &'tcx BareFnTy<'tcx>),
|
||||
|
||||
/// A pointer to a function. Written as `fn() -> i32`.
|
||||
/// FIXME: This is currently also used to represent the callee of a method;
|
||||
/// see ty::MethodCallee etc.
|
||||
TyFnPtr(&'tcx BareFnTy<'tcx>),
|
||||
|
||||
/// A trait, defined with `trait`.
|
||||
TyTrait(Box<TraitTy<'tcx>>),
|
||||
|
|
@ -1029,7 +1031,7 @@ impl<'tcx> TyS<'tcx> {
|
|||
match self.sty {
|
||||
TyBool | TyChar | TyInt(_) | TyFloat(_) | TyUint(_) |
|
||||
TyInfer(IntVar(_)) | TyInfer(FloatVar(_)) |
|
||||
TyBareFn(..) | TyRawPtr(_) => true,
|
||||
TyFnDef(..) | TyFnPtr(_) | TyRawPtr(_) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
|
@ -1080,20 +1082,6 @@ impl<'tcx> TyS<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_bare_fn(&self) -> bool {
|
||||
match self.sty {
|
||||
TyBareFn(..) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_bare_fn_item(&self) -> bool {
|
||||
match self.sty {
|
||||
TyBareFn(Some(_), _) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_fp(&self) -> bool {
|
||||
match self.sty {
|
||||
TyInfer(FloatVar(_)) | TyFloat(_) => true,
|
||||
|
|
@ -1154,7 +1142,7 @@ impl<'tcx> TyS<'tcx> {
|
|||
|
||||
pub fn fn_sig(&self) -> &'tcx PolyFnSig<'tcx> {
|
||||
match self.sty {
|
||||
TyBareFn(_, ref f) => &f.sig,
|
||||
TyFnDef(_, ref f) | TyFnPtr(ref f) => &f.sig,
|
||||
_ => panic!("Ty::fn_sig() called on non-fn type: {:?}", self)
|
||||
}
|
||||
}
|
||||
|
|
@ -1162,7 +1150,7 @@ impl<'tcx> TyS<'tcx> {
|
|||
/// Returns the ABI of the given function.
|
||||
pub fn fn_abi(&self) -> abi::Abi {
|
||||
match self.sty {
|
||||
TyBareFn(_, ref f) => f.abi,
|
||||
TyFnDef(_, ref f) | TyFnPtr(ref f) => f.abi,
|
||||
_ => panic!("Ty::fn_abi() called on non-fn type"),
|
||||
}
|
||||
}
|
||||
|
|
@ -1178,7 +1166,7 @@ impl<'tcx> TyS<'tcx> {
|
|||
|
||||
pub fn is_fn(&self) -> bool {
|
||||
match self.sty {
|
||||
TyBareFn(..) => true,
|
||||
TyFnDef(..) | TyFnPtr(_) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
|
@ -1224,7 +1212,8 @@ impl<'tcx> TyS<'tcx> {
|
|||
TyProjection(ref data) => {
|
||||
data.trait_ref.substs.regions().as_slice().to_vec()
|
||||
}
|
||||
TyBareFn(..) |
|
||||
TyFnDef(..) |
|
||||
TyFnPtr(_) |
|
||||
TyBool |
|
||||
TyChar |
|
||||
TyInt(_) |
|
||||
|
|
|
|||
|
|
@ -514,9 +514,16 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
region(state, *r);
|
||||
mt(state, m);
|
||||
}
|
||||
TyBareFn(opt_def_id, ref b) => {
|
||||
TyFnDef(def_id, ref b) => {
|
||||
byte!(14);
|
||||
hash!(opt_def_id);
|
||||
hash!(def_id);
|
||||
hash!(b.unsafety);
|
||||
hash!(b.abi);
|
||||
fn_sig(state, &b.sig);
|
||||
return false;
|
||||
}
|
||||
TyFnPtr(ref b) => {
|
||||
byte!(15);
|
||||
hash!(b.unsafety);
|
||||
hash!(b.abi);
|
||||
fn_sig(state, &b.sig);
|
||||
|
|
@ -677,7 +684,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
|||
// Fast-path for primitive types
|
||||
let result = match self.sty {
|
||||
TyBool | TyChar | TyInt(..) | TyUint(..) | TyFloat(..) |
|
||||
TyRawPtr(..) | TyBareFn(..) | TyRef(_, TypeAndMut {
|
||||
TyRawPtr(..) | TyFnDef(..) | TyFnPtr(_) | TyRef(_, TypeAndMut {
|
||||
mutbl: hir::MutImmutable, ..
|
||||
}) => Some(false),
|
||||
|
||||
|
|
@ -719,7 +726,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
|||
// Fast-path for primitive types
|
||||
let result = match self.sty {
|
||||
TyBool | TyChar | TyInt(..) | TyUint(..) | TyFloat(..) |
|
||||
TyBox(..) | TyRawPtr(..) | TyRef(..) | TyBareFn(..) |
|
||||
TyBox(..) | TyRawPtr(..) | TyRef(..) | TyFnDef(..) | TyFnPtr(_) |
|
||||
TyArray(..) | TyTuple(..) | TyClosure(..) => Some(true),
|
||||
|
||||
TyStr | TyTrait(..) | TySlice(_) => Some(false),
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ fn push_subtypes<'tcx>(stack: &mut Vec<Ty<'tcx>>, parent_ty: Ty<'tcx>) {
|
|||
ty::TyTuple(ref ts) => {
|
||||
push_reversed(stack, ts);
|
||||
}
|
||||
ty::TyBareFn(_, ref ft) => {
|
||||
ty::TyFnDef(_, ref ft) | ty::TyFnPtr(ref ft) => {
|
||||
push_sig_subtypes(stack, &ft.sig);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -354,8 +354,8 @@ impl<'a,'tcx> WfPredicates<'a,'tcx> {
|
|||
// WFedness.)
|
||||
}
|
||||
|
||||
ty::TyBareFn(..) => {
|
||||
// let the loop iterator into the argument/return
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
|
||||
// let the loop iterate into the argument/return
|
||||
// types appearing in the fn signature
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use middle::def_id::DefId;
|
|||
use middle::subst::{self, Subst};
|
||||
use middle::ty::{BrAnon, BrEnv, BrFresh, BrNamed};
|
||||
use middle::ty::{TyBool, TyChar, TyStruct, TyEnum};
|
||||
use middle::ty::{TyError, TyStr, TyArray, TySlice, TyFloat, TyBareFn};
|
||||
use middle::ty::{TyError, TyStr, TyArray, TySlice, TyFloat, TyFnDef, TyFnPtr};
|
||||
use middle::ty::{TyParam, TyRawPtr, TyRef, TyTuple};
|
||||
use middle::ty::TyClosure;
|
||||
use middle::ty::{TyBox, TyTrait, TyInt, TyUint, TyInfer};
|
||||
|
|
@ -812,7 +812,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
|
|||
}
|
||||
write!(f, ")")
|
||||
}
|
||||
TyBareFn(opt_def_id, ref bare_fn) => {
|
||||
TyFnDef(def_id, ref bare_fn) => {
|
||||
if bare_fn.unsafety == hir::Unsafety::Unsafe {
|
||||
try!(write!(f, "unsafe "));
|
||||
}
|
||||
|
|
@ -823,12 +823,20 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
|
|||
|
||||
try!(write!(f, "{}", bare_fn.sig.0));
|
||||
|
||||
if let Some(def_id) = opt_def_id {
|
||||
try!(write!(f, " {{{}}}", ty::tls::with(|tcx| {
|
||||
tcx.item_path_str(def_id)
|
||||
})));
|
||||
write!(f, " {{{}}}", ty::tls::with(|tcx| {
|
||||
tcx.item_path_str(def_id)
|
||||
}))
|
||||
}
|
||||
TyFnPtr(ref bare_fn) => {
|
||||
if bare_fn.unsafety == hir::Unsafety::Unsafe {
|
||||
try!(write!(f, "unsafe "));
|
||||
}
|
||||
Ok(())
|
||||
|
||||
if bare_fn.abi != Abi::Rust {
|
||||
try!(write!(f, "extern {} ", bare_fn.abi));
|
||||
}
|
||||
|
||||
write!(f, "{}", bare_fn.sig.0)
|
||||
}
|
||||
TyInfer(infer_ty) => write!(f, "{}", infer_ty),
|
||||
TyError => write!(f, "[type error]"),
|
||||
|
|
|
|||
|
|
@ -261,16 +261,15 @@ impl<'a, 'tcx> Env<'a, 'tcx> {
|
|||
|
||||
pub fn t_fn(&self, input_tys: &[Ty<'tcx>], output_ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
let input_args = input_tys.iter().cloned().collect();
|
||||
self.infcx.tcx.mk_fn(None,
|
||||
self.infcx.tcx.mk_bare_fn(ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
inputs: input_args,
|
||||
output: ty::FnConverging(output_ty),
|
||||
variadic: false,
|
||||
}),
|
||||
}))
|
||||
self.infcx.tcx.mk_fn_ptr(ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
inputs: input_args,
|
||||
output: ty::FnConverging(output_ty),
|
||||
variadic: false,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn t_nil(&self) -> Ty<'tcx> {
|
||||
|
|
|
|||
|
|
@ -1065,7 +1065,7 @@ impl LateLintPass for MutableTransmutes {
|
|||
}
|
||||
let typ = cx.tcx.node_id_to_type(expr.id);
|
||||
match typ.sty {
|
||||
ty::TyBareFn(_, ref bare_fn) if bare_fn.abi == RustIntrinsic => {
|
||||
ty::TyFnDef(_, ref bare_fn) if bare_fn.abi == RustIntrinsic => {
|
||||
if let ty::FnConverging(to) = bare_fn.sig.0.output {
|
||||
let from = bare_fn.sig.0.inputs[0];
|
||||
return Some((&from.sty, &to.sty));
|
||||
|
|
@ -1079,7 +1079,7 @@ impl LateLintPass for MutableTransmutes {
|
|||
|
||||
fn def_id_is_transmute(cx: &LateContext, def_id: DefId) -> bool {
|
||||
match cx.tcx.lookup_item_type(def_id).ty.sty {
|
||||
ty::TyBareFn(_, ref bfty) if bfty.abi == RustIntrinsic => (),
|
||||
ty::TyFnDef(_, ref bfty) if bfty.abi == RustIntrinsic => (),
|
||||
_ => return false
|
||||
}
|
||||
cx.tcx.with_path(def_id, |path| match path.last() {
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ fn is_repr_nullable_ptr<'tcx>(tcx: &TyCtxt<'tcx>,
|
|||
|
||||
if def.variants[data_idx].fields.len() == 1 {
|
||||
match def.variants[data_idx].fields[0].ty(tcx, substs).sty {
|
||||
ty::TyBareFn(None, _) => { return true; }
|
||||
ty::TyFnPtr(_) => { return true; }
|
||||
ty::TyRef(..) => { return true; }
|
||||
_ => { }
|
||||
}
|
||||
|
|
@ -556,7 +556,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||
self.check_type_for_ffi(cache, ty)
|
||||
}
|
||||
|
||||
ty::TyBareFn(None, bare_fn) => {
|
||||
ty::TyFnPtr(bare_fn) => {
|
||||
match bare_fn.abi {
|
||||
Abi::Rust |
|
||||
Abi::RustIntrinsic |
|
||||
|
|
@ -595,7 +595,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||
|
||||
ty::TyParam(..) | ty::TyInfer(..) | ty::TyError |
|
||||
ty::TyClosure(..) | ty::TyProjection(..) |
|
||||
ty::TyBareFn(Some(_), _) => {
|
||||
ty::TyFnDef(..) => {
|
||||
panic!("Unexpected type in foreign function")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -472,7 +472,7 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
|
|||
variant.name,
|
||||
ctor_ty);
|
||||
let field_tys = match ctor_ty.sty {
|
||||
ty::TyBareFn(_, &ty::BareFnTy { sig: ty::Binder(ty::FnSig {
|
||||
ty::TyFnDef(_, &ty::BareFnTy { sig: ty::Binder(ty::FnSig {
|
||||
ref inputs, ..
|
||||
}), ..}) => {
|
||||
// tuple-struct constructors don't have escaping regions
|
||||
|
|
@ -988,7 +988,7 @@ pub fn get_impl_or_trait_item<'tcx>(intr: Rc<IdentInterner>,
|
|||
let predicates = doc_predicates(item_doc, tcx, cdata, tag_method_ty_generics);
|
||||
let ity = tcx.lookup_item_type(def_id).ty;
|
||||
let fty = match ity.sty {
|
||||
ty::TyBareFn(_, fty) => fty.clone(),
|
||||
ty::TyFnDef(_, fty) => fty.clone(),
|
||||
_ => tcx.sess.bug(&format!(
|
||||
"the type {:?} of the method {:?} is not a function?",
|
||||
ity, name))
|
||||
|
|
@ -1582,7 +1582,8 @@ pub fn is_extern_item(cdata: Cmd, id: DefIndex, tcx: &TyCtxt) -> bool {
|
|||
let ty::TypeScheme { generics, ty } = get_type(cdata, id, tcx);
|
||||
let no_generics = generics.types.is_empty();
|
||||
match ty.sty {
|
||||
ty::TyBareFn(_, fn_ty) if fn_ty.abi != Abi::Rust => return no_generics,
|
||||
ty::TyFnDef(_, fn_ty) | ty::TyFnPtr(fn_ty)
|
||||
if fn_ty.abi != Abi::Rust => return no_generics,
|
||||
_ => no_generics,
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -380,10 +380,10 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
|
|||
}
|
||||
'F' => {
|
||||
let def_id = self.parse_def();
|
||||
return tcx.mk_fn(Some(def_id), tcx.mk_bare_fn(self.parse_bare_fn_ty()));
|
||||
return tcx.mk_fn_def(def_id, self.parse_bare_fn_ty());
|
||||
}
|
||||
'G' => {
|
||||
return tcx.mk_fn(None, tcx.mk_bare_fn(self.parse_bare_fn_ty()));
|
||||
return tcx.mk_fn_ptr(self.parse_bare_fn_ty());
|
||||
}
|
||||
'#' => {
|
||||
// This is a hacky little caching scheme. The idea is that if we encode
|
||||
|
|
|
|||
|
|
@ -135,12 +135,12 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Cursor<Vec<u8>>, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx
|
|||
ty::TyStr => {
|
||||
write!(w, "v");
|
||||
}
|
||||
ty::TyBareFn(Some(def_id), f) => {
|
||||
ty::TyFnDef(def_id, f) => {
|
||||
write!(w, "F");
|
||||
write!(w, "{}|", (cx.ds)(def_id));
|
||||
enc_bare_fn_ty(w, cx, f);
|
||||
}
|
||||
ty::TyBareFn(None, f) => {
|
||||
ty::TyFnPtr(f) => {
|
||||
write!(w, "G");
|
||||
enc_bare_fn_ty(w, cx, f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,7 +239,9 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
|||
}
|
||||
ExprKind::Call { ty, fun, args } => {
|
||||
let diverges = match ty.sty {
|
||||
ty::TyBareFn(_, ref f) => f.sig.0.output.diverges(),
|
||||
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f) => {
|
||||
f.sig.0.output.diverges()
|
||||
}
|
||||
_ => false
|
||||
};
|
||||
let fun = unpack!(block = this.as_operand(block, fun));
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
|
|||
let method = method_callee(cx, self, ty::MethodCall::expr(self.id));
|
||||
|
||||
let sig = match method.ty.sty {
|
||||
ty::TyBareFn(_, fn_ty) => &fn_ty.sig,
|
||||
ty::TyFnDef(_, fn_ty) => &fn_ty.sig,
|
||||
_ => cx.tcx.sess.span_bug(self.span, "type of method is not an fn")
|
||||
};
|
||||
|
||||
|
|
@ -625,7 +625,7 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
|
|||
Def::Struct(def_id) => match cx.tcx.node_id_to_type(expr.id).sty {
|
||||
// A tuple-struct constructor. Should only be reached if not called in the same
|
||||
// expression.
|
||||
ty::TyBareFn(..) => (def_id, ItemKind::Function),
|
||||
ty::TyFnDef(..) => (def_id, ItemKind::Function),
|
||||
// A unit struct which is used as a value. We return a completely different ExprKind
|
||||
// here to account for this special case.
|
||||
ty::TyStruct(adt_def, substs) => return ExprKind::Adt {
|
||||
|
|
@ -640,7 +640,7 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
|
|||
Def::Variant(enum_id, variant_id) => match cx.tcx.node_id_to_type(expr.id).sty {
|
||||
// A variant constructor. Should only be reached if not called in the same
|
||||
// expression.
|
||||
ty::TyBareFn(..) => (variant_id, ItemKind::Function),
|
||||
ty::TyFnDef(..) => (variant_id, ItemKind::Function),
|
||||
// A unit variant, similar special case to the struct case above.
|
||||
ty::TyEnum(adt_def, substs) => {
|
||||
debug_assert!(adt_def.did == enum_id);
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
let func_ty = mir.operand_ty(tcx, func);
|
||||
debug!("check_terminator: call, func_ty={:?}", func_ty);
|
||||
let func_ty = match func_ty.sty {
|
||||
ty::TyBareFn(_, func_ty) => func_ty,
|
||||
ty::TyFnDef(_, func_ty) | ty::TyFnPtr(func_ty) => func_ty,
|
||||
_ => {
|
||||
span_mirbug!(self, term, "call to non-function {:?}", func_ty);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -582,7 +582,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
|
|||
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
|
||||
}
|
||||
Some(Def::Struct(..)) => {
|
||||
if let ty::TyBareFn(..) = node_ty.sty {
|
||||
if let ty::TyFnDef(..) = node_ty.sty {
|
||||
// Count the function pointer.
|
||||
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -857,7 +857,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
|||
if let Def::Struct(..) = self.tcx.resolve_expr(expr) {
|
||||
let expr_ty = self.tcx.expr_ty(expr);
|
||||
let def = match expr_ty.sty {
|
||||
ty::TyBareFn(_, &ty::BareFnTy { sig: ty::Binder(ty::FnSig {
|
||||
ty::TyFnDef(_, &ty::BareFnTy { sig: ty::Binder(ty::FnSig {
|
||||
output: ty::FnConverging(ty), ..
|
||||
}), ..}) => ty,
|
||||
_ => expr_ty
|
||||
|
|
|
|||
|
|
@ -451,8 +451,8 @@ fn find_discr_field_candidate<'tcx>(tcx: &TyCtxt<'tcx>,
|
|||
// Regular thin pointer: &T/&mut T/Box<T>
|
||||
ty::TyRef(..) | ty::TyBox(..) => Some(path),
|
||||
|
||||
// Functions are just pointers
|
||||
ty::TyBareFn(..) => Some(path),
|
||||
// Function pointer: `fn() -> i32`
|
||||
ty::TyFnPtr(_) => Some(path),
|
||||
|
||||
// Is this the NonZero lang item wrapping a pointer or integer type?
|
||||
ty::TyStruct(def, substs) if Some(def.did) == tcx.lang_items.non_zero() => {
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
|
|||
|
||||
let function_type;
|
||||
let (fn_sig, abi, env_ty) = match fn_type.sty {
|
||||
ty::TyBareFn(_, ref f) => (&f.sig, f.abi, None),
|
||||
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f) => (&f.sig, f.abi, None),
|
||||
ty::TyClosure(closure_did, ref substs) => {
|
||||
let infcx = infer::normalizing_infer_ctxt(ccx.tcx(), &ccx.tcx().tables);
|
||||
function_type = infcx.closure_type(closure_did, substs);
|
||||
|
|
@ -162,7 +162,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
|
|||
_ => ccx.sess().bug("expected tuple'd inputs")
|
||||
}
|
||||
},
|
||||
ty::TyBareFn(..) if abi == Abi::RustCall => {
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) if abi == Abi::RustCall => {
|
||||
let mut inputs = vec![fn_sig.inputs[0]];
|
||||
|
||||
match fn_sig.inputs[1].sty {
|
||||
|
|
|
|||
|
|
@ -390,7 +390,7 @@ pub fn compare_scalar_types<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
_ => bcx.sess().bug("compare_scalar_types: must be a comparison operator"),
|
||||
}
|
||||
}
|
||||
ty::TyBareFn(..) | ty::TyBool | ty::TyUint(_) | ty::TyChar => {
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) | ty::TyBool | ty::TyUint(_) | ty::TyChar => {
|
||||
ICmp(bcx,
|
||||
bin_op_to_icmp_predicate(bcx.ccx(), op, false),
|
||||
lhs,
|
||||
|
|
@ -906,7 +906,7 @@ pub fn trans_external_path<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
-> ValueRef {
|
||||
let name = ccx.sess().cstore.item_symbol(did);
|
||||
match t.sty {
|
||||
ty::TyBareFn(_, ref fn_ty) => {
|
||||
ty::TyFnDef(_, ref fn_ty) => {
|
||||
match ccx.sess().target.target.adjust_abi(fn_ty.abi) {
|
||||
Abi::Rust | Abi::RustCall => {
|
||||
get_extern_rust_fn(ccx, t, &name[..], did)
|
||||
|
|
@ -2610,7 +2610,7 @@ fn register_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
node_id: ast::NodeId,
|
||||
node_type: Ty<'tcx>)
|
||||
-> ValueRef {
|
||||
if let ty::TyBareFn(_, ref f) = node_type.sty {
|
||||
if let ty::TyFnDef(_, ref f) = node_type.sty {
|
||||
if f.abi != Abi::Rust && f.abi != Abi::RustCall {
|
||||
ccx.sess().span_bug(sp,
|
||||
&format!("only the `{}` or `{}` calling conventions are valid \
|
||||
|
|
@ -2915,7 +2915,7 @@ fn register_method(ccx: &CrateContext,
|
|||
|
||||
let sym = exported_name(ccx, id, mty, &attrs);
|
||||
|
||||
if let ty::TyBareFn(_, ref f) = mty.sty {
|
||||
if let ty::TyFnDef(_, ref f) = mty.sty {
|
||||
let llfn = if f.abi == Abi::Rust || f.abi == Abi::RustCall {
|
||||
register_fn(ccx, span, sym, id, mty)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &hir::Expr)
|
|||
-> Callee<'blk, 'tcx> {
|
||||
let DatumBlock { bcx, datum, .. } = expr::trans(bcx, expr);
|
||||
match datum.ty.sty {
|
||||
ty::TyBareFn(..) => {
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
|
||||
Callee {
|
||||
bcx: bcx,
|
||||
ty: datum.ty,
|
||||
|
|
@ -157,8 +157,8 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &hir::Expr)
|
|||
}
|
||||
}
|
||||
Def::Fn(did) if match expr_ty.sty {
|
||||
ty::TyBareFn(_, ref f) => f.abi == Abi::RustIntrinsic ||
|
||||
f.abi == Abi::PlatformIntrinsic,
|
||||
ty::TyFnDef(_, ref f) => f.abi == Abi::RustIntrinsic ||
|
||||
f.abi == Abi::PlatformIntrinsic,
|
||||
_ => false
|
||||
} => {
|
||||
let substs = common::node_id_substs(bcx.ccx(),
|
||||
|
|
@ -292,11 +292,16 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
|
|||
// which is the fn pointer, and `args`, which is the arguments tuple.
|
||||
let (opt_def_id, sig) =
|
||||
match bare_fn_ty.sty {
|
||||
ty::TyBareFn(opt_def_id,
|
||||
&ty::BareFnTy { unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
ref sig }) => {
|
||||
(opt_def_id, sig)
|
||||
ty::TyFnDef(def_id,
|
||||
&ty::BareFnTy { unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
ref sig }) => {
|
||||
(Some(def_id), sig)
|
||||
}
|
||||
ty::TyFnPtr(&ty::BareFnTy { unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
ref sig }) => {
|
||||
(None, sig)
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
|
@ -307,16 +312,20 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
|
|||
let sig = tcx.erase_late_bound_regions(sig);
|
||||
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
|
||||
let tuple_input_ty = tcx.mk_tup(sig.inputs.to_vec());
|
||||
let tuple_fn_ty = tcx.mk_fn(opt_def_id,
|
||||
tcx.mk_bare_fn(ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::RustCall,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
inputs: vec![bare_fn_ty_maybe_ref,
|
||||
tuple_input_ty],
|
||||
output: sig.output,
|
||||
variadic: false
|
||||
})}));
|
||||
let bare_tuple_fn = ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::RustCall,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
inputs: vec![bare_fn_ty_maybe_ref,
|
||||
tuple_input_ty],
|
||||
output: sig.output,
|
||||
variadic: false
|
||||
})
|
||||
};
|
||||
let tuple_fn_ty = match opt_def_id {
|
||||
Some(def_id) => tcx.mk_fn_def(def_id, bare_tuple_fn),
|
||||
None => tcx.mk_fn_ptr(bare_tuple_fn),
|
||||
};
|
||||
debug!("tuple_fn_ty: {:?}", tuple_fn_ty);
|
||||
|
||||
//
|
||||
|
|
@ -606,7 +615,7 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
|
|||
let mut bcx = callee.bcx;
|
||||
|
||||
let (abi, ret_ty) = match callee.ty.sty {
|
||||
ty::TyBareFn(_, ref f) => {
|
||||
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f) => {
|
||||
let sig = bcx.tcx().erase_late_bound_regions(&f.sig);
|
||||
let sig = infer::normalize_associated_type(bcx.tcx(), &sig);
|
||||
(f.abi, sig.output)
|
||||
|
|
|
|||
|
|
@ -355,28 +355,31 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
|
|||
// Make a version with the type of by-ref closure.
|
||||
let ty::ClosureTy { unsafety, abi, mut sig } = infcx.closure_type(closure_def_id, &substs);
|
||||
sig.0.inputs.insert(0, ref_closure_ty); // sig has no self type as of yet
|
||||
let llref_bare_fn_ty = tcx.mk_bare_fn(ty::BareFnTy { unsafety: unsafety,
|
||||
abi: abi,
|
||||
sig: sig.clone() });
|
||||
let llref_fn_ty = tcx.mk_fn(None, llref_bare_fn_ty);
|
||||
let llref_fn_ty = tcx.mk_fn_ptr(ty::BareFnTy {
|
||||
unsafety: unsafety,
|
||||
abi: abi,
|
||||
sig: sig.clone()
|
||||
});
|
||||
debug!("trans_fn_once_adapter_shim: llref_fn_ty={:?}",
|
||||
llref_fn_ty);
|
||||
|
||||
let ret_ty = tcx.erase_late_bound_regions(&sig.output());
|
||||
let ret_ty = infer::normalize_associated_type(ccx.tcx(), &ret_ty);
|
||||
|
||||
// Make a version of the closure type with the same arguments, but
|
||||
// with argument #0 being by value.
|
||||
assert_eq!(abi, RustCall);
|
||||
sig.0.inputs[0] = closure_ty;
|
||||
let llonce_bare_fn_ty = tcx.mk_bare_fn(ty::BareFnTy { unsafety: unsafety,
|
||||
abi: abi,
|
||||
sig: sig });
|
||||
let llonce_fn_ty = tcx.mk_fn(None, llonce_bare_fn_ty);
|
||||
let llonce_fn_ty = tcx.mk_fn_ptr(ty::BareFnTy {
|
||||
unsafety: unsafety,
|
||||
abi: abi,
|
||||
sig: sig
|
||||
});
|
||||
|
||||
// Create the by-value helper.
|
||||
let function_name = link::mangle_internal_name_by_type_and_seq(ccx, llonce_fn_ty, "once_shim");
|
||||
let lloncefn = declare::define_internal_rust_fn(ccx, &function_name,
|
||||
llonce_fn_ty);
|
||||
let sig = tcx.erase_late_bound_regions(&llonce_bare_fn_ty.sig);
|
||||
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
|
||||
|
||||
let (block_arena, fcx): (TypedArena<_>, FunctionContext);
|
||||
block_arena = TypedArena::new();
|
||||
|
|
@ -384,11 +387,11 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
|
|||
lloncefn,
|
||||
ast::DUMMY_NODE_ID,
|
||||
false,
|
||||
sig.output,
|
||||
ret_ty,
|
||||
substs.func_substs,
|
||||
None,
|
||||
&block_arena);
|
||||
let mut bcx = init_function(&fcx, false, sig.output);
|
||||
let mut bcx = init_function(&fcx, false, ret_ty);
|
||||
|
||||
let llargs = get_params(fcx.llfn);
|
||||
|
||||
|
|
@ -408,7 +411,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
|
|||
|
||||
let dest =
|
||||
fcx.llretslotptr.get().map(
|
||||
|_| expr::SaveIn(fcx.get_ret_slot(bcx, sig.output, "ret_slot")));
|
||||
|_| expr::SaveIn(fcx.get_ret_slot(bcx, ret_ty, "ret_slot")));
|
||||
|
||||
let callee_data = TraitItem(MethodData { llfn: llreffn,
|
||||
llself: env_datum.val });
|
||||
|
|
@ -423,7 +426,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
|
|||
|
||||
fcx.pop_and_trans_custom_cleanup_scope(bcx, self_scope);
|
||||
|
||||
finish_fn(&fcx, bcx, sig.output, DebugLoc::None);
|
||||
finish_fn(&fcx, bcx, ret_ty, DebugLoc::None);
|
||||
|
||||
lloncefn
|
||||
}
|
||||
|
|
|
|||
|
|
@ -600,13 +600,14 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
|||
def_id: DefId)
|
||||
-> bool {
|
||||
if !match ccx.tcx().lookup_item_type(def_id).ty.sty {
|
||||
ty::TyBareFn(Some(def_id), _) => {
|
||||
// Some constructors also have type TyBareFn but they are
|
||||
ty::TyFnDef(def_id, _) => {
|
||||
// Some constructors also have type TyFnDef but they are
|
||||
// always instantiated inline and don't result in
|
||||
// translation item.
|
||||
// translation item. Same for FFI functions.
|
||||
match ccx.tcx().map.get_if_local(def_id) {
|
||||
Some(hir_map::NodeVariant(_)) |
|
||||
Some(hir_map::NodeStructCtor(_)) => false,
|
||||
Some(hir_map::NodeStructCtor(_)) |
|
||||
Some(hir_map::NodeForeignItem(_)) => false,
|
||||
Some(_) => true,
|
||||
None => {
|
||||
ccx.sess().cstore.variant_kind(def_id).is_none()
|
||||
|
|
@ -697,17 +698,18 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
|
||||
// Finally add the types of nested values
|
||||
match ty.sty {
|
||||
ty::TyBool |
|
||||
ty::TyChar |
|
||||
ty::TyInt(_) |
|
||||
ty::TyUint(_) |
|
||||
ty::TyStr |
|
||||
ty::TyFloat(_) |
|
||||
ty::TyRawPtr(_) |
|
||||
ty::TyRef(..) |
|
||||
ty::TyBareFn(..) |
|
||||
ty::TySlice(_) |
|
||||
ty::TyTrait(_) => {
|
||||
ty::TyBool |
|
||||
ty::TyChar |
|
||||
ty::TyInt(_) |
|
||||
ty::TyUint(_) |
|
||||
ty::TyStr |
|
||||
ty::TyFloat(_) |
|
||||
ty::TyRawPtr(_) |
|
||||
ty::TyRef(..) |
|
||||
ty::TyFnDef(..) |
|
||||
ty::TyFnPtr(_) |
|
||||
ty::TySlice(_) |
|
||||
ty::TyTrait(_) => {
|
||||
/* nothing to do */
|
||||
}
|
||||
ty::TyStruct(ref adt_def, substs) |
|
||||
|
|
@ -1289,7 +1291,8 @@ pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
&trait_data.bounds.projection_bounds,
|
||||
output);
|
||||
},
|
||||
ty::TyBareFn(_, &ty::BareFnTy{ unsafety, abi, ref sig } ) => {
|
||||
ty::TyFnDef(_, &ty::BareFnTy{ unsafety, abi, ref sig } ) |
|
||||
ty::TyFnPtr(&ty::BareFnTy{ unsafety, abi, ref sig } ) => {
|
||||
if unsafety == hir::Unsafety::Unsafe {
|
||||
output.push_str("unsafe ");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1277,7 +1277,7 @@ pub fn inlined_variant_def<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
debug!("inlined_variant_def: ctor_ty={:?} inlined_vid={:?}", ctor_ty,
|
||||
inlined_vid);
|
||||
let adt_def = match ctor_ty.sty {
|
||||
ty::TyBareFn(_, &ty::BareFnTy { sig: ty::Binder(ty::FnSig {
|
||||
ty::TyFnDef(_, &ty::BareFnTy { sig: ty::Binder(ty::FnSig {
|
||||
output: ty::FnConverging(ty), ..
|
||||
}), ..}) => ty,
|
||||
_ => ctor_ty
|
||||
|
|
|
|||
|
|
@ -917,7 +917,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
}
|
||||
}
|
||||
Def::Struct(..) => {
|
||||
if let ty::TyBareFn(..) = ety.sty {
|
||||
if let ty::TyFnDef(..) = ety.sty {
|
||||
// Tuple struct.
|
||||
expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -253,7 +253,8 @@ impl<'tcx> TypeMap<'tcx> {
|
|||
principal.substs,
|
||||
&mut unique_type_id);
|
||||
},
|
||||
ty::TyBareFn(_, &ty::BareFnTy{ unsafety, abi, ref sig } ) => {
|
||||
ty::TyFnDef(_, &ty::BareFnTy{ unsafety, abi, ref sig } ) |
|
||||
ty::TyFnPtr(&ty::BareFnTy{ unsafety, abi, ref sig } ) => {
|
||||
if unsafety == hir::Unsafety::Unsafe {
|
||||
unique_type_id.push_str("unsafe ");
|
||||
}
|
||||
|
|
@ -765,7 +766,7 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
}
|
||||
}
|
||||
}
|
||||
ty::TyBareFn(_, ref barefnty) => {
|
||||
ty::TyFnDef(_, ref barefnty) | ty::TyFnPtr(ref barefnty) => {
|
||||
let fn_metadata = subroutine_type_metadata(cx,
|
||||
unique_type_id,
|
||||
&barefnty.sig,
|
||||
|
|
|
|||
|
|
@ -430,7 +430,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
let fn_type = monomorphize::apply_param_substs(cx.tcx(), param_substs, &fn_type);
|
||||
|
||||
let (sig, abi) = match fn_type.sty {
|
||||
ty::TyBareFn(_, ref barefnty) => {
|
||||
ty::TyFnDef(_, ref barefnty) | ty::TyFnPtr(ref barefnty) => {
|
||||
let sig = cx.tcx().erase_late_bound_regions(&barefnty.sig);
|
||||
let sig = infer::normalize_associated_type(cx.tcx(), &sig);
|
||||
(sig, barefnty.abi)
|
||||
|
|
|
|||
|
|
@ -101,7 +101,8 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
push_item_name(cx, principal.def_id, false, output);
|
||||
push_type_params(cx, principal.substs, output);
|
||||
},
|
||||
ty::TyBareFn(_, &ty::BareFnTy{ unsafety, abi, ref sig } ) => {
|
||||
ty::TyFnDef(_, &ty::BareFnTy{ unsafety, abi, ref sig } ) |
|
||||
ty::TyFnPtr(&ty::BareFnTy{ unsafety, abi, ref sig } ) => {
|
||||
if unsafety == hir::Unsafety::Unsafe {
|
||||
output.push_str("unsafe ");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,8 @@ pub fn declare_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
|
|||
|
||||
let function_type; // placeholder so that the memory ownership works out ok
|
||||
let (sig, abi, env) = match fn_type.sty {
|
||||
ty::TyBareFn(_, ref f) => {
|
||||
ty::TyFnDef(_, f) |
|
||||
ty::TyFnPtr(f) => {
|
||||
(&f.sig, f.abi, None)
|
||||
}
|
||||
ty::TyClosure(closure_did, ref substs) => {
|
||||
|
|
|
|||
|
|
@ -2525,7 +2525,7 @@ fn expr_kind(tcx: &TyCtxt, expr: &hir::Expr) -> ExprKind {
|
|||
hir::ExprPath(..) => {
|
||||
match tcx.resolve_expr(expr) {
|
||||
Def::Struct(..) | Def::Variant(..) => {
|
||||
if let ty::TyBareFn(..) = tcx.node_id_to_type(expr.id).sty {
|
||||
if let ty::TyFnDef(..) = tcx.node_id_to_type(expr.id).sty {
|
||||
// ctor function
|
||||
ExprKind::RvalueDatum
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -262,7 +262,8 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
ccx.tn().val_to_string(llretptr));
|
||||
|
||||
let (fn_abi, fn_sig) = match callee_ty.sty {
|
||||
ty::TyBareFn(_, ref fn_ty) => (fn_ty.abi, &fn_ty.sig),
|
||||
ty::TyFnDef(_, ref fn_ty) |
|
||||
ty::TyFnPtr(ref fn_ty) => (fn_ty.abi, &fn_ty.sig),
|
||||
_ => ccx.sess().bug("trans_native_call called on non-function type")
|
||||
};
|
||||
let fn_sig = ccx.tcx().erase_late_bound_regions(fn_sig);
|
||||
|
|
@ -501,7 +502,8 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) {
|
|||
abi => {
|
||||
let ty = ccx.tcx().node_id_to_type(foreign_item.id);
|
||||
match ty.sty {
|
||||
ty::TyBareFn(_, bft) => gate_simd_ffi(ccx.tcx(), &decl, bft),
|
||||
ty::TyFnDef(_, bft) |
|
||||
ty::TyFnPtr(bft) => gate_simd_ffi(ccx.tcx(), &decl, bft),
|
||||
_ => ccx.tcx().sess.span_bug(foreign_item.span,
|
||||
"foreign fn's sty isn't a bare_fn_ty?")
|
||||
}
|
||||
|
|
@ -552,7 +554,7 @@ pub fn decl_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
let tys = foreign_types_for_fn_ty(ccx, t);
|
||||
let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys);
|
||||
let cconv = match t.sty {
|
||||
ty::TyBareFn(_, ref fn_ty) => {
|
||||
ty::TyFnDef(_, ref fn_ty) | ty::TyFnPtr(ref fn_ty) => {
|
||||
llvm_calling_convention(ccx, fn_ty.abi)
|
||||
}
|
||||
_ => panic!("expected bare fn in decl_rust_fn_with_foreign_abi")
|
||||
|
|
@ -574,7 +576,7 @@ pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext,
|
|||
|
||||
let t = ccx.tcx().node_id_to_type(node_id);
|
||||
let cconv = match t.sty {
|
||||
ty::TyBareFn(_, ref fn_ty) => {
|
||||
ty::TyFnDef(_, ref fn_ty) | ty::TyFnPtr(ref fn_ty) => {
|
||||
llvm_calling_convention(ccx, fn_ty.abi)
|
||||
}
|
||||
_ => panic!("expected bare fn in register_rust_fn_with_foreign_abi")
|
||||
|
|
@ -634,7 +636,7 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
// 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 t.sty {
|
||||
ty::TyBareFn(_, ref f) => {
|
||||
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f)=> {
|
||||
assert!(f.abi != Abi::Rust);
|
||||
assert!(f.abi != Abi::RustIntrinsic);
|
||||
assert!(f.abi != Abi::PlatformIntrinsic);
|
||||
|
|
@ -957,7 +959,7 @@ fn foreign_signature<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
fn foreign_types_for_fn_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
ty: Ty<'tcx>) -> ForeignTypes<'tcx> {
|
||||
let fn_sig = match ty.sty {
|
||||
ty::TyBareFn(_, ref fn_ty) => &fn_ty.sig,
|
||||
ty::TyFnDef(_, ref fn_ty) | ty::TyFnPtr(ref fn_ty) => &fn_ty.sig,
|
||||
_ => ccx.sess().bug("foreign_types_for_fn_ty called on non-function type")
|
||||
};
|
||||
let fn_sig = ccx.tcx().erase_late_bound_regions(fn_sig);
|
||||
|
|
|
|||
|
|
@ -1264,7 +1264,7 @@ fn get_rust_try_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
|
|||
// Define the type up front for the signature of the rust_try function.
|
||||
let tcx = ccx.tcx();
|
||||
let i8p = tcx.mk_mut_ptr(tcx.types.i8);
|
||||
let fn_ty = tcx.mk_bare_fn(ty::BareFnTy {
|
||||
let fn_ty = tcx.mk_fn_ptr(ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Unsafe,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
|
|
@ -1273,9 +1273,8 @@ fn get_rust_try_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
|
|||
variadic: false,
|
||||
}),
|
||||
});
|
||||
let fn_ty = tcx.mk_fn(None, fn_ty);
|
||||
let output = ty::FnOutput::FnConverging(tcx.types.i32);
|
||||
let try_fn_ty = tcx.mk_bare_fn(ty::BareFnTy {
|
||||
let try_fn_ty = ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Unsafe,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
|
|
@ -1283,8 +1282,8 @@ fn get_rust_try_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
|
|||
output: output,
|
||||
variadic: false,
|
||||
}),
|
||||
});
|
||||
let rust_try = gen_fn(fcx, "__rust_try", tcx.mk_fn(None, try_fn_ty), output,
|
||||
};
|
||||
let rust_try = gen_fn(fcx, "__rust_try", tcx.mk_fn_ptr(try_fn_ty), output,
|
||||
trans);
|
||||
*ccx.rust_try_fn().borrow_mut() = Some(rust_try);
|
||||
return rust_try
|
||||
|
|
@ -1353,7 +1352,7 @@ fn generate_filter_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
|
|||
// going on here, all I can say is that there's a few tests cases in
|
||||
// LLVM's test suite which follow this pattern of instructions, so we
|
||||
// just do the same.
|
||||
let filter_fn_ty = tcx.mk_bare_fn(ty::BareFnTy {
|
||||
let filter_fn_ty = tcx.mk_fn_ptr(ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Unsafe,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
|
|
@ -1362,7 +1361,6 @@ fn generate_filter_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
|
|||
variadic: false,
|
||||
}),
|
||||
});
|
||||
let filter_fn_ty = tcx.mk_fn(None, filter_fn_ty);
|
||||
gen_fn(fcx, "__rustc_try_filter", filter_fn_ty, output, &mut |bcx| {
|
||||
let ebp = Call(bcx, frameaddress, &[C_i32(ccx, 1)], None, dloc);
|
||||
let exn = InBoundsGEP(bcx, ebp, &[C_i32(ccx, -20)]);
|
||||
|
|
@ -1373,7 +1371,7 @@ fn generate_filter_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
|
|||
// Conveniently on x86_64 the EXCEPTION_POINTERS handle and base pointer
|
||||
// are passed in as arguments to the filter function, so we just pass
|
||||
// those along.
|
||||
let filter_fn_ty = tcx.mk_bare_fn(ty::BareFnTy {
|
||||
let filter_fn_ty = tcx.mk_fn_ptr(ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Unsafe,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
|
|
@ -1382,7 +1380,6 @@ fn generate_filter_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
|
|||
variadic: false,
|
||||
}),
|
||||
});
|
||||
let filter_fn_ty = tcx.mk_fn(None, filter_fn_ty);
|
||||
gen_fn(fcx, "__rustc_try_filter", filter_fn_ty, output, &mut |bcx| {
|
||||
let exn = llvm::get_param(bcx.fcx.llfn, 0);
|
||||
let rbp = llvm::get_param(bcx.fcx.llfn, 1);
|
||||
|
|
|
|||
|
|
@ -259,8 +259,8 @@ fn trans_monomorphized_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
traits::VtableObject(ref data) => {
|
||||
let idx = traits::get_vtable_index_of_object_method(bcx.tcx(), data, method_id);
|
||||
if let Some(self_expr) = self_expr {
|
||||
if let ty::TyBareFn(_, ref fty) = monomorphize_type(bcx, method_ty).sty {
|
||||
let ty = bcx.tcx().mk_fn(None, opaque_method_ty(bcx.tcx(), fty));
|
||||
if let ty::TyFnDef(_, ref fty) = monomorphize_type(bcx, method_ty).sty {
|
||||
let ty = opaque_method_ty(bcx.tcx(), fty);
|
||||
return trans_trait_callee(bcx, ty, idx, self_expr, arg_cleanup_scope);
|
||||
}
|
||||
}
|
||||
|
|
@ -401,19 +401,19 @@ pub fn trans_object_shim<'a, 'tcx>(
|
|||
}
|
||||
};
|
||||
let fty = monomorphize::apply_param_substs(tcx, &object_substs, &method_ty.fty);
|
||||
let fty = tcx.mk_bare_fn(fty);
|
||||
let method_ty = opaque_method_ty(tcx, fty);
|
||||
debug!("trans_object_shim: fty={:?} method_ty={:?}", fty, method_ty);
|
||||
|
||||
let ret_ty = ccx.tcx().erase_late_bound_regions(&fty.sig.output());
|
||||
let ret_ty = infer::normalize_associated_type(ccx.tcx(), &ret_ty);
|
||||
|
||||
let method_fn_ty = opaque_method_ty(tcx, &fty);
|
||||
let shim_fn_ty = tcx.mk_fn_ptr(fty);
|
||||
debug!("trans_object_shim: shim_fn_ty={:?} method_fn_ty={:?}",
|
||||
shim_fn_ty, method_fn_ty);
|
||||
|
||||
//
|
||||
let shim_fn_ty = tcx.mk_fn(None, fty);
|
||||
let method_bare_fn_ty = tcx.mk_fn(None, method_ty);
|
||||
let function_name = link::mangle_internal_name_by_type_and_seq(ccx, shim_fn_ty, "object_shim");
|
||||
let llfn = declare::define_internal_rust_fn(ccx, &function_name, shim_fn_ty);
|
||||
|
||||
let sig = ccx.tcx().erase_late_bound_regions(&fty.sig);
|
||||
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
|
||||
|
||||
let empty_substs = tcx.mk_substs(Substs::trans_empty());
|
||||
let (block_arena, fcx): (TypedArena<_>, FunctionContext);
|
||||
block_arena = TypedArena::new();
|
||||
|
|
@ -421,11 +421,11 @@ pub fn trans_object_shim<'a, 'tcx>(
|
|||
llfn,
|
||||
ast::DUMMY_NODE_ID,
|
||||
false,
|
||||
sig.output,
|
||||
ret_ty,
|
||||
empty_substs,
|
||||
None,
|
||||
&block_arena);
|
||||
let mut bcx = init_function(&fcx, false, sig.output);
|
||||
let mut bcx = init_function(&fcx, false, ret_ty);
|
||||
|
||||
let llargs = get_params(fcx.llfn);
|
||||
|
||||
|
|
@ -440,7 +440,7 @@ pub fn trans_object_shim<'a, 'tcx>(
|
|||
|
||||
let dest =
|
||||
fcx.llretslotptr.get().map(
|
||||
|_| expr::SaveIn(fcx.get_ret_slot(bcx, sig.output, "ret_slot")));
|
||||
|_| expr::SaveIn(fcx.get_ret_slot(bcx, ret_ty, "ret_slot")));
|
||||
|
||||
debug!("trans_object_shim: method_offset_in_vtable={}",
|
||||
vtable_index);
|
||||
|
|
@ -448,13 +448,13 @@ pub fn trans_object_shim<'a, 'tcx>(
|
|||
bcx = trans_call_inner(bcx,
|
||||
DebugLoc::None,
|
||||
|bcx, _| trans_trait_callee_from_llval(bcx,
|
||||
method_bare_fn_ty,
|
||||
method_fn_ty,
|
||||
vtable_index,
|
||||
llself, llvtable),
|
||||
ArgVals(&llargs[(self_idx + 2)..]),
|
||||
dest).bcx;
|
||||
|
||||
finish_fn(&fcx, bcx, sig.output, DebugLoc::None);
|
||||
finish_fn(&fcx, bcx, ret_ty, DebugLoc::None);
|
||||
|
||||
immediate_rvalue(llfn, shim_fn_ty)
|
||||
}
|
||||
|
|
@ -642,11 +642,11 @@ pub fn get_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
|
||||
/// Replace the self type (&Self or Box<Self>) with an opaque pointer.
|
||||
fn opaque_method_ty<'tcx>(tcx: &TyCtxt<'tcx>, method_ty: &ty::BareFnTy<'tcx>)
|
||||
-> &'tcx ty::BareFnTy<'tcx> {
|
||||
-> Ty<'tcx> {
|
||||
let mut inputs = method_ty.sig.0.inputs.clone();
|
||||
inputs[0] = tcx.mk_mut_ptr(tcx.mk_mach_int(ast::IntTy::I8));
|
||||
|
||||
tcx.mk_bare_fn(ty::BareFnTy {
|
||||
tcx.mk_fn_ptr(ty::BareFnTy {
|
||||
unsafety: method_ty.unsafety,
|
||||
abi: method_ty.abi,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
|
|
|
|||
|
|
@ -37,17 +37,18 @@ enum AbiStyle {
|
|||
|
||||
impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
fn abi_style(&self, fn_ty: Ty<'tcx>) -> AbiStyle {
|
||||
if let ty::TyBareFn(_, ref f) = fn_ty.sty {
|
||||
// We do not translate intrinsics here (they shouldn’t be functions)
|
||||
assert!(f.abi != Abi::RustIntrinsic && f.abi != Abi::PlatformIntrinsic);
|
||||
match fn_ty.sty {
|
||||
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f) => {
|
||||
// We do not translate intrinsics here (they shouldn’t be functions)
|
||||
assert!(f.abi != Abi::RustIntrinsic && f.abi != Abi::PlatformIntrinsic);
|
||||
|
||||
match f.abi {
|
||||
Abi::Rust => AbiStyle::Rust,
|
||||
Abi::RustCall => AbiStyle::RustCall,
|
||||
_ => AbiStyle::Foreign
|
||||
match f.abi {
|
||||
Abi::Rust => AbiStyle::Rust,
|
||||
Abi::RustCall => AbiStyle::RustCall,
|
||||
_ => AbiStyle::Foreign
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unreachable!()
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ pub fn type_of_rust_fn<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
// Given a function type and a count of ty params, construct an llvm type
|
||||
pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>) -> Type {
|
||||
match fty.sty {
|
||||
ty::TyBareFn(_, ref f) => {
|
||||
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f) => {
|
||||
// FIXME(#19925) once fn item types are
|
||||
// zero-sized, we'll need to do something here
|
||||
if f.abi == Abi::Rust || f.abi == Abi::RustCall {
|
||||
|
|
@ -210,7 +210,7 @@ pub fn sizing_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Typ
|
|||
}
|
||||
}
|
||||
|
||||
ty::TyBareFn(..) => Type::i8p(cx),
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) => Type::i8p(cx),
|
||||
|
||||
ty::TyArray(ty, size) => {
|
||||
let llty = sizing_type_of(cx, ty);
|
||||
|
|
@ -415,7 +415,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
|
|||
ty::TySlice(ty) => in_memory_type_of(cx, ty),
|
||||
ty::TyStr | ty::TyTrait(..) => Type::i8(cx),
|
||||
|
||||
ty::TyBareFn(..) => {
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
|
||||
type_of_fn_from_ty(cx, t).ptr_to()
|
||||
}
|
||||
ty::TyTuple(ref tys) if tys.is_empty() => Type::nil(cx),
|
||||
|
|
|
|||
|
|
@ -1636,8 +1636,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
}
|
||||
hir::TyBareFn(ref bf) => {
|
||||
require_c_abi_if_variadic(tcx, &bf.decl, bf.abi, ast_ty.span);
|
||||
let bare_fn = ty_of_bare_fn(this, bf.unsafety, bf.abi, &bf.decl);
|
||||
tcx.mk_fn(None, tcx.mk_bare_fn(bare_fn))
|
||||
tcx.mk_fn_ptr(ty_of_bare_fn(this, bf.unsafety, bf.abi, &bf.decl))
|
||||
}
|
||||
hir::TyPolyTraitRef(ref bounds) => {
|
||||
conv_ty_poly_trait_ref(this, rscope, ast_ty.span, bounds)
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
|
||||
// If the callee is a bare function or a closure, then we're all set.
|
||||
match structurally_resolved_type(fcx, callee_expr.span, adjusted_ty).sty {
|
||||
ty::TyBareFn(..) => {
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
|
||||
fcx.write_autoderef_adjustment(callee_expr.id, autoderefs);
|
||||
return Some(CallStep::Builtin);
|
||||
}
|
||||
|
|
@ -225,7 +225,8 @@ fn confirm_builtin_call<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
|
|||
let error_fn_sig;
|
||||
|
||||
let fn_sig = match callee_ty.sty {
|
||||
ty::TyBareFn(_, &ty::BareFnTy {ref sig, ..}) => {
|
||||
ty::TyFnDef(_, &ty::BareFnTy {ref sig, ..}) |
|
||||
ty::TyFnPtr(&ty::BareFnTy {ref sig, ..}) => {
|
||||
sig
|
||||
}
|
||||
_ => {
|
||||
|
|
|
|||
|
|
@ -141,13 +141,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
}
|
||||
|
||||
match a.sty {
|
||||
ty::TyBareFn(Some(_), a_f) => {
|
||||
ty::TyFnDef(_, a_f) => {
|
||||
// Function items are coercible to any closure
|
||||
// type; function pointers are not (that would
|
||||
// require double indirection).
|
||||
self.coerce_from_fn_item(a, a_f, b)
|
||||
}
|
||||
ty::TyBareFn(None, a_f) => {
|
||||
ty::TyFnPtr(a_f) => {
|
||||
// We permit coercion of fn pointers to drop the
|
||||
// unsafe qualifier.
|
||||
self.coerce_from_fn_pointer(a, a_f, b)
|
||||
|
|
@ -357,7 +357,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
debug!("coerce_from_fn_pointer(a={:?}, b={:?})",
|
||||
a, b);
|
||||
|
||||
if let ty::TyBareFn(None, fn_ty_b) = b.sty {
|
||||
if let ty::TyFnPtr(fn_ty_b) = b.sty {
|
||||
match (fn_ty_a.unsafety, fn_ty_b.unsafety) {
|
||||
(hir::Unsafety::Normal, hir::Unsafety::Unsafe) => {
|
||||
let unsafe_a = self.tcx().safe_to_unsafe_fn_ty(fn_ty_a);
|
||||
|
|
@ -386,8 +386,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
a, b);
|
||||
|
||||
match b.sty {
|
||||
ty::TyBareFn(None, _) => {
|
||||
let a_fn_pointer = self.tcx().mk_fn(None, fn_ty_a);
|
||||
ty::TyFnPtr(_) => {
|
||||
let a_fn_pointer = self.tcx().mk_ty(ty::TyFnPtr(fn_ty_a));
|
||||
try!(self.subtype(a_fn_pointer, b));
|
||||
Ok(Some(AdjustReifyFnPointer))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -276,9 +276,9 @@ pub fn compare_impl_method<'tcx>(tcx: &TyCtxt<'tcx>,
|
|||
// type.
|
||||
|
||||
// Compute skolemized form of impl and trait method tys.
|
||||
let impl_fty = tcx.mk_fn(None, tcx.mk_bare_fn(impl_m.fty.clone()));
|
||||
let impl_fty = tcx.mk_fn_ptr(impl_m.fty.clone());
|
||||
let impl_fty = impl_fty.subst(tcx, impl_to_skol_substs);
|
||||
let trait_fty = tcx.mk_fn(None, tcx.mk_bare_fn(trait_m.fty.clone()));
|
||||
let trait_fty = tcx.mk_fn_ptr(trait_m.fty.clone());
|
||||
let trait_fty = trait_fty.subst(tcx, &trait_to_skol_substs);
|
||||
|
||||
let err = infcx.commit_if_ok(|snapshot| {
|
||||
|
|
@ -296,11 +296,11 @@ pub fn compare_impl_method<'tcx>(tcx: &TyCtxt<'tcx>,
|
|||
impl_m_span,
|
||||
impl_m_body_id,
|
||||
&impl_sig);
|
||||
let impl_fty = tcx.mk_fn(None, tcx.mk_bare_fn(ty::BareFnTy {
|
||||
let impl_fty = tcx.mk_fn_ptr(ty::BareFnTy {
|
||||
unsafety: impl_m.fty.unsafety,
|
||||
abi: impl_m.fty.abi,
|
||||
sig: ty::Binder(impl_sig)
|
||||
}));
|
||||
});
|
||||
debug!("compare_impl_method: impl_fty={:?}",
|
||||
impl_fty);
|
||||
|
||||
|
|
@ -314,11 +314,11 @@ pub fn compare_impl_method<'tcx>(tcx: &TyCtxt<'tcx>,
|
|||
impl_m_span,
|
||||
impl_m_body_id,
|
||||
&trait_sig);
|
||||
let trait_fty = tcx.mk_fn(None, tcx.mk_bare_fn(ty::BareFnTy {
|
||||
let trait_fty = tcx.mk_fn_ptr(ty::BareFnTy {
|
||||
unsafety: trait_m.fty.unsafety,
|
||||
abi: trait_m.fty.abi,
|
||||
sig: ty::Binder(trait_sig)
|
||||
}));
|
||||
});
|
||||
|
||||
debug!("compare_impl_method: trait_fty={:?}",
|
||||
trait_fty);
|
||||
|
|
|
|||
|
|
@ -479,7 +479,7 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'b, 'tcx>(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
ty::TyBareFn(..) => {
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
|
||||
// FIXME(#26656): this type is always destruction-safe, but
|
||||
// it implicitly witnesses Self: Fn, which can be false.
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: &TyCtxt<'tcx>, it: &hir::ForeignItem,
|
|||
abi: Abi,
|
||||
inputs: Vec<ty::Ty<'tcx>>,
|
||||
output: ty::FnOutput<'tcx>) {
|
||||
let fty = tcx.mk_fn(None, tcx.mk_bare_fn(ty::BareFnTy {
|
||||
let def_id = tcx.map.local_def_id(it.id);
|
||||
let fty = tcx.mk_fn_def(def_id, ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Unsafe,
|
||||
abi: abi,
|
||||
sig: ty::Binder(FnSig {
|
||||
|
|
@ -41,8 +42,8 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: &TyCtxt<'tcx>, it: &hir::ForeignItem,
|
|||
output: output,
|
||||
variadic: false,
|
||||
}),
|
||||
}));
|
||||
let i_ty = tcx.lookup_item_type(tcx.map.local_def_id(it.id));
|
||||
});
|
||||
let i_ty = tcx.lookup_item_type(def_id);
|
||||
let i_n_tps = i_ty.generics.types.len(subst::FnSpace);
|
||||
if i_n_tps != n_tps {
|
||||
span_err!(tcx.sess, it.span, E0094,
|
||||
|
|
@ -296,8 +297,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &hir::ForeignItem) {
|
|||
variadic: false,
|
||||
}),
|
||||
};
|
||||
let fn_ty = tcx.mk_bare_fn(fn_ty);
|
||||
(0, vec![tcx.mk_fn(None, fn_ty), mut_u8, mut_u8], tcx.types.i32)
|
||||
(0, vec![tcx.mk_fn_ptr(fn_ty), mut_u8, mut_u8], tcx.types.i32)
|
||||
}
|
||||
|
||||
ref other => {
|
||||
|
|
|
|||
|
|
@ -105,11 +105,11 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
|
|||
|
||||
// Create the method type
|
||||
let method_ty = pick.item.as_opt_method().unwrap();
|
||||
let fty = self.tcx().mk_fn(None, self.tcx().mk_bare_fn(ty::BareFnTy {
|
||||
let fty = self.tcx().mk_fn_ptr(ty::BareFnTy {
|
||||
sig: ty::Binder(method_sig),
|
||||
unsafety: method_ty.fty.unsafety,
|
||||
abi: method_ty.fty.abi.clone(),
|
||||
}));
|
||||
});
|
||||
|
||||
// Add any trait/regions obligations specified on the method's type parameters.
|
||||
self.add_obligations(fty, &all_substs, &method_predicates);
|
||||
|
|
@ -457,7 +457,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
|
|||
fn fixup_derefs_on_method_receiver_if_necessary(&self,
|
||||
method_callee: &ty::MethodCallee) {
|
||||
let sig = match method_callee.ty.sty {
|
||||
ty::TyBareFn(_, ref f) => f.sig.clone(),
|
||||
ty::TyFnPtr(ref f) => f.sig.clone(),
|
||||
_ => return,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -230,11 +230,11 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
&method_ty.fty.sig).0;
|
||||
let fn_sig = fcx.instantiate_type_scheme(span, trait_ref.substs, &fn_sig);
|
||||
let transformed_self_ty = fn_sig.inputs[0];
|
||||
let fty = tcx.mk_fn(None, tcx.mk_bare_fn(ty::BareFnTy {
|
||||
let fty = tcx.mk_fn_ptr(ty::BareFnTy {
|
||||
sig: ty::Binder(fn_sig),
|
||||
unsafety: method_ty.fty.unsafety,
|
||||
abi: method_ty.fty.abi.clone(),
|
||||
}));
|
||||
});
|
||||
|
||||
debug!("lookup_in_trait_adjusted: matched method fty={:?} obligation={:?}",
|
||||
fty,
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
match field_ty.sty {
|
||||
// Not all of these (e.g. unsafe fns) implement FnOnce
|
||||
// so we look for these beforehand
|
||||
ty::TyClosure(..) | ty::TyBareFn(..) => {
|
||||
ty::TyClosure(..) | ty::TyFnDef(..) | ty::TyFnPtr(_) => {
|
||||
span_stored_function!();
|
||||
}
|
||||
// If it's not a simple function, look for things which implement FnOnce
|
||||
|
|
|
|||
|
|
@ -434,7 +434,7 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
param_env: ty::ParameterEnvironment<'a, 'tcx>)
|
||||
{
|
||||
match raw_fty.sty {
|
||||
ty::TyBareFn(_, ref fn_ty) => {
|
||||
ty::TyFnDef(_, ref fn_ty) => {
|
||||
let tables = RefCell::new(ty::Tables::empty());
|
||||
let inh = Inherited::new(ccx.tcx, &tables, param_env);
|
||||
|
||||
|
|
@ -2340,7 +2340,7 @@ fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
ty::FnConverging(fcx.tcx().types.err)
|
||||
} else {
|
||||
match method_fn_ty.sty {
|
||||
ty::TyBareFn(_, ref fty) => {
|
||||
ty::TyFnPtr(ref fty) => {
|
||||
// HACK(eddyb) ignore self in the definition (see above).
|
||||
let expected_arg_tys = expected_types_for_fn_args(fcx,
|
||||
sp,
|
||||
|
|
@ -2619,7 +2619,7 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
ty::TyInt(_) | ty::TyUint(_) => Some(ty),
|
||||
ty::TyChar => Some(tcx.types.u8),
|
||||
ty::TyRawPtr(..) => Some(tcx.types.usize),
|
||||
ty::TyBareFn(..) => Some(tcx.types.usize),
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) => Some(tcx.types.usize),
|
||||
_ => None
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -881,7 +881,7 @@ fn constrain_callee(rcx: &mut Rcx,
|
|||
_callee_expr: &hir::Expr) {
|
||||
let callee_ty = rcx.resolve_node_type(callee_id);
|
||||
match callee_ty.sty {
|
||||
ty::TyBareFn(..) => { }
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) => { }
|
||||
_ => {
|
||||
// this should not happen, but it does if the program is
|
||||
// erroneous
|
||||
|
|
|
|||
|
|
@ -255,9 +255,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
let type_scheme = fcx.tcx().lookup_item_type(fcx.tcx().map.local_def_id(item.id));
|
||||
let item_ty = fcx.instantiate_type_scheme(item.span, free_substs, &type_scheme.ty);
|
||||
let bare_fn_ty = match item_ty.sty {
|
||||
ty::TyBareFn(_, ref bare_fn_ty) => bare_fn_ty,
|
||||
ty::TyFnDef(_, ref bare_fn_ty) => bare_fn_ty,
|
||||
_ => {
|
||||
this.tcx().sess.span_bug(item.span, "Fn item without bare fn type");
|
||||
this.tcx().sess.span_bug(item.span, "Fn item without fn type");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use middle::ty::{Ty, TyBool, TyChar, TyEnum, TyError};
|
|||
use middle::ty::{TyParam, TyRawPtr};
|
||||
use middle::ty::{TyRef, TyStruct, TyTrait, TyTuple};
|
||||
use middle::ty::{TyStr, TyArray, TySlice, TyFloat, TyInfer, TyInt};
|
||||
use middle::ty::{TyUint, TyClosure, TyBox, TyBareFn};
|
||||
use middle::ty::{TyUint, TyClosure, TyBox, TyFnDef, TyFnPtr};
|
||||
use middle::ty::TyProjection;
|
||||
use middle::ty::util::CopyImplementationError;
|
||||
use middle::free_region::FreeRegionMap;
|
||||
|
|
@ -67,8 +67,8 @@ fn get_base_type_def_id<'a, 'tcx>(inference_context: &InferCtxt<'a, 'tcx>,
|
|||
}
|
||||
|
||||
TyBool | TyChar | TyInt(..) | TyUint(..) | TyFloat(..) |
|
||||
TyStr | TyArray(..) | TySlice(..) | TyBareFn(..) | TyTuple(..) |
|
||||
TyParam(..) | TyError |
|
||||
TyStr | TyArray(..) | TySlice(..) | TyFnDef(..) | TyFnPtr(_) |
|
||||
TyTuple(..) | TyParam(..) | TyError |
|
||||
TyRawPtr(_) | TyRef(_, _) | TyProjection(..) => {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -552,8 +552,7 @@ fn convert_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
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 {
|
||||
|
|
@ -1436,7 +1435,7 @@ fn compute_type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'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) => {
|
||||
|
|
@ -1556,7 +1555,9 @@ fn compute_type_scheme_of_foreign_item<'a, 'tcx>(
|
|||
{
|
||||
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 {
|
||||
|
|
@ -2107,6 +2108,7 @@ fn conv_param_bounds<'a,'tcx>(astconv: &AstConv<'tcx>,
|
|||
|
||||
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)
|
||||
|
|
@ -2140,14 +2142,13 @@ fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -72,7 +72,8 @@ fn parameters_for_type_shallow<'tcx>(ty: Ty<'tcx>) -> Vec<Parameter> {
|
|||
parameters_for_regions_in_substs(&pi.trait_ref.substs),
|
||||
ty::TyBool | ty::TyChar | ty::TyInt(..) | ty::TyUint(..) |
|
||||
ty::TyFloat(..) | ty::TyBox(..) | ty::TyStr |
|
||||
ty::TyArray(..) | ty::TySlice(..) | ty::TyBareFn(..) |
|
||||
ty::TyArray(..) | ty::TySlice(..) |
|
||||
ty::TyFnDef(..) | ty::TyFnPtr(_) |
|
||||
ty::TyTuple(..) | ty::TyRawPtr(..) |
|
||||
ty::TyInfer(..) | ty::TyClosure(..) | ty::TyError =>
|
||||
vec![]
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
|
|||
let tcx = ccx.tcx;
|
||||
let main_t = tcx.node_id_to_type(main_id);
|
||||
match main_t.sty {
|
||||
ty::TyBareFn(..) => {
|
||||
ty::TyFnDef(..) => {
|
||||
match tcx.map.find(main_id) {
|
||||
Some(hir_map::NodeItem(it)) => {
|
||||
match it.node {
|
||||
|
|
@ -236,7 +236,7 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
|
|||
_ => ()
|
||||
}
|
||||
let main_def_id = tcx.map.local_def_id(main_id);
|
||||
let se_ty = tcx.mk_fn(Some(main_def_id), tcx.mk_bare_fn(ty::BareFnTy {
|
||||
let se_ty = tcx.mk_fn_def(main_def_id, ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
|
|
@ -244,7 +244,7 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
|
|||
output: ty::FnConverging(tcx.mk_nil()),
|
||||
variadic: false
|
||||
})
|
||||
}));
|
||||
});
|
||||
|
||||
require_same_types(tcx, None, false, main_span, main_t, se_ty,
|
||||
|| {
|
||||
|
|
@ -266,7 +266,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
|
|||
let tcx = ccx.tcx;
|
||||
let start_t = tcx.node_id_to_type(start_id);
|
||||
match start_t.sty {
|
||||
ty::TyBareFn(..) => {
|
||||
ty::TyFnDef(..) => {
|
||||
match tcx.map.find(start_id) {
|
||||
Some(hir_map::NodeItem(it)) => {
|
||||
match it.node {
|
||||
|
|
@ -282,8 +282,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
|
|||
_ => ()
|
||||
}
|
||||
|
||||
let se_ty = tcx.mk_fn(Some(ccx.tcx.map.local_def_id(start_id)),
|
||||
tcx.mk_bare_fn(ty::BareFnTy {
|
||||
let se_ty = tcx.mk_fn_def(ccx.tcx.map.local_def_id(start_id), ty::BareFnTy {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
sig: ty::Binder(ty::FnSig {
|
||||
|
|
@ -294,7 +293,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
|
|||
output: ty::FnConverging(tcx.types.isize),
|
||||
variadic: false,
|
||||
}),
|
||||
}));
|
||||
});
|
||||
|
||||
require_same_types(tcx, None, false, start_span, start_t, se_ty,
|
||||
|| {
|
||||
|
|
|
|||
|
|
@ -429,7 +429,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
ty::TyBareFn(_, &ty::BareFnTy { ref sig, .. }) => {
|
||||
ty::TyFnDef(_, &ty::BareFnTy { ref sig, .. }) |
|
||||
ty::TyFnPtr(&ty::BareFnTy { ref sig, .. }) => {
|
||||
self.add_constraints_from_sig(generics, sig, variance);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ pub fn build_external_trait(cx: &DocContext, tcx: &TyCtxt,
|
|||
fn build_external_function(cx: &DocContext, tcx: &TyCtxt, did: DefId) -> clean::Function {
|
||||
let t = tcx.lookup_item_type(did);
|
||||
let (decl, style, abi) = match t.ty.sty {
|
||||
ty::TyBareFn(_, ref f) => ((did, &f.sig).clean(cx), f.unsafety, f.abi),
|
||||
ty::TyFnDef(_, ref f) => ((did, &f.sig).clean(cx), f.unsafety, f.abi),
|
||||
_ => panic!("bad function"),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1663,7 +1663,8 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
|
|||
mutability: mt.mutbl.clean(cx),
|
||||
type_: box mt.ty.clean(cx),
|
||||
},
|
||||
ty::TyBareFn(_, ref fty) => BareFunction(box BareFunctionDecl {
|
||||
ty::TyFnDef(_, ref fty) |
|
||||
ty::TyFnPtr(ref fty) => BareFunction(box BareFunctionDecl {
|
||||
unsafety: fty.unsafety,
|
||||
generics: Generics {
|
||||
lifetimes: Vec::new(),
|
||||
|
|
|
|||
|
|
@ -14,26 +14,26 @@ pub mod testtypes {
|
|||
use std::any::TypeId;
|
||||
|
||||
pub fn type_ids() -> Vec<TypeId> {
|
||||
let mut ids = vec!();
|
||||
ids.push(TypeId::of::<FooNil>());
|
||||
ids.push(TypeId::of::<FooBool>());
|
||||
ids.push(TypeId::of::<FooInt>());
|
||||
ids.push(TypeId::of::<FooUint>());
|
||||
ids.push(TypeId::of::<FooFloat>());
|
||||
ids.push(TypeId::of::<FooEnum>());
|
||||
ids.push(TypeId::of::<FooUniq>());
|
||||
ids.push(TypeId::of::<FooPtr>());
|
||||
ids.push(TypeId::of::<&'static FooTrait>());
|
||||
ids.push(TypeId::of::<FooStruct>());
|
||||
ids.push(TypeId::of::<FooTuple>());
|
||||
ids
|
||||
vec![
|
||||
TypeId::of::<FooBool>(),
|
||||
TypeId::of::<FooInt>(),
|
||||
TypeId::of::<FooUint>(),
|
||||
TypeId::of::<FooFloat>(),
|
||||
TypeId::of::<FooStr>(),
|
||||
TypeId::of::<FooArray>(),
|
||||
TypeId::of::<FooSlice>(),
|
||||
TypeId::of::<FooBox>(),
|
||||
TypeId::of::<FooPtr>(),
|
||||
TypeId::of::<FooRef>(),
|
||||
TypeId::of::<FooFnPtr>(),
|
||||
TypeId::of::<FooNil>(),
|
||||
TypeId::of::<FooTuple>(),
|
||||
TypeId::of::<FooTrait>(),
|
||||
TypeId::of::<FooStruct>(),
|
||||
TypeId::of::<FooEnum>()
|
||||
]
|
||||
}
|
||||
|
||||
// Tests ty_nil
|
||||
pub type FooNil = ();
|
||||
|
||||
// Skipping ty_bot
|
||||
|
||||
// Tests TyBool
|
||||
pub type FooBool = bool;
|
||||
|
||||
|
|
@ -49,25 +49,26 @@ pub mod testtypes {
|
|||
// Tests TyFloat (does not test all variants of FloatTy)
|
||||
pub type FooFloat = f64;
|
||||
|
||||
// For TyStr, what kind of string should I use? &'static str? String? Raw str?
|
||||
// Tests TyStr
|
||||
pub type FooStr = str;
|
||||
|
||||
// Tests TyEnum
|
||||
pub enum FooEnum {
|
||||
VarA(usize),
|
||||
VarB(usize, usize)
|
||||
}
|
||||
// Tests TyArray
|
||||
pub type FooArray = [u8; 1];
|
||||
|
||||
// Tests TySlice
|
||||
pub type FooSlice = [u8];
|
||||
|
||||
// Tests TyBox (of u8)
|
||||
pub type FooUniq = Box<u8>;
|
||||
|
||||
// As with TyStr, what type should be used for TyArray?
|
||||
pub type FooBox = Box<u8>;
|
||||
|
||||
// Tests TyRawPtr
|
||||
pub type FooPtr = *const u8;
|
||||
|
||||
// Skipping TyRef
|
||||
// Tests TyRef
|
||||
pub type FooRef = &'static u8;
|
||||
|
||||
// Skipping TyBareFn (how do you get a bare function type, rather than proc or closure?)
|
||||
// Tests TyFnPtr
|
||||
pub type FooFnPtr = fn(u8) -> bool;
|
||||
|
||||
// Tests TyTrait
|
||||
pub trait FooTrait {
|
||||
|
|
@ -80,14 +81,17 @@ pub mod testtypes {
|
|||
foo_field: usize
|
||||
}
|
||||
|
||||
// Tests TyEnum
|
||||
pub enum FooEnum {
|
||||
VarA(usize),
|
||||
VarB(usize, usize)
|
||||
}
|
||||
|
||||
// Tests TyTuple
|
||||
pub type FooNil = ();
|
||||
pub type FooTuple = (u8, i8, bool);
|
||||
|
||||
// Skipping ty_param
|
||||
|
||||
// Skipping ty_self
|
||||
|
||||
// Skipping ty_self
|
||||
// Skipping TyParam
|
||||
|
||||
// Skipping TyInfer
|
||||
|
||||
|
|
|
|||
16
src/test/compile-fail/invalid-intrinsic.rs
Normal file
16
src/test/compile-fail/invalid-intrinsic.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(intrinsics)]
|
||||
extern "rust-intrinsic" {
|
||||
pub static breakpoint : unsafe extern "rust-intrinsic" fn();
|
||||
//~^ ERROR intrinsic has wrong type
|
||||
}
|
||||
fn main() { unsafe { breakpoint(); } }
|
||||
|
|
@ -22,7 +22,7 @@ fn main() {
|
|||
let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
|
||||
//~^ ERROR: mismatched types
|
||||
//~| expected `unsafe extern "C" fn(isize, u8)`
|
||||
//~| found `unsafe extern "C" fn(isize, u8, ...)`
|
||||
//~| found `unsafe extern "C" fn(isize, u8, ...) {foo}`
|
||||
//~| expected non-variadic fn
|
||||
//~| found variadic function
|
||||
|
||||
|
|
|
|||
|
|
@ -19,23 +19,29 @@ use issue13507::testtypes;
|
|||
use std::any::TypeId;
|
||||
|
||||
pub fn type_ids() -> Vec<TypeId> {
|
||||
let mut ids = vec!();
|
||||
ids.push(TypeId::of::<testtypes::FooNil>());
|
||||
ids.push(TypeId::of::<testtypes::FooBool>());
|
||||
ids.push(TypeId::of::<testtypes::FooInt>());
|
||||
ids.push(TypeId::of::<testtypes::FooUint>());
|
||||
ids.push(TypeId::of::<testtypes::FooFloat>());
|
||||
ids.push(TypeId::of::<testtypes::FooEnum>());
|
||||
ids.push(TypeId::of::<testtypes::FooUniq>());
|
||||
ids.push(TypeId::of::<testtypes::FooPtr>());
|
||||
ids.push(TypeId::of::<&'static testtypes::FooTrait>());
|
||||
ids.push(TypeId::of::<testtypes::FooStruct>());
|
||||
ids.push(TypeId::of::<testtypes::FooTuple>());
|
||||
ids
|
||||
use issue13507::testtypes::*;
|
||||
vec![
|
||||
TypeId::of::<FooBool>(),
|
||||
TypeId::of::<FooInt>(),
|
||||
TypeId::of::<FooUint>(),
|
||||
TypeId::of::<FooFloat>(),
|
||||
TypeId::of::<FooStr>(),
|
||||
TypeId::of::<FooArray>(),
|
||||
TypeId::of::<FooSlice>(),
|
||||
TypeId::of::<FooBox>(),
|
||||
TypeId::of::<FooPtr>(),
|
||||
TypeId::of::<FooRef>(),
|
||||
TypeId::of::<FooFnPtr>(),
|
||||
TypeId::of::<FooNil>(),
|
||||
TypeId::of::<FooTuple>(),
|
||||
TypeId::of::<FooTrait>(),
|
||||
TypeId::of::<FooStruct>(),
|
||||
TypeId::of::<FooEnum>()
|
||||
]
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let othercrate = testtypes::type_ids();
|
||||
let othercrate = issue13507::testtypes::type_ids();
|
||||
let thiscrate = type_ids();
|
||||
assert_eq!(thiscrate, othercrate);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue