Skip to content

Commit 2e6b13a

Browse files
committed
references must be aligned; also move up the warning that fn ptrs must be non-NULL
1 parent 21b502b commit 2e6b13a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/libstd/primitive_docs.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,9 @@ mod prim_usize { }
895895
/// A reference represents a borrow of some owned value. You can get one by using the `&` or `&mut`
896896
/// operators on a value, or by using a `ref` or `ref mut` pattern.
897897
///
898-
/// For those familiar with pointers, a reference is just a pointer that is assumed to not be null.
899-
/// In fact, `Option<&T>` has the same memory representation as a nullable pointer, and can be
900-
/// passed across FFI boundaries as such.
898+
/// For those familiar with pointers, a reference is just a pointer that is assumed to be
899+
/// aligned and not null. In fact, `Option<&T>` has the same memory representation as a
900+
/// nullable but aligned pointer, and can be passed across FFI boundaries as such.
901901
///
902902
/// In most cases, references can be used much like the original value. Field access, method
903903
/// calling, and indexing work the same (save for mutability rules, of course). In addition, the
@@ -1040,6 +1040,11 @@ mod prim_ref { }
10401040
/// [`FnMut`]: ops/trait.FnMut.html
10411041
/// [`FnOnce`]: ops/trait.FnOnce.html
10421042
///
1043+
/// Function pointers are pointers that point to *code*, not data. They can be called
1044+
/// just like functions. Like references, function pointers are assumed to not be null,
1045+
/// so if you want to pass a function pointer over FFI and be able to accommodate null pointers,
1046+
/// make your type `Option<fn()>` with your required signature.
1047+
///
10431048
/// Plain function pointers are obtained by casting either plain functions, or closures that don't
10441049
/// capture an environment:
10451050
///
@@ -1095,10 +1100,6 @@ mod prim_ref { }
10951100
///
10961101
/// These markers can be combined, so `unsafe extern "stdcall" fn()` is a valid type.
10971102
///
1098-
/// Like references in rust, function pointers are assumed to not be null, so if you want to pass a
1099-
/// function pointer over FFI and be able to accommodate null pointers, make your type
1100-
/// `Option<fn()>` with your required signature.
1101-
///
11021103
/// Function pointers implement the following traits:
11031104
///
11041105
/// * [`Clone`]

0 commit comments

Comments
 (0)