Skip to content

Commit ac53367

Browse files
Dylan MacKenzieecstatic-morse
Dylan MacKenzie
authored andcommitted
Mention alignment in top-level docs
This also removes the overlong link that failed tidy xD.
1 parent 85f97e5 commit ac53367

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/libcore/ptr.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,23 @@
1616
//!
1717
//! # Safety
1818
//!
19-
//! Most functions in this module [dereference raw pointers].
20-
//!
21-
//! In order for a pointer dereference to be safe, the pointer must be "valid".
22-
//! A valid pointer is one that satisfies **all** of the following conditions:
19+
//! Many functions in this module take raw pointers as arguments and dereference
20+
//! them. For this to be safe, these pointers must be valid. A valid pointer
21+
//! is one that satisfies **all** of the following conditions:
2322
//!
2423
//! * The pointer is not null.
2524
//! * The pointer is not dangling (it does not point to memory which has been
2625
//! freed).
2726
//! * The pointer satisfies [LLVM's pointer aliasing rules].
2827
//!
29-
//! [dereference raw pointers]: https://doc.rust-lang.org/book/second-edition/ch19-01-unsafe-rust.html#dereferencing-a-raw-pointer
28+
//! Valid pointers are not necessarily properly aligned. However, except for
29+
//! [`read_unaligned`] and [`write_unaligned`], most functions require their
30+
//! arguments to be aligned. Any alignment requirements will be explicitly
31+
//! stated in the function's documentation.
32+
//!
3033
//! [LLVM's pointer aliasing rules]: https://llvm.org/docs/LangRef.html#pointer-aliasing-rules
34+
//! [`read_unaligned`]: ./fn.read_unaligned.html
35+
//! [`write_unaligned`]: ./fn.write_unaligned.html
3136
3237
#![stable(feature = "rust1", since = "1.0.0")]
3338

@@ -654,6 +659,7 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
654659
///
655660
/// // Accessing unaligned values directly is safe.
656661
/// assert!(x.unaligned == v);
662+
/// ```
657663
#[inline]
658664
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
659665
pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {

0 commit comments

Comments
 (0)