From 0dc215741b34236c310e409c437600ba0165c97c Mon Sep 17 00:00:00 2001 From: Falco Hirschenberger Date: Tue, 5 Aug 2014 09:59:03 +0200 Subject: Fixes missing overflow lint for i64 #14269 The `type_overflow` lint, doesn't catch the overflow for `i64` because the overflow happens earlier in the parse phase when the `u64` as biggest possible int gets casted to `i64` , without checking the for overflows. We can't lint in the parse phase, so a refactoring of the `LitInt` type was necessary. The types `LitInt`, `LitUint` and `LitIntUnsuffixed` where merged to one type `LitInt` which stores it's value as `u64`. An additional parameter was added which indicate the signedness of the type and the sign of the value. --- src/libsyntax/print/pprust.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/libsyntax/print/pprust.rs') diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 675588a4460..095dca66164 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2415,15 +2415,25 @@ impl<'a> State<'a> { word(&mut self.s, res.as_slice()) } ast::LitInt(i, t) => { - word(&mut self.s, - ast_util::int_ty_to_string(t, Some(i)).as_slice()) - } - ast::LitUint(u, t) => { - word(&mut self.s, - ast_util::uint_ty_to_string(t, Some(u)).as_slice()) - } - ast::LitIntUnsuffixed(i) => { - word(&mut self.s, format!("{}", i).as_slice()) + match t { + ast::SignedIntLit(st, ast::Plus) => { + word(&mut self.s, + ast_util::int_ty_to_string(st, Some(i as i64)).as_slice()) + } + ast::SignedIntLit(st, ast::Minus) => { + word(&mut self.s, + ast_util::int_ty_to_string(st, Some(-(i as i64))).as_slice()) + } + ast::UnsignedIntLit(ut) => { + word(&mut self.s, ast_util::uint_ty_to_string(ut, Some(i)).as_slice()) + } + ast::UnsuffixedIntLit(ast::Plus) => { + word(&mut self.s, format!("{}", i).as_slice()) + } + ast::UnsuffixedIntLit(ast::Minus) => { + word(&mut self.s, format!("-{}", i).as_slice()) + } + } } ast::LitFloat(ref f, t) => { word(&mut self.s, -- cgit 1.4.1-3-g733a5