diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2011-09-16 13:03:11 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2011-09-16 13:06:31 -0700 |
| commit | 1b2c5c4c9b8235885e70a3dd94dc3e5bee7c7ffd (patch) | |
| tree | e109dfd7c5e9dbda2e712348b71c80ea5c7707e4 /src/comp | |
| parent | 43b219dbec5a3fa0ded5c02c95149d8517343087 (diff) | |
| download | rust-1b2c5c4c9b8235885e70a3dd94dc3e5bee7c7ffd.tar.gz rust-1b2c5c4c9b8235885e70a3dd94dc3e5bee7c7ffd.zip | |
Make ty_fn_ret pure and get rid of a duplicate function
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/middle/ty.rs | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index a71811fccf7..f97bbd68f52 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -92,7 +92,6 @@ export pat_ty; export cname; export rename; export ret_ty_of_fn; -export ret_ty_of_fn_ty; export sequence_element_type; export struct; export sort_methods; @@ -1600,11 +1599,21 @@ fn ty_fn_abi(cx: ctxt, fty: t) -> ast::native_abi { } } -fn ty_fn_ret(cx: ctxt, fty: t) -> t { - alt struct(cx, fty) { +pure fn ty_fn_ret(cx: ctxt, fty: t) -> t { + // Should be pure, as type interner contents + // shouldn't change once set... + let sty = unchecked { struct(cx, fty) }; + alt sty { ty::ty_fn(_, _, r, _, _) { ret r; } ty::ty_native_fn(_, _, r) { ret r; } - _ { cx.sess.bug("ty_fn_ret() called on non-fn type"); } + _ { + // Unchecked is ok since we diverge here + // (might want to change the typechecker to allow + // it without an unchecked) + // Or, it wouldn't be necessary if we had the right + // typestate constraint on cx and t (then we could + // call unreachable() instead) + unchecked { cx.sess.bug("ty_fn_ret() called on non-fn type"); }} } } @@ -2634,19 +2643,8 @@ fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_kinds_and_ty { } } -fn ret_ty_of_fn_ty(cx: ctxt, a_ty: t) -> t { - alt ty::struct(cx, a_ty) { - ty::ty_fn(_, _, ret_ty, _, _) { ret ret_ty; } - ty::ty_native_fn(_, _, ret_ty) { ret ret_ty; } - _ { - cx.sess.bug("ret_ty_of_fn_ty() called on non-function type: " + - ty_to_str(cx, a_ty)); - } - } -} - fn ret_ty_of_fn(cx: ctxt, id: ast::node_id) -> t { - ret ret_ty_of_fn_ty(cx, node_id_to_type(cx, id)); + ty_fn_ret(cx, node_id_to_type(cx, id)) } fn is_binopable(cx: ctxt, ty: t, op: ast::binop) -> bool { |
