Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ee85bfdc
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ee85bfdc
编写于
2月 16, 2018
作者:
S
Simon Sapin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make core::nonzero private
It is now an implementation detail of ptr::NonNull and num::NonZero*
上级
2a3f5367
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
10 addition
and
110 deletion
+10
-110
src/libcore/lib.rs
src/libcore/lib.rs
+1
-1
src/libcore/nonzero.rs
src/libcore/nonzero.rs
+3
-93
src/libcore/num/mod.rs
src/libcore/num/mod.rs
+1
-3
src/libcore/ptr.rs
src/libcore/ptr.rs
+2
-9
src/test/run-pass/ctfe/tuple-struct-constructors.rs
src/test/run-pass/ctfe/tuple-struct-constructors.rs
+3
-4
未找到文件。
src/libcore/lib.rs
浏览文件 @
ee85bfdc
...
...
@@ -171,7 +171,6 @@
pub
mod
intrinsics
;
pub
mod
mem
;
pub
mod
nonzero
;
pub
mod
ptr
;
pub
mod
hint
;
...
...
@@ -221,6 +220,7 @@ pub mod heap {
// note: does not need to be public
mod
iter_private
;
mod
nonzero
;
mod
tuple
;
mod
unit
;
...
...
src/libcore/nonzero.rs
浏览文件 @
ee85bfdc
...
...
@@ -9,103 +9,13 @@
// except according to those terms.
//! Exposes the NonZero lang item which provides optimization hints.
#![unstable(feature
=
"nonzero"
,
reason
=
"deprecated"
,
issue
=
"49137"
)]
#![rustc_deprecated(reason
=
"use `std::ptr::NonNull` or `std::num::NonZero*` instead"
,
since
=
"1.26.0"
)]
#![allow(deprecated)]
use
ops
::
CoerceUnsized
;
/// Unsafe trait to indicate what types are usable with the NonZero struct
pub
unsafe
trait
Zeroable
{
/// Whether this value is zero
fn
is_zero
(
&
self
)
->
bool
;
}
macro_rules!
impl_zeroable_for_pointer_types
{
(
$
(
$Ptr
:
ty
)
+
)
=>
{
$
(
/// For fat pointers to be considered "zero", only the "data" part needs to be null.
unsafe
impl
<
T
:
?
Sized
>
Zeroable
for
$Ptr
{
#[inline]
fn
is_zero
(
&
self
)
->
bool
{
(
*
self
)
.is_null
()
}
}
)
+
}
}
macro_rules!
impl_zeroable_for_integer_types
{
(
$
(
$Int
:
ty
)
+
)
=>
{
$
(
unsafe
impl
Zeroable
for
$Int
{
#[inline]
fn
is_zero
(
&
self
)
->
bool
{
*
self
==
0
}
}
)
+
}
}
impl_zeroable_for_pointer_types!
{
*
const
T
*
mut
T
}
impl_zeroable_for_integer_types!
{
usize
u8
u16
u32
u64
u128
isize
i8
i16
i32
i64
i128
}
/// A wrapper type for raw pointers and integers that will never be
/// NULL or 0 that might allow certain optimizations.
#[lang
=
"non_zero"
]
#[derive(Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Debug,
Hash)]
pub
struct
NonZero
<
T
:
Zeroable
>
(
pub
(
crate
)
T
);
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_unchecked
(
inner
:
T
)
->
Self
{
NonZero
(
inner
)
}
/// Creates an instance of NonZero with the provided value.
#[inline]
pub
fn
new
(
inner
:
T
)
->
Option
<
Self
>
{
if
inner
.is_zero
()
{
None
}
else
{
Some
(
NonZero
(
inner
))
}
}
/// Gets the inner value.
pub
fn
get
(
self
)
->
T
{
self
.0
}
}
impl
<
T
:
Zeroable
+
CoerceUnsized
<
U
>
,
U
:
Zeroable
>
CoerceUnsized
<
NonZero
<
U
>>
for
NonZero
<
T
>
{}
impl
<
'a
,
T
:
?
Sized
>
From
<&
'a
mut
T
>
for
NonZero
<*
mut
T
>
{
fn
from
(
reference
:
&
'a
mut
T
)
->
Self
{
NonZero
(
reference
)
}
}
impl
<
'a
,
T
:
?
Sized
>
From
<&
'a
mut
T
>
for
NonZero
<*
const
T
>
{
fn
from
(
reference
:
&
'a
mut
T
)
->
Self
{
let
ptr
:
*
mut
T
=
reference
;
NonZero
(
ptr
)
}
}
#[derive(Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash)]
pub
(
crate
)
struct
NonZero
<
T
>
(
pub
(
crate
)
T
);
impl
<
'a
,
T
:
?
Sized
>
From
<&
'a
T
>
for
NonZero
<*
const
T
>
{
fn
from
(
reference
:
&
'a
T
)
->
Self
{
NonZero
(
reference
)
}
}
impl
<
T
:
CoerceUnsized
<
U
>
,
U
>
CoerceUnsized
<
NonZero
<
U
>>
for
NonZero
<
T
>
{}
src/libcore/num/mod.rs
浏览文件 @
ee85bfdc
...
...
@@ -16,7 +16,7 @@
use
fmt
;
use
intrinsics
;
use
mem
;
#[allow(deprecated)]
use
nonzero
::
NonZero
;
use
nonzero
::
NonZero
;
use
ops
;
use
str
::
FromStr
;
...
...
@@ -49,11 +49,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
/// ```
#[
$
stability]
#[
$
deprecation]
#[allow(deprecated)]
#[derive(Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash)]
pub
struct
$Ty
(
NonZero
<
$Int
>
);
#[allow(deprecated)]
impl
$Ty
{
/// Create a non-zero without checking the value.
///
...
...
src/libcore/ptr.rs
浏览文件 @
ee85bfdc
...
...
@@ -23,7 +23,7 @@
use
hash
;
use
marker
::{
PhantomData
,
Unsize
};
use
mem
;
#[allow(deprecated)]
use
nonzero
::
NonZero
;
use
nonzero
::
NonZero
;
use
cmp
::
Ordering
::{
self
,
Less
,
Equal
,
Greater
};
...
...
@@ -2742,7 +2742,6 @@ fn ge(&self, other: &*mut T) -> bool { *self >= *other }
#[unstable(feature
=
"ptr_internals"
,
issue
=
"0"
,
reason
=
"use NonNull instead and consider PhantomData<T>
\
(if you also use #[may_dangle]), Send, and/or Sync"
)]
#[allow(deprecated)]
#[doc(hidden)]
pub
struct
Unique
<
T
:
?
Sized
>
{
pointer
:
NonZero
<*
const
T
>
,
...
...
@@ -2790,7 +2789,6 @@ pub const fn empty() -> Self {
}
#[unstable(feature
=
"ptr_internals"
,
issue
=
"0"
)]
#[allow(deprecated)]
impl
<
T
:
?
Sized
>
Unique
<
T
>
{
/// Creates a new `Unique`.
///
...
...
@@ -2855,7 +2853,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
#[unstable(feature
=
"ptr_internals"
,
issue
=
"0"
)]
#[allow(deprecated)]
impl
<
'a
,
T
:
?
Sized
>
From
<&
'a
mut
T
>
for
Unique
<
T
>
{
fn
from
(
reference
:
&
'a
mut
T
)
->
Self
{
Unique
{
pointer
:
NonZero
(
reference
as
_
),
_
marker
:
PhantomData
}
...
...
@@ -2863,7 +2860,6 @@ fn from(reference: &'a mut T) -> Self {
}
#[unstable(feature
=
"ptr_internals"
,
issue
=
"0"
)]
#[allow(deprecated)]
impl
<
'a
,
T
:
?
Sized
>
From
<&
'a
T
>
for
Unique
<
T
>
{
fn
from
(
reference
:
&
'a
T
)
->
Self
{
Unique
{
pointer
:
NonZero
(
reference
as
_
),
_
marker
:
PhantomData
}
...
...
@@ -2896,7 +2892,7 @@ fn from(p: NonNull<T>) -> Self {
/// provide a public API that follows the normal shared XOR mutable rules of Rust.
#[stable(feature
=
"nonnull"
,
since
=
"1.25.0"
)]
pub
struct
NonNull
<
T
:
?
Sized
>
{
#[allow(deprecated)]
pointer
:
NonZero
<*
const
T
>
,
pointer
:
NonZero
<*
const
T
>
,
}
/// `NonNull` pointers are not `Send` because the data they reference may be aliased.
...
...
@@ -2923,7 +2919,6 @@ pub fn dangling() -> Self {
}
}
#[allow(deprecated)]
impl
<
T
:
?
Sized
>
NonNull
<
T
>
{
/// Creates a new `NonNull`.
///
...
...
@@ -3054,7 +3049,6 @@ fn from(unique: Unique<T>) -> Self {
}
#[stable(feature
=
"nonnull"
,
since
=
"1.25.0"
)]
#[allow(deprecated)]
impl
<
'a
,
T
:
?
Sized
>
From
<&
'a
mut
T
>
for
NonNull
<
T
>
{
fn
from
(
reference
:
&
'a
mut
T
)
->
Self
{
NonNull
{
pointer
:
NonZero
(
reference
as
_
)
}
...
...
@@ -3062,7 +3056,6 @@ fn from(reference: &'a mut T) -> Self {
}
#[stable(feature
=
"nonnull"
,
since
=
"1.25.0"
)]
#[allow(deprecated)]
impl
<
'a
,
T
:
?
Sized
>
From
<&
'a
T
>
for
NonNull
<
T
>
{
fn
from
(
reference
:
&
'a
T
)
->
Self
{
NonNull
{
pointer
:
NonZero
(
reference
as
_
)
}
...
...
src/test/run-pass/ctfe/tuple-struct-constructors.rs
浏览文件 @
ee85bfdc
...
...
@@ -10,11 +10,10 @@
// https://github.com/rust-lang/rust/issues/41898
#![feature(nonzero,
const_fn)]
extern
crate
core
;
use
core
::
nonzero
::
NonZero
;
#![feature(nonzero)]
use
std
::
num
::
NonZeroU64
;
fn
main
()
{
const
FOO
:
NonZero
<
u64
>
=
unsafe
{
NonZero
::
new_unchecked
(
2
)
};
const
FOO
:
NonZero
U64
=
unsafe
{
NonZeroU64
::
new_unchecked
(
2
)
};
if
let
FOO
=
FOO
{}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录