Skip to content

Commit 88fb1b0

Browse files
committed
---
yaml --- r: 274765 b: refs/heads/stable c: bfa66bb h: refs/heads/master i: 274763: 67cd8a7
1 parent 4266110 commit 88fb1b0

File tree

11 files changed

+56
-83
lines changed

11 files changed

+56
-83
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: c0221c8897db309a79990367476177b1230bb264
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 625e78b7001c6e20f29928a5da8c9d21e9aed6c5
32+
refs/heads/stable: bfa66bb389ce1c7ce4aff09d1842b3428015bd4d
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/librustc/middle/const_eval.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,15 +1328,13 @@ fn lit_to_const(sess: &Session, span: Span, lit: &ast::Lit, ty_hint: Option<Ty>)
13281328
}
13291329
ast::LitByte(n) => Uint(n as u64),
13301330
ast::LitChar(n) => Uint(n as u64),
1331-
ast::LitInt(n, ast::SignedIntLit(_, ast::Plus)) => Int(n as i64),
1332-
ast::LitInt(n, ast::UnsuffixedIntLit(ast::Plus)) => {
1331+
ast::LitInt(n, ast::SignedIntLit(_)) => Int(n as i64),
1332+
ast::LitInt(n, ast::UnsuffixedIntLit) => {
13331333
match ty_hint.map(|ty| &ty.sty) {
13341334
Some(&ty::TyUint(_)) => Uint(n),
13351335
_ => Int(n as i64)
13361336
}
13371337
}
1338-
ast::LitInt(n, ast::SignedIntLit(_, ast::Minus)) |
1339-
ast::LitInt(n, ast::UnsuffixedIntLit(ast::Minus)) => Int(-(n as i64)),
13401338
ast::LitInt(n, ast::UnsignedIntLit(_)) => Uint(n),
13411339
ast::LitFloat(ref n, _) |
13421340
ast::LitFloatUnsuffixed(ref n) => {

branches/stable/src/librustc_lint/types.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl LateLintPass for TypeLimits {
106106
ast::LitInt(_, ast::UnsignedIntLit(_)) => {
107107
forbid_unsigned_negation(cx, e.span);
108108
},
109-
ast::LitInt(_, ast::UnsuffixedIntLit(_)) => {
109+
ast::LitInt(_, ast::UnsuffixedIntLit) => {
110110
if let ty::TyUint(_) = cx.tcx.node_id_to_type(e.id).sty {
111111
forbid_unsigned_negation(cx, e.span);
112112
}
@@ -159,8 +159,8 @@ impl LateLintPass for TypeLimits {
159159
match cx.tcx.node_id_to_type(e.id).sty {
160160
ty::TyInt(t) => {
161161
match lit.node {
162-
ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) |
163-
ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => {
162+
ast::LitInt(v, ast::SignedIntLit(_)) |
163+
ast::LitInt(v, ast::UnsuffixedIntLit) => {
164164
let int_type = if let ast::IntTy::Is = t {
165165
cx.sess().target.int_type
166166
} else {
@@ -311,10 +311,8 @@ impl LateLintPass for TypeLimits {
311311
let (min, max) = int_ty_range(int_ty);
312312
let lit_val: i64 = match lit.node {
313313
hir::ExprLit(ref li) => match li.node {
314-
ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) |
315-
ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => v as i64,
316-
ast::LitInt(v, ast::SignedIntLit(_, ast::Minus)) |
317-
ast::LitInt(v, ast::UnsuffixedIntLit(ast::Minus)) => -(v as i64),
314+
ast::LitInt(v, ast::SignedIntLit(_)) |
315+
ast::LitInt(v, ast::UnsuffixedIntLit) => v as i64,
318316
_ => return true
319317
},
320318
_ => panic!()

branches/stable/src/librustc_trans/trans/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit)
6666
match lit.node {
6767
ast::LitByte(b) => C_integral(Type::uint_from_ty(cx, ast::UintTy::U8), b as u64, false),
6868
ast::LitChar(i) => C_integral(Type::char(cx), i as u64, false),
69-
ast::LitInt(i, ast::SignedIntLit(t, _)) => {
69+
ast::LitInt(i, ast::SignedIntLit(t)) => {
7070
C_integral(Type::int_from_ty(cx, t), i, true)
7171
}
7272
ast::LitInt(u, ast::UnsignedIntLit(t)) => {
7373
C_integral(Type::uint_from_ty(cx, t), u, false)
7474
}
75-
ast::LitInt(i, ast::UnsuffixedIntLit(_)) => {
75+
ast::LitInt(i, ast::UnsuffixedIntLit) => {
7676
let lit_int_ty = cx.tcx().node_id_to_type(e.id);
7777
match lit_int_ty.sty {
7878
ty::TyInt(t) => {

branches/stable/src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,9 +2613,9 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26132613
}
26142614
ast::LitByte(_) => tcx.types.u8,
26152615
ast::LitChar(_) => tcx.types.char,
2616-
ast::LitInt(_, ast::SignedIntLit(t, _)) => tcx.mk_mach_int(t),
2616+
ast::LitInt(_, ast::SignedIntLit(t)) => tcx.mk_mach_int(t),
26172617
ast::LitInt(_, ast::UnsignedIntLit(t)) => tcx.mk_mach_uint(t),
2618-
ast::LitInt(_, ast::UnsuffixedIntLit(_)) => {
2618+
ast::LitInt(_, ast::UnsuffixedIntLit) => {
26192619
let opt_ty = expected.to_option(fcx).and_then(|ty| {
26202620
match ty.sty {
26212621
ty::TyInt(_) | ty::TyUint(_) => Some(ty),

branches/stable/src/libsyntax/ast.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub use self::Mutability::*;
2121
pub use self::Pat_::*;
2222
pub use self::PathListItem_::*;
2323
pub use self::PrimTy::*;
24-
pub use self::Sign::*;
2524
pub use self::Stmt_::*;
2625
pub use self::StrStyle::*;
2726
pub use self::StructFieldKind::*;
@@ -1269,36 +1268,11 @@ pub enum StrStyle {
12691268
/// A literal
12701269
pub type Lit = Spanned<Lit_>;
12711270

1272-
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1273-
pub enum Sign {
1274-
Minus,
1275-
Plus
1276-
}
1277-
1278-
impl Sign {
1279-
pub fn new<T: IntSign>(n: T) -> Sign {
1280-
n.sign()
1281-
}
1282-
}
1283-
1284-
pub trait IntSign {
1285-
fn sign(&self) -> Sign;
1286-
}
1287-
macro_rules! doit {
1288-
($($t:ident)*) => ($(impl IntSign for $t {
1289-
#[allow(unused_comparisons)]
1290-
fn sign(&self) -> Sign {
1291-
if *self < 0 {Minus} else {Plus}
1292-
}
1293-
})*)
1294-
}
1295-
doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize }
1296-
12971271
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
12981272
pub enum LitIntType {
1299-
SignedIntLit(IntTy, Sign),
1273+
SignedIntLit(IntTy),
13001274
UnsignedIntLit(UintTy),
1301-
UnsuffixedIntLit(Sign)
1275+
UnsuffixedIntLit,
13021276
}
13031277

13041278
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]

branches/stable/src/libsyntax/ext/build.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
683683
self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::UintTy::Us)))
684684
}
685685
fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr> {
686-
self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is,
687-
ast::Sign::new(i))))
686+
if i < 0 {
687+
let i = (-i) as u64;
688+
let lit = self.expr_lit(sp, ast::LitInt(i, ast::SignedIntLit(ast::IntTy::Is)));
689+
self.expr_unary(sp, ast::UnOp::Neg, lit)
690+
} else {
691+
self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is)))
692+
}
688693
}
689694
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
690695
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::UintTy::U32)))

branches/stable/src/libsyntax/ext/quote.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,27 @@ pub mod rt {
263263
(signed, $t:ty, $tag:expr) => (
264264
impl ToTokens for $t {
265265
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
266-
let lit = ast::LitInt(*self as u64, ast::SignedIntLit($tag,
267-
ast::Sign::new(*self)));
268-
dummy_spanned(lit).to_tokens(cx)
266+
let val = if *self < 0 {
267+
-self
268+
} else {
269+
*self
270+
};
271+
let lit = ast::LitInt(val as u64, ast::SignedIntLit($tag));
272+
let lit = P(ast::Expr {
273+
id: ast::DUMMY_NODE_ID,
274+
node: ast::ExprKind::Lit(P(dummy_spanned(lit))),
275+
span: DUMMY_SP,
276+
attrs: None,
277+
});
278+
if *self >= 0 {
279+
return lit.to_tokens(cx);
280+
}
281+
P(ast::Expr {
282+
id: ast::DUMMY_NODE_ID,
283+
node: ast::ExprKind::Unary(ast::UnOp::Neg, lit),
284+
span: DUMMY_SP,
285+
attrs: None,
286+
}).to_tokens(cx)
269287
}
270288
}
271289
);

branches/stable/src/libsyntax/parse/mod.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ pub fn integer_lit(s: &str,
586586

587587
let mut base = 10;
588588
let orig = s;
589-
let mut ty = ast::UnsuffixedIntLit(ast::Plus);
589+
let mut ty = ast::UnsuffixedIntLit;
590590

591591
if char_at(s, 0) == '0' && s.len() > 1 {
592592
match char_at(s, 1) {
@@ -618,11 +618,11 @@ pub fn integer_lit(s: &str,
618618
if let Some(ref suf) = suffix {
619619
if suf.is_empty() { sd.span_bug(sp, "found empty literal suffix in Some")}
620620
ty = match &**suf {
621-
"isize" => ast::SignedIntLit(ast::IntTy::Is, ast::Plus),
622-
"i8" => ast::SignedIntLit(ast::IntTy::I8, ast::Plus),
623-
"i16" => ast::SignedIntLit(ast::IntTy::I16, ast::Plus),
624-
"i32" => ast::SignedIntLit(ast::IntTy::I32, ast::Plus),
625-
"i64" => ast::SignedIntLit(ast::IntTy::I64, ast::Plus),
621+
"isize" => ast::SignedIntLit(ast::IntTy::Is),
622+
"i8" => ast::SignedIntLit(ast::IntTy::I8),
623+
"i16" => ast::SignedIntLit(ast::IntTy::I16),
624+
"i32" => ast::SignedIntLit(ast::IntTy::I32),
625+
"i64" => ast::SignedIntLit(ast::IntTy::I64),
626626
"usize" => ast::UnsignedIntLit(ast::UintTy::Us),
627627
"u8" => ast::UnsignedIntLit(ast::UintTy::U8),
628628
"u16" => ast::UnsignedIntLit(ast::UintTy::U16),
@@ -651,9 +651,9 @@ pub fn integer_lit(s: &str,
651651
debug!("integer_lit: the type is {:?}, base {:?}, the new string is {:?}, the original \
652652
string was {:?}, the original suffix was {:?}", ty, base, s, orig, suffix);
653653

654-
let res = match u64::from_str_radix(s, base).ok() {
655-
Some(r) => r,
656-
None => {
654+
match u64::from_str_radix(s, base) {
655+
Ok(r) => ast::LitInt(r, ty),
656+
Err(_) => {
657657
// small bases are lexed as if they were base 10, e.g, the string
658658
// might be `0b10201`. This will cause the conversion above to fail,
659659
// but these cases have errors in the lexer: we don't want to emit
@@ -665,16 +665,8 @@ pub fn integer_lit(s: &str,
665665
if !already_errored {
666666
sd.span_err(sp, "int literal is too large");
667667
}
668-
0
668+
ast::LitInt(0, ty)
669669
}
670-
};
671-
672-
// adjust the sign
673-
let sign = ast::Sign::new(res);
674-
match ty {
675-
ast::SignedIntLit(t, _) => ast::LitInt(res, ast::SignedIntLit(t, sign)),
676-
ast::UnsuffixedIntLit(_) => ast::LitInt(res, ast::UnsuffixedIntLit(sign)),
677-
us@ast::UnsignedIntLit(_) => ast::LitInt(res, us)
678670
}
679671
}
680672

branches/stable/src/libsyntax/print/pprust.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -645,24 +645,16 @@ pub trait PrintState<'a> {
645645
}
646646
ast::LitInt(i, t) => {
647647
match t {
648-
ast::SignedIntLit(st, ast::Plus) => {
648+
ast::SignedIntLit(st) => {
649649
word(self.writer(),
650650
&st.val_to_string(i as i64))
651651
}
652-
ast::SignedIntLit(st, ast::Minus) => {
653-
let istr = st.val_to_string(-(i as i64));
654-
word(self.writer(),
655-
&format!("-{}", istr))
656-
}
657652
ast::UnsignedIntLit(ut) => {
658653
word(self.writer(), &ut.val_to_string(i))
659654
}
660-
ast::UnsuffixedIntLit(ast::Plus) => {
655+
ast::UnsuffixedIntLit => {
661656
word(self.writer(), &format!("{}", i))
662657
}
663-
ast::UnsuffixedIntLit(ast::Minus) => {
664-
word(self.writer(), &format!("-{}", i))
665-
}
666658
}
667659
}
668660
ast::LitFloat(ref f, t) => {

branches/stable/src/libsyntax_ext/concat.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,10 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
3838
accumulator.push(c);
3939
}
4040
ast::LitInt(i, ast::UnsignedIntLit(_)) |
41-
ast::LitInt(i, ast::SignedIntLit(_, ast::Plus)) |
42-
ast::LitInt(i, ast::UnsuffixedIntLit(ast::Plus)) => {
41+
ast::LitInt(i, ast::SignedIntLit(_)) |
42+
ast::LitInt(i, ast::UnsuffixedIntLit) => {
4343
accumulator.push_str(&format!("{}", i));
4444
}
45-
ast::LitInt(i, ast::SignedIntLit(_, ast::Minus)) |
46-
ast::LitInt(i, ast::UnsuffixedIntLit(ast::Minus)) => {
47-
accumulator.push_str(&format!("-{}", i));
48-
}
4945
ast::LitBool(b) => {
5046
accumulator.push_str(&format!("{}", b));
5147
}

0 commit comments

Comments
 (0)