Skip to content
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

stop treating char as an integer type #8974

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
1 change: 1 addition & 0 deletions src/etc/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def emit_property_module(f, mod, tbl):
keys.sort()
emit_bsearch_range_table(f);
for cat in keys:
if cat == "Cs": continue
f.write(" static %s_table : &'static [(char,char)] = &[\n" % cat)
ix = 0
for pair in tbl[cat]:
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/ebml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#[allow(missing_doc)];


use std::str;

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

pub mod reader {
use std::char;
use super::*;

use serialize;
Expand Down Expand Up @@ -426,7 +426,7 @@ pub mod reader {
(unsafe { transmute::<u64, f64>(bits) }) as float
}
fn read_char(&mut self) -> char {
doc_as_u32(self.next_doc(EsChar)) as char
char::from_u32(doc_as_u32(self.next_doc(EsChar))).unwrap()
}
fn read_str(&mut self) -> ~str {
self.next_doc(EsStr).as_str()
Expand Down
11 changes: 7 additions & 4 deletions src/libextra/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

//! json parsing and serialization

use std::char;
use std::cast::transmute;
use std::iterator;
use std::float;
use std::hashmap::HashMap;
Expand Down Expand Up @@ -490,7 +492,7 @@ pub struct Parser<T> {
pub fn Parser<T : iterator::Iterator<char>>(rdr: ~T) -> Parser<T> {
let mut p = Parser {
rdr: rdr,
ch: 0 as char,
ch: '\x00',
line: 1,
col: 0,
};
Expand All @@ -517,12 +519,13 @@ impl<T: iterator::Iterator<char>> Parser<T> {
}

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

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

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

res.push_char(n as char);
res.push_char(char::from_u32(n as u32).unwrap());
}
_ => return self.error(~"invalid escape")
}
Expand Down
10 changes: 5 additions & 5 deletions src/libextra/terminfo/parm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
' ' => flags.space = true,
'.' => fstate = FormatStatePrecision,
'0'..'9' => {
flags.width = (cur - '0') as uint;
flags.width = (cur as uint - '0' as uint);
fstate = FormatStateWidth;
}
_ => util::unreachable()
Expand Down Expand Up @@ -330,7 +330,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
state = Nothing;
}
'0'..'9' => {
state = IntConstant(i*10 + ((cur - '0') as int));
state = IntConstant(i*10 + (cur as int - '0' as int));
old_state = Nothing;
}
_ => return Err(~"bad int constant")
Expand Down Expand Up @@ -358,23 +358,23 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
flags.space = true;
}
(FormatStateFlags,'0'..'9') => {
flags.width = (cur - '0') as uint;
flags.width = (cur as uint - '0' as uint);
*fstate = FormatStateWidth;
}
(FormatStateFlags,'.') => {
*fstate = FormatStatePrecision;
}
(FormatStateWidth,'0'..'9') => {
let old = flags.width;
flags.width = flags.width * 10 + ((cur - '0') as uint);
flags.width = flags.width * 10 + (cur as uint - '0' as uint);
if flags.width < old { return Err(~"format width overflow") }
}
(FormatStateWidth,'.') => {
*fstate = FormatStatePrecision;
}
(FormatStatePrecision,'0'..'9') => {
let old = flags.precision;
flags.precision = flags.precision * 10 + ((cur - '0') as uint);
flags.precision = flags.precision * 10 + (cur as uint - '0' as uint);
if flags.precision < old { return Err(~"format precision overflow") }
}
_ => return Err(~"invalid format specifier")
Expand Down
10 changes: 5 additions & 5 deletions src/libextra/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn encode_inner(s: &str, full_url: bool) -> ~str {
let mut out = ~"";

while !rdr.eof() {
let ch = rdr.read_byte() as char;
let ch = rdr.read_byte() as u8 as char;
match ch {
// unreserved:
'A' .. 'Z' |
Expand Down Expand Up @@ -135,7 +135,7 @@ fn decode_inner(s: &str, full_url: bool) -> ~str {
match rdr.read_char() {
'%' => {
let bytes = rdr.read_bytes(2u);
let ch = uint::parse_bytes(bytes, 16u).unwrap() as char;
let ch = uint::parse_bytes(bytes, 16u).unwrap() as u8 as char;

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

while !rdr.eof() {
let ch = rdr.read_byte() as char;
let ch = rdr.read_byte() as u8 as char;
match ch {
'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '_' | '.' | '-' => {
out.push_char(ch);
Expand Down Expand Up @@ -258,7 +258,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
let ch = match ch {
'%' => {
let bytes = rdr.read_bytes(2u);
uint::parse_bytes(bytes, 16u).unwrap() as char
uint::parse_bytes(bytes, 16u).unwrap() as u8 as char
}
'+' => ' ',
ch => ch
Expand Down Expand Up @@ -295,7 +295,7 @@ fn split_char_first(s: &str, c: char) -> (~str, ~str) {
do io::with_str_reader(s) |rdr| {
let mut ch;
while !rdr.eof() {
ch = rdr.read_byte() as char;
ch = rdr.read_byte() as u8 as char;
if ch == c {
// found a match, adjust markers
index = rdr.tell()-1;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ fn enc_sty(w: @io::Writer, cx: @ctxt, st: &ty::sty) {
ty::ty_nil => w.write_char('n'),
ty::ty_bot => w.write_char('z'),
ty::ty_bool => w.write_char('b'),
ty::ty_char => w.write_char('c'),
ty::ty_int(t) => {
match t {
ty_i => w.write_char('i'),
ty_char => w.write_char('c'),
ty_i8 => w.write_str(&"MB"),
ty_i16 => w.write_str(&"MW"),
ty_i32 => w.write_str(&"ML"),
Expand Down
16 changes: 7 additions & 9 deletions src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,19 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
}
}
match e.node {
ExprLit(@codemap::Spanned {node: lit_int(v, t), _}) => {
if t != ty_char {
ExprLit(@codemap::Spanned {node: lit_int(v, t), _}) => {
if (v as u64) > ast_util::int_ty_max(
if t == ty_i { sess.targ_cfg.int_type } else { t }) {
sess.span_err(e.span, "literal out of range for its type");
}
}
}
ExprLit(@codemap::Spanned {node: lit_uint(v, t), _}) => {
if v > ast_util::uint_ty_max(
if t == ty_u { sess.targ_cfg.uint_type } else { t }) {
sess.span_err(e.span, "literal out of range for its type");
ExprLit(@codemap::Spanned {node: lit_uint(v, t), _}) => {
if v > ast_util::uint_ty_max(
if t == ty_u { sess.targ_cfg.uint_type } else { t }) {
sess.span_err(e.span, "literal out of range for its type");
}
}
}
_ => ()
_ => ()
}
visit::walk_expr(v, e, is_const);
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
pub fn lit_to_const(lit: &lit) -> const_val {
match lit.node {
lit_str(s) => const_str(s),
lit_char(n) => const_uint(n as u64),
lit_int(n, _) => const_int(n),
lit_uint(n, _) => const_uint(n),
lit_int_unsuffixed(n) => const_int(n),
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,6 @@ impl TypeLimitsLintVisitor {
fn int_ty_range(&mut self, int_ty: ast::int_ty) -> (i64, i64) {
match int_ty {
ast::ty_i => (i64::min_value, i64::max_value),
ast::ty_char => (u32::min_value as i64, u32::max_value as i64),
ast::ty_i8 => (i8::min_value as i64, i8::max_value as i64),
ast::ty_i16 => (i16::min_value as i64, i16::max_value as i64),
ast::ty_i32 => (i32::min_value as i64, i32::max_value as i64),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ pub fn PrimitiveTypeTable() -> PrimitiveTypeTable {
};

table.intern("bool", ty_bool);
table.intern("char", ty_int(ty_char));
table.intern("char", ty_char);
table.intern("float", ty_float(ty_f));
table.intern("f32", ty_float(ty_f32));
table.intern("f64", ty_float(ty_f64));
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ pub fn compare_scalar_types(cx: @mut Block,
match ty::get(t).sty {
ty::ty_nil => rslt(cx, f(nil_type)),
ty::ty_bool | ty::ty_ptr(_) => rslt(cx, f(unsigned_int)),
ty::ty_char => rslt(cx, f(unsigned_int)),
ty::ty_int(_) => rslt(cx, f(signed_int)),
ty::ty_uint(_) => rslt(cx, f(unsigned_int)),
ty::ty_float(_) => rslt(cx, f(floating_point)),
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn const_lit(cx: &mut CrateContext, e: &ast::Expr, lit: ast::lit)
-> ValueRef {
let _icx = push_ctxt("trans_lit");
match lit.node {
ast::lit_char(i) => C_integral(Type::char(), i as u64, false),
ast::lit_int(i, t) => C_integral(Type::int_from_ty(cx, t), i as u64, true),
ast::lit_uint(u, t) => C_integral(Type::uint_from_ty(cx, t), u, false),
ast::lit_int_unsuffixed(i) => {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,9 @@ fn basic_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType {
let (name, encoding) = match ty::get(t).sty {
ty::ty_nil | ty::ty_bot => (~"uint", DW_ATE_unsigned),
ty::ty_bool => (~"bool", DW_ATE_boolean),
ty::ty_char => (~"char", DW_ATE_unsigned_char),
ty::ty_int(int_ty) => match int_ty {
ast::ty_i => (~"int", DW_ATE_signed),
ast::ty_char => (~"char", DW_ATE_signed_char),
ast::ty_i8 => (~"i8", DW_ATE_signed),
ast::ty_i16 => (~"i16", DW_ATE_signed),
ast::ty_i32 => (~"i32", DW_ATE_signed),
Expand Down Expand Up @@ -1344,6 +1344,7 @@ fn type_metadata(cx: &mut CrateContext,
ty::ty_nil |
ty::ty_bot |
ty::ty_bool |
ty::ty_char |
ty::ty_int(_) |
ty::ty_uint(_) |
ty::ty_float(_) => {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,7 @@ pub enum cast_kind {

pub fn cast_type_kind(t: ty::t) -> cast_kind {
match ty::get(t).sty {
ty::ty_char => cast_integral,
ty::ty_float(*) => cast_float,
ty::ty_ptr(*) => cast_pointer,
ty::ty_rptr(*) => cast_pointer,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ impl Reflector {
ty::ty_bot => self.leaf("bot"),
ty::ty_nil => self.leaf("nil"),
ty::ty_bool => self.leaf("bool"),
ty::ty_char => self.leaf("char"),
ty::ty_int(ast::ty_i) => self.leaf("int"),
ty::ty_int(ast::ty_char) => self.leaf("char"),
ty::ty_int(ast::ty_i8) => self.leaf("i8"),
ty::ty_int(ast::ty_i16) => self.leaf("i16"),
ty::ty_int(ast::ty_i32) => self.leaf("i32"),
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/trans/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ impl Type {
pub fn int_from_ty(ctx: &CrateContext, t: ast::int_ty) -> Type {
match t {
ast::ty_i => ctx.int_type,
ast::ty_char => Type::char(),
ast::ty_i8 => Type::i8(),
ast::ty_i16 => Type::i16(),
ast::ty_i32 => Type::i32(),
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/middle/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub fn sizing_type_of(cx: &mut CrateContext, t: ty::t) -> Type {
let llsizingty = match ty::get(t).sty {
ty::ty_nil | ty::ty_bot => Type::nil(),
ty::ty_bool => Type::bool(),
ty::ty_char => Type::char(),
ty::ty_int(t) => Type::int_from_ty(cx, t),
ty::ty_uint(t) => Type::uint_from_ty(cx, t),
ty::ty_float(t) => Type::float_from_ty(cx, t),
Expand Down Expand Up @@ -195,6 +196,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
let mut llty = match ty::get(t).sty {
ty::ty_nil | ty::ty_bot => Type::nil(),
ty::ty_bool => Type::bool(),
ty::ty_char => Type::char(),
ty::ty_int(t) => Type::int_from_ty(cx, t),
ty::ty_uint(t) => Type::uint_from_ty(cx, t),
ty::ty_float(t) => Type::float_from_ty(cx, t),
Expand Down
Loading