- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
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
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
  
    | libs-api, could you weigh in here? Specifically, do you want all the traits in the top post with all possible impls to become  @rustbot label +I-libs-api-nominated @clarfonthey personally I think this needs to be split up, maybe having a PR that makes all the traits  | 
| 
 this has been delegated to wg-const-eval. Only stabilization is where libs is interested | 
| 
 I think there still needs to be some coordination here, the usual questions still exist: what makes sense to be  My thoughts, mostly with respect to this PR: 
 | 
eeadfef    to
    f347c62      
    Compare
  
    
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
f347c62    to
    263ab29      
    Compare
  
    
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| ☔ The latest upstream changes (presumably #144997) made this pull request unmergeable. Please resolve the merge conflicts. | 
263ab29    to
    8cd3b1f      
    Compare
  
    
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| @rustbot author Just to be clear - I'm still expecting the changes to  | 
| Reminder, once the PR becomes ready for a review, use  | 
| 
 Yeah, I mostly just rebased this to see if the miri error was there; I'll split this PR into smaller bits soon-ish. | 
8cd3b1f    to
    c7b8cdd      
    Compare
  
    | The job  Click to see the possible cause of the failure (guessed by this bot) | 
| Closing for now, will open new PRs for split parts. | 
Constify conversion traits (part 1) This is the first part of #144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature: * `From` * `Into` * `TryFrom` * `TryInto` * `FromStr` * `AsRef` * `AsMut` * `Borrow` * `BorrowMut` * `Deref` * `DerefMut` 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 under `bstr` feature) * `OsStr::new` * `Path::new` Those which directly use `Into`: * `Result::into_ok` * `Result::into_err` And those which use `Deref` and `DerefMut`: * `Pin::as_ref` * `Pin::as_mut` * `Pin::as_deref_mut` * `Option::as_deref` * `Option::as_deref_mut` * `Result::as_deref` * `Result::as_deref_mut` (note: the `Option` and `Result` methods were suggested by `@npmccallum` initially as #146101) The parts which are missing from this PR are: * Anything that involves heap-allocated types * Making any method const than the ones listed above * Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO) r? `@tgross35` (who mostly already reviewed this)
… r=tgross35 Constify conversion traits (part 1) This is the first part of rust-lang#144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature: * `From` * `Into` * `TryFrom` * `TryInto` * `FromStr` * `AsRef` * `AsMut` * `Borrow` * `BorrowMut` * `Deref` * `DerefMut` 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 under `bstr` feature) * `OsStr::new` * `Path::new` Those which directly use `Into`: * `Result::into_ok` * `Result::into_err` And those which use `Deref` and `DerefMut`: * `Pin::as_ref` * `Pin::as_mut` * `Pin::as_deref_mut` * `Option::as_deref` * `Option::as_deref_mut` * `Result::as_deref` * `Result::as_deref_mut` (note: the `Option` and `Result` methods were suggested by `@npmccallum` initially as rust-lang#146101) The parts which are missing from this PR are: * Anything that involves heap-allocated types * Making any method const than the ones listed above * Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO) r? `@tgross35` (who mostly already reviewed this)
… r=tgross35 Constify conversion traits (part 1) This is the first part of rust-lang#144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature: * `From` * `Into` * `TryFrom` * `TryInto` * `FromStr` * `AsRef` * `AsMut` * `Borrow` * `BorrowMut` * `Deref` * `DerefMut` 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 under `bstr` feature) * `OsStr::new` * `Path::new` Those which directly use `Into`: * `Result::into_ok` * `Result::into_err` And those which use `Deref` and `DerefMut`: * `Pin::as_ref` * `Pin::as_mut` * `Pin::as_deref_mut` * `Option::as_deref` * `Option::as_deref_mut` * `Result::as_deref` * `Result::as_deref_mut` (note: the `Option` and `Result` methods were suggested by `@npmccallum` initially as rust-lang#146101) The parts which are missing from this PR are: * Anything that involves heap-allocated types * Making any method const than the ones listed above * Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO) r? `@tgross35` (who mostly already reviewed this)
… r=tgross35 Constify conversion traits (part 1) This is the first part of rust-lang#144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature: * `From` * `Into` * `TryFrom` * `TryInto` * `FromStr` * `AsRef` * `AsMut` * `Borrow` * `BorrowMut` * `Deref` * `DerefMut` 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 under `bstr` feature) * `OsStr::new` * `Path::new` Those which directly use `Into`: * `Result::into_ok` * `Result::into_err` And those which use `Deref` and `DerefMut`: * `Pin::as_ref` * `Pin::as_mut` * `Pin::as_deref_mut` * `Option::as_deref` * `Option::as_deref_mut` * `Result::as_deref` * `Result::as_deref_mut` (note: the `Option` and `Result` methods were suggested by ``@npmccallum`` initially as rust-lang#146101) The parts which are missing from this PR are: * Anything that involves heap-allocated types * Making any method const than the ones listed above * Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO) r? ``@tgross35`` (who mostly already reviewed this)
Rollup merge of #145279 - clarfonthey:const-convert-initial, r=tgross35 Constify conversion traits (part 1) This is the first part of #144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature: * `From` * `Into` * `TryFrom` * `TryInto` * `FromStr` * `AsRef` * `AsMut` * `Borrow` * `BorrowMut` * `Deref` * `DerefMut` 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 under `bstr` feature) * `OsStr::new` * `Path::new` Those which directly use `Into`: * `Result::into_ok` * `Result::into_err` And those which use `Deref` and `DerefMut`: * `Pin::as_ref` * `Pin::as_mut` * `Pin::as_deref_mut` * `Option::as_deref` * `Option::as_deref_mut` * `Result::as_deref` * `Result::as_deref_mut` (note: the `Option` and `Result` methods were suggested by ``@npmccallum`` initially as #146101) The parts which are missing from this PR are: * Anything that involves heap-allocated types * Making any method const than the ones listed above * Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO) r? ``@tgross35`` (who mostly already reviewed this)
… r=tgross35 Constify conversion traits (part 1) This is the first part of rust-lang#144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature: * `From` * `Into` * `TryFrom` * `TryInto` * `FromStr` * `AsRef` * `AsMut` * `Borrow` * `BorrowMut` * `Deref` * `DerefMut` 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 under `bstr` feature) * `OsStr::new` * `Path::new` Those which directly use `Into`: * `Result::into_ok` * `Result::into_err` And those which use `Deref` and `DerefMut`: * `Pin::as_ref` * `Pin::as_mut` * `Pin::as_deref_mut` * `Option::as_deref` * `Option::as_deref_mut` * `Result::as_deref` * `Result::as_deref_mut` (note: the `Option` and `Result` methods were suggested by ``@npmccallum`` initially as rust-lang#146101) The parts which are missing from this PR are: * Anything that involves heap-allocated types * Making any method const than the ones listed above * Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO) r? ``@tgross35`` (who mostly already reviewed this)
Tracking issue: #143773
Note that this renames the feature from
const_fromtoconst_convert. Several impls were wrongly included underconst_tryand those have been moved appropriately.Feature includes the constification of the following traits:
FromIntoTryFromTryIntoFromStrAsRefAsMutBorrowBorrowMutDerefDerefMutNote that
DerefandDerefMutare 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 underbstrfeature)OsStr::newPath::newThose which directly use
Into:Result::into_okResult::into_errAnd those which use
DerefandDerefMut:Pin::as_refPin::as_mutPin::as_deref_mutThere 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:Box::into_boxed_slice(Box<T> -> Box<[T]>)Box::into_pin(Box<T> -> Pin<Box<T>>)CStr::as_bytesCStr::as_bytes_with_nulCString::as_c_strCString::into_bytesCString::into_bytes_with_nulCString::into_stringIntoStringError::into_cstringIntoStringError::utf8_error<Box<OsStr>>::into_os_stringOsString::as_os_str<Box<Path>>::into_path_bufPathBuf::as_pathpath::{Component, PrefixComponent}::as_os_str<Box<str>>::into_boxed_bytes<Box<str>>::into_stringString::from_utf8String::from_utf8_uncheckedFromUtf8Error::as_bytesFromUtf8Error::into_bytesFromUtf8Error::utf8_errorBox<[T]>::into_vecAdditionally, rust-lang/libs-team#624 proposes adding the following methods, which are added by this PR but marked private:
OsString::as_mut_os_strPathBuf::as_mut_pathI've checked through the list in rustdoc to make sure I got all the important stuff, but here's what I missed:
~const Destructis required for destructured arrays and tuples #144280)VaList(unfinished, unstable)path::{Components, Iter}(derive_const(Clone)needs some work, didn't feel like it)ptr::addr)FromStrimpls (a lot of these use iterators and I didn't feel like converting them)