diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2017-06-29 01:03:35 +0200 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2017-07-22 20:38:16 +0200 |
| commit | 0a08ad0443631ca86e61526916fb4ee61fe1abce (patch) | |
| tree | c8dd36ae38044adabc45b83e84d08333eb118dd7 /src/libcore | |
| parent | e9af03a22279b62ded4c7ea897d5ac3a9b54728c (diff) | |
| download | rust-0a08ad0443631ca86e61526916fb4ee61fe1abce.tar.gz rust-0a08ad0443631ca86e61526916fb4ee61fe1abce.zip | |
Rename {NonZero,Shared,Unique}::new to new_unchecked
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/nonzero.rs | 2 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 12 | ||||
| -rw-r--r-- | src/libcore/tests/nonzero.rs | 6 | ||||
| -rw-r--r-- | src/libcore/tests/ptr.rs | 2 |
4 files changed, 11 insertions, 11 deletions
diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs index 0564d73dd6d..6acdcad8763 100644 --- a/src/libcore/nonzero.rs +++ b/src/libcore/nonzero.rs @@ -69,7 +69,7 @@ impl<T: Zeroable> NonZero<T> { /// Creates an instance of NonZero with the provided value. /// You must indeed ensure that the value is actually "non-zero". #[inline] - pub const unsafe fn new(inner: T) -> Self { + pub const unsafe fn new_unchecked(inner: T) -> Self { NonZero(inner) } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index e83ca63834a..5ece63e23b1 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -1098,7 +1098,7 @@ impl<T: Sized> Unique<T> { pub fn empty() -> Self { unsafe { let ptr = mem::align_of::<T>() as *mut T; - Unique::new(ptr) + Unique::new_unchecked(ptr) } } } @@ -1110,8 +1110,8 @@ impl<T: ?Sized> Unique<T> { /// # Safety /// /// `ptr` must be non-null. - pub const unsafe fn new(ptr: *mut T) -> Self { - Unique { pointer: NonZero::new(ptr), _marker: PhantomData } + pub const unsafe fn new_unchecked(ptr: *mut T) -> Self { + Unique { pointer: NonZero::new_unchecked(ptr), _marker: PhantomData } } /// Creates a new `Unique` if `ptr` is non-null. @@ -1217,7 +1217,7 @@ impl<T: Sized> Shared<T> { pub fn empty() -> Self { unsafe { let ptr = mem::align_of::<T>() as *mut T; - Shared::new(ptr) + Shared::new_unchecked(ptr) } } } @@ -1229,8 +1229,8 @@ impl<T: ?Sized> Shared<T> { /// # Safety /// /// `ptr` must be non-null. - pub const unsafe fn new(ptr: *mut T) -> Self { - Shared { pointer: NonZero::new(ptr), _marker: PhantomData } + pub const unsafe fn new_unchecked(ptr: *mut T) -> Self { + Shared { pointer: NonZero::new_unchecked(ptr), _marker: PhantomData } } /// Creates a new `Shared` if `ptr` is non-null. 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); |
