rust/library/alloc
Yuki Okushi 77c985f765
Rollup merge of #90607 - WaffleLapkin:const_str_from_utf8, r=oli-obk
Make slice->str conversion and related functions `const`

This PR marks the following APIs as `const`:
```rust
// core::str
pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>;
pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error>;
pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str;

impl Utf8Error {
    pub const fn valid_up_to(&self) -> usize;
    pub const fn error_len(&self) -> Option<usize>;
}
```

Everything but `from_utf8_unchecked_mut` uses `const_str_from_utf8` feature gate, `from_utf8_unchecked_mut` uses `const_str_from_utf8_unchecked_mut` feature gate.

---

I'm not sure why `from_utf8_unchecked_mut` was left out being  non-`const`, considering that `from_utf8_unchecked` is not only `const`, but **`const` stable**.

---

r? ```@oli-obk``` (performance-only `const_eval_select` use)
2021-11-19 02:22:57 +09:00
..
benches Add #[must_use] to remaining alloc functions 2021-10-15 11:46:49 -04:00
src Rollup merge of #90480 - r00ster91:remove, r=kennytm 2021-11-19 02:22:56 +09:00
tests Make slice->str conversion and related functions const 2021-11-18 00:50:42 +03:00
Cargo.toml rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00