Skip to content

Docs mention rvalue #153350

Description

@redweasel

Location (URL)

https://doc.rust-lang.org/std/mem/fn.transmute.html

Summary

transmute docs mention rvalues in a comment in the last example. This should instead be called a value or just not named.

E.g. the comment could be

// This now has three mutable references pointing at the same
// memory: `slice`, `returned.0` and `returned.1`.
// `slice` is never used after `let ptr = ...`, and so one can
// treat it as "dead", and therefore, you only have two real
// mutable slices.

maybe a better way of writing it would be:

unsafe {
    let ptr = slice.as_mut_ptr();
    // This now has three mutable references pointing at the same
    // memory: `slice`, `ret.0` and `ret.1`. `slice` is never used after
    // `let ptr = ...`, and so one can treat it as "dead", and therefore,
    // you only have two real mutable slices.
    let ret = (slice::from_raw_parts_mut(ptr, mid),
               slice::from_raw_parts_mut(ptr.add(mid), len - mid))
    ret
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions