cannot apply unary operator `-` to type `u8`

cannot apply unary operator `-` to type `u8`error[E0600]: cannot apply unary operator `-` to type `u8`
  --> src\main.rs:17:19
   |
17 |     let u8_1:u8 = -1;
   |                   ^^
   |                   |
   |                   cannot apply unary operator `-`
   |                   help: you may have meant the maximum value of `u8`: `u8::MAX`
   |
   = note: unsigned values cannot be negated

error: aborting due to previous error

无符号类型不能为负数,去掉-号,或者用有符号类型

猜你喜欢

转载自blog.csdn.net/qq_39308071/article/details/112603476