diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2016-02-11 09:52:55 +0100 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2016-02-11 12:34:48 +0100 |
| commit | bfa66bb389ce1c7ce4aff09d1842b3428015bd4d (patch) | |
| tree | f6252627aac7945dec962bacb43ed50186c8ab9b /src/libsyntax/ext | |
| parent | 625e78b7001c6e20f29928a5da8c9d21e9aed6c5 (diff) | |
| download | rust-bfa66bb389ce1c7ce4aff09d1842b3428015bd4d.tar.gz rust-bfa66bb389ce1c7ce4aff09d1842b3428015bd4d.zip | |
[breaking-change] remove the sign from integer literals in the ast
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/build.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 24 |
2 files changed, 28 insertions, 5 deletions
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<ast::Expr> { - 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<ast::Expr> { 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<TokenTree> { - 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) } } ); |
