Skip to content

Commit ffa0860

Browse files
committed
Track fn type and lifetime parameters in TyFnDef.
1 parent b423a0f commit ffa0860

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

+130
-116
lines changed

src/librustc/middle/effect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum RootUnsafeContext {
4444

4545
fn type_is_unsafe_function(ty: Ty) -> bool {
4646
match ty.sty {
47-
ty::TyFnDef(_, ref f) |
47+
ty::TyFnDef(_, _, ref f) |
4848
ty::TyFnPtr(ref f) => f.unsafety == hir::Unsafety::Unsafe,
4949
_ => false,
5050
}

src/librustc/middle/intrinsicck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct IntrinsicCheckingVisitor<'a, 'tcx: 'a> {
5353
impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
5454
fn def_id_is_transmute(&self, def_id: DefId) -> bool {
5555
let intrinsic = match self.tcx.lookup_item_type(def_id).ty.sty {
56-
ty::TyFnDef(_, ref bfty) => bfty.abi == RustIntrinsic,
56+
ty::TyFnDef(_, _, ref bfty) => bfty.abi == RustIntrinsic,
5757
_ => return false
5858
};
5959
intrinsic && self.tcx.item_name(def_id).as_str() == "transmute"
@@ -238,7 +238,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> {
238238
Def::Fn(did) if self.def_id_is_transmute(did) => {
239239
let typ = self.tcx.node_id_to_type(expr.id);
240240
match typ.sty {
241-
ty::TyFnDef(_, ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
241+
ty::TyFnDef(_, _, ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
242242
if let ty::FnConverging(to) = bare_fn_ty.sig.0.output {
243243
let from = bare_fn_ty.sig.0.inputs[0];
244244
self.check_transmute(expr.span, from, to, expr.id);

src/librustc/middle/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12861286
}
12871287

12881288
// provide an impl, but only for suitable `fn` pointers
1289-
ty::TyFnDef(_, &ty::BareFnTy {
1289+
ty::TyFnDef(_, _, &ty::BareFnTy {
12901290
unsafety: hir::Unsafety::Normal,
12911291
abi: Abi::Rust,
12921292
sig: ty::Binder(ty::FnSig {

src/librustc/middle/ty/adjustment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'tcx> ty::TyS<'tcx> {
155155
match *adjustment {
156156
AdjustReifyFnPointer => {
157157
match self.sty {
158-
ty::TyFnDef(_, b) => {
158+
ty::TyFnDef(_, _, b) => {
159159
cx.mk_ty(ty::TyFnPtr(b))
160160
}
161161
_ => {

src/librustc/middle/ty/context.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use std::borrow::Borrow;
4141
use std::cell::{Cell, RefCell, Ref};
4242
use std::hash::{Hash, Hasher};
4343
use std::rc::Rc;
44-
use syntax::abi::Abi;
4544
use syntax::ast::{self, Name, NodeId};
4645
use syntax::attr;
4746
use syntax::parse::token::special_idents;
@@ -946,30 +945,15 @@ impl<'tcx> TyCtxt<'tcx> {
946945
}
947946

948947
pub fn mk_fn_def(&self, def_id: DefId,
948+
substs: &'tcx Substs<'tcx>,
949949
fty: BareFnTy<'tcx>) -> Ty<'tcx> {
950-
self.mk_ty(TyFnDef(def_id, self.mk_bare_fn(fty)))
950+
self.mk_ty(TyFnDef(def_id, substs, self.mk_bare_fn(fty)))
951951
}
952952

953953
pub fn mk_fn_ptr(&self, fty: BareFnTy<'tcx>) -> Ty<'tcx> {
954954
self.mk_ty(TyFnPtr(self.mk_bare_fn(fty)))
955955
}
956956

957-
pub fn mk_ctor_fn(&self,
958-
def_id: DefId,
959-
input_tys: &[Ty<'tcx>],
960-
output: Ty<'tcx>) -> Ty<'tcx> {
961-
let input_args = input_tys.iter().cloned().collect();
962-
self.mk_fn_def(def_id, BareFnTy {
963-
unsafety: hir::Unsafety::Normal,
964-
abi: Abi::Rust,
965-
sig: ty::Binder(ty::FnSig {
966-
inputs: input_args,
967-
output: ty::FnConverging(output),
968-
variadic: false
969-
})
970-
})
971-
}
972-
973957
pub fn mk_trait(&self,
974958
principal: ty::PolyTraitRef<'tcx>,
975959
bounds: ExistentialBounds<'tcx>)

src/librustc/middle/ty/fast_reject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn simplify_type(tcx: &TyCtxt,
8383
ty::TyTuple(ref tys) => {
8484
Some(TupleSimplifiedType(tys.len()))
8585
}
86-
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f) => {
86+
ty::TyFnDef(_, _, ref f) | ty::TyFnPtr(ref f) => {
8787
Some(FunctionSimplifiedType(f.sig.0.inputs.len()))
8888
}
8989
ty::TyProjection(_) | ty::TyParam(_) => {

src/librustc/middle/ty/flags.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ impl FlagComputation {
134134
self.add_tys(&ts[..]);
135135
}
136136

137-
&ty::TyFnDef(_, ref f) | &ty::TyFnPtr(ref f) => {
137+
&ty::TyFnDef(_, substs, ref f) => {
138+
self.add_substs(substs);
139+
self.add_fn_sig(&f.sig);
140+
}
141+
142+
&ty::TyFnPtr(ref f) => {
138143
self.add_fn_sig(&f.sig);
139144
}
140145
}

src/librustc/middle/ty/relate.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,13 @@ pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R,
568568
}
569569
}
570570

571-
(&ty::TyFnDef(a_def_id, a_fty), &ty::TyFnDef(b_def_id, b_fty))
571+
(&ty::TyFnDef(a_def_id, a_substs, a_fty),
572+
&ty::TyFnDef(b_def_id, b_substs, b_fty))
572573
if a_def_id == b_def_id =>
573574
{
575+
let substs = try!(relate_substs(relation, None, a_substs, b_substs));
574576
let fty = try!(relation.relate(a_fty, b_fty));
575-
Ok(tcx.mk_fn_def(a_def_id, fty))
577+
Ok(tcx.mk_fn_def(a_def_id, tcx.mk_substs(substs), fty))
576578
}
577579

578580
(&ty::TyFnPtr(a_fty), &ty::TyFnPtr(b_fty)) =>

src/librustc/middle/ty/structural_impls.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,12 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
282282
}
283283
ty::TyTrait(ref trait_ty) => ty::TyTrait(trait_ty.fold_with(folder)),
284284
ty::TyTuple(ref ts) => ty::TyTuple(ts.fold_with(folder)),
285-
ty::TyFnDef(def_id, ref f) => {
285+
ty::TyFnDef(def_id, substs, ref f) => {
286+
let substs = substs.fold_with(folder);
286287
let bfn = f.fold_with(folder);
287-
ty::TyFnDef(def_id, folder.tcx().mk_bare_fn(bfn))
288+
ty::TyFnDef(def_id,
289+
folder.tcx().mk_substs(substs),
290+
folder.tcx().mk_bare_fn(bfn))
288291
}
289292
ty::TyFnPtr(ref f) => {
290293
let bfn = f.fold_with(folder);
@@ -322,7 +325,10 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
322325
ty::TyEnum(_tid, ref substs) => substs.visit_with(visitor),
323326
ty::TyTrait(ref trait_ty) => trait_ty.visit_with(visitor),
324327
ty::TyTuple(ref ts) => ts.visit_with(visitor),
325-
ty::TyFnDef(_, ref f) | ty::TyFnPtr(ref f) => f.visit_with(visitor),
328+
ty::TyFnDef(_, substs, ref f) => {
329+
substs.visit_with(visitor) || f.visit_with(visitor)
330+
}
331+
ty::TyFnPtr(ref f) => f.visit_with(visitor),
326332
ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor),
327333
ty::TyStruct(_did, ref substs) => substs.visit_with(visitor),
328334
ty::TyClosure(_did, ref substs) => substs.visit_with(visitor),

src/librustc/middle/ty/sty.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ pub enum TypeVariants<'tcx> {
129129

130130
/// The anonymous type of a function declaration/definition. Each
131131
/// function has a unique type.
132-
/// FIXME: Does this need to include substitutions?
133-
/// `g::<i32>` and `g::<u32>` should have different types.
134-
TyFnDef(DefId, &'tcx BareFnTy<'tcx>),
132+
TyFnDef(DefId, &'tcx Substs<'tcx>, &'tcx BareFnTy<'tcx>),
135133

136134
/// A pointer to a function. Written as `fn() -> i32`.
137135
/// FIXME: This is currently also used to represent the callee of a method;
@@ -1142,15 +1140,15 @@ impl<'tcx> TyS<'tcx> {
11421140

11431141
pub fn fn_sig(&self) -> &'tcx PolyFnSig<'tcx> {
11441142
match self.sty {
1145-
TyFnDef(_, ref f) | TyFnPtr(ref f) => &f.sig,
1143+
TyFnDef(_, _, ref f) | TyFnPtr(ref f) => &f.sig,
11461144
_ => panic!("Ty::fn_sig() called on non-fn type: {:?}", self)
11471145
}
11481146
}
11491147

11501148
/// Returns the ABI of the given function.
11511149
pub fn fn_abi(&self) -> abi::Abi {
11521150
match self.sty {
1153-
TyFnDef(_, ref f) | TyFnPtr(ref f) => f.abi,
1151+
TyFnDef(_, _, ref f) | TyFnPtr(ref f) => f.abi,
11541152
_ => panic!("Ty::fn_abi() called on non-fn type"),
11551153
}
11561154
}

0 commit comments

Comments
 (0)