Skip to content

Commit 730381d

Browse files
committed
Annotate and fix FIXMEs in typeck
1 parent 87af3f3 commit 730381d

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed

src/rustc/middle/typeck.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ type crate_ctxt = {impl_map: resolve::impl_map,
120120
vtable_map: vtable_map,
121121
tcx: ty::ctxt};
122122

123-
type class_map = hashmap<ast::node_id, ty::t>;
124-
125123
// Functions that write types into the node type table
126124
fn write_ty_to_tcx(tcx: ty::ctxt, node_id: ast::node_id, ty: ty::t) {
127125
#debug["write_ty_to_tcx(%d, %s)", node_id, ty_to_str(tcx, ty)];

src/rustc/middle/typeck/check.rs

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ type fn_ctxt =
9999

100100
ccx: @crate_ctxt};
101101

102+
// Used by check_const and check_enum_variants
103+
fn blank_fn_ctxt(ccx: @crate_ctxt, rty: ty::t) -> @fn_ctxt {
104+
// It's kind of a kludge to manufacture a fake function context
105+
// and statement context, but we might as well do write the code only once
106+
@{self_ty: none,
107+
ret_ty: rty,
108+
indirect_ret_ty: none,
109+
purity: ast::pure_fn,
110+
infcx: infer::new_infer_ctxt(ccx.tcx),
111+
locals: int_hash(),
112+
mut blocks: [],
113+
in_scope_regions: @nil,
114+
node_types: smallintmap::mk(),
115+
node_type_substs: map::int_hash(),
116+
ccx: ccx}
117+
}
118+
102119
// a list of mapping from in-scope-region-names ("isr") to the
103120
// corresponding ty::region
104121
type isr_alist = @list<(ty::bound_region, ty::region)>;
@@ -705,7 +722,7 @@ fn impl_self_ty(fcx: @fn_ctxt, did: ast::def_id) -> ty_param_substs_and_ty {
705722
}
706723

707724
// Only for fields! Returns <none> for methods>
708-
// FIXME: privacy flags
725+
// Indifferent to privacy flags
709726
fn lookup_field_ty(tcx: ty::ctxt, class_id: ast::def_id,
710727
items:[ty::field_ty], fieldname: ast::ident,
711728
substs: ty::substs) -> option<ty::t> {
@@ -1390,7 +1407,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
13901407
alt structure_of(fcx, expr.span, fty) {
13911408
// FIXME:
13921409
// probably need to munge the constrs to drop constraints
1393-
// for any bound args
1410+
// for any bound args (contingent on #2588 not getting accepted)
13941411
ty::ty_fn(f) {
13951412
proto = f.proto;
13961413
arg_tys = f.inputs;
@@ -1460,7 +1477,11 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
14601477
if type_is_c_like_enum(fcx,expr.span,t_e) && t_1_is_scalar {
14611478
/* this case is allowed */
14621479
} else if !(type_is_scalar(fcx,expr.span,t_e) && t_1_is_scalar) {
1463-
// FIXME there are more forms of cast to support, eventually.
1480+
/*
1481+
If more type combinations should be supported than are
1482+
supported here, then file an enhancement issue and record the
1483+
issue number in this comment.
1484+
*/
14641485
tcx.sess.span_err(expr.span,
14651486
"non-scalar cast: " +
14661487
ty_to_str(tcx, t_e) + " as " +
@@ -1516,14 +1537,13 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
15161537
}
15171538
some(bexpr) {
15181539
let bexpr_t = fcx.expr_ty(bexpr);
1519-
let mut base_fields; // FIXME remove mut after snapshot
1520-
alt structure_of(fcx, expr.span, bexpr_t) {
1521-
ty::ty_rec(flds) { base_fields = flds; }
1540+
let base_fields = alt structure_of(fcx, expr.span, bexpr_t) {
1541+
ty::ty_rec(flds) { flds }
15221542
_ {
15231543
tcx.sess.span_fatal(expr.span,
15241544
"record update has non-record base");
15251545
}
1526-
}
1546+
};
15271547
fcx.write_ty(id, bexpr_t);
15281548
for fields_t.each {|f|
15291549
let mut found = false;
@@ -1586,7 +1606,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
15861606
alt lookup_field_ty(tcx, base_id, cls_items, field, substs) {
15871607
some(field_ty) {
15881608
// (2) look up what field's type is, and return it
1589-
// FIXME: actually instantiate any type params
15901609
fcx.write_ty(id, field_ty);
15911610
handled = true;
15921611
}
@@ -1843,21 +1862,8 @@ fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool {
18431862
}
18441863

18451864
fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
1846-
// FIXME: this is kinda a kludge; we manufacture a fake function context
1847-
// and statement context for checking the initializer expression.
18481865
let rty = ty::node_id_to_type(ccx.tcx, id);
1849-
let fcx: @fn_ctxt =
1850-
@{self_ty: none,
1851-
ret_ty: rty,
1852-
indirect_ret_ty: none,
1853-
purity: ast::pure_fn,
1854-
infcx: infer::new_infer_ctxt(ccx.tcx),
1855-
locals: int_hash(),
1856-
mut blocks: [],
1857-
in_scope_regions: @nil,
1858-
node_types: smallintmap::mk(),
1859-
node_type_substs: map::int_hash(),
1860-
ccx: ccx};
1866+
let fcx = blank_fn_ctxt(ccx, rty);
18611867
check_expr(fcx, e, none);
18621868
let cty = fcx.expr_ty(e);
18631869
let declty = fcx.ccx.tcx.tcache.get(local_def(id)).ty;
@@ -1882,21 +1888,8 @@ fn check_enum_variants(ccx: @crate_ctxt,
18821888
sp: span,
18831889
vs: [ast::variant],
18841890
id: ast::node_id) {
1885-
// FIXME: this is kinda a kludge; we manufacture a fake function context
1886-
// and statement context for checking the initializer expression.
18871891
let rty = ty::node_id_to_type(ccx.tcx, id);
1888-
let fcx: @fn_ctxt =
1889-
@{self_ty: none,
1890-
ret_ty: rty,
1891-
indirect_ret_ty: none,
1892-
purity: ast::pure_fn,
1893-
infcx: infer::new_infer_ctxt(ccx.tcx),
1894-
locals: int_hash(),
1895-
mut blocks: [],
1896-
in_scope_regions: @nil,
1897-
node_types: smallintmap::mk(),
1898-
node_type_substs: map::int_hash(),
1899-
ccx: ccx};
1892+
let fcx = blank_fn_ctxt(ccx, rty);
19001893
let mut disr_vals: [int] = [];
19011894
let mut disr_val = 0;
19021895
for vs.each {|v|
@@ -2140,9 +2133,17 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
21402133
ast::def_upvar(_, inner, _) {
21412134
ret ty_param_bounds_and_ty_for_def(fcx, sp, *inner);
21422135
}
2143-
_ {
2144-
// FIXME: handle other names.
2145-
fcx.ccx.tcx.sess.unimpl("definition variant");
2136+
ast::def_ty_param(did, n) {
2137+
ret no_params(ty::mk_param(fcx.ccx.tcx, n, did));
2138+
}
2139+
ast::def_mod(*) | ast::def_native_mod(*) {
2140+
fcx.ccx.tcx.sess.span_fatal(sp, "expected value but found module");
2141+
}
2142+
ast::def_use(*) {
2143+
fcx.ccx.tcx.sess.span_fatal(sp, "expected value but found use");
2144+
}
2145+
ast::def_region(*) {
2146+
fcx.ccx.tcx.sess.span_fatal(sp, "expected value but found region");
21462147
}
21472148
}
21482149
}

0 commit comments

Comments
 (0)