forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suggest
MAX
constant if -1 is assigned to unsigned type
- Loading branch information
Showing
4 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 `-` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |