auto merge of #13452 : Ryman/rust/fix_uint_as_u, r=alexcrichton
Fixes #13359.
This commit is contained in:
commit
465109df62
@ -341,10 +341,8 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
|
||||
ty_bot => ~"!",
|
||||
ty_bool => ~"bool",
|
||||
ty_char => ~"char",
|
||||
ty_int(ast::TyI) => ~"int",
|
||||
ty_int(t) => ast_util::int_ty_to_str(t),
|
||||
ty_uint(ast::TyU) => ~"uint",
|
||||
ty_uint(t) => ast_util::uint_ty_to_str(t),
|
||||
ty_int(t) => ast_util::int_ty_to_str(t, None),
|
||||
ty_uint(t) => ast_util::uint_ty_to_str(t, None),
|
||||
ty_float(t) => ast_util::float_ty_to_str(t),
|
||||
ty_box(typ) => ~"@" + ty_to_str(cx, typ),
|
||||
ty_uniq(typ) => ~"~" + ty_to_str(cx, typ),
|
||||
|
@ -707,7 +707,7 @@ pub enum IntTy {
|
||||
|
||||
impl fmt::Show for IntTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f.buf, "{}", ast_util::int_ty_to_str(*self))
|
||||
write!(f.buf, "{}", ast_util::int_ty_to_str(*self, None))
|
||||
}
|
||||
}
|
||||
|
||||
@ -722,7 +722,7 @@ pub enum UintTy {
|
||||
|
||||
impl fmt::Show for UintTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f.buf, "{}", ast_util::uint_ty_to_str(*self))
|
||||
write!(f.buf, "{}", ast_util::uint_ty_to_str(*self, None))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,13 +132,21 @@ pub fn is_path(e: @Expr) -> bool {
|
||||
return match e.node { ExprPath(_) => true, _ => false };
|
||||
}
|
||||
|
||||
pub fn int_ty_to_str(t: IntTy) -> ~str {
|
||||
match t {
|
||||
TyI => ~"",
|
||||
TyI8 => ~"i8",
|
||||
TyI16 => ~"i16",
|
||||
TyI32 => ~"i32",
|
||||
TyI64 => ~"i64"
|
||||
// Get a string representation of a signed int type, with its value.
|
||||
// We want to avoid "45int" and "-3int" in favor of "45" and "-3"
|
||||
pub fn int_ty_to_str(t: IntTy, val: Option<i64>) -> ~str {
|
||||
let s = match t {
|
||||
TyI if val.is_some() => "",
|
||||
TyI => "int",
|
||||
TyI8 => "i8",
|
||||
TyI16 => "i16",
|
||||
TyI32 => "i32",
|
||||
TyI64 => "i64"
|
||||
};
|
||||
|
||||
match val {
|
||||
Some(n) => format!("{}{}", n, s),
|
||||
None => s.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,13 +159,21 @@ pub fn int_ty_max(t: IntTy) -> u64 {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn uint_ty_to_str(t: UintTy) -> ~str {
|
||||
match t {
|
||||
TyU => ~"u",
|
||||
TyU8 => ~"u8",
|
||||
TyU16 => ~"u16",
|
||||
TyU32 => ~"u32",
|
||||
TyU64 => ~"u64"
|
||||
// Get a string representation of an unsigned int type, with its value.
|
||||
// We want to avoid "42uint" in favor of "42u"
|
||||
pub fn uint_ty_to_str(t: UintTy, val: Option<u64>) -> ~str {
|
||||
let s = match t {
|
||||
TyU if val.is_some() => "u",
|
||||
TyU => "uint",
|
||||
TyU8 => "u8",
|
||||
TyU16 => "u16",
|
||||
TyU32 => "u32",
|
||||
TyU64 => "u64"
|
||||
};
|
||||
|
||||
match val {
|
||||
Some(n) => format!("{}{}", n, s),
|
||||
None => s.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,12 +201,8 @@ pub fn to_str(t: &Token) -> ~str {
|
||||
res.push_char('\'');
|
||||
res.into_owned()
|
||||
}
|
||||
LIT_INT(i, t) => {
|
||||
i.to_str() + ast_util::int_ty_to_str(t)
|
||||
}
|
||||
LIT_UINT(u, t) => {
|
||||
u.to_str() + ast_util::uint_ty_to_str(t)
|
||||
}
|
||||
LIT_INT(i, t) => ast_util::int_ty_to_str(t, Some(i)),
|
||||
LIT_UINT(u, t) => ast_util::uint_ty_to_str(t, Some(u)),
|
||||
LIT_INT_UNSUFFIXED(i) => { i.to_str() }
|
||||
LIT_FLOAT(s, t) => {
|
||||
let mut body = StrBuf::from_str(get_ident(s).get());
|
||||
|
@ -2171,10 +2171,10 @@ impl<'a> State<'a> {
|
||||
word(&mut self.s, res.into_owned())
|
||||
}
|
||||
ast::LitInt(i, t) => {
|
||||
word(&mut self.s, format!("{}{}", i, ast_util::int_ty_to_str(t)))
|
||||
word(&mut self.s, ast_util::int_ty_to_str(t, Some(i)))
|
||||
}
|
||||
ast::LitUint(u, t) => {
|
||||
word(&mut self.s, format!("{}{}", u, ast_util::uint_ty_to_str(t)))
|
||||
word(&mut self.s, ast_util::uint_ty_to_str(t, Some(u)))
|
||||
}
|
||||
ast::LitIntUnsuffixed(i) => {
|
||||
word(&mut self.s, format!("{}", i))
|
||||
|
21
src/test/compile-fail/issue13359.rs
Normal file
21
src/test/compile-fail/issue13359.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn foo(_s: i16) { }
|
||||
|
||||
fn bar(_s: u32) { }
|
||||
|
||||
fn main() {
|
||||
foo(1*(1 as int));
|
||||
//~^ ERROR: mismatched types: expected `i16` but found `int` (expected `i16` but found `int`)
|
||||
|
||||
bar(1*(1 as uint));
|
||||
//~^ ERROR: mismatched types: expected `u32` but found `uint` (expected `u32` but found `uint`)
|
||||
}
|
Loading…
Reference in New Issue
Block a user