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.
Rollup merge of rust-lang#102341 - jmillikin:nonzero-impl-neg, r=dtolnay
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 impls for two stable types can't be marked unstable. See discussion on rust-lang/libs-team#105 for additional context.
- Loading branch information
Showing
3 changed files
with
46 additions
and
3 deletions.
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,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(); | ||
} |