diff options
| author | John Millikin <john@john-millikin.com> | 2022-09-27 11:40:39 +0900 |
|---|---|---|
| committer | John Millikin <john@john-millikin.com> | 2023-04-20 14:27:29 +0900 |
| commit | 4e2797dd76363370eac74cc9480e7d8c0ff17b4b (patch) | |
| tree | 509fe2f357fc7270af5aa2a9cd9f65a6c2410c72 /tests | |
| parent | dc730521efad6acf9b31fcc99c8a26789fa9a654 (diff) | |
| download | rust-4e2797dd76363370eac74cc9480e7d8c0ff17b4b.tar.gz rust-4e2797dd76363370eac74cc9480e7d8c0ff17b4b.zip | |
Implement `Neg` for signed non-zero integers.
Negating a non-zero integer currently requires unpacking to a
primitive and re-wrapping. Since negation of non-zero signed
integers always produces a non-zero result, it is safe to
implement `Neg` for `NonZeroI{N}`.
The new `impl` is marked as stable because trait implementations
for two stable types can't be marked unstable.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs b/tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs new file mode 100644 index 00000000000..565b7e86fc4 --- /dev/null +++ b/tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs @@ -0,0 +1,12 @@ +// run-fail +// error-pattern:thread 'main' panicked at 'attempt to negate with overflow' +// ignore-emscripten no processes +// compile-flags: -C debug-assertions + +#![allow(arithmetic_overflow)] + +use std::num::NonZeroI8; + +fn main() { + let _x = -NonZeroI8::new(i8::MIN).unwrap(); +} |
