-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
const Path initialisation #92930
const Path initialisation #92930
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
192a9c3
to
5bb397d
Compare
I think it may sometimes make sense to have methods like this regardless, both for self-documenting code and to usefully constrain inference. To evaluate whether these methods carry enough weight to add, it would help to know roughly when enough of const traits will become available to make these methods unnecessary for that purpose. cc @oli-obk @rust-lang/wg-const-eval; do you have a rough idea of the timeline upon which we can support const traits well enough to not need these methods? That would help determine whether we want to add workarounds like this. |
Perhaps a sane way is to stabilize a subset of |
☔ The latest upstream changes (presumably #91673) made this pull request unmergeable. Please resolve the merge conflicts. |
@conradludgate if you can resolve the conflicts we can push this forward |
This looks reasonable to me. It seems like the common case will be making a const path from a cc @rust-lang/libs-api: name suggestions? Also, could you please file a tracking issue and use it in the stability attributes? |
#[inline] | ||
#[unstable(feature = "const_path", reason = "TBD", issue = "none")] | ||
pub const fn from_os_str(s: &OsStr) -> &Path { | ||
unsafe { &*(s as *const OsStr as *const Path) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
osstr.as_ref() -> Path
already exists. Imo it's better to wait until that can be made const before introducing additional API surface for the sole purpose of supporting constification.
Ping from triage. @conradludgate you still need to reference the tracking issue in your stability attributes. @joshtriplett It appears there are mixed reactions, are you still interested in these additions? |
Ping from triage: I'm closing this due to inactivity, Please reopen when you are ready to continue with this. @rustbot label: +S-inactive |
I find this really useful. Without it we sometimes have to resort to |
Path::new
cannot be madeconst
currently, due to its usage ofAsRef<OsStr>
.Since Rust does not yet have any concept of const traits, this PR adds a couple new methods in order to construct const Paths.
The expected usage is
Alternatives
In some future, we may get const traits, such that we could do