Skip to content

Cleanups to previous commits for issue #1393. #1491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/comp/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/comp/syntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/syntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/comp/syntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/tag-variant-disr-non-nullary.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down