Skip to content

Commit 51331f6

Browse files
committed
auto merge of #8974 : thestinger/rust/char, r=huonw
Closes #7609
2 parents 787f4c9 + 62a3434 commit 51331f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+227
-215
lines changed

src/etc/unicode.py

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def emit_property_module(f, mod, tbl):
158158
keys.sort()
159159
emit_bsearch_range_table(f);
160160
for cat in keys:
161+
if cat == "Cs": continue
161162
f.write(" static %s_table : &'static [(char,char)] = &[\n" % cat)
162163
ix = 0
163164
for pair in tbl[cat]:

src/libextra/ebml.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#[allow(missing_doc)];
1212

13-
1413
use std::str;
1514

1615
// Simple Extensible Binary Markup Language (ebml) reader and writer on a
@@ -90,6 +89,7 @@ pub enum EbmlEncoderTag {
9089
// --------------------------------------
9190

9291
pub mod reader {
92+
use std::char;
9393
use super::*;
9494

9595
use serialize;
@@ -426,7 +426,7 @@ pub mod reader {
426426
(unsafe { transmute::<u64, f64>(bits) }) as float
427427
}
428428
fn read_char(&mut self) -> char {
429-
doc_as_u32(self.next_doc(EsChar)) as char
429+
char::from_u32(doc_as_u32(self.next_doc(EsChar))).unwrap()
430430
}
431431
fn read_str(&mut self) -> ~str {
432432
self.next_doc(EsStr).as_str()

src/libextra/json.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
//! json parsing and serialization
1818
19+
use std::char;
20+
use std::cast::transmute;
1921
use std::iterator;
2022
use std::float;
2123
use std::hashmap::HashMap;
@@ -490,7 +492,7 @@ pub struct Parser<T> {
490492
pub fn Parser<T : iterator::Iterator<char>>(rdr: ~T) -> Parser<T> {
491493
let mut p = Parser {
492494
rdr: rdr,
493-
ch: 0 as char,
495+
ch: '\x00',
494496
line: 1,
495497
col: 0,
496498
};
@@ -517,12 +519,13 @@ impl<T: iterator::Iterator<char>> Parser<T> {
517519
}
518520

519521
impl<T : iterator::Iterator<char>> Parser<T> {
520-
fn eof(&self) -> bool { self.ch == -1 as char }
522+
// FIXME: #8971: unsound
523+
fn eof(&self) -> bool { self.ch == unsafe { transmute(-1u32) } }
521524

522525
fn bump(&mut self) {
523526
match self.rdr.next() {
524527
Some(ch) => self.ch = ch,
525-
None() => self.ch = -1 as char,
528+
None() => self.ch = unsafe { transmute(-1u32) }, // FIXME: #8971: unsound
526529
}
527530

528531
if self.ch == '\n' {
@@ -755,7 +758,7 @@ impl<T : iterator::Iterator<char>> Parser<T> {
755758
~"invalid \\u escape (not four digits)");
756759
}
757760

758-
res.push_char(n as char);
761+
res.push_char(char::from_u32(n as u32).unwrap());
759762
}
760763
_ => return self.error(~"invalid escape")
761764
}

src/libextra/terminfo/parm.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
258258
' ' => flags.space = true,
259259
'.' => fstate = FormatStatePrecision,
260260
'0'..'9' => {
261-
flags.width = (cur - '0') as uint;
261+
flags.width = (cur as uint - '0' as uint);
262262
fstate = FormatStateWidth;
263263
}
264264
_ => util::unreachable()
@@ -330,7 +330,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
330330
state = Nothing;
331331
}
332332
'0'..'9' => {
333-
state = IntConstant(i*10 + ((cur - '0') as int));
333+
state = IntConstant(i*10 + (cur as int - '0' as int));
334334
old_state = Nothing;
335335
}
336336
_ => return Err(~"bad int constant")
@@ -358,23 +358,23 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
358358
flags.space = true;
359359
}
360360
(FormatStateFlags,'0'..'9') => {
361-
flags.width = (cur - '0') as uint;
361+
flags.width = (cur as uint - '0' as uint);
362362
*fstate = FormatStateWidth;
363363
}
364364
(FormatStateFlags,'.') => {
365365
*fstate = FormatStatePrecision;
366366
}
367367
(FormatStateWidth,'0'..'9') => {
368368
let old = flags.width;
369-
flags.width = flags.width * 10 + ((cur - '0') as uint);
369+
flags.width = flags.width * 10 + (cur as uint - '0' as uint);
370370
if flags.width < old { return Err(~"format width overflow") }
371371
}
372372
(FormatStateWidth,'.') => {
373373
*fstate = FormatStatePrecision;
374374
}
375375
(FormatStatePrecision,'0'..'9') => {
376376
let old = flags.precision;
377-
flags.precision = flags.precision * 10 + ((cur - '0') as uint);
377+
flags.precision = flags.precision * 10 + (cur as uint - '0' as uint);
378378
if flags.precision < old { return Err(~"format precision overflow") }
379379
}
380380
_ => return Err(~"invalid format specifier")

src/libextra/url.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn encode_inner(s: &str, full_url: bool) -> ~str {
7272
let mut out = ~"";
7373

7474
while !rdr.eof() {
75-
let ch = rdr.read_byte() as char;
75+
let ch = rdr.read_byte() as u8 as char;
7676
match ch {
7777
// unreserved:
7878
'A' .. 'Z' |
@@ -135,7 +135,7 @@ fn decode_inner(s: &str, full_url: bool) -> ~str {
135135
match rdr.read_char() {
136136
'%' => {
137137
let bytes = rdr.read_bytes(2u);
138-
let ch = uint::parse_bytes(bytes, 16u).unwrap() as char;
138+
let ch = uint::parse_bytes(bytes, 16u).unwrap() as u8 as char;
139139

140140
if full_url {
141141
// Only decode some characters:
@@ -186,7 +186,7 @@ fn encode_plus(s: &str) -> ~str {
186186
let mut out = ~"";
187187

188188
while !rdr.eof() {
189-
let ch = rdr.read_byte() as char;
189+
let ch = rdr.read_byte() as u8 as char;
190190
match ch {
191191
'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '_' | '.' | '-' => {
192192
out.push_char(ch);
@@ -258,7 +258,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
258258
let ch = match ch {
259259
'%' => {
260260
let bytes = rdr.read_bytes(2u);
261-
uint::parse_bytes(bytes, 16u).unwrap() as char
261+
uint::parse_bytes(bytes, 16u).unwrap() as u8 as char
262262
}
263263
'+' => ' ',
264264
ch => ch
@@ -295,7 +295,7 @@ fn split_char_first(s: &str, c: char) -> (~str, ~str) {
295295
do io::with_str_reader(s) |rdr| {
296296
let mut ch;
297297
while !rdr.eof() {
298-
ch = rdr.read_byte() as char;
298+
ch = rdr.read_byte() as u8 as char;
299299
if ch == c {
300300
// found a match, adjust markers
301301
index = rdr.tell()-1;

src/librustc/metadata/tyencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ fn enc_sty(w: @io::Writer, cx: @ctxt, st: &ty::sty) {
239239
ty::ty_nil => w.write_char('n'),
240240
ty::ty_bot => w.write_char('z'),
241241
ty::ty_bool => w.write_char('b'),
242+
ty::ty_char => w.write_char('c'),
242243
ty::ty_int(t) => {
243244
match t {
244245
ty_i => w.write_char('i'),
245-
ty_char => w.write_char('c'),
246246
ty_i8 => w.write_str(&"MB"),
247247
ty_i16 => w.write_str(&"MW"),
248248
ty_i32 => w.write_str(&"ML"),

src/librustc/middle/check_const.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,19 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
200200
}
201201
}
202202
match e.node {
203-
ExprLit(@codemap::Spanned {node: lit_int(v, t), _}) => {
204-
if t != ty_char {
203+
ExprLit(@codemap::Spanned {node: lit_int(v, t), _}) => {
205204
if (v as u64) > ast_util::int_ty_max(
206205
if t == ty_i { sess.targ_cfg.int_type } else { t }) {
207206
sess.span_err(e.span, "literal out of range for its type");
208207
}
209208
}
210-
}
211-
ExprLit(@codemap::Spanned {node: lit_uint(v, t), _}) => {
212-
if v > ast_util::uint_ty_max(
213-
if t == ty_u { sess.targ_cfg.uint_type } else { t }) {
214-
sess.span_err(e.span, "literal out of range for its type");
209+
ExprLit(@codemap::Spanned {node: lit_uint(v, t), _}) => {
210+
if v > ast_util::uint_ty_max(
211+
if t == ty_u { sess.targ_cfg.uint_type } else { t }) {
212+
sess.span_err(e.span, "literal out of range for its type");
213+
}
215214
}
216-
}
217-
_ => ()
215+
_ => ()
218216
}
219217
visit::walk_expr(v, e, is_const);
220218
}

src/librustc/middle/const_eval.rs

+1
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
472472
pub fn lit_to_const(lit: &lit) -> const_val {
473473
match lit.node {
474474
lit_str(s) => const_str(s),
475+
lit_char(n) => const_uint(n as u64),
475476
lit_int(n, _) => const_int(n),
476477
lit_uint(n, _) => const_uint(n),
477478
lit_int_unsuffixed(n) => const_int(n),

src/librustc/middle/lint.rs

-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ impl TypeLimitsLintVisitor {
778778
fn int_ty_range(&mut self, int_ty: ast::int_ty) -> (i64, i64) {
779779
match int_ty {
780780
ast::ty_i => (i64::min_value, i64::max_value),
781-
ast::ty_char => (u32::min_value as i64, u32::max_value as i64),
782781
ast::ty_i8 => (i8::min_value as i64, i8::max_value as i64),
783782
ast::ty_i16 => (i16::min_value as i64, i16::max_value as i64),
784783
ast::ty_i32 => (i32::min_value as i64, i32::max_value as i64),

src/librustc/middle/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ pub fn PrimitiveTypeTable() -> PrimitiveTypeTable {
777777
};
778778

779779
table.intern("bool", ty_bool);
780-
table.intern("char", ty_int(ty_char));
780+
table.intern("char", ty_char);
781781
table.intern("float", ty_float(ty_f));
782782
table.intern("f32", ty_float(ty_f32));
783783
table.intern("f64", ty_float(ty_f64));

src/librustc/middle/trans/base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ pub fn compare_scalar_types(cx: @mut Block,
566566
match ty::get(t).sty {
567567
ty::ty_nil => rslt(cx, f(nil_type)),
568568
ty::ty_bool | ty::ty_ptr(_) => rslt(cx, f(unsigned_int)),
569+
ty::ty_char => rslt(cx, f(unsigned_int)),
569570
ty::ty_int(_) => rslt(cx, f(signed_int)),
570571
ty::ty_uint(_) => rslt(cx, f(unsigned_int)),
571572
ty::ty_float(_) => rslt(cx, f(floating_point)),

src/librustc/middle/trans/consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn const_lit(cx: &mut CrateContext, e: &ast::Expr, lit: ast::lit)
3939
-> ValueRef {
4040
let _icx = push_ctxt("trans_lit");
4141
match lit.node {
42+
ast::lit_char(i) => C_integral(Type::char(), i as u64, false),
4243
ast::lit_int(i, t) => C_integral(Type::int_from_ty(cx, t), i as u64, true),
4344
ast::lit_uint(u, t) => C_integral(Type::uint_from_ty(cx, t), u, false),
4445
ast::lit_int_unsuffixed(i) => {

src/librustc/middle/trans/debuginfo.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,9 @@ fn basic_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType {
746746
let (name, encoding) = match ty::get(t).sty {
747747
ty::ty_nil | ty::ty_bot => (~"uint", DW_ATE_unsigned),
748748
ty::ty_bool => (~"bool", DW_ATE_boolean),
749+
ty::ty_char => (~"char", DW_ATE_unsigned_char),
749750
ty::ty_int(int_ty) => match int_ty {
750751
ast::ty_i => (~"int", DW_ATE_signed),
751-
ast::ty_char => (~"char", DW_ATE_signed_char),
752752
ast::ty_i8 => (~"i8", DW_ATE_signed),
753753
ast::ty_i16 => (~"i16", DW_ATE_signed),
754754
ast::ty_i32 => (~"i32", DW_ATE_signed),
@@ -1344,6 +1344,7 @@ fn type_metadata(cx: &mut CrateContext,
13441344
ty::ty_nil |
13451345
ty::ty_bot |
13461346
ty::ty_bool |
1347+
ty::ty_char |
13471348
ty::ty_int(_) |
13481349
ty::ty_uint(_) |
13491350
ty::ty_float(_) => {

src/librustc/middle/trans/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,7 @@ pub enum cast_kind {
16301630

16311631
pub fn cast_type_kind(t: ty::t) -> cast_kind {
16321632
match ty::get(t).sty {
1633+
ty::ty_char => cast_integral,
16331634
ty::ty_float(*) => cast_float,
16341635
ty::ty_ptr(*) => cast_pointer,
16351636
ty::ty_rptr(*) => cast_pointer,

src/librustc/middle/trans/reflect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ impl Reflector {
157157
ty::ty_bot => self.leaf("bot"),
158158
ty::ty_nil => self.leaf("nil"),
159159
ty::ty_bool => self.leaf("bool"),
160+
ty::ty_char => self.leaf("char"),
160161
ty::ty_int(ast::ty_i) => self.leaf("int"),
161-
ty::ty_int(ast::ty_char) => self.leaf("char"),
162162
ty::ty_int(ast::ty_i8) => self.leaf("i8"),
163163
ty::ty_int(ast::ty_i16) => self.leaf("i16"),
164164
ty::ty_int(ast::ty_i32) => self.leaf("i32"),

src/librustc/middle/trans/type_.rs

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ impl Type {
119119
pub fn int_from_ty(ctx: &CrateContext, t: ast::int_ty) -> Type {
120120
match t {
121121
ast::ty_i => ctx.int_type,
122-
ast::ty_char => Type::char(),
123122
ast::ty_i8 => Type::i8(),
124123
ast::ty_i16 => Type::i16(),
125124
ast::ty_i32 => Type::i32(),

src/librustc/middle/trans/type_of.rs

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub fn sizing_type_of(cx: &mut CrateContext, t: ty::t) -> Type {
108108
let llsizingty = match ty::get(t).sty {
109109
ty::ty_nil | ty::ty_bot => Type::nil(),
110110
ty::ty_bool => Type::bool(),
111+
ty::ty_char => Type::char(),
111112
ty::ty_int(t) => Type::int_from_ty(cx, t),
112113
ty::ty_uint(t) => Type::uint_from_ty(cx, t),
113114
ty::ty_float(t) => Type::float_from_ty(cx, t),
@@ -195,6 +196,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
195196
let mut llty = match ty::get(t).sty {
196197
ty::ty_nil | ty::ty_bot => Type::nil(),
197198
ty::ty_bool => Type::bool(),
199+
ty::ty_char => Type::char(),
198200
ty::ty_int(t) => Type::int_from_ty(cx, t),
199201
ty::ty_uint(t) => Type::uint_from_ty(cx, t),
200202
ty::ty_float(t) => Type::float_from_ty(cx, t),

0 commit comments

Comments
 (0)