Skip to content

Documentation for addr_of_mut! is contradictory #94473

@nicholasbishop

Description

@nicholasbishop

The documentation for addr_of_mut! says:

Note, however, that the expr in addr_of_mut!(expr) is still subject to all the usual rules. In particular, addr_of_mut!(*ptr::null_mut()) is Undefined Behavior because it dereferences a null pointer.

However, in the example for Creating a pointer to uninitialized data it shows this code:

let f1_ptr = unsafe { ptr::addr_of_mut!((*uninit.as_mut_ptr()).field) };

In that example it appears as though expr contains a dereference of uninitialized data, which is not normally valid. That seems in conflict with the earlier warning that "all the usual rules" apply.

I'm guessing that maybe dereferencing is allowed in expr as long as the pointer isn't dangling?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions