Skip to content

Commit

Permalink
fix printing signed literal in print_literal
Browse files Browse the repository at this point in the history
  • Loading branch information
koshlo committed Oct 19, 2014
1 parent c121cba commit 49ec356
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)));
}
}

5 comments on commit 49ec356

@bors
Copy link
Contributor

@bors bors commented on 49ec356 Oct 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at koshlo@49ec356

@bors
Copy link
Contributor

@bors bors commented on 49ec356 Oct 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging koshlo/rust/to-source-fix = 49ec356 into auto

@bors
Copy link
Contributor

@bors bors commented on 49ec356 Oct 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

koshlo/rust/to-source-fix = 49ec356 merged ok, testing candidate = aff4f11

@bors
Copy link
Contributor

@bors bors commented on 49ec356 Oct 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 49ec356 Oct 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = aff4f11

Please sign in to comment.