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

Tracking issue for the cast method of raw pointers #60602

Closed
SimonSapin opened this issue May 7, 2019 · 6 comments · Fixed by #62713
Closed

Tracking issue for the cast method of raw pointers #60602

SimonSapin opened this issue May 7, 2019 · 6 comments · Fixed by #62713
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@SimonSapin
Copy link
Contributor

#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=()>).

@SimonSapin SimonSapin added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels May 7, 2019
@SimonSapin
Copy link
Contributor Author

Let’s?

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Jul 3, 2019

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

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.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jul 3, 2019
@rfcbot
Copy link
Collaborator

rfcbot commented Jul 3, 2019

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

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Jul 3, 2019
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jul 13, 2019
@rfcbot
Copy link
Collaborator

rfcbot commented Jul 13, 2019

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.

@jpryne
Copy link

jpryne commented Mar 3, 2020

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

@sfackler
Copy link
Member

sfackler commented Mar 3, 2020

Your Rust installation is out of date.

fishilico added a commit to fishilico/shared that referenced this issue May 29, 2020
rust/download_web now fails on Fedora 39 (rustc 1.37) with:

    error[E0658]: use of unstable library feature 'ptr_cast'
      --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/object-0.19.0/src/pod.rs:35:30
       |
    35 |     let val = unsafe { &*ptr.cast() };
       |                              ^^^^
       |
       = note: for more information, see rust-lang/rust#60602

    error[E0658]: use of unstable library feature 'ptr_cast'
      --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/object-0.19.0/src/pod.rs:53:52
       |
    53 |     let slice = unsafe { slice::from_raw_parts(ptr.cast(), count) };
       |                                                    ^^^^
       |
       = note: for more information, see rust-lang/rust#60602

    error[E0658]: use of unstable library feature 'ptr_cast'
      --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/object-0.19.0/src/pod.rs:65:66
       |
    65 |     unsafe { slice::from_raw_parts(slice::from_ref(val).as_ptr().cast(), size) }
       |                                                                  ^^^^
       |
       = note: for more information, see rust-lang/rust#60602

This feature is
https://doc.bccnsoft.com/docs/rust-1.36.0-docs-html/unstable-book/library-features/ptr-cast.html,
stabilized in rust-lang/rust#62713 merged in
Rust 1.38 (2019-09-26).
dtolnay added a commit to dtolnay/oqueue that referenced this issue Jul 24, 2022
Required by the transitive dev-dependency (via rayon) on crossbeam-utils.

    error[E0277]: the trait bound `atomic::seq_lock::SeqLock: std::marker::Copy` is not satisfied
       --> github.com-1ecc6299db9ec823/crossbeam-utils-0.8.11/src/atomic/atomic_cell.rs:905:36
        |
    905 |     static LOCKS: [SeqLock; LEN] = [L; LEN];
        |                                    ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `atomic::seq_lock::SeqLock`
        |
        = note: the `Copy` trait is required because the repeated element will be copied

    error[E0658]: use of unstable library feature 'ptr_cast'
       --> github.com-1ecc6299db9ec823/crossbeam-utils-0.8.11/src/atomic/atomic_cell.rs:183:26
        |
    183 |         self.value.get().cast::<T>()
        |                          ^^^^
        |
        = note: for more information, see rust-lang/rust#60602

    error[E0658]: use of unstable library feature 'ptr_cast'
        --> github.com-1ecc6299db9ec823/crossbeam-utils-0.8.11/src/atomic/atomic_cell.rs:1008:50
         |
    1008 |                 let val = ptr::read_volatile(src.cast::<MaybeUninit<T>>());
         |                                                  ^^^^
         |
         = note: for more information, see rust-lang/rust#60602

    error[E0658]: use of unstable library feature 'ptr_cast'
       --> github.com-1ecc6299db9ec823/crossbeam-utils-0.8.11/src/sync/parker.rs:267:35
        |
    267 |         Arc::into_raw(this.inner).cast::<()>()
        |                                   ^^^^
        |
        = note: for more information, see rust-lang/rust#60602

    error[E0658]: use of unstable library feature 'ptr_cast'
       --> github.com-1ecc6299db9ec823/crossbeam-utils-0.8.11/src/sync/parker.rs:289:38
        |
    289 |             inner: Arc::from_raw(ptr.cast::<Inner>()),
        |                                      ^^^^
        |
        = note: for more information, see rust-lang/rust#60602
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants