diff options
| author | bors <bors@rust-lang.org> | 2018-09-29 19:38:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-09-29 19:38:12 +0000 |
| commit | bb0896af11bb6b79051d4b794c70f78cd45d080f (patch) | |
| tree | ff0704a8ea6fb34f4a7aef0d122e0aac27edad19 /src | |
| parent | eb50e75729bce449272ffb3bfbca2f7234f2ae13 (diff) | |
| parent | 95c1d817ae6ec50d3c636c54e33b4d51cab57148 (diff) | |
| download | rust-bb0896af11bb6b79051d4b794c70f78cd45d080f.tar.gz rust-bb0896af11bb6b79051d4b794c70f78cd45d080f.zip | |
Auto merge of #54240 - csmoe:nonzero_from, r=alexcrichton
Impl From<NonZero<T>> for T Closes https://github.com/rust-lang/rust/issues/54171 r? @SimonSapin
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/num/mod.rs | 7 | ||||
| -rw-r--r-- | src/libcore/tests/nonzero.rs | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 12da0455cc5..c4b59738478 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -93,6 +93,13 @@ assert_eq!(size_of::<Option<std::num::", stringify!($Ty), ">>(), size_of::<", st } + #[stable(feature = "from_nonzero", since = "1.31.0")] + impl From<$Ty> for $Int { + fn from(nonzero: $Ty) -> Self { + nonzero.0 .0 + } + } + impl_nonzero_fmt! { (Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty } diff --git a/src/libcore/tests/nonzero.rs b/src/libcore/tests/nonzero.rs index 8d39298bac3..bbb1ef76bcc 100644 --- a/src/libcore/tests/nonzero.rs +++ b/src/libcore/tests/nonzero.rs @@ -121,3 +121,10 @@ fn test_match_nonzero_const_pattern() { _ => panic!("Expected the const item as a pattern to match.") } } + +#[test] +fn test_from_nonzero() { + let nz = NonZeroU32::new(1).unwrap(); + let num: u32 = nz.into(); + assert_eq!(num, 1u32); +} |
