@@ -99,6 +99,23 @@ type fn_ctxt =
99
99
100
100
ccx : @crate_ctxt } ;
101
101
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
+
102
119
// a list of mapping from in-scope-region-names ("isr") to the
103
120
// corresponding ty::region
104
121
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 {
705
722
}
706
723
707
724
// Only for fields! Returns <none> for methods>
708
- // FIXME: privacy flags
725
+ // Indifferent to privacy flags
709
726
fn lookup_field_ty ( tcx : ty:: ctxt , class_id : ast:: def_id ,
710
727
items : [ ty:: field_ty ] , fieldname : ast:: ident ,
711
728
substs : ty:: substs ) -> option < ty:: t > {
@@ -1390,7 +1407,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1390
1407
alt structure_of ( fcx, expr. span , fty) {
1391
1408
// FIXME:
1392
1409
// 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)
1394
1411
ty:: ty_fn ( f) {
1395
1412
proto = f. proto ;
1396
1413
arg_tys = f. inputs ;
@@ -1460,7 +1477,11 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1460
1477
if type_is_c_like_enum ( fcx, expr. span , t_e) && t_1_is_scalar {
1461
1478
/* this case is allowed */
1462
1479
} 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
+ */
1464
1485
tcx. sess . span_err ( expr. span ,
1465
1486
"non-scalar cast: " +
1466
1487
ty_to_str ( tcx, t_e) + " as " +
@@ -1516,14 +1537,13 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1516
1537
}
1517
1538
some ( bexpr) {
1518
1539
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 }
1522
1542
_ {
1523
1543
tcx. sess . span_fatal ( expr. span ,
1524
1544
"record update has non-record base" ) ;
1525
1545
}
1526
- }
1546
+ } ;
1527
1547
fcx. write_ty ( id, bexpr_t) ;
1528
1548
for fields_t. each { |f|
1529
1549
let mut found = false;
@@ -1586,7 +1606,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1586
1606
alt lookup_field_ty ( tcx, base_id, cls_items, field, substs) {
1587
1607
some ( field_ty) {
1588
1608
// (2) look up what field's type is, and return it
1589
- // FIXME: actually instantiate any type params
1590
1609
fcx. write_ty ( id, field_ty) ;
1591
1610
handled = true ;
1592
1611
}
@@ -1843,21 +1862,8 @@ fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool {
1843
1862
}
1844
1863
1845
1864
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.
1848
1865
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) ;
1861
1867
check_expr ( fcx, e, none) ;
1862
1868
let cty = fcx. expr_ty ( e) ;
1863
1869
let declty = fcx. ccx . tcx . tcache . get ( local_def ( id) ) . ty ;
@@ -1882,21 +1888,8 @@ fn check_enum_variants(ccx: @crate_ctxt,
1882
1888
sp : span ,
1883
1889
vs : [ ast:: variant ] ,
1884
1890
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.
1887
1891
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) ;
1900
1893
let mut disr_vals: [ int ] = [ ] ;
1901
1894
let mut disr_val = 0 ;
1902
1895
for vs. each { |v|
@@ -2140,9 +2133,17 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
2140
2133
ast:: def_upvar ( _, inner, _) {
2141
2134
ret ty_param_bounds_and_ty_for_def ( fcx, sp, * inner) ;
2142
2135
}
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" ) ;
2146
2147
}
2147
2148
}
2148
2149
}
0 commit comments