Skip to content

Commit 0739849

Browse files
committed
rustc: Make all type lookups go through the one ty::ann_to_ty_param_substs_opt_and_ty() function
1 parent 4f2eb31 commit 0739849

File tree

1 file changed

+22
-44
lines changed

1 file changed

+22
-44
lines changed

src/comp/middle/ty.rs

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,35 +1440,7 @@ fn eq_raw_ty(&raw_t a, &raw_t b) -> bool {
14401440
fn eq_ty(&t a, &t b) -> bool { ret a == b; }
14411441

14421442

1443-
fn ann_to_type(&node_type_table ntt, &ast::ann ann) -> t {
1444-
alt (ann) {
1445-
case (ast::ann_none(_)) {
1446-
log_err "ann_to_type() called on node with no type";
1447-
fail;
1448-
}
1449-
case (ast::ann_type(_, ?ty, _, _)) {
1450-
ret ty;
1451-
}
1452-
}
1453-
}
1454-
1455-
fn ann_to_type_params(&node_type_table ntt, &ast::ann ann) -> vec[t] {
1456-
alt (ann) {
1457-
case (ast::ann_none(_)) {
1458-
log_err "ann_to_type_params() called on node with no type params";
1459-
fail;
1460-
}
1461-
case (ast::ann_type(_, _, ?tps, _)) {
1462-
alt (tps) {
1463-
case (none[vec[t]]) {
1464-
let vec[t] result = vec();
1465-
ret result;
1466-
}
1467-
case (some[vec[t]](?tps)) { ret tps; }
1468-
}
1469-
}
1470-
}
1471-
}
1443+
// Type lookups
14721444

14731445
fn ann_to_ty_param_substs_opt_and_ty(&node_type_table ntt, &ast::ann ann)
14741446
-> ty_param_substs_opt_and_ty {
@@ -1482,27 +1454,33 @@ fn ann_to_ty_param_substs_opt_and_ty(&node_type_table ntt, &ast::ann ann)
14821454
}
14831455
}
14841456

1457+
fn ann_to_type(&node_type_table ntt, &ast::ann ann) -> t {
1458+
ret ann_to_ty_param_substs_opt_and_ty(ntt, ann)._1;
1459+
}
1460+
1461+
fn ann_to_type_params(&node_type_table ntt, &ast::ann ann) -> vec[t] {
1462+
alt (ann_to_ty_param_substs_opt_and_ty(ntt, ann)._0) {
1463+
case (none[vec[t]]) {
1464+
let vec[t] result = vec();
1465+
ret result;
1466+
}
1467+
case (some[vec[t]](?tps)) { ret tps; }
1468+
}
1469+
}
1470+
14851471
// Returns the type of an annotation, with type parameter substitutions
14861472
// performed if applicable.
1487-
fn ann_to_monotype(ctxt cx, &node_type_table ntt, ast::ann a) -> t {
1488-
// TODO: Refactor to use recursive pattern matching when we're more
1489-
// confident that it works.
1490-
alt (a) {
1491-
case (ast::ann_none(_)) {
1492-
log_err "ann_to_monotype() called on expression with no type!";
1493-
fail;
1494-
}
1495-
case (ast::ann_type(_, ?typ, ?tps_opt, _)) {
1496-
alt (tps_opt) {
1497-
case (none[vec[t]]) { ret typ; }
1498-
case (some[vec[t]](?tps)) {
1499-
ret substitute_type_params(cx, tps, typ);
1500-
}
1501-
}
1473+
fn ann_to_monotype(ctxt cx, &node_type_table ntt, ast::ann a) -> t {
1474+
auto tpot = ann_to_ty_param_substs_opt_and_ty(ntt, a);
1475+
alt (tpot._0) {
1476+
case (none[vec[t]]) { ret tpot._1; }
1477+
case (some[vec[t]](?tps)) {
1478+
ret substitute_type_params(cx, tps, tpot._1);
15021479
}
15031480
}
15041481
}
15051482

1483+
15061484
// Turns a type into an ann_type, using defaults for other fields.
15071485
fn triv_ann(uint node_id, t typ) -> ast::ann {
15081486
ret ast::ann_type(node_id, typ, none[vec[t]], none[@ts_ann]);

0 commit comments

Comments
 (0)