Skip to content

Split TyBareFn into TyFnDef and TyFnPtr. #26284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
@@ -719,7 +719,7 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
item, tcx, cdata);
let name = item_name(&*intr, item);
let (ctor_ty, arg_tys, arg_names) = match ctor_ty.sty {
ty::TyBareFn(_, ref f) =>
ty::TyFnDef(_, ref f) =>
(Some(ctor_ty), f.sig.0.inputs.clone(), None),
_ => { // Nullary or struct enum variant.
let mut arg_names = Vec::new();
4 changes: 2 additions & 2 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
@@ -123,12 +123,12 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
ty::TyStr => {
mywrite!(w, "v");
}
ty::TyBareFn(Some(def_id), f) => {
ty::TyFnDef(def_id, f) => {
mywrite!(w, "F");
mywrite!(w, "{}|", (cx.ds)(def_id));
enc_bare_fn_ty(w, cx, f);
}
ty::TyBareFn(None, f) => {
ty::TyFnPtr(f) => {
mywrite!(w, "G");
enc_bare_fn_ty(w, cx, f);
}
4 changes: 3 additions & 1 deletion src/librustc/middle/cast.rs
Original file line number Diff line number Diff line change
@@ -70,7 +70,9 @@ impl<'tcx> CastTy<'tcx> {
tcx, t) => 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,
}
}
2 changes: 1 addition & 1 deletion src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
@@ -612,7 +612,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
}
Some(def::DefStruct(_)) => {
if let ty::TyBareFn(..) = node_ty.sty {
if let ty::TyFnDef(..) = node_ty.sty {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TyFnPtr too.

// Count the function pointer.
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
}
3 changes: 2 additions & 1 deletion src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
@@ -31,7 +31,8 @@ enum UnsafeContext {

fn type_is_unsafe_function(ty: Ty) -> bool {
match ty.sty {
ty::TyBareFn(_, ref f) => f.unsafety == ast::Unsafety::Unsafe,
ty::TyFnDef(_, ref f) |
ty::TyFnPtr(ref f) => f.unsafety == ast::Unsafety::Unsafe,
_ => false,
}
}
2 changes: 1 addition & 1 deletion src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
@@ -622,7 +622,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
callee.repr(self.tcx()), callee_ty.repr(self.tcx()));
let call_scope = region::CodeExtent::from_node_id(call.id);
match callee_ty.sty {
ty::TyBareFn(..) => {
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
self.consume_expr(callee);
}
ty::TyError => { }
2 changes: 1 addition & 1 deletion src/librustc/middle/fast_reject.rs
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ pub fn simplify_type(tcx: &ty::ctxt,
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(_) => {
3 changes: 2 additions & 1 deletion src/librustc/middle/implicator.rs
Original file line number Diff line number Diff line change
@@ -93,7 +93,8 @@ impl<'a, 'tcx> Implicator<'a, 'tcx> {
ty::TyInt(..) |
ty::TyUint(..) |
ty::TyFloat(..) |
ty::TyBareFn(..) |
ty::TyFnDef(..) |
ty::TyFnPtr(..) |
ty::TyError |
ty::TyStr => {
// No borrowed content reachable here.
3 changes: 2 additions & 1 deletion src/librustc/middle/infer/freshen.rs
Original file line number Diff line number Diff line change
@@ -162,7 +162,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(..) |
6 changes: 3 additions & 3 deletions src/librustc/middle/intrinsicck.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ use ast_map::NodeForeignItem;
use metadata::csearch;
use middle::def::DefFn;
use middle::subst::{Subst, Substs, EnumeratedItems};
use middle::ty::{TransmuteRestriction, ctxt, TyBareFn};
use middle::ty::{TransmuteRestriction, ctxt};
use middle::ty::{self, Ty};
use util::ppaux::Repr;

@@ -54,7 +54,7 @@ struct IntrinsicCheckingVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
fn def_id_is_transmute(&self, def_id: DefId) -> bool {
let intrinsic = match ty::lookup_item_type(self.tcx, def_id).ty.sty {
ty::TyBareFn(_, ref bfty) => bfty.abi == RustIntrinsic,
ty::TyFnDef(_, ref bfty) => bfty.abi == RustIntrinsic,
_ => return false
};
if def_id.krate == ast::LOCAL_CRATE {
@@ -256,7 +256,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> {
DefFn(did, _) if self.def_id_is_transmute(did) => {
let typ = ty::node_id_to_type(self.tcx, 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);
3 changes: 2 additions & 1 deletion src/librustc/middle/traits/coherence.rs
Original file line number Diff line number Diff line change
@@ -304,7 +304,8 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>,
ty::TyUint(..) |
ty::TyFloat(..) |
ty::TyStr(..) |
ty::TyBareFn(..) |
ty::TyFnDef(..) |
ty::TyFnPtr(_) |
ty::TyArray(..) |
ty::TySlice(..) |
ty::TyRawPtr(..) |
17 changes: 14 additions & 3 deletions src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
@@ -1185,7 +1185,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: ast::Unsafety::Normal,
abi: abi::Rust,
sig: ty::Binder(ty::FnSig {
inputs: _,
output: ty::FnConverging(_),
variadic: false
})
}) |
ty::TyFnPtr(&ty::BareFnTy {
unsafety: ast::Unsafety::Normal,
abi: abi::Rust,
sig: ty::Binder(ty::FnSig {
@@ -1585,7 +1594,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())
@@ -1807,7 +1817,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(_)) |
Loading