From bfa66bb389ce1c7ce4aff09d1842b3428015bd4d Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 11 Feb 2016 09:52:55 +0100 Subject: [breaking-change] remove the sign from integer literals in the ast --- src/libsyntax/ext/build.rs | 9 +++++++-- src/libsyntax/ext/quote.rs | 24 +++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 1af29f2f93a..1c2d1cebf3d 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -683,8 +683,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::UintTy::Us))) } fn expr_isize(&self, sp: Span, i: isize) -> P { - self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is, - ast::Sign::new(i)))) + if i < 0 { + let i = (-i) as u64; + let lit = self.expr_lit(sp, ast::LitInt(i, ast::SignedIntLit(ast::IntTy::Is))); + self.expr_unary(sp, ast::UnOp::Neg, lit) + } else { + self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is))) + } } fn expr_u32(&self, sp: Span, u: u32) -> P { self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::UintTy::U32))) diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index a9f480daa0e..dfe3f8e3c54 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -263,9 +263,27 @@ pub mod rt { (signed, $t:ty, $tag:expr) => ( impl ToTokens for $t { fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - let lit = ast::LitInt(*self as u64, ast::SignedIntLit($tag, - ast::Sign::new(*self))); - dummy_spanned(lit).to_tokens(cx) + let val = if *self < 0 { + -self + } else { + *self + }; + let lit = ast::LitInt(val as u64, ast::SignedIntLit($tag)); + let lit = P(ast::Expr { + id: ast::DUMMY_NODE_ID, + node: ast::ExprKind::Lit(P(dummy_spanned(lit))), + span: DUMMY_SP, + attrs: None, + }); + if *self >= 0 { + return lit.to_tokens(cx); + } + P(ast::Expr { + id: ast::DUMMY_NODE_ID, + node: ast::ExprKind::Unary(ast::UnOp::Neg, lit), + span: DUMMY_SP, + attrs: None, + }).to_tokens(cx) } } ); -- cgit 1.4.1-3-g733a5