diff options
| author | Falco Hirschenberger <falco.hirschenberger@gmail.com> | 2014-08-05 09:59:03 +0200 |
|---|---|---|
| committer | Falco Hirschenberger <falco.hirschenberger@gmail.com> | 2014-08-05 09:59:03 +0200 |
| commit | 0dc215741b34236c310e409c437600ba0165c97c (patch) | |
| tree | bfaee6d4c3d1b082fadf859cb106b5e99d458028 /src/libsyntax/ext/bytes.rs | |
| parent | 795f6ae829ab1bfd72394a5da9096e2717ec0f62 (diff) | |
| download | rust-0dc215741b34236c310e409c437600ba0165c97c.tar.gz rust-0dc215741b34236c310e409c437600ba0165c97c.zip | |
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.
Diffstat (limited to 'src/libsyntax/ext/bytes.rs')
| -rw-r--r-- | src/libsyntax/ext/bytes.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index ce13fa2a7c6..6ea55096348 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -47,7 +47,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } // u8 literal, push to vector expression - ast::LitUint(v, ast::TyU8) => { + ast::LitInt(v, ast::UnsignedIntLit(ast::TyU8)) => { if v > 0xFF { cx.span_err(expr.span, "too large u8 literal in bytes!"); err = true; @@ -57,13 +57,14 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } // integer literal, push to vector expression - ast::LitIntUnsuffixed(v) => { + ast::LitInt(_, ast::UnsuffixedIntLit(ast::Minus)) => { + cx.span_err(expr.span, "negative integer literal in bytes!"); + err = true; + } + ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => { if v > 0xFF { cx.span_err(expr.span, "too large integer literal in bytes!"); err = true; - } else if v < 0 { - cx.span_err(expr.span, "negative integer literal in bytes!"); - err = true; } else { bytes.push(cx.expr_u8(expr.span, v as u8)); } |
