From 9e3d0b002a5c2e81d43351c9b8550a3f4ccfb8f9 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 21 Apr 2014 17:58:52 -0400 Subject: librustc: Remove the fallback to `int` from typechecking. This breaks a fair amount of code. The typical patterns are: * `for _ in range(0, 10)`: change to `for _ in range(0u, 10)`; * `println!("{}", 3)`: change to `println!("{}", 3i)`; * `[1, 2, 3].len()`: change to `[1i, 2, 3].len()`. RFC #30. Closes #6023. [breaking-change] --- src/libsyntax/abi.rs | 8 ++++---- src/libsyntax/ast.rs | 6 ++---- src/libsyntax/ast_util.rs | 19 ++++--------------- src/libsyntax/parse/token.rs | 6 ++---- src/libsyntax/print/pp.rs | 2 +- src/libsyntax/print/pprust.rs | 6 ++---- src/libsyntax/util/small_vector.rs | 16 ++++++++-------- 7 files changed, 23 insertions(+), 40 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 3d6266fd4c0..9771bc9386b 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -150,7 +150,7 @@ impl Abi { impl Architecture { fn bit(&self) -> u32 { - 1 << (*self as u32) + 1 << (*self as uint) } } @@ -198,11 +198,11 @@ fn indices_are_correct() { assert_eq!(i, abi_data.abi.index()); } - let bits = 1 << (X86 as u32); - let bits = bits | 1 << (X86_64 as u32); + let bits = 1 << (X86 as uint); + let bits = bits | 1 << (X86_64 as uint); assert_eq!(IntelBits, bits); - let bits = 1 << (Arm as u32); + let bits = 1 << (Arm as uint); assert_eq!(ArmBits, bits); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index aeafc0e306c..64d381d2b12 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -675,8 +675,7 @@ pub enum IntTy { impl fmt::Show for IntTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", - ast_util::int_ty_to_str(*self, None, ast_util::AutoSuffix)) + write!(f, "{}", ast_util::int_ty_to_str(*self, None)) } } @@ -691,8 +690,7 @@ pub enum UintTy { impl fmt::Show for UintTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", - ast_util::uint_ty_to_str(*self, None, ast_util::AutoSuffix)) + write!(f, "{}", ast_util::uint_ty_to_str(*self, None)) } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index d28553da691..95bd35764e7 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -107,19 +107,11 @@ pub fn is_path(e: Gc) -> bool { return match e.node { ExprPath(_) => true, _ => false }; } -pub enum SuffixMode { - ForceSuffix, - AutoSuffix, -} - // 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, mode: SuffixMode) -> String { +pub fn int_ty_to_str(t: IntTy, val: Option) -> String { let s = match t { - TyI if val.is_some() => match mode { - AutoSuffix => "", - ForceSuffix => "i", - }, + TyI if val.is_some() => "i", TyI => "int", TyI8 => "i8", TyI16 => "i16", @@ -147,12 +139,9 @@ pub fn int_ty_max(t: IntTy) -> 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, mode: SuffixMode) -> String { +pub fn uint_ty_to_str(t: UintTy, val: Option) -> String { let s = match t { - TyU if val.is_some() => match mode { - AutoSuffix => "", - ForceSuffix => "u", - }, + TyU if val.is_some() => "u", TyU => "uint", TyU8 => "u8", TyU16 => "u16", diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 8e36339b0e5..9549d5b8389 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -212,10 +212,8 @@ pub fn to_str(t: &Token) -> String { res.push_char('\''); res } - LIT_INT(i, t) => ast_util::int_ty_to_str(t, Some(i), - ast_util::ForceSuffix), - LIT_UINT(u, t) => ast_util::uint_ty_to_str(t, Some(u), - ast_util::ForceSuffix), + 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 as u64).to_str() } LIT_FLOAT(s, t) => { let mut body = String::from_str(get_ident(s).get()); diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 672e08af2d8..854aa80ca34 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -163,7 +163,7 @@ pub fn mk_printer(out: Box, linewidth: uint) -> Printer { let n: uint = 3 * linewidth; debug!("mk_printer {}", linewidth); let token: Vec = Vec::from_elem(n, Eof); - let size: Vec = Vec::from_elem(n, 0); + let size: Vec = Vec::from_elem(n, 0i); let scan_stack: Vec = Vec::from_elem(n, 0u); Printer { out: out, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index fafebd3c5dc..97e99ca692d 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2319,13 +2319,11 @@ impl<'a> State<'a> { } ast::LitInt(i, t) => { word(&mut self.s, - ast_util::int_ty_to_str(t, Some(i), - ast_util::AutoSuffix).as_slice()) + ast_util::int_ty_to_str(t, Some(i)).as_slice()) } ast::LitUint(u, t) => { word(&mut self.s, - ast_util::uint_ty_to_str(t, Some(u), - ast_util::ForceSuffix).as_slice()) + ast_util::uint_ty_to_str(t, Some(u)).as_slice()) } ast::LitIntUnsuffixed(i) => { word(&mut self.s, format!("{}", i).as_slice()) diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index a3b2c23dfdf..d5cc2c7f304 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -173,7 +173,7 @@ mod test { #[test] fn test_push_get() { let mut v = SmallVector::zero(); - v.push(1); + v.push(1i); assert_eq!(1, v.len()); assert_eq!(&1, v.get(0)); v.push(2); @@ -186,7 +186,7 @@ mod test { #[test] fn test_from_iter() { - let v: SmallVector = (vec!(1, 2, 3)).move_iter().collect(); + let v: SmallVector = (vec!(1i, 2, 3)).move_iter().collect(); assert_eq!(3, v.len()); assert_eq!(&1, v.get(0)); assert_eq!(&2, v.get(1)); @@ -199,11 +199,11 @@ mod test { let v: Vec = v.move_iter().collect(); assert_eq!(Vec::new(), v); - let v = SmallVector::one(1); - assert_eq!(vec!(1), v.move_iter().collect()); + let v = SmallVector::one(1i); + assert_eq!(vec!(1i), v.move_iter().collect()); - let v = SmallVector::many(vec!(1, 2, 3)); - assert_eq!(vec!(1, 2, 3), v.move_iter().collect()); + let v = SmallVector::many(vec!(1i, 2i, 3i)); + assert_eq!(vec!(1i, 2i, 3i), v.move_iter().collect()); } #[test] @@ -220,7 +220,7 @@ mod test { #[test] fn test_expect_one_one() { - assert_eq!(1, SmallVector::one(1).expect_one("")); - assert_eq!(1, SmallVector::many(vec!(1)).expect_one("")); + assert_eq!(1i, SmallVector::one(1i).expect_one("")); + assert_eq!(1i, SmallVector::many(vec!(1i)).expect_one("")); } } -- cgit 1.4.1-3-g733a5