about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-10-19 23:32:07 +0000
committerbors <bors@rust-lang.org>2014-10-19 23:32:07 +0000
commitaff4f11cddadae56fe26980329b610066eb487b0 (patch)
tree1585802a9faaf2ada99741fc8eb1cc5aed469295
parent5cba29d3343ee17b28d39c8d675aa0980d0c5b9c (diff)
parent49ec356c601b3c2fb6ff78df9e22786ec93d34f8 (diff)
downloadrust-aff4f11cddadae56fe26980329b610066eb487b0.tar.gz
rust-aff4f11cddadae56fe26980329b610066eb487b0.zip
auto merge of #18160 : koshlo/rust/to-source-fix, r=alexcrichton
Fix for issue #18091 

The problem seems to be that `ast_util::int_ty_to_string` takes unsigned number, and no one adds `-` to result string. I've fixed it by putting `-` before result string using `format!`.

I've also added `test_signed_int_to_string()` to check if implementation is valid.

-rw-r--r--src/libsyntax/print/pprust.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index d32828192e9..f654bc30680 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -2680,8 +2680,9 @@ impl<'a> State<'a> {
                              ast_util::int_ty_to_string(st, Some(i as i64)).as_slice())
                     }
                     ast::SignedIntLit(st, ast::Minus) => {
+                        let istr = ast_util::int_ty_to_string(st, Some(-(i as i64)));
                         word(&mut self.s,
-                             ast_util::int_ty_to_string(st, Some(-(i as i64))).as_slice())
+                             format!("-{}", istr).as_slice())
                     }
                     ast::UnsignedIntLit(ut) => {
                         word(&mut self.s, ast_util::uint_ty_to_string(ut, Some(i)).as_slice())
@@ -2930,4 +2931,12 @@ mod test {
         let varstr = variant_to_string(&var);
         assert_eq!(&varstr,&"pub principal_skinner".to_string());
     }
+
+    #[test]
+    fn test_signed_int_to_string() {
+        let pos_int = ast::LitInt(42, ast::SignedIntLit(ast::TyI32, ast::Plus));
+        let neg_int = ast::LitInt((-42) as u64, ast::SignedIntLit(ast::TyI32, ast::Minus));
+        assert_eq!(format!("-{}", lit_to_string(&codemap::dummy_spanned(pos_int))),
+                   lit_to_string(&codemap::dummy_spanned(neg_int)));
+    }
 }