Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
13ffa43b
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
13ffa43b
编写于
1月 10, 2021
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename raw_const/mut -> const/mut_addr_of, and stabilize them
上级
d3163e96
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
30 addition
and
37 deletion
+30
-37
library/alloc/src/collections/btree/node.rs
library/alloc/src/collections/btree/node.rs
+2
-2
library/alloc/src/lib.rs
library/alloc/src/lib.rs
+0
-1
library/alloc/src/rc.rs
library/alloc/src/rc.rs
+3
-3
library/alloc/src/sync.rs
library/alloc/src/sync.rs
+3
-3
library/core/src/lib.rs
library/core/src/lib.rs
+0
-1
library/core/src/ptr/mod.rs
library/core/src/ptr/mod.rs
+8
-10
library/core/src/slice/mod.rs
library/core/src/slice/mod.rs
+2
-2
library/std/src/lib.rs
library/std/src/lib.rs
+0
-1
src/test/ui/consts/min_const_fn/allow_raw_ptr_dereference_const_fn.rs
...consts/min_const_fn/allow_raw_ptr_dereference_const_fn.rs
+1
-2
src/test/ui/consts/ptr_comparisons.rs
src/test/ui/consts/ptr_comparisons.rs
+2
-3
src/test/ui/consts/ptr_comparisons.stderr
src/test/ui/consts/ptr_comparisons.stderr
+9
-9
未找到文件。
library/alloc/src/collections/btree/node.rs
浏览文件 @
13ffa43b
...
...
@@ -543,8 +543,8 @@ unsafe fn into_key_val_mut_at(mut self, idx: usize) -> (&'a K, &'a mut V) {
// to avoid aliasing with outstanding references to other elements,
// in particular, those returned to the caller in earlier iterations.
let
leaf
=
Self
::
as_leaf_ptr
(
&
mut
self
);
let
keys
=
unsafe
{
&
raw
const
(
*
leaf
)
.keys
};
let
vals
=
unsafe
{
&
raw
mut
(
*
leaf
)
.vals
};
let
keys
=
unsafe
{
ptr
::
addr_of!
((
*
leaf
)
.keys
)
};
let
vals
=
unsafe
{
ptr
::
addr_of_mut!
((
*
leaf
)
.vals
)
};
// We must coerce to unsized array pointers because of Rust issue #74679.
let
keys
:
*
const
[
_
]
=
keys
;
let
vals
:
*
mut
[
_
]
=
vals
;
...
...
library/alloc/src/lib.rs
浏览文件 @
13ffa43b
...
...
@@ -115,7 +115,6 @@
#![feature(pattern)]
#![feature(ptr_internals)]
#![feature(range_bounds_assert_len)]
#![feature(raw_ref_op)]
#![feature(rustc_attrs)]
#![feature(receiver_trait)]
#![cfg_attr(bootstrap,
feature(min_const_generics))]
...
...
library/alloc/src/rc.rs
浏览文件 @
13ffa43b
...
...
@@ -398,7 +398,7 @@ pub fn new_cyclic(data_fn: impl FnOnce(&Weak<T>) -> T) -> Rc<T> {
unsafe
{
let
inner
=
init_ptr
.as_ptr
();
ptr
::
write
(
&
raw
mut
(
*
inner
)
.value
,
data
);
ptr
::
write
(
ptr
::
addr_of_mut!
((
*
inner
)
.value
)
,
data
);
let
prev_value
=
(
*
inner
)
.strong
.get
();
debug_assert_eq!
(
prev_value
,
0
,
"No prior strong references should exist"
);
...
...
@@ -804,7 +804,7 @@ pub fn as_ptr(this: &Self) -> *const T {
// SAFETY: This cannot go through Deref::deref or Rc::inner because
// this is required to retain raw/mut provenance such that e.g. `get_mut` can
// write through the pointer after the Rc is recovered through `from_raw`.
unsafe
{
&
raw
const
(
*
ptr
)
.value
}
unsafe
{
ptr
::
addr_of_mut!
((
*
ptr
)
.value
)
}
}
/// Constructs an `Rc<T>` from a raw pointer.
...
...
@@ -1917,7 +1917,7 @@ pub fn as_ptr(&self) -> *const T {
// SAFETY: if is_dangling returns false, then the pointer is dereferencable.
// The payload may be dropped at this point, and we have to maintain provenance,
// so use raw pointer manipulation.
unsafe
{
&
raw
const
(
*
ptr
)
.value
}
unsafe
{
ptr
::
addr_of_mut!
((
*
ptr
)
.value
)
}
}
}
...
...
library/alloc/src/sync.rs
浏览文件 @
13ffa43b
...
...
@@ -384,7 +384,7 @@ pub fn new_cyclic(data_fn: impl FnOnce(&Weak<T>) -> T) -> Arc<T> {
// reference into a strong reference.
unsafe
{
let
inner
=
init_ptr
.as_ptr
();
ptr
::
write
(
&
raw
mut
(
*
inner
)
.data
,
data
);
ptr
::
write
(
ptr
::
addr_of_mut!
((
*
inner
)
.data
)
,
data
);
// The above write to the data field must be visible to any threads which
// observe a non-zero strong count. Therefore we need at least "Release" ordering
...
...
@@ -800,7 +800,7 @@ pub fn as_ptr(this: &Self) -> *const T {
// SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner because
// this is required to retain raw/mut provenance such that e.g. `get_mut` can
// write through the pointer after the Rc is recovered through `from_raw`.
unsafe
{
&
raw
const
(
*
ptr
)
.data
}
unsafe
{
ptr
::
addr_of_mut!
((
*
ptr
)
.data
)
}
}
/// Constructs an `Arc<T>` from a raw pointer.
...
...
@@ -1677,7 +1677,7 @@ pub fn as_ptr(&self) -> *const T {
// SAFETY: if is_dangling returns false, then the pointer is dereferencable.
// The payload may be dropped at this point, and we have to maintain provenance,
// so use raw pointer manipulation.
unsafe
{
&
raw
mut
(
*
ptr
)
.data
}
unsafe
{
ptr
::
addr_of_mut!
((
*
ptr
)
.data
)
}
}
}
...
...
library/core/src/lib.rs
浏览文件 @
13ffa43b
...
...
@@ -126,7 +126,6 @@
#![feature(auto_traits)]
#![feature(or_patterns)]
#![feature(prelude_import)]
#![feature(raw_ref_macros)]
#![feature(repr_simd,
platform_intrinsics)]
#![feature(rustc_attrs)]
#![feature(simd_ffi)]
...
...
library/core/src/ptr/mod.rs
浏览文件 @
13ffa43b
...
...
@@ -1501,7 +1501,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// # Example
///
/// ```
/// #![feature(raw_ref_macros)]
/// use std::ptr;
///
/// #[repr(packed)]
...
...
@@ -1512,14 +1511,14 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
///
/// let packed = Packed { f1: 1, f2: 2 };
/// // `&packed.f2` would create an unaligned reference, and thus be Undefined Behavior!
/// let raw_f2 = ptr::
raw_const
!(packed.f2);
/// let raw_f2 = ptr::
addr_of
!(packed.f2);
/// assert_eq!(unsafe { raw_f2.read_unaligned() }, 2);
/// ```
#[
unstable(feature
=
"raw_ref_macros"
,
issue
=
"73394
"
)]
#[
stable(feature
=
"raw_ref_macros"
,
since
=
"1.51.0
"
)]
#[rustc_macro_transparency
=
"semitransparent"
]
#[allow_internal_unstable(raw_ref_op)]
pub
macro
raw_const
(
$
e
:
expr
)
{
&
raw
const
$
e
pub
macro
addr_of
(
$
plac
e
:
expr
)
{
&
raw
const
$
plac
e
}
/// Create a `mut` raw pointer to a place, without creating an intermediate reference.
...
...
@@ -1534,7 +1533,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// # Example
///
/// ```
/// #![feature(raw_ref_macros)]
/// use std::ptr;
///
/// #[repr(packed)]
...
...
@@ -1545,13 +1543,13 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
///
/// let mut packed = Packed { f1: 1, f2: 2 };
/// // `&mut packed.f2` would create an unaligned reference, and thus be Undefined Behavior!
/// let raw_f2 = ptr::
raw
_mut!(packed.f2);
/// let raw_f2 = ptr::
addr_of
_mut!(packed.f2);
/// unsafe { raw_f2.write_unaligned(42); }
/// assert_eq!({packed.f2}, 42); // `{...}` forces copying the field instead of creating a reference.
/// ```
#[
unstable(feature
=
"raw_ref_macros"
,
issue
=
"73394
"
)]
#[
stable(feature
=
"raw_ref_macros"
,
since
=
"1.51.0
"
)]
#[rustc_macro_transparency
=
"semitransparent"
]
#[allow_internal_unstable(raw_ref_op)]
pub
macro
raw_mut
(
$
e
:
expr
)
{
&
raw
mut
$
e
pub
macro
addr_of_mut
(
$
plac
e
:
expr
)
{
&
raw
mut
$
plac
e
}
library/core/src/slice/mod.rs
浏览文件 @
13ffa43b
...
...
@@ -543,8 +543,8 @@ pub const fn as_mut_ptr_range(&mut self) -> Range<*mut T> {
#[inline]
pub
fn
swap
(
&
mut
self
,
a
:
usize
,
b
:
usize
)
{
// Can't take two mutable loans from one vector, so instead use raw pointers.
let
pa
=
ptr
::
raw
_mut!
(
self
[
a
]);
let
pb
=
ptr
::
raw
_mut!
(
self
[
b
]);
let
pa
=
ptr
::
addr_of
_mut!
(
self
[
a
]);
let
pb
=
ptr
::
addr_of
_mut!
(
self
[
b
]);
// SAFETY: `pa` and `pb` have been created from safe mutable references and refer
// to elements in the slice and therefore are guaranteed to be valid and aligned.
// Note that accessing the elements behind `a` and `b` is checked and will
...
...
library/std/src/lib.rs
浏览文件 @
13ffa43b
...
...
@@ -298,7 +298,6 @@
#![feature(prelude_import)]
#![feature(ptr_internals)]
#![feature(raw)]
#![feature(raw_ref_macros)]
#![feature(ready_macro)]
#![feature(rustc_attrs)]
#![feature(rustc_private)]
...
...
src/test/ui/consts/min_const_fn/allow_raw_ptr_dereference_const_fn.rs
浏览文件 @
13ffa43b
// check-pass
#![feature(const_raw_ptr_deref)]
#![feature(raw_ref_macros)]
use
std
::
ptr
;
const
fn
test_fn
(
x
:
*
const
i32
)
{
let
x2
=
unsafe
{
ptr
::
raw_const
!
(
*
x
)
};
let
x2
=
unsafe
{
ptr
::
addr_of
!
(
*
x
)
};
}
fn
main
()
{}
src/test/ui/consts/ptr_comparisons.rs
浏览文件 @
13ffa43b
...
...
@@ -9,8 +9,7 @@
core_intrinsics,
const_raw_ptr_comparison,
const_ptr_offset,
const_raw_ptr_deref,
raw_ref_macros
const_raw_ptr_deref
)]
const
FOO
:
&
usize
=
&
42
;
...
...
@@ -64,7 +63,7 @@
const
_
:
*
const
u8
=
//~^ NOTE
unsafe
{
std
::
ptr
::
raw_const
!
((
*
(
FOO
as
*
const
usize
as
*
const
[
u8
;
1000
]))[
999
])
};
unsafe
{
std
::
ptr
::
addr_of
!
((
*
(
FOO
as
*
const
usize
as
*
const
[
u8
;
1000
]))[
999
])
};
//~^ ERROR any use of this value will cause an error
//~| NOTE
...
...
src/test/ui/consts/ptr_comparisons.stderr
浏览文件 @
13ffa43b
...
...
@@ -6,9 +6,9 @@ LL | unsafe { intrinsics::offset(self, count) }
| |
| inbounds test failed: pointer must be in-bounds at offset $TWO_WORDS, but is outside bounds of alloc2 which has size $WORD
| inside `ptr::const_ptr::<impl *const usize>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
| inside `_` at $DIR/ptr_comparisons.rs:6
2
:34
| inside `_` at $DIR/ptr_comparisons.rs:6
1
:34
|
::: $DIR/ptr_comparisons.rs:6
2
:1
::: $DIR/ptr_comparisons.rs:6
1
:1
|
LL | const _: *const usize = unsafe { (FOO as *const usize).offset(2) };
| -------------------------------------------------------------------
...
...
@@ -16,17 +16,17 @@ LL | const _: *const usize = unsafe { (FOO as *const usize).offset(2) };
= note: `#[deny(const_err)]` on by default
error: any use of this value will cause an error
--> $DIR/ptr_comparisons.rs:6
7:35
--> $DIR/ptr_comparisons.rs:6
6:33
|
LL | / const _: *const u8 =
LL | |
LL | | unsafe { std::ptr::
raw_const
!((*(FOO as *const usize as *const [u8; 1000]))[999]) };
| |_________________________________
__
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^___-
|
|
|
memory access failed: pointer must be in-bounds at offset 1000, but is outside bounds of alloc2 which has size $WORD
LL | | unsafe { std::ptr::
addr_of
!((*(FOO as *const usize as *const [u8; 1000]))[999]) };
| |_________________________________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^___-
| |
| memory access failed: pointer must be in-bounds at offset 1000, but is outside bounds of alloc2 which has size $WORD
error: any use of this value will cause an error
--> $DIR/ptr_comparisons.rs:7
1
:27
--> $DIR/ptr_comparisons.rs:7
0
:27
|
LL | const _: usize = unsafe { std::mem::transmute::<*const usize, usize>(FOO) + 4 };
| --------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
...
...
@@ -34,7 +34,7 @@ LL | const _: usize = unsafe { std::mem::transmute::<*const usize, usize>(FOO) +
| "pointer-to-integer cast" needs an rfc before being allowed inside constants
error: any use of this value will cause an error
--> $DIR/ptr_comparisons.rs:7
6
:27
--> $DIR/ptr_comparisons.rs:7
5
:27
|
LL | const _: usize = unsafe { *std::mem::transmute::<&&usize, &usize>(&FOO) + 4 };
| --------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录