Skip to content

Commit 5ec30cb

Browse files
committed
---
yaml --- r: 39552 b: refs/heads/incoming c: 65839fa h: refs/heads/master v: v3
1 parent e179219 commit 5ec30cb

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
9-
refs/heads/incoming: 5c6e928e32390b410187f39f3bab9ffbcae4bd6a
9+
refs/heads/incoming: 65839fa622c623393893b5610b6d3b4151abe233
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/librustc/middle/ty.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,11 @@ export kind_is_durable;
144144
export meta_kind, kind_lteq, type_kind, type_kind_ext;
145145
export operators;
146146
export type_err, terr_vstore_kind;
147-
export terr_mismatch, terr_onceness_mismatch;
147+
export terr_integer_as_char, terr_mismatch, terr_onceness_mismatch;
148148
export type_err_to_str, note_and_explain_type_err;
149149
export expected_found;
150150
export type_needs_drop;
151+
export type_is_char;
151152
export type_is_empty;
152153
export type_is_integral;
153154
export type_is_numeric;
@@ -696,6 +697,7 @@ enum type_err {
696697
terr_in_field(@type_err, ast::ident),
697698
terr_sorts(expected_found<t>),
698699
terr_self_substs,
700+
terr_integer_as_char,
699701
terr_no_integral_type,
700702
terr_no_floating_point_type,
701703
}
@@ -2520,6 +2522,13 @@ fn type_is_integral(ty: t) -> bool {
25202522
}
25212523
}
25222524
2525+
fn type_is_char(ty: t) -> bool {
2526+
match get(ty).sty {
2527+
ty_int(ty_char) => true,
2528+
_ => false
2529+
}
2530+
}
2531+
25232532
fn type_is_fp(ty: t) -> bool {
25242533
match get(ty).sty {
25252534
ty_infer(FloatVar(_)) | ty_float(_) => true,
@@ -3489,6 +3498,10 @@ fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str {
34893498
~"couldn't determine an appropriate integral type for integer \
34903499
literal"
34913500
}
3501+
terr_integer_as_char => {
3502+
~"integer literals can't be inferred to char type \
3503+
(try an explicit cast)"
3504+
}
34923505
terr_no_floating_point_type => {
34933506
~"couldn't determine an appropriate floating point type for \
34943507
floating point literal"

branches/incoming/src/librustc/middle/typeck/infer/unify.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ impl infer_ctxt {
362362
}
363363

364364
fn int_var_sub_t(a_id: ty::IntVid, b: ty::t) -> ures {
365+
if ty::type_is_char(b) {
366+
return Err(ty::terr_integer_as_char);
367+
}
368+
365369
assert ty::type_is_integral(b);
366370

367371
let vb = &self.int_var_bindings;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let _p: char = 100; //~ ERROR mismatched types: expected `char` but found
3+
}

0 commit comments

Comments
 (0)