From d5c1d15d31dc6164ac67e71526fe15f23a8014e7 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Sat, 15 Sep 2018 09:34:36 +0800 Subject: implement From> for Int --- src/libcore/num/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/libcore') diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 12da0455cc5..82a30864fd2 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -93,6 +93,13 @@ assert_eq!(size_of::>(), size_of::<", st } + #[stable(feature = "nonzero", since = "1.28.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 } -- cgit 1.4.1-3-g733a5 From ac61a9ce21546414547025c8bb49a85f1cf821e8 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Mon, 17 Sep 2018 16:34:24 +0800 Subject: introduce from_nonzero feature --- src/libcore/num/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 82a30864fd2..c4b59738478 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -93,7 +93,7 @@ assert_eq!(size_of::>(), size_of::<", st } - #[stable(feature = "nonzero", since = "1.28.0")] + #[stable(feature = "from_nonzero", since = "1.31.0")] impl From<$Ty> for $Int { fn from(nonzero: $Ty) -> Self { nonzero.0 .0 -- cgit 1.4.1-3-g733a5 From 95c1d817ae6ec50d3c636c54e33b4d51cab57148 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Mon, 17 Sep 2018 16:35:08 +0800 Subject: move from_nonzero test from run-pass to libcore --- src/libcore/tests/nonzero.rs | 7 +++++++ src/test/run-pass/nonzero.rs | 16 ---------------- 2 files changed, 7 insertions(+), 16 deletions(-) delete mode 100644 src/test/run-pass/nonzero.rs (limited to 'src/libcore') 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); +} diff --git a/src/test/run-pass/nonzero.rs b/src/test/run-pass/nonzero.rs deleted file mode 100644 index 0f2b1dcc8d3..00000000000 --- a/src/test/run-pass/nonzero.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - use std::num::NonZeroU32; - let nz = NonZeroU32::new(5).unwrap(); - let num: u32 = nz.into(); -} - -- cgit 1.4.1-3-g733a5