]> git.lizzy.rs Git - rust.git/commitdiff
references must be aligned; also move up the warning that fn ptrs must be non-NULL
authorRalf Jung <post@ralfj.de>
Sat, 20 Jul 2019 11:20:08 +0000 (13:20 +0200)
committerRalf Jung <post@ralfj.de>
Sat, 20 Jul 2019 11:20:08 +0000 (13:20 +0200)
src/libstd/primitive_docs.rs

index cab58799d68d4b1344f79805a1b779c04c03fdeb..95b803e3461ec4c9583a068b5cdd2d0089c1a563 100644 (file)
@@ -895,9 +895,9 @@ mod prim_usize { }
 /// A reference represents a borrow of some owned value. You can get one by using the `&` or `&mut`
 /// operators on a value, or by using a `ref` or `ref mut` pattern.
 ///
-/// For those familiar with pointers, a reference is just a pointer that is assumed to not be null.
-/// In fact, `Option<&T>` has the same memory representation as a nullable pointer, and can be
-/// passed across FFI boundaries as such.
+/// For those familiar with pointers, a reference is just a pointer that is assumed to be
+/// aligned and not null. In fact, `Option<&T>` has the same memory representation as a
+/// nullable but aligned pointer, and can be passed across FFI boundaries as such.
 ///
 /// In most cases, references can be used much like the original value. Field access, method
 /// calling, and indexing work the same (save for mutability rules, of course). In addition, the
@@ -1040,6 +1040,11 @@ mod prim_ref { }
 /// [`FnMut`]: ops/trait.FnMut.html
 /// [`FnOnce`]: ops/trait.FnOnce.html
 ///
+/// Function pointers are pointers that point to *code*, not data. They can be called
+/// just like functions. Like references, function pointers are assumed to not be null,
+/// so if you want to pass a function pointer over FFI and be able to accommodate null pointers,
+/// make your type `Option<fn()>` with your required signature.
+///
 /// Plain function pointers are obtained by casting either plain functions, or closures that don't
 /// capture an environment:
 ///
@@ -1095,10 +1100,6 @@ mod prim_ref { }
 ///
 /// These markers can be combined, so `unsafe extern "stdcall" fn()` is a valid type.
 ///
-/// Like references in rust, function pointers are assumed to not be null, so if you want to pass a
-/// function pointer over FFI and be able to accommodate null pointers, make your type
-/// `Option<fn()>` with your required signature.
-///
 /// Function pointers implement the following traits:
 ///
 /// * [`Clone`]