diff options
| author | Andy Russell <arussell123@gmail.com> | 2020-10-05 12:23:36 -0400 |
|---|---|---|
| committer | Andy Russell <arussell123@gmail.com> | 2020-10-08 13:11:31 -0400 |
| commit | ced11a83cb6cae998df514eb08d1f3dc4bd990c8 (patch) | |
| tree | 1a5529218aae588e1e80914592709a017f5c0c83 /src/test | |
| parent | a585aaefb662ae26f8675955f26fad9be4fea96b (diff) | |
suggest `MAX` constant if -1 is assigned to unsigned type
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/feature-gates/feature-gate-negate-unsigned.stderr | 5 | ||||
| -rw-r--r-- | src/test/ui/unsigned-literal-negation.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/unsigned-literal-negation.stderr | 36 |
3 files changed, 45 insertions, 1 deletions
diff --git a/src/test/ui/feature-gates/feature-gate-negate-unsigned.stderr b/src/test/ui/feature-gates/feature-gate-negate-unsigned.stderr index aa84c27e40f..d1f4ed5cb04 100644 --- a/src/test/ui/feature-gates/feature-gate-negate-unsigned.stderr +++ b/src/test/ui/feature-gates/feature-gate-negate-unsigned.stderr @@ -2,7 +2,10 @@ error[E0600]: cannot apply unary operator `-` to type `usize` --> $DIR/feature-gate-negate-unsigned.rs:10:23 | LL | let _max: usize = -1; - | ^^ cannot apply unary operator `-` + | ^^ + | | + | cannot apply unary operator `-` + | help: you may have meant the maximum value of `usize`: `usize::MAX` | = note: unsigned values cannot be negated diff --git a/src/test/ui/unsigned-literal-negation.rs b/src/test/ui/unsigned-literal-negation.rs new file mode 100644 index 00000000000..943c7f79742 --- /dev/null +++ b/src/test/ui/unsigned-literal-negation.rs @@ -0,0 +1,5 @@ +fn main() { + let x = -1 as usize; //~ ERROR: cannot apply unary operator `-` + let x = (-1) as usize; //~ ERROR: cannot apply unary operator `-` + let x: u32 = -1; //~ ERROR: cannot apply unary operator `-` +} diff --git a/src/test/ui/unsigned-literal-negation.stderr b/src/test/ui/unsigned-literal-negation.stderr new file mode 100644 index 00000000000..0aaa8c3b72f --- /dev/null +++ b/src/test/ui/unsigned-literal-negation.stderr @@ -0,0 +1,36 @@ +error[E0600]: cannot apply unary operator `-` to type `usize` + --> $DIR/unsigned-literal-negation.rs:2:13 + | +LL | let x = -1 as usize; + | ^^ + | | + | cannot apply unary operator `-` + | help: you may have meant the maximum value of `usize`: `usize::MAX` + | + = note: unsigned values cannot be negated + +error[E0600]: cannot apply unary operator `-` to type `usize` + --> $DIR/unsigned-literal-negation.rs:3:13 + | +LL | let x = (-1) as usize; + | ^^^^ + | | + | cannot apply unary operator `-` + | help: you may have meant the maximum value of `usize`: `usize::MAX` + | + = note: unsigned values cannot be negated + +error[E0600]: cannot apply unary operator `-` to type `u32` + --> $DIR/unsigned-literal-negation.rs:4:18 + | +LL | let x: u32 = -1; + | ^^ + | | + | cannot apply unary operator `-` + | help: you may have meant the maximum value of `u32`: `u32::MAX` + | + = note: unsigned values cannot be negated + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0600`. |
