diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-01-03 21:48:17 +0200 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-01-03 21:48:17 +0200 |
| commit | fbdadcbed4c9a04b909246a8145e3e722c63525b (patch) | |
| tree | aa9c948cb47d2e534021a9f491365283c463608d /src/test | |
| parent | df61658c8afc8b24800f5437e0000a99d04ea2b0 (diff) | |
Properly ban the negation of unsigned integers in type-checking.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/const-eval-overflow0.rs | 100 | ||||
| -rw-r--r-- | src/test/compile-fail/feature-gate-negate-unsigned.rs | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/feature-gate-negate-unsigned0.rs | 34 |
3 files changed, 6 insertions, 143 deletions
diff --git a/src/test/compile-fail/const-eval-overflow0.rs b/src/test/compile-fail/const-eval-overflow0.rs deleted file mode 100644 index 7db7de9cee3..00000000000 --- a/src/test/compile-fail/const-eval-overflow0.rs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(unused_imports)] - -// Note: the relevant lint pass here runs before some of the constant -// evaluation below (e.g. that performed by trans and llvm), so if you -// change this warn to a deny, then the compiler will exit before -// those errors are detected. - -use std::fmt; -use std::{i8, i16, i32, i64, isize}; -use std::{u8, u16, u32, u64, usize}; - -const VALS_I8: (i8, i8, i8, i8) = - (-i8::MIN, - i8::MIN - 1, - i8::MAX + 1, - i8::MIN * 2, - ); - -const VALS_I16: (i16, i16, i16, i16) = - (-i16::MIN, - i16::MIN - 1, - i16::MAX + 1, - i16::MIN * 2, - ); - -const VALS_I32: (i32, i32, i32, i32) = - (-i32::MIN, - i32::MIN - 1, - i32::MAX + 1, - i32::MIN * 2, - ); - -const VALS_I64: (i64, i64, i64, i64) = - (-i64::MIN, - i64::MIN - 1, - i64::MAX + 1, - i64::MAX * 2, - ); - -const VALS_U8: (u8, u8, u8, u8) = - (-u8::MIN, - //~^ ERROR unary negation of unsigned integer - //~| HELP use a cast or the `!` operator - u8::MIN - 1, - u8::MAX + 1, - u8::MAX * 2, - ); - -const VALS_U16: (u16, u16, u16, u16) = - (-u16::MIN, - //~^ ERROR unary negation of unsigned integer - //~| HELP use a cast or the `!` operator - u16::MIN - 1, - u16::MAX + 1, - u16::MAX * 2, - ); - -const VALS_U32: (u32, u32, u32, u32) = - (-u32::MIN, - //~^ ERROR unary negation of unsigned integer - //~| HELP use a cast or the `!` operator - u32::MIN - 1, - u32::MAX + 1, - u32::MAX * 2, - ); - -const VALS_U64: (u64, u64, u64, u64) = - (-u64::MIN, - //~^ ERROR unary negation of unsigned integer - //~| HELP use a cast or the `!` operator - u64::MIN - 1, - u64::MAX + 1, - u64::MAX * 2, - ); - -fn main() { - foo(VALS_I8); - foo(VALS_I16); - foo(VALS_I32); - foo(VALS_I64); - - foo(VALS_U8); - foo(VALS_U16); - foo(VALS_U32); - foo(VALS_U64); -} - -fn foo<T:fmt::Debug>(x: T) { - println!("{:?}", x); -} diff --git a/src/test/compile-fail/feature-gate-negate-unsigned.rs b/src/test/compile-fail/feature-gate-negate-unsigned.rs index 98cc2fc0c3e..599e31341f2 100644 --- a/src/test/compile-fail/feature-gate-negate-unsigned.rs +++ b/src/test/compile-fail/feature-gate-negate-unsigned.rs @@ -16,16 +16,13 @@ impl std::ops::Neg for S { fn neg(self) -> u32 { 0 } } -// FIXME(eddyb) move this back to a `-1` literal when -// MIR building stops eagerly erroring in that case. -const _MAX: usize = -(2 - 1); -//~^ WARN unary negation of unsigned integer -//~| ERROR unary negation of unsigned integer -//~| HELP use a cast or the `!` operator - fn main() { + let _max: usize = -1; + //~^ ERROR cannot apply unary operator `-` to type `usize` + let x = 5u8; - let _y = -x; //~ ERROR unary negation of unsigned integer - //~^ HELP use a cast or the `!` operator + let _y = -x; + //~^ ERROR cannot apply unary operator `-` to type `u8` + -S; // should not trigger the gate; issue 26840 } diff --git a/src/test/compile-fail/feature-gate-negate-unsigned0.rs b/src/test/compile-fail/feature-gate-negate-unsigned0.rs deleted file mode 100644 index 89ae1a09bd3..00000000000 --- a/src/test/compile-fail/feature-gate-negate-unsigned0.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that negating unsigned integers doesn't compile - -struct S; -impl std::ops::Neg for S { - type Output = u32; - fn neg(self) -> u32 { 0 } -} - -fn main() { - let a = -1; - //~^ ERROR E0080 - //~| unary negation of unsigned integer - let _b : u8 = a; // for infering variable a to u8. - - let _d = -1u8; - //~^ ERROR E0080 - //~| unary negation of unsigned integer - - for _ in -10..10u8 {} - //~^ ERROR E0080 - //~| unary negation of unsigned integer - - -S; // should not trigger the gate; issue 26840 -} |
