Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1011b8a3
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,发现更多精彩内容 >>
提交
1011b8a3
编写于
2月 16, 2018
作者:
T
tinaun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Stabilize Unsafe Pointer Methods
also minor doc fixes. Closes #43941
上级
5570cdcc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
78 deletion
+30
-78
src/libcore/ptr.rs
src/libcore/ptr.rs
+30
-78
未找到文件。
src/libcore/ptr.rs
浏览文件 @
1011b8a3
...
...
@@ -740,8 +740,6 @@ pub fn offset_to(self, other: *const T) -> Option<isize> where T: Sized {
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let s: &str = "123";
/// let ptr: *const u8 = s.as_ptr();
///
...
...
@@ -750,7 +748,7 @@ pub fn offset_to(self, other: *const T) -> Option<isize> where T: Sized {
/// println!("{}", *ptr.add(2) as char);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
add
(
self
,
count
:
usize
)
->
Self
where
T
:
Sized
,
...
...
@@ -799,8 +797,6 @@ pub unsafe fn add(self, count: usize) -> Self
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let s: &str = "123";
///
/// unsafe {
...
...
@@ -809,7 +805,7 @@ pub unsafe fn add(self, count: usize) -> Self
/// println!("{}", *end.sub(2) as char);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
sub
(
self
,
count
:
usize
)
->
Self
where
T
:
Sized
,
...
...
@@ -836,8 +832,6 @@ pub unsafe fn sub(self, count: usize) -> Self
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// // Iterate using a raw pointer in increments of two elements
/// let data = [1u8, 2, 3, 4, 5];
/// let mut ptr: *const u8 = data.as_ptr();
...
...
@@ -852,7 +846,7 @@ pub unsafe fn sub(self, count: usize) -> Self
/// ptr = ptr.wrapping_add(step);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
fn
wrapping_add
(
self
,
count
:
usize
)
->
Self
where
T
:
Sized
,
...
...
@@ -879,8 +873,6 @@ pub fn wrapping_add(self, count: usize) -> Self
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// // Iterate using a raw pointer in increments of two elements (backwards)
/// let data = [1u8, 2, 3, 4, 5];
/// let mut ptr: *const u8 = data.as_ptr();
...
...
@@ -895,7 +887,7 @@ pub fn wrapping_add(self, count: usize) -> Self
/// ptr = ptr.wrapping_sub(step);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
fn
wrapping_sub
(
self
,
count
:
usize
)
->
Self
where
T
:
Sized
,
...
...
@@ -922,8 +914,6 @@ pub fn wrapping_sub(self, count: usize) -> Self
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let x = 12;
/// let y = &x as *const i32;
///
...
...
@@ -931,7 +921,7 @@ pub fn wrapping_sub(self, count: usize) -> Self
/// assert_eq!(y.read(), 12);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
read
(
self
)
->
T
where
T
:
Sized
,
...
...
@@ -974,8 +964,6 @@ pub unsafe fn read(self) -> T
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let x = 12;
/// let y = &x as *const i32;
///
...
...
@@ -983,7 +971,7 @@ pub unsafe fn read(self) -> T
/// assert_eq!(y.read_volatile(), 12);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
read_volatile
(
self
)
->
T
where
T
:
Sized
,
...
...
@@ -1010,8 +998,6 @@ pub unsafe fn read_volatile(self) -> T
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let x = 12;
/// let y = &x as *const i32;
///
...
...
@@ -1019,7 +1005,7 @@ pub unsafe fn read_volatile(self) -> T
/// assert_eq!(y.read_unaligned(), 12);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
read_unaligned
(
self
)
->
T
where
T
:
Sized
,
...
...
@@ -1046,8 +1032,6 @@ pub unsafe fn read_unaligned(self) -> T
/// Efficiently create a Rust vector from an unsafe buffer:
///
/// ```
/// #![feature(pointer_methods)]
///
/// # #[allow(dead_code)]
/// unsafe fn from_buf_raw<T: Copy>(ptr: *const T, elts: usize) -> Vec<T> {
/// let mut dst = Vec::with_capacity(elts);
...
...
@@ -1056,7 +1040,7 @@ pub unsafe fn read_unaligned(self) -> T
/// dst
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
copy_to
(
self
,
dest
:
*
mut
T
,
count
:
usize
)
where
T
:
Sized
,
...
...
@@ -1085,8 +1069,6 @@ pub unsafe fn copy_to(self, dest: *mut T, count: usize)
/// Efficiently create a Rust vector from an unsafe buffer:
///
/// ```
/// #![feature(pointer_methods)]
///
/// # #[allow(dead_code)]
/// unsafe fn from_buf_raw<T: Copy>(ptr: *const T, elts: usize) -> Vec<T> {
/// let mut dst = Vec::with_capacity(elts);
...
...
@@ -1095,7 +1077,7 @@ pub unsafe fn copy_to(self, dest: *mut T, count: usize)
/// dst
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
copy_to_nonoverlapping
(
self
,
dest
:
*
mut
T
,
count
:
usize
)
where
T
:
Sized
,
...
...
@@ -1443,8 +1425,6 @@ pub fn align_offset(self, align: usize) -> usize {
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let s: &str = "123";
/// let ptr: *const u8 = s.as_ptr();
///
...
...
@@ -1453,7 +1433,7 @@ pub fn align_offset(self, align: usize) -> usize {
/// println!("{}", *ptr.add(2) as char);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
add
(
self
,
count
:
usize
)
->
Self
where
T
:
Sized
,
...
...
@@ -1502,8 +1482,6 @@ pub unsafe fn add(self, count: usize) -> Self
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let s: &str = "123";
///
/// unsafe {
...
...
@@ -1512,7 +1490,7 @@ pub unsafe fn add(self, count: usize) -> Self
/// println!("{}", *end.sub(2) as char);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
sub
(
self
,
count
:
usize
)
->
Self
where
T
:
Sized
,
...
...
@@ -1539,8 +1517,6 @@ pub unsafe fn sub(self, count: usize) -> Self
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// // Iterate using a raw pointer in increments of two elements
/// let data = [1u8, 2, 3, 4, 5];
/// let mut ptr: *const u8 = data.as_ptr();
...
...
@@ -1555,7 +1531,7 @@ pub unsafe fn sub(self, count: usize) -> Self
/// ptr = ptr.wrapping_add(step);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
fn
wrapping_add
(
self
,
count
:
usize
)
->
Self
where
T
:
Sized
,
...
...
@@ -1582,8 +1558,6 @@ pub fn wrapping_add(self, count: usize) -> Self
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// // Iterate using a raw pointer in increments of two elements (backwards)
/// let data = [1u8, 2, 3, 4, 5];
/// let mut ptr: *const u8 = data.as_ptr();
...
...
@@ -1598,7 +1572,7 @@ pub fn wrapping_add(self, count: usize) -> Self
/// ptr = ptr.wrapping_sub(step);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
fn
wrapping_sub
(
self
,
count
:
usize
)
->
Self
where
T
:
Sized
,
...
...
@@ -1625,8 +1599,6 @@ pub fn wrapping_sub(self, count: usize) -> Self
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let x = 12;
/// let y = &x as *const i32;
///
...
...
@@ -1634,7 +1606,7 @@ pub fn wrapping_sub(self, count: usize) -> Self
/// assert_eq!(y.read(), 12);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
read
(
self
)
->
T
where
T
:
Sized
,
...
...
@@ -1668,7 +1640,7 @@ pub unsafe fn read(self) -> T
/// Beyond accepting a raw pointer, this is unsafe because it semantically
/// moves the value out of `self` without preventing further usage of `self`.
/// If `T` is not `Copy`, then care must be taken to ensure that the value at
/// `s
rc
` is not used before the data is overwritten again (e.g. with `write`,
/// `s
elf
` is not used before the data is overwritten again (e.g. with `write`,
/// `write_bytes`, or `copy`). Note that `*self = foo` counts as a use
/// because it will attempt to drop the value previously at `*self`.
///
...
...
@@ -1677,8 +1649,6 @@ pub unsafe fn read(self) -> T
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let x = 12;
/// let y = &x as *const i32;
///
...
...
@@ -1686,7 +1656,7 @@ pub unsafe fn read(self) -> T
/// assert_eq!(y.read_volatile(), 12);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
read_volatile
(
self
)
->
T
where
T
:
Sized
,
...
...
@@ -1713,8 +1683,6 @@ pub unsafe fn read_volatile(self) -> T
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let x = 12;
/// let y = &x as *const i32;
///
...
...
@@ -1722,7 +1690,7 @@ pub unsafe fn read_volatile(self) -> T
/// assert_eq!(y.read_unaligned(), 12);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
read_unaligned
(
self
)
->
T
where
T
:
Sized
,
...
...
@@ -1749,8 +1717,6 @@ pub unsafe fn read_unaligned(self) -> T
/// Efficiently create a Rust vector from an unsafe buffer:
///
/// ```
/// #![feature(pointer_methods)]
///
/// # #[allow(dead_code)]
/// unsafe fn from_buf_raw<T: Copy>(ptr: *const T, elts: usize) -> Vec<T> {
/// let mut dst = Vec::with_capacity(elts);
...
...
@@ -1759,7 +1725,7 @@ pub unsafe fn read_unaligned(self) -> T
/// dst
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
copy_to
(
self
,
dest
:
*
mut
T
,
count
:
usize
)
where
T
:
Sized
,
...
...
@@ -1788,8 +1754,6 @@ pub unsafe fn copy_to(self, dest: *mut T, count: usize)
/// Efficiently create a Rust vector from an unsafe buffer:
///
/// ```
/// #![feature(pointer_methods)]
///
/// # #[allow(dead_code)]
/// unsafe fn from_buf_raw<T: Copy>(ptr: *const T, elts: usize) -> Vec<T> {
/// let mut dst = Vec::with_capacity(elts);
...
...
@@ -1798,7 +1762,7 @@ pub unsafe fn copy_to(self, dest: *mut T, count: usize)
/// dst
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
copy_to_nonoverlapping
(
self
,
dest
:
*
mut
T
,
count
:
usize
)
where
T
:
Sized
,
...
...
@@ -1825,8 +1789,6 @@ pub unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
/// Efficiently create a Rust vector from an unsafe buffer:
///
/// ```
/// #![feature(pointer_methods)]
///
/// # #[allow(dead_code)]
/// unsafe fn from_buf_raw<T: Copy>(ptr: *const T, elts: usize) -> Vec<T> {
/// let mut dst: Vec<T> = Vec::with_capacity(elts);
...
...
@@ -1835,7 +1797,7 @@ pub unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
/// dst
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
copy_from
(
self
,
src
:
*
const
T
,
count
:
usize
)
where
T
:
Sized
,
...
...
@@ -1864,8 +1826,6 @@ pub unsafe fn copy_from(self, src: *const T, count: usize)
/// Efficiently create a Rust vector from an unsafe buffer:
///
/// ```
/// #![feature(pointer_methods)]
///
/// # #[allow(dead_code)]
/// unsafe fn from_buf_raw<T: Copy>(ptr: *const T, elts: usize) -> Vec<T> {
/// let mut dst: Vec<T> = Vec::with_capacity(elts);
...
...
@@ -1874,7 +1834,7 @@ pub unsafe fn copy_from(self, src: *const T, count: usize)
/// dst
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
copy_from_nonoverlapping
(
self
,
src
:
*
const
T
,
count
:
usize
)
where
T
:
Sized
,
...
...
@@ -1899,7 +1859,7 @@ pub unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize)
///
/// This has all the same safety problems as `ptr::read` with respect to
/// invalid pointers, types, and double drops.
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
drop_in_place
(
self
)
{
drop_in_place
(
self
)
...
...
@@ -1929,8 +1889,6 @@ pub unsafe fn drop_in_place(self) {
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let mut x = 0;
/// let y = &mut x as *mut i32;
/// let z = 12;
...
...
@@ -1940,7 +1898,7 @@ pub unsafe fn drop_in_place(self) {
/// assert_eq!(y.read(), 12);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
write
(
self
,
val
:
T
)
where
T
:
Sized
,
...
...
@@ -1954,8 +1912,6 @@ pub unsafe fn write(self, val: T)
/// # Examples
///
/// ```
/// #![feature(pointer_methods)]
///
/// let mut vec = vec![0; 4];
/// unsafe {
/// let vec_ptr = vec.as_mut_ptr();
...
...
@@ -1963,7 +1919,7 @@ pub unsafe fn write(self, val: T)
/// }
/// assert_eq!(vec, [b'a', b'a', 0, 0]);
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
write_bytes
(
self
,
val
:
u8
,
count
:
usize
)
where
T
:
Sized
,
...
...
@@ -2008,8 +1964,6 @@ pub unsafe fn write_bytes(self, val: u8, count: usize)
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let mut x = 0;
/// let y = &mut x as *mut i32;
/// let z = 12;
...
...
@@ -2019,7 +1973,7 @@ pub unsafe fn write_bytes(self, val: u8, count: usize)
/// assert_eq!(y.read_volatile(), 12);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
write_volatile
(
self
,
val
:
T
)
where
T
:
Sized
,
...
...
@@ -2040,8 +1994,8 @@ pub unsafe fn write_volatile(self, val: T)
/// allocations or resources, so care must be taken not to overwrite an object
/// that should be dropped.
///
/// Additionally, it does not drop `s
rc`. Semantically, `src
` is moved into the
/// location pointed to by `
dst
`.
/// Additionally, it does not drop `s
elf`. Semantically, `self
` is moved into the
/// location pointed to by `
val
`.
///
/// This is appropriate for initializing uninitialized memory, or overwriting
/// memory that has previously been `read` from.
...
...
@@ -2051,8 +2005,6 @@ pub unsafe fn write_volatile(self, val: T)
/// Basic usage:
///
/// ```
/// #![feature(pointer_methods)]
///
/// let mut x = 0;
/// let y = &mut x as *mut i32;
/// let z = 12;
...
...
@@ -2062,7 +2014,7 @@ pub unsafe fn write_volatile(self, val: T)
/// assert_eq!(y.read_unaligned(), 12);
/// }
/// ```
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
write_unaligned
(
self
,
val
:
T
)
where
T
:
Sized
,
...
...
@@ -2077,7 +2029,7 @@ pub unsafe fn write_unaligned(self, val: T)
///
/// This is only unsafe because it accepts a raw pointer.
/// Otherwise, this operation is identical to `mem::replace`.
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
replace
(
self
,
src
:
T
)
->
T
where
T
:
Sized
,
...
...
@@ -2095,7 +2047,7 @@ pub unsafe fn replace(self, src: T) -> T
/// as arguments.
///
/// Ensure that these pointers are valid before calling `swap`.
#[
unstable(feature
=
"pointer_methods"
,
issue
=
"43941
"
)]
#[
stable(feature
=
"pointer_methods"
,
since
=
"1.26.0
"
)]
#[inline]
pub
unsafe
fn
swap
(
self
,
with
:
*
mut
T
)
where
T
:
Sized
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录