Rollup merge of #97229 - Nilstrieb:doc-box-noalias, r=dtolnay
Document the current aliasing rules for `Box<T>`. Currently, `Box<T>` gets `noalias`, meaning it has the same rules as `&mut T`. This is sparsely documented, even though it can have quite a big impact on unsafe code using box. Therefore, these rules are documented here, with a big warning that they are not normative and subject to change, since we have not yet committed to an aliasing model and the state of `Box<T>` is especially uncertain. If you have any suggestions and improvements, make sure to leave them here. This is mostly intended to inform people about what is currently going on (to prevent misunderstandings such as [Jon Gjengset's Box aliasing](https://www.youtube.com/watch?v=EY7Wi9fV5bk)). This is supposed to _only document current UB_ and not add any new guarantees or rules.
This commit is contained in:
commit
9c72f16b9f
@ -122,7 +122,21 @@
|
||||
//! definition is just using `T*` can lead to undefined behavior, as
|
||||
//! described in [rust-lang/unsafe-code-guidelines#198][ucg#198].
|
||||
//!
|
||||
//! # Considerations for unsafe code
|
||||
//!
|
||||
//! **Warning: This section is not normative and is subject to change, possibly
|
||||
//! being relaxed in the future! It is a simplified summary of the rules
|
||||
//! currently implemented in the compiler.**
|
||||
//!
|
||||
//! The aliasing rules for `Box<T>` are the same as for `&mut T`. `Box<T>`
|
||||
//! asserts uniqueness over its content. Using raw pointers derived from a box
|
||||
//! after that box has been mutated through, moved or borrowed as `&mut T`
|
||||
//! is not allowed. For more guidance on working with box from unsafe code, see
|
||||
//! [rust-lang/unsafe-code-guidelines#326][ucg#326].
|
||||
//!
|
||||
//!
|
||||
//! [ucg#198]: https://github.com/rust-lang/unsafe-code-guidelines/issues/198
|
||||
//! [ucg#326]: https://github.com/rust-lang/unsafe-code-guidelines/issues/326
|
||||
//! [dereferencing]: core::ops::Deref
|
||||
//! [`Box::<T>::from_raw(value)`]: Box::from_raw
|
||||
//! [`Global`]: crate::alloc::Global
|
||||
|
Loading…
x
Reference in New Issue
Block a user