Skip to content

Commit 2c75256

Browse files
committed
Exise 'unsafe pointer' in favor of 'raw pointer'
Using two terms for one thing is confusing, these are called 'raw pointers' today.
1 parent 7b0f2af commit 2c75256

File tree

22 files changed

+33
-33
lines changed

22 files changed

+33
-33
lines changed

src/doc/trpl/ffi.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ However it is often desired that the callback is targeted to a special
238238
Rust object. This could be the object that represents the wrapper for the
239239
respective C object.
240240
241-
This can be achieved by passing an unsafe pointer to the object down to the
241+
This can be achieved by passing an raw pointer to the object down to the
242242
C library. The C library can then include the pointer to the Rust object in
243243
the notification. This will allow the callback to unsafely access the
244244
referenced Rust object.
@@ -368,7 +368,7 @@ On OSX, frameworks behave with the same semantics as a dynamic library.
368368
369369
# Unsafe blocks
370370
371-
Some operations, like dereferencing unsafe pointers or calling functions that have been marked
371+
Some operations, like dereferencing raw pointers or calling functions that have been marked
372372
unsafe are only allowed inside unsafe blocks. Unsafe blocks isolate unsafety and are a promise to
373373
the compiler that the unsafety does not leak out of the block.
374374

src/doc/trpl/raw-pointers.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ println!("raw points at {}", *raw);
5252
It gives this error:
5353

5454
```text
55-
error: dereference of unsafe pointer requires unsafe function or block [E0133]
56-
println!("raw points at{}", *raw);
57-
^~~~
55+
error: dereference of raw pointer requires unsafe function or block [E0133]
56+
println!("raw points at {}", *raw);
57+
^~~~
5858
```
5959

6060
When you dereference a raw pointer, you’re taking responsibility that it’s not

src/libcollections/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<T> [T] {
370370
core_slice::SliceExt::get_unchecked_mut(self, index)
371371
}
372372

373-
/// Returns an unsafe pointer to the slice's buffer
373+
/// Returns an raw pointer to the slice's buffer
374374
///
375375
/// The caller must ensure that the slice outlives the pointer this
376376
/// function returns, or else it will end up pointing to garbage.

src/libcollections/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl str {
525525
core_str::StrExt::as_bytes(&self[..])
526526
}
527527

528-
/// Returns an unsafe pointer to the `&str`'s buffer.
528+
/// Returns a raw pointer to the `&str`'s buffer.
529529
///
530530
/// The caller must ensure that the string outlives this pointer, and
531531
/// that it is not

src/libcollections/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ impl<T: PartialEq> Vec<T> {
12151215
let ln = self.len();
12161216
if ln < 1 { return; }
12171217

1218-
// Avoid bounds checks by using unsafe pointers.
1218+
// Avoid bounds checks by using raw pointers.
12191219
let p = self.as_mut_ptr();
12201220
let mut r: usize = 1;
12211221
let mut w: usize = 1;

src/libcore/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use marker::Sized;
4646

4747
extern "rust-intrinsic" {
4848

49-
// NB: These intrinsics take unsafe pointers because they mutate aliased
49+
// NB: These intrinsics take raw pointers because they mutate aliased
5050
// memory, which is not valid for either `&` or `&mut`.
5151

5252
pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> T;

src/libcore/marker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ macro_rules! impls{
357357
/// struct is dropped, it may in turn drop one or more instances of
358358
/// the type `T`, though that may not be apparent from the other
359359
/// structure of the type itself. This is commonly necessary if the
360-
/// structure is using an unsafe pointer like `*mut T` whose referent
360+
/// structure is using a raw pointer like `*mut T` whose referent
361361
/// may be dropped when the type is dropped, as a `*mut T` is
362362
/// otherwise not treated as owned.
363363
///

src/libcore/ptr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111
// FIXME: talk about offset, copy_memory, copy_nonoverlapping_memory
1212

13-
//! Operations on unsafe pointers, `*const T`, and `*mut T`.
13+
//! Operations on raw pointers, `*const T`, and `*mut T`.
1414
//!
15-
//! Working with unsafe pointers in Rust is uncommon,
15+
//! Working with raw pointers in Rust is uncommon,
1616
//! typically limited to a few patterns.
1717
//!
1818
//! Use the `null` function to create null pointers, and the `is_null` method
1919
//! of the `*const T` type to check for null. The `*const T` type also defines
2020
//! the `offset` method, for pointer math.
2121
//!
22-
//! # Common ways to create unsafe pointers
22+
//! # Common ways to create raw pointers
2323
//!
2424
//! ## 1. Coerce a reference (`&T`) or mutable reference (`&mut T`).
2525
//!
@@ -86,7 +86,7 @@
8686
//!
8787
//! Usually you wouldn't literally use `malloc` and `free` from Rust,
8888
//! but C APIs hand out a lot of pointers generally, so are a common source
89-
//! of unsafe pointers in Rust.
89+
//! of raw pointers in Rust.
9090
9191
#![stable(feature = "rust1", since = "1.0.0")]
9292
#![doc(primitive = "pointer")]

src/librustc/middle/effect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
162162
debug!("effect: unary case, base type is {}",
163163
ppaux::ty_to_string(self.tcx, base_type));
164164
if let ty::ty_ptr(_) = base_type.sty {
165-
self.require_unsafe(expr.span, "dereference of unsafe pointer")
165+
self.require_unsafe(expr.span, "dereference of raw pointer")
166166
}
167167
}
168168
ast::ExprAssign(ref base, _) | ast::ExprAssignOp(_, ref base, _) => {

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ impl<'tcx> cmt_<'tcx> {
15461546
format!("`Box` content")
15471547
}
15481548
UnsafePtr(..) => {
1549-
format!("dereference of unsafe pointer")
1549+
format!("dereference of raw pointer")
15501550
}
15511551
BorrowedPtr(..) => {
15521552
format!("borrowed content")

src/librustc/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3644,7 +3644,7 @@ impl TypeContents {
36443644
*self & TC::ReachesAll)
36453645
}
36463646

3647-
/// Includes only those bits that still apply when indirected through an unsafe pointer (`*`)
3647+
/// Includes only those bits that still apply when indirected through a raw pointer (`*`)
36483648
pub fn unsafe_pointer(&self) -> TypeContents {
36493649
*self & TC::ReachesAll
36503650
}

src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn gather_move<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
137137
move_info.id, move_info.kind);
138138
}
139139
None => {
140-
// move from rvalue or unsafe pointer, hence ok
140+
// move from rvalue or raw pointer, hence ok
141141
}
142142
}
143143
}

src/librustc_borrowck/borrowck/gather_loans/restrictions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
145145
}
146146
}
147147
}
148-
// Borrowck is not relevant for unsafe pointers
148+
// Borrowck is not relevant for raw pointers
149149
mc::UnsafePtr(..) => Safe
150150
}
151151
}

src/librustc_typeck/check/cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ impl<'tcx> CastCheck<'tcx> {
341341
// Due to the limitations of LLVM global constants,
342342
// region pointers end up pointing at copies of
343343
// vector elements instead of the original values.
344-
// To allow unsafe pointers to work correctly, we
345-
// need to special-case obtaining an unsafe pointer
344+
// To allow raw pointers to work correctly, we
345+
// need to special-case obtaining a raw pointer
346346
// from a region pointer to a vector.
347347

348348
// this will report a type mismatch if needed

src/libstd/sys/common/thread_local.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub struct StaticKey {
102102
/// type is entirely safe to use.
103103
///
104104
/// Implementations will likely, however, contain unsafe code as this type only
105-
/// operates on `*mut u8`, an unsafe pointer.
105+
/// operates on `*mut u8`, a raw pointer.
106106
///
107107
/// # Examples
108108
///

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4215,7 +4215,7 @@ impl<'a> Parser<'a> {
42154215
};
42164216
if self.is_self_ident() {
42174217
let span = self.span;
4218-
self.span_err(span, "cannot pass self by unsafe pointer");
4218+
self.span_err(span, "cannot pass self by raw pointer");
42194219
try!(self.bump());
42204220
}
42214221
// error case, making bogus self ident:

src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
fn foo(x: *const Box<isize>) -> Box<isize> {
13-
let y = *x; //~ ERROR dereference of unsafe pointer requires unsafe function or block
13+
let y = *x; //~ ERROR dereference of raw pointer requires unsafe function or block
1414
return y;
1515
}
1616

src/test/compile-fail/issue-20801.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub fn main() {
4040
//~^ ERROR cannot move out of borrowed content
4141

4242
let c = unsafe { *mut_ptr() };
43-
//~^ ERROR cannot move out of dereference of unsafe pointer
43+
//~^ ERROR cannot move out of dereference of raw pointer
4444

4545
let d = unsafe { *const_ptr() };
46-
//~^ ERROR cannot move out of dereference of unsafe pointer
46+
//~^ ERROR cannot move out of dereference of raw pointer
4747
}

src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn box_with_region_not_ok<'a>() {
5454
assert_send::<Box<&'a isize>>(); //~ ERROR does not fulfill the required lifetime
5555
}
5656

57-
// unsafe pointers are ok unless they point at unsendable things
57+
// raw pointers are ok unless they point at unsendable things
5858

5959
fn unsafe_ok1<'a>(_: &'a isize) {
6060
assert_send::<*const isize>();

src/test/compile-fail/unsafe-fn-assign-deref-ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
fn f(p: *const u8) {
13-
*p = 0; //~ ERROR dereference of unsafe pointer requires unsafe function or block
13+
*p = 0; //~ ERROR dereference of raw pointer requires unsafe function or block
1414
return;
1515
}
1616

src/test/compile-fail/unsafe-fn-deref-ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
fn f(p: *const u8) -> u8 {
13-
return *p; //~ ERROR dereference of unsafe pointer requires unsafe function or block
13+
return *p; //~ ERROR dereference of raw pointer requires unsafe function or block
1414
}
1515

1616
fn main() {

src/test/parse-fail/no-unsafe-self.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
// compile-flags: -Z parse-only
1212

1313
trait A {
14-
fn foo(*mut self); //~ ERROR cannot pass self by unsafe pointer
15-
fn bar(*self); //~ ERROR cannot pass self by unsafe pointer
14+
fn foo(*mut self); //~ ERROR cannot pass self by raw pointer
15+
fn bar(*self); //~ ERROR cannot pass self by raw pointer
1616
}
1717

1818
struct X;
1919
impl A for X {
20-
fn foo(*mut self) { } //~ ERROR cannot pass self by unsafe pointer
21-
fn bar(*self) { } //~ ERROR cannot pass self by unsafe pointer
20+
fn foo(*mut self) { } //~ ERROR cannot pass self by raw pointer
21+
fn bar(*self) { } //~ ERROR cannot pass self by raw pointer
2222
}
2323

2424
fn main() { }

0 commit comments

Comments
 (0)