Skip to content

Commit 9c9d199

Browse files
committed
---
yaml --- r: 38231 b: refs/heads/try c: a75c0b3 h: refs/heads/master i: 38229: 4de4a4e 38227: 68903d6 38223: 46fe885 v: v3
1 parent 44be5a8 commit 9c9d199

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
@@ -2,7 +2,7 @@
22
refs/heads/master: 09bb07bed9166105ea961a42b5fff7739ae0d2e9
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
5-
refs/heads/try: 13879d8e9f172de888db91d59ce267d0116d687d
5+
refs/heads/try: a75c0b3b3210cc842a02b2dc2a9976278ef9c427
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ export kind_is_durable;
162162
export meta_kind, kind_lteq, type_kind, type_kind_ext;
163163
export operators;
164164
export type_err, terr_vstore_kind;
165-
export terr_mismatch, terr_onceness_mismatch;
165+
export terr_integer_as_char, terr_mismatch, terr_onceness_mismatch;
166166
export type_err_to_str, note_and_explain_type_err;
167167
export expected_found;
168168
export type_needs_drop;
169+
export type_is_char;
169170
export type_is_empty;
170171
export type_is_integral;
171172
export type_is_numeric;
@@ -714,6 +715,7 @@ enum type_err {
714715
terr_in_field(@type_err, ast::ident),
715716
terr_sorts(expected_found<t>),
716717
terr_self_substs,
718+
terr_integer_as_char,
717719
terr_no_integral_type,
718720
terr_no_floating_point_type,
719721
}
@@ -2541,6 +2543,13 @@ fn type_is_integral(ty: t) -> bool {
25412543
}
25422544
}
25432545
2546+
fn type_is_char(ty: t) -> bool {
2547+
match get(ty).sty {
2548+
ty_int(ty_char) => true,
2549+
_ => false
2550+
}
2551+
}
2552+
25442553
fn type_is_fp(ty: t) -> bool {
25452554
match get(ty).sty {
25462555
ty_infer(FloatVar(_)) | ty_float(_) => true,
@@ -3510,6 +3519,10 @@ fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str {
35103519
~"couldn't determine an appropriate integral type for integer \
35113520
literal"
35123521
}
3522+
terr_integer_as_char => {
3523+
~"integer literals can't be inferred to char type \
3524+
(try an explicit cast)"
3525+
}
35133526
terr_no_floating_point_type => {
35143527
~"couldn't determine an appropriate floating point type for \
35153528
floating point literal"

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ impl infer_ctxt {
366366
}
367367

368368
fn int_var_sub_t(a_id: ty::IntVid, b: ty::t) -> ures {
369+
if ty::type_is_char(b) {
370+
return Err(ty::terr_integer_as_char);
371+
}
372+
369373
assert ty::type_is_integral(b);
370374

371375
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)