提交 44352df5 编写于 作者: K Kevin Atkinson 提交者: Marijn Haverbeke

Cleanups to previous commits for issue #1393.

上级 175196bb
......@@ -174,7 +174,7 @@
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);
......
......@@ -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 lower_bound_proto(proto: ast::proto) -> ast::proto {
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.
......
......@@ -245,6 +245,8 @@ fn ternary_to_if(e: @expr) -> @expr {
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 {
......
......@@ -473,9 +473,9 @@ fn fold_variant_arg_(va: variant_arg, fld: ast_fold) -> variant_arg {
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
}
};
......
......@@ -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);
......
//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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册