Rust: Tracking issue for the `cast` method of raw pointers

Created on 7 May 2019  Â·  6Comments  Â·  Source: rust-lang/rust

https://github.com/rust-lang/rust/pull/60601 adds:

impl<T: ?Sized> *mut T {
    /// Cast to a pointer to a different type
    #[inline]
    pub const fn cast<U>(self) -> *mut U {
        self as _
    }
}

impl<T: ?Sized> *const T {
    /// Cast to a pointer to a different type
    #[inline]
    pub const fn cast<U>(self) -> *const U {
        self as _
    }
}

Like with NonNull::cast, the input pointed type does not need to be Sized but the output pointed type does, because we wouldn’t know what appropriate pointer metadata (slice length, trait object vtable, …) to insert. The actual requirement is that the pointer is thin, but Sized is the closest approximation we have (until we add something like T: ptr::Pointee<Metadata=()>).

B-unstable C-tracking-issue T-libs disposition-merge finished-final-comment-period

Most helpful comment

Your Rust installation is out of date.

All 6 comments

Let’s?

@rfcbot fcp merge

Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged team members:

  • [x] @Amanieu
  • [ ] @Kimundi
  • [x] @SimonSapin
  • [x] @alexcrichton
  • [x] @dtolnay
  • [x] @sfackler
  • [ ] @withoutboats

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

:bell: This is now entering its final comment period, as per the review above. :bell:

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

Getting this issue when executing:
cargo install cargo-generate

More detail:

   Compiling backtrace v0.3.44
error[E0658]: use of unstable library feature 'ptr_cast'
   --> C:\Users\jack_\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.44\src\backtrace\dbghelp.rs:110:74
    |
110 |                 RtlLookupFunctionEntry(addr, &mut base, ptr::null_mut()).cast()
    |                                                                          ^^^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/60602

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
error: Could not compile `backtrace`.
warning: build failed, waiting for other jobs to finish...
error: failed to compile `cargo-generate v0.5.0`, intermediate artifacts can be found at `C:\Users\jack_\AppData\Local\Temp\cargo-installM3JL39`

Caused by:
  build failed

Your Rust installation is out of date.

Was this page helpful?
0 / 5 - 0 ratings