Skip to content

Commit 134388e

Browse files
committed
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.
1 parent b850046 commit 134388e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+200
-134
lines changed

src/librustc/metadata/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
719719
item, tcx, cdata);
720720
let name = item_name(&*intr, item);
721721
let (ctor_ty, arg_tys, arg_names) = match ctor_ty.sty {
722-
ty::TyBareFn(_, ref f) =>
722+
ty::TyFnDef(_, ref f) =>
723723
(Some(ctor_ty), f.sig.0.inputs.clone(), None),
724724
_ => { // Nullary or struct enum variant.
725725
let mut arg_names = Vec::new();

src/librustc/metadata/tyencode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
123123
ty::TyStr => {
124124
mywrite!(w, "v");
125125
}
126-
ty::TyBareFn(Some(def_id), f) => {
126+
ty::TyFnDef(def_id, f) => {
127127
mywrite!(w, "F");
128128
mywrite!(w, "{}|", (cx.ds)(def_id));
129129
enc_bare_fn_ty(w, cx, f);
130130
}
131-
ty::TyBareFn(None, f) => {
131+
ty::TyFnPtr(f) => {
132132
mywrite!(w, "G");
133133
enc_bare_fn_ty(w, cx, f);
134134
}

src/librustc/middle/cast.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ impl<'tcx> CastTy<'tcx> {
7070
tcx, t) => Some(CastTy::Int(IntTy::CEnum)),
7171
ty::TyRawPtr(ref mt) => Some(CastTy::Ptr(mt)),
7272
ty::TyRef(_, ref mt) => Some(CastTy::RPtr(mt)),
73-
ty::TyBareFn(..) => Some(CastTy::FnPtr),
73+
// FIXME: Treating TyFnDef as a pointer here is a bit dubious;
74+
// we should be coercing the operand to an actual pointer.
75+
ty::TyFnDef(..) | ty::TyFnPtr(..) => Some(CastTy::FnPtr),
7476
_ => None,
7577
}
7678
}

src/librustc/middle/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
612612
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
613613
}
614614
Some(def::DefStruct(_)) => {
615-
if let ty::TyBareFn(..) = node_ty.sty {
615+
if let ty::TyFnDef(..) = node_ty.sty {
616616
// Count the function pointer.
617617
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
618618
}

src/librustc/middle/effect.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ enum UnsafeContext {
3131

3232
fn type_is_unsafe_function(ty: Ty) -> bool {
3333
match ty.sty {
34-
ty::TyBareFn(_, ref f) => f.unsafety == ast::Unsafety::Unsafe,
34+
ty::TyFnDef(_, ref f) |
35+
ty::TyFnPtr(ref f) => f.unsafety == ast::Unsafety::Unsafe,
3536
_ => false,
3637
}
3738
}

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
622622
callee.repr(self.tcx()), callee_ty.repr(self.tcx()));
623623
let call_scope = region::CodeExtent::from_node_id(call.id);
624624
match callee_ty.sty {
625-
ty::TyBareFn(..) => {
625+
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
626626
self.consume_expr(callee);
627627
}
628628
ty::TyError => { }

src/librustc/middle/fast_reject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn simplify_type(tcx: &ty::ctxt,
8080
ty::TyTuple(ref tys) => {
8181
Some(TupleSimplifiedType(tys.len()))
8282
}
83-
ty::TyBareFn(_, ref f) => {
83+
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f) => {
8484
Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
8585
}
8686
ty::TyProjection(_) => {

src/librustc/middle/implicator.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ impl<'a, 'tcx> Implicator<'a, 'tcx> {
9393
ty::TyInt(..) |
9494
ty::TyUint(..) |
9595
ty::TyFloat(..) |
96-
ty::TyBareFn(..) |
96+
ty::TyFnDef(..) |
97+
ty::TyFnPtr(..) |
9798
ty::TyError |
9899
ty::TyStr => {
99100
// No borrowed content reachable here.

src/librustc/middle/infer/freshen.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
162162
ty::TySlice(..) |
163163
ty::TyRawPtr(..) |
164164
ty::TyRef(..) |
165-
ty::TyBareFn(..) |
165+
ty::TyFnDef(..) |
166+
ty::TyFnPtr(_) |
166167
ty::TyTrait(..) |
167168
ty::TyStruct(..) |
168169
ty::TyClosure(..) |

src/librustc/middle/intrinsicck.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use ast_map::NodeForeignItem;
1212
use metadata::csearch;
1313
use middle::def::DefFn;
1414
use middle::subst::{Subst, Substs, EnumeratedItems};
15-
use middle::ty::{TransmuteRestriction, ctxt, TyBareFn};
15+
use middle::ty::{TransmuteRestriction, ctxt};
1616
use middle::ty::{self, Ty};
1717
use util::ppaux::Repr;
1818

@@ -54,7 +54,7 @@ struct IntrinsicCheckingVisitor<'a, 'tcx: 'a> {
5454
impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
5555
fn def_id_is_transmute(&self, def_id: DefId) -> bool {
5656
let intrinsic = match ty::lookup_item_type(self.tcx, def_id).ty.sty {
57-
ty::TyBareFn(_, ref bfty) => bfty.abi == RustIntrinsic,
57+
ty::TyFnDef(_, ref bfty) => bfty.abi == RustIntrinsic,
5858
_ => return false
5959
};
6060
if def_id.krate == ast::LOCAL_CRATE {
@@ -256,7 +256,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> {
256256
DefFn(did, _) if self.def_id_is_transmute(did) => {
257257
let typ = ty::node_id_to_type(self.tcx, expr.id);
258258
match typ.sty {
259-
TyBareFn(_, ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
259+
ty::TyFnDef(_, ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
260260
if let ty::FnConverging(to) = bare_fn_ty.sig.0.output {
261261
let from = bare_fn_ty.sig.0.inputs[0];
262262
self.check_transmute(expr.span, from, to, expr.id);

src/librustc/middle/traits/coherence.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>,
304304
ty::TyUint(..) |
305305
ty::TyFloat(..) |
306306
ty::TyStr(..) |
307-
ty::TyBareFn(..) |
307+
ty::TyFnDef(..) |
308+
ty::TyFnPtr(_) |
308309
ty::TyArray(..) |
309310
ty::TySlice(..) |
310311
ty::TyRawPtr(..) |

src/librustc/middle/traits/select.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11851185
}
11861186

11871187
// provide an impl, but only for suitable `fn` pointers
1188-
ty::TyBareFn(_, &ty::BareFnTy {
1188+
ty::TyFnDef(_, &ty::BareFnTy {
1189+
unsafety: ast::Unsafety::Normal,
1190+
abi: abi::Rust,
1191+
sig: ty::Binder(ty::FnSig {
1192+
inputs: _,
1193+
output: ty::FnConverging(_),
1194+
variadic: false
1195+
})
1196+
}) |
1197+
ty::TyFnPtr(&ty::BareFnTy {
11891198
unsafety: ast::Unsafety::Normal,
11901199
abi: abi::Rust,
11911200
sig: ty::Binder(ty::FnSig {
@@ -1585,7 +1594,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15851594
ty::TyInt(_) |
15861595
ty::TyBool |
15871596
ty::TyFloat(_) |
1588-
ty::TyBareFn(..) |
1597+
ty::TyFnDef(..) |
1598+
ty::TyFnPtr(_) |
15891599
ty::TyChar => {
15901600
// safe for everything
15911601
ok_if(Vec::new())
@@ -1807,7 +1817,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18071817
ty::TyInt(_) |
18081818
ty::TyBool |
18091819
ty::TyFloat(_) |
1810-
ty::TyBareFn(..) |
1820+
ty::TyFnDef(..) |
1821+
ty::TyFnPtr(_) |
18111822
ty::TyStr |
18121823
ty::TyError |
18131824
ty::TyInfer(ty::IntVar(_)) |

0 commit comments

Comments
 (0)