Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust argument type for mutable with_metadata_of (#75091) #103346

Merged

Commits on Oct 21, 2022

  1. Argument type for mutable with_metadata_of (rust-lang#75091)

    The method takes two pointer arguments: one `self` supplying the pointer
    value, and a second pointer supplying the metadata.
    
    The new parameter type more clearly reflects the actual requirements.
    The provenance of the metadata parameter is disregarded completely.
    Using a mutable pointer in the call site can be coerced to a const
    pointer while the reverse is not true.
    
    An example of the current use:
    
    ```rust
    // Manually taking an unsized object from a `ManuallyDrop` into another allocation.
    let val: &core::mem::ManuallyDrop<T> = …;
    
    let ptr = val as *const _ as *mut T;
    let ptr = uninit.as_ptr().with_metadata_of(ptr);
    ```
    
    This could then instead be simplified to:
    
    ```rust
    // Manually taking an unsized object from a `ManuallyDrop` into another allocation.
    let val: &core::mem::ManuallyDrop<T> = …;
    
    let ptr = uninit.as_ptr().with_metadata_of(&**val);
    ```
    Andreas Molzer committed Oct 21, 2022
    Configuration menu
    Copy the full SHA
    71c39de View commit details
    Browse the repository at this point in the history
  2. Reduce mutability in std-use of with_metadata_of

    Andreas Molzer committed Oct 21, 2022
    Configuration menu
    Copy the full SHA
    e3606b2 View commit details
    Browse the repository at this point in the history