diff options
| author | bors <bors@rust-lang.org> | 2015-11-24 17:10:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-11-24 17:10:55 +0000 |
| commit | 1004860dd42632733d985bbf23bd12d0fd23badb (patch) | |
| tree | e95279740b4684ddf1920e66194de5477030e4ed /src/libsyntax | |
| parent | ebb560a069c7edb9dc506fdc302dbf1c57576952 (diff) | |
| parent | 204fe21e5b9536c62f0494cd0f3fe80960be8541 (diff) | |
| download | rust-1004860dd42632733d985bbf23bd12d0fd23badb.tar.gz rust-1004860dd42632733d985bbf23bd12d0fd23badb.zip | |
Auto merge of #30028 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #29397, #29933, #30004, #30019, #30020, #30023 - Failed merges:
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 42 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 6 |
3 files changed, 23 insertions, 29 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e4697a7fd91..ab62c8d9421 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1258,7 +1258,7 @@ impl fmt::Debug for IntTy { impl fmt::Display for IntTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", ast_util::int_ty_to_string(*self, None)) + write!(f, "{}", ast_util::int_ty_to_string(*self)) } } @@ -1303,7 +1303,7 @@ impl fmt::Debug for UintTy { impl fmt::Display for UintTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", ast_util::uint_ty_to_string(*self, None)) + write!(f, "{}", ast_util::uint_ty_to_string(*self)) } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 44334762d90..489c61b83da 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -111,26 +111,23 @@ pub fn is_path(e: P<Expr>) -> bool { match e.node { ExprPath(..) => true, _ => false } } -/// 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_string(t: IntTy, val: Option<i64>) -> String { - let s = match t { +pub fn int_ty_to_string(t: IntTy) -> &'static str { + match t { TyIs => "isize", TyI8 => "i8", TyI16 => "i16", TyI32 => "i32", TyI64 => "i64" - }; - - match val { - // cast to a u64 so we can correctly print INT64_MIN. All integral types - // are parsed as u64, so we wouldn't want to print an extra negative - // sign. - Some(n) => format!("{}{}", n as u64, s), - None => s.to_string() } } +pub fn int_val_to_string(t: IntTy, val: i64) -> String { + // cast to a u64 so we can correctly print INT64_MIN. All integral types + // are parsed as u64, so we wouldn't want to print an extra negative + // sign. + format!("{}{}", val as u64, int_ty_to_string(t)) +} + pub fn int_ty_max(t: IntTy) -> u64 { match t { TyI8 => 0x80, @@ -140,23 +137,20 @@ pub fn int_ty_max(t: IntTy) -> u64 { } } -/// Get a string representation of an unsigned int type, with its value. -/// We want to avoid "42u" in favor of "42us". "42uint" is right out. -pub fn uint_ty_to_string(t: UintTy, val: Option<u64>) -> String { - let s = match t { +pub fn uint_ty_to_string(t: UintTy) -> &'static str { + match t { TyUs => "usize", TyU8 => "u8", TyU16 => "u16", TyU32 => "u32", TyU64 => "u64" - }; - - match val { - Some(n) => format!("{}{}", n, s), - None => s.to_string() } } +pub fn uint_val_to_string(t: UintTy, val: u64) -> String { + format!("{}{}", val, uint_ty_to_string(t)) +} + pub fn uint_ty_max(t: UintTy) -> u64 { match t { TyU8 => 0xff, @@ -166,10 +160,10 @@ pub fn uint_ty_max(t: UintTy) -> u64 { } } -pub fn float_ty_to_string(t: FloatTy) -> String { +pub fn float_ty_to_string(t: FloatTy) -> &'static str { match t { - TyF32 => "f32".to_string(), - TyF64 => "f64".to_string(), + TyF32 => "f32", + TyF64 => "f64", } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index e9c716017c0..6de86de9c54 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -651,15 +651,15 @@ pub trait PrintState<'a> { match t { ast::SignedIntLit(st, ast::Plus) => { word(self.writer(), - &ast_util::int_ty_to_string(st, Some(i as i64))) + &ast_util::int_val_to_string(st, i as i64)) } ast::SignedIntLit(st, ast::Minus) => { - let istr = ast_util::int_ty_to_string(st, Some(-(i as i64))); + let istr = ast_util::int_val_to_string(st, -(i as i64)); word(self.writer(), &format!("-{}", istr)) } ast::UnsignedIntLit(ut) => { - word(self.writer(), &ast_util::uint_ty_to_string(ut, Some(i))) + word(self.writer(), &ast_util::uint_val_to_string(ut, i)) } ast::UnsuffixedIntLit(ast::Plus) => { word(self.writer(), &format!("{}", i)) |
