diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index a79e4401569eb..2cf62fcb2d4df 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -174,7 +174,7 @@ export type_is_tup_like; export type_is_str; export type_is_unique; export type_is_tag; -export type_is_enum_like; +export type_is_c_like_enum; export type_structurally_contains_uniques; export type_autoderef; export type_param; @@ -1274,7 +1274,7 @@ fn type_is_tag(cx: ctxt, ty: t) -> bool { // Whether a type is enum like, that is a tag type with only nullary // constructors -fn type_is_enum_like(cx: ctxt, ty: t) -> bool { +fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_tag(did, tps) { let variants = tag_variants(cx, did); diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 1d701f9b9ab6f..fe2cffa222034 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -211,9 +211,9 @@ fn type_is_scalar(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool { ret ty::type_is_scalar(fcx.ccx.tcx, typ_s); } -fn type_is_enum_like(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool { +fn type_is_c_like_enum(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool { let typ_s = structurally_resolved_type(fcx, sp, typ); - ret ty::type_is_enum_like(fcx.ccx.tcx, typ_s); + ret ty::type_is_c_like_enum(fcx.ccx.tcx, typ_s); } // Parses the programmer's textual representation of a type into our internal @@ -2216,7 +2216,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, ty::ty_iface(_, _) {} _ { let t_1_is_scalar = type_is_scalar(fcx, expr.span, t_1); - if type_is_enum_like(fcx,expr.span,t_e) && t_1_is_scalar { + if type_is_c_like_enum(fcx,expr.span,t_e) && t_1_is_scalar { /* this case is allowed */ } else if !(type_is_scalar(fcx,expr.span,t_e) && t_1_is_scalar) { // FIXME there are more forms of cast to support, eventually. diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index 121abc1ce5c3a..4a9c51286c790 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -245,6 +245,8 @@ tag const_val { const_str(str); } +// FIXME (#1417): any function that uses this function should likely be moved +// into the middle end fn eval_const_expr(e: @expr) -> const_val { fn fromb(b: bool) -> const_val { const_int(b as i64) } alt e.node { diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index f075979b7f676..a2cb8066a6780 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -473,9 +473,9 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ { let (de, dv) = alt v.disr_expr { some(e) { let de = fld.fold_expr(e); + // FIXME (#1417): see parser.rs let dv = alt syntax::ast_util::eval_const_expr(e) { ast_util::const_int(val) { - // FIXME (#1417): check that value is in range val as int } }; diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index c3fb803e48915..13396d6822722 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -2117,7 +2117,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item { // probably be doing." (See issue #1417) alt syntax::ast_util::eval_const_expr(e) { syntax::ast_util::const_int(val) { - // FIXME (#1417): check that value is in range + // FIXME: check that value is in range disr_val = val as int; } } @@ -2148,7 +2148,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item { } let hi = p.get_hi_pos(); if (have_disr && !all_nullary) { - p.fatal("discriminator values can only be used with enum-like tag"); + p.fatal("discriminator values can only be used with a c-like enum"); } p.bump(); ret mk_item(p, lo, hi, id, ast::item_tag(variants, ty_params), attrs); diff --git a/src/test/compile-fail/tag-variant-disr-non-nullary.rs b/src/test/compile-fail/tag-variant-disr-non-nullary.rs index 1d3a59e172ff0..3c8f25d931370 100644 --- a/src/test/compile-fail/tag-variant-disr-non-nullary.rs +++ b/src/test/compile-fail/tag-variant-disr-non-nullary.rs @@ -1,4 +1,4 @@ -//error-pattern: discriminator values can only be used with enum-like tag +//error-pattern: discriminator values can only be used with a c-like enum // black and white have the same discriminator value ... tag color {