mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-23 02:27:39 +03:00
fix printing signed literal in print_literal
This commit is contained in:
@@ -2680,8 +2680,9 @@ pub fn print_literal(&mut self, lit: &ast::Lit) -> IoResult<()> {
|
||||
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 @@ fn test_variant_to_string() {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user