rust/library
Matthias Krüger 016c306ce6
Rollup merge of #107624 - tgross35:const-cstr-methods, r=dtolnay
Stabilize `const_cstr_methods`

This PR seeks to stabilize `const_cstr_methods`. Fixes most of #101719

## New const stable API

```rust
impl CStr {
    // depends: memchr
    pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, FromBytesWithNulError> {...}
    // depends: const_slice_index
    pub const fn to_bytes(&self) -> &[u8] {}
    // depends: pointer casts
    pub const fn to_bytes_with_nul(&self) -> &[u8] {}
    // depends: str::from_utf8
    pub const fn to_str(&self) -> Result<&str, str::Utf8Error> {}
}
```

I don't think any of these methods will have any issue when `CStr` becomes a thin pointer as long as `memchr` is const  (which also allows for const `strlen`) .

## Notes

- `from_bytes_until_nul` relies on `const_slice_index`, which relies on `const_trait_impls`, and generally this should be avoided. After talking with Oli, it should be OK in this case because we could replace the ranges with pointer tricks if needed (worst case being those feature gates disappear). https://github.com/rust-lang/rust/pull/107624#discussion_r1101468480
- Making `from_ptr` const is deferred because it depends on `const_eval_select`. I have moved this under the new flag `const_cstr_from_ptr` https://github.com/rust-lang/rust/pull/107624#discussion_r1101555239

cc ``@oli-obk`` I think you're the const expert

``@rustbot`` modify labels: +T-libs-api +needs-fcp
2023-06-30 08:01:12 +02:00
..
alloc Rollup merge of #112628 - gootorov:box_alloc_partialeq, r=joshtriplett 2023-06-27 22:10:13 +02:00
backtrace@4245978ca8 PS Vita std support 2023-05-07 18:57:43 +03:00
core Rollup merge of #107624 - tgross35:const-cstr-methods, r=dtolnay 2023-06-30 08:01:12 +02:00
panic_abort Remove unnecessary raw pointer in __rust_start_panic arg 2023-03-26 16:40:18 +00:00
panic_unwind Partial stabilisation of c_unwind 2023-04-29 13:01:44 +01:00
portable-simd Explicit set workspace.resolver = "1" 2023-05-31 00:08:11 +01:00
proc_macro Merge proc_macro_span_shrink and proc_macro_span 2023-06-20 19:40:26 -04:00
profiler_builtins Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rtstartup Remove custom frame info registration on i686-pc-windows-gnu 2022-08-23 16:12:58 +08:00
rustc-std-workspace-alloc Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00
rustc-std-workspace-core
rustc-std-workspace-std
std Auto merge of #113001 - ChrisDenton:win-arm32-shim, r=thomcc 2023-06-25 11:27:19 +00:00
stdarch@d77878b729 Bump stdarch 2023-06-13 21:45:04 -07:00
sysroot Expose compiler-builtins-weak-intrinsics feature for -Zbuild-std 2023-06-23 11:15:34 +01:00
test ignore core, alloc and test tests that require unwinding on panic=abort 2023-06-13 15:53:24 +02:00
unwind wip: Support Apple tvOS in libstd 2023-06-21 14:59:37 -07:00