Skip to content

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Sep 1, 2022

Motivation: To make migrating to extern type easier.

While this type of casting is achievable today using a normal as cast, it requires that the type is known since the compiler doesn't know that it can handle a Thin bound specially. While that would also be nice to fix, this PR is at least a first step.

Unsure of how to proceed with this, as the implementation now uses from_raw_parts and from_raw_parts_mut which are unstable in const contexts.

Relatedly, see #93959.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 1, 2022
@rust-highfive
Copy link
Contributor

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 1, 2022
This is achievable today using a normal `as` cast when the type is known, but allowing this makes it possible to easily cast extern types in generic contexts, as well as `cast` being generally preferable to `as`.
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-13 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (/checkout/library/std)
   Compiling compiler_builtins v0.1.79
   Compiling unwind v0.0.0 (/checkout/library/unwind)
error: `ptr::metadata::from_raw_parts` is not yet stable as a const fn
   |
48 |         from_raw_parts(self as *const (), ())
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   |
   = help: const-stable functions can only call other const-stable functions

error: `ptr::metadata::from_raw_parts_mut` is not yet stable as a const fn
  --> library/core/src/ptr/mut_ptr.rs:47:9
   |
47 |         from_raw_parts_mut(self as *mut (), ())
   |
   = help: const-stable functions can only call other const-stable functions

error: could not compile `core` due to 2 previous errors

@madsmtm
Copy link
Contributor Author

madsmtm commented Sep 2, 2022

One approach would be to create from_raw_parts_inner and from_raw_parts_mut_inner which are const functions without the rustc_const_unstable attribute

@JohnCSimon
Copy link
Member

@madsmtm
Returning to you to address broken build.

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 8, 2022
@bors
Copy link
Collaborator

bors commented Dec 9, 2022

☔ The latest upstream changes (presumably #105262) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon
Copy link
Member

@madsmtm
Ping from triage: I'm closing this due to inactivity, Please reopen when you are ready to continue with this.
Note: if you do please open the PR BEFORE you push to it, else you won't be able to reopen - this is a quirk of github.
Thanks for your contribution.

@rustbot label: +S-inactive

@JohnCSimon JohnCSimon closed this Jan 1, 2023
@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Jan 1, 2023
@madsmtm
Copy link
Contributor Author

madsmtm commented Jan 3, 2023

Yeah, I didn't really have the time to dig further into it, so I just kinda left it. Thanks for responding and following up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants