Skip to content

Commit 2261ddc

Browse files
committed
Move ast_constr_to_constr from typeck to ty
so that it can be used in places that import ty.
1 parent 075a094 commit 2261ddc

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/comp/middle/ty.rs

+17
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export any_item_native;
3030
export any_item_rust;
3131
export arg;
3232
export args_eq;
33+
export ast_constr_to_constr;
3334
export bind_params_in_type;
3435
export block_ty;
3536
export constr;
@@ -3120,6 +3121,22 @@ fn is_binopable(&ctxt cx, t ty, ast::binop op) -> bool {
31203121
ret tbl.(tycat(cx, ty)).(opcat(op));
31213122
}
31223123

3124+
fn ast_constr_to_constr[T](ty::ctxt tcx, &@ast::constr_general[T] c)
3125+
-> @ty::constr_general[T] {
3126+
alt (tcx.def_map.find(c.node.id)) {
3127+
case (some(ast::def_fn(?pred_id, ast::pure_fn))) {
3128+
ret @respan(c.span, rec(path=c.node.path, args=c.node.args,
3129+
id=pred_id));
3130+
}
3131+
case (_) {
3132+
tcx.sess.span_fatal(c.span, "Predicate "
3133+
+ path_to_str(c.node.path)
3134+
+ " is unbound or bound to a non-function or an \
3135+
impure function");
3136+
}
3137+
}
3138+
}
3139+
31233140
// Local Variables:
31243141
// mode: rust
31253142
// fill-column: 78;

src/comp/middle/typeck.rs

+7-22
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
347347

348348
auto out_constrs = ~[];
349349
for (@ast::constr constr in constrs) {
350-
out_constrs += ~[ast_constr_to_constr(tcx, constr)];
350+
out_constrs += ~[ty::ast_constr_to_constr(tcx, constr)];
351351
}
352352
typ = ty::mk_fn(tcx, proto, i, out_ty, cf, out_constrs);
353353
}
@@ -383,7 +383,7 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
383383

384384
auto out_constrs = ~[];
385385
for (@ast::constr constr in m.node.constrs) {
386-
out_constrs += ~[ast_constr_to_constr(tcx, constr)];
386+
out_constrs += ~[ty::ast_constr_to_constr(tcx, constr)];
387387
}
388388
let ty::method new_m =
389389
rec(proto=m.node.proto,
@@ -399,7 +399,7 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
399399
case (ast::ty_constr(?t, ?cs)) {
400400
auto out_cs = ~[];
401401
for (@ast::ty_constr constr in cs) {
402-
out_cs += ~[ast_constr_to_constr(tcx, constr)];
402+
out_cs += ~[ty::ast_constr_to_constr(tcx, constr)];
403403
}
404404
typ = ty::mk_constr(tcx, ast_ty_to_ty(tcx, getter, t), out_cs);
405405
}
@@ -509,7 +509,7 @@ mod collect {
509509

510510
auto out_constrs = ~[];
511511
for (@ast::constr constr in decl.constraints) {
512-
out_constrs += ~[ast_constr_to_constr(cx.tcx, constr)];
512+
out_constrs += ~[ty::ast_constr_to_constr(cx.tcx, constr)];
513513
}
514514
auto t_fn =
515515
ty::mk_fn(cx.tcx, proto, input_tys, output_ty, decl.cf,
@@ -589,7 +589,7 @@ mod collect {
589589

590590
auto out_constrs = ~[];
591591
for (@ast::constr constr in m.node.meth.decl.constraints) {
592-
out_constrs += ~[ast_constr_to_constr(cx.tcx, constr)];
592+
out_constrs += ~[ty::ast_constr_to_constr(cx.tcx, constr)];
593593
}
594594
ret rec(proto=m.node.meth.proto, ident=m.node.ident,
595595
inputs=inputs, output=output, cf=m.node.meth.decl.cf,
@@ -2422,7 +2422,8 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
24222422

24232423
auto out_constrs = ~[];
24242424
for (@ast::constr constr in m.node.meth.decl.constraints) {
2425-
out_constrs += ~[ast_constr_to_constr(ccx.tcx, constr)];
2425+
out_constrs +=
2426+
~[ty::ast_constr_to_constr(ccx.tcx, constr)];
24262427
}
24272428

24282429
ret rec(proto=m.node.meth.proto, ident=m.node.ident,
@@ -2535,22 +2536,6 @@ fn get_obj_info(&@crate_ctxt ccx) -> option::t[obj_info] {
25352536
ret ivec::last[obj_info](ccx.obj_infos);
25362537
}
25372538

2538-
fn ast_constr_to_constr[T](ty::ctxt tcx, &@ast::constr_general[T] c)
2539-
-> @ty::constr_general[T] {
2540-
alt (tcx.def_map.find(c.node.id)) {
2541-
case (some(ast::def_fn(?pred_id, ast::pure_fn))) {
2542-
ret @respan(c.span, rec(path=c.node.path, args=c.node.args,
2543-
id=pred_id));
2544-
}
2545-
case (_) {
2546-
tcx.sess.span_fatal(c.span, "Predicate "
2547-
+ path_to_str(c.node.path)
2548-
+ " is unbound or bound to a non-function or an \
2549-
impure function");
2550-
}
2551-
}
2552-
}
2553-
25542539
fn check_decl_initializer(&@fn_ctxt fcx, ast::node_id nid,
25552540
&ast::initializer init) {
25562541
check_expr(fcx, init.expr);

0 commit comments

Comments
 (0)