-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Constify conversion traits #144289
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
base: master
Are you sure you want to change the base?
Constify conversion traits #144289
Conversation
This comment has been minimized.
This comment has been minimized.
21c84d1
to
cb3f0a6
Compare
This comment has been minimized.
This comment has been minimized.
cb3f0a6
to
5620209
Compare
Cc @rust-lang/wg-const-eval @rust-lang/libs-api
Adding these new methods seems orthogonal and needs an ACP (or libs-api signoff). Could it be split to a separate PR to be discussed independently?
|
I guess I could split this PR into several parts; my main justification was that all the new additions are unstable and if they were not accepted, could be kept that way and potentially left unstable. I figured it'd be better to just mark the methods as unstably const and leave them that way, than work around that to leave the code in an undesirable state just to avoid having to run extra votes. |
Also to clarify what I mean by leaving the code in a worse state: I could make a bunch of private methods with the same functionality and then update the stable ones to use that, thus sidestepping the bureaucracy of adding constness to existing API which is in libs-api' domain. or I could just mark these methods as unstably const or outright unstable knowing that they are very similar to existing methods, but still leave them open to libs-api to discuss in a dedicated forum, as I have. The issue here is, I know that whenever I submit a dedicated libs-api PR, I risk months of things not even being noticed, because there are several people in that review pool who seemingly do not actually review PRs. So, rather than doing things via hacky private methods, or waiting on libs-api to actually review these methods separately, I just tack them on this PR and let libs-api review them at their own pace. Knowing that they're all unstable anyway, since this isn't actually affecting a stable API. |
Nothing here does anything interesting const-wise, right? No new intrinsics or anything like that? This is entirely up to t-libs-api then, as far as I am concerned. It's not clear to me why these new methods were added (why does the old implementation of I know things taking a week or three to land can be frustrating, but please be mindful that many reviewers are volunteers, and trying to bypass processes is more harmful than helpful for the project as a whole. If a process is broken, it needs to be fixed. For tiny additions such as new public methods on existing types, all signs I am aware of indicate that the ACP process works just fine. |
You're right that I'm combining just adding constness to things with making them into actual public methods. I'll close this for now and open a few separate PRs + an ACP. |
Also, to fully clarify: the main issue here is the addition of the new methods. It has generally been okay to just mark some methods as const-unstable without an ACP, since the methods were already accepted, just not in const context. I'll resubmit this PR in a modified form once I'm feeling in a less venty mood. Sorry for not being entirely clear here and trying to bypass some bureaucracy. ACPs are still important. |
Yes, new unstable methods need ACP, new unstable constness does not. |
Okay, after spending more time to reflect, the changes I need to make to this PR are actually pretty small and I just marked the methods as private instead of unstable. Apologies for trying to bypass procedure: I understand why it's there, but sometimes when I get frustrated by things I get a bit overzealous. I can still split up the PR into the parts doing different things if you want (adding unstable constness, changing features for impls, and adding the impls) but it felt all related enough that it should go together and be reviewed by the same person. For now though, I'll at least reopen until we make that decision. (assuming that rustbot/bors can handle it…) |
5620209
to
5a74039
Compare
5a74039
to
316426e
Compare
Tracking issue: #143773
Note that this renames the feature from
const_from
toconst_convert
. Several impls were wrongly included underconst_try
and those have been moved appropriately.Feature includes the constification of the following traits:
From
Into
TryFrom
TryInto
AsRef
AsMut
Borrow
BorrowMut
Deref
DerefMut
Note that
Deref
andDerefMut
are currently listed under the now-closed #88955, but I decided it's worth just including that here instead. Since these all end up being needed for each other, it's best to bundle them all together, even though the semantics are different.There are a few methods that are intrinsically tied to these traits which I've included in the feature. Particularly, those which are wrappers over
AsRef
:ByteStr::new
(unstable underbstr
feature)OsStr::new
Path::new
Those which directly use
Into
:Result::into_ok
Result::into_err
And those which use
Deref
andDerefMut
:Pin::as_ref
Pin::as_mut
Pin::as_deref_mut
There are a few methods which were not const-stable before, but are used in the constification of these methods or tangential to them. I added them under a separate feature,
const_convert_methods
, and filed them under #144288. They are:CStr::as_bytes
(existing method, now const)CStr::as_bytes_with_nul
(existing method, now const)CStr::as_c_str
(existing method, now const)OsString::as_os_str
(existing method, now const)PathBuf::as_path
(existing method, now const)path::{Component, PrefixComponent}::as_os_str
(existing method, now const)Additionally, rust-lang/libs-team#624 proposes adding the following methods, which are added by this PR but marked private:
OsString::as_mut_os_str
(new method;DerefMut
implementation exists)PathBuf::as_mut_path
(new method;DerefMut
implementation exists)I've checked through the list in rustdoc to make sure I got all the important stuff, but here's what I missed:
VaList
(unfinished, unstable)path::{Components, Iter}
(derive_const(Clone)
needs some work, didn't feel like it)ptr::addr
; probably fixed by Make slice iterators carry only a single provenance #122971)I tried to do the heap-allocated conversions that don't technically require reallocating, like
PathBuf <-> OsString
, but quickly realised that due to the wayconst Destruct
works, I would have to replace all of them with versions that go viaManuallyDrop
, and decided to hold off for now.