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/parse/mod.rs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 2472da36d52..d800b6925c0 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -586,7 +586,7 @@ pub fn integer_lit(s: &str, let mut base = 10; let orig = s; - let mut ty = ast::UnsuffixedIntLit(ast::Plus); + let mut ty = ast::UnsuffixedIntLit; if char_at(s, 0) == '0' && s.len() > 1 { match char_at(s, 1) { @@ -618,11 +618,11 @@ pub fn integer_lit(s: &str, if let Some(ref suf) = suffix { if suf.is_empty() { sd.span_bug(sp, "found empty literal suffix in Some")} ty = match &**suf { - "isize" => ast::SignedIntLit(ast::IntTy::Is, ast::Plus), - "i8" => ast::SignedIntLit(ast::IntTy::I8, ast::Plus), - "i16" => ast::SignedIntLit(ast::IntTy::I16, ast::Plus), - "i32" => ast::SignedIntLit(ast::IntTy::I32, ast::Plus), - "i64" => ast::SignedIntLit(ast::IntTy::I64, ast::Plus), + "isize" => ast::SignedIntLit(ast::IntTy::Is), + "i8" => ast::SignedIntLit(ast::IntTy::I8), + "i16" => ast::SignedIntLit(ast::IntTy::I16), + "i32" => ast::SignedIntLit(ast::IntTy::I32), + "i64" => ast::SignedIntLit(ast::IntTy::I64), "usize" => ast::UnsignedIntLit(ast::UintTy::Us), "u8" => ast::UnsignedIntLit(ast::UintTy::U8), "u16" => ast::UnsignedIntLit(ast::UintTy::U16), @@ -651,9 +651,9 @@ pub fn integer_lit(s: &str, debug!("integer_lit: the type is {:?}, base {:?}, the new string is {:?}, the original \ string was {:?}, the original suffix was {:?}", ty, base, s, orig, suffix); - let res = match u64::from_str_radix(s, base).ok() { - Some(r) => r, - None => { + match u64::from_str_radix(s, base) { + Ok(r) => ast::LitInt(r, ty), + Err(_) => { // small bases are lexed as if they were base 10, e.g, the string // might be `0b10201`. This will cause the conversion above to fail, // but these cases have errors in the lexer: we don't want to emit @@ -665,16 +665,8 @@ pub fn integer_lit(s: &str, if !already_errored { sd.span_err(sp, "int literal is too large"); } - 0 + ast::LitInt(0, ty) } - }; - - // adjust the sign - let sign = ast::Sign::new(res); - match ty { - ast::SignedIntLit(t, _) => ast::LitInt(res, ast::SignedIntLit(t, sign)), - ast::UnsuffixedIntLit(_) => ast::LitInt(res, ast::UnsuffixedIntLit(sign)), - us@ast::UnsignedIntLit(_) => ast::LitInt(res, us) } } -- cgit 1.4.1-3-g733a5