diff options
| author | Mark Simulacrum <mark.simulacrum@gmail.com> | 2017-07-26 06:15:01 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-26 06:15:01 -0600 |
| commit | b5b7266b786cb953581ba588d400bddcdae4a852 (patch) | |
| tree | c957402d4bf9f3f60cc718e86bf45ebba616bf4b /src/libcore/tests | |
| parent | bad58f27916e7e233cc2916dcc9167708077e792 (diff) | |
| parent | 0d1864b8cf9585e6133aa3da2b06b29cbfb791bd (diff) | |
| download | rust-b5b7266b786cb953581ba588d400bddcdae4a852.tar.gz rust-b5b7266b786cb953581ba588d400bddcdae4a852.zip | |
Rollup merge of #42959 - SimonSapin:nonzero-checked, r=sfackler
Make the "main" constructors of NonZero/Shared/Unique return Option Per discussion in https://github.com/rust-lang/rust/issues/27730#issuecomment-303939441. This is a breaking change to unstable APIs. The old behavior is still available under the name `new_unchecked`. Note that only that one can be `const fn`, since `if` is currently not allowed in constant contexts. In the case of `NonZero` this requires adding a new `is_zero` method to the `Zeroable` trait. I mildly dislike this, but it’s not much worse than having a `Zeroable` trait in the first place. `Zeroable` and `NonZero` are both unstable, this can be reworked later.
Diffstat (limited to 'src/libcore/tests')
| -rw-r--r-- | src/libcore/tests/nonzero.rs | 6 | ||||
| -rw-r--r-- | src/libcore/tests/ptr.rs | 2 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/libcore/tests/nonzero.rs b/src/libcore/tests/nonzero.rs index 588fffda35f..a795dd57504 100644 --- a/src/libcore/tests/nonzero.rs +++ b/src/libcore/tests/nonzero.rs @@ -16,7 +16,7 @@ use std::mem::size_of; #[test] fn test_create_nonzero_instance() { let _a = unsafe { - NonZero::new(21) + NonZero::new_unchecked(21) }; } @@ -28,14 +28,14 @@ fn test_size_nonzero_in_option() { #[test] fn test_match_on_nonzero_option() { let a = Some(unsafe { - NonZero::new(42) + NonZero::new_unchecked(42) }); match a { Some(val) => assert_eq!(val.get(), 42), None => panic!("unexpected None while matching on Some(NonZero(_))") } - match unsafe { Some(NonZero::new(43)) } { + match unsafe { Some(NonZero::new_unchecked(43)) } { Some(val) => assert_eq!(val.get(), 43), None => panic!("unexpected None while matching on Some(NonZero(_))") } diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index e28dc6a6881..c2d53840f8f 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -167,7 +167,7 @@ fn test_set_memory() { #[test] fn test_unsized_unique() { let xs: &[i32] = &[1, 2, 3]; - let ptr = unsafe { Unique::new(xs as *const [i32] as *mut [i32]) }; + let ptr = unsafe { Unique::new_unchecked(xs as *const [i32] as *mut [i32]) }; let ys = unsafe { ptr.as_ref() }; let zs: &[i32] = &[1, 2, 3]; assert!(ys == zs); |
