Commit Graph

16 Commits

Author SHA1 Message Date
Urgau
7f99c7d3e6 Add invalid_from_utf8 analogous to invalid_from_utf8_unchecked 2023-05-27 00:18:28 +02:00
Urgau
7f8846a9ef Uplift clippy::invalid_utf8_in_unchecked as invalid_from_utf8_unchecked 2023-05-27 00:16:47 +02:00
ismailmaj
005c6dfde6 type annotate &str when stack allocating a string 2022-11-21 10:38:04 +01:00
Maybe Waffle
89295352ee Allow some internal instability 2022-05-26 13:00:14 +04:00
Maybe Waffle
138aa99503 Stabilize checked slice->str conversion functions 2022-05-24 22:58:28 +04:00
Christopher Durham
b92cd1a32c Clarify str::from_utf8_unchecked's invariants
Specifically, make it clear that it is immediately UB to pass ill-formed UTF-8 into the function. The previous wording left space to interpret that the UB only occurred when calling another function, which "assumes that `&str`s are valid UTF-8."

This does not change whether str being UTF-8 is a safety or a validity invariant. (As per previous discussion, it is a safety invariant, not a validity invariant.) It just makes it clear that valid UTF-8 is a precondition of str::from_utf8_unchecked, and that emitting an Abstract Machine fault (e.g. UB or a sanitizer error) on invalid UTF-8 is a valid thing to do.

If user code wants to create an unsafe `&str` pointing to ill-formed UTF-8, it must be done via transmutes. Also, just, don't.
2022-04-10 15:04:57 -05:00
Maybe Waffle
573a00e3f9 Fill in tracking issues for const_str_from_utf8 and const_str_from_utf8_unchecked_mut features 2021-11-18 14:04:01 +03:00
Maybe Waffle
cf6f64a963 Make slice->str conversion and related functions const
This commit makes the following functions from `core::str` `const fn`:
- `from_utf8[_mut]` (`feature(const_str_from_utf8)`)
- `from_utf8_unchecked_mut` (`feature(const_str_from_utf8_unchecked_mut)`)
- `Utf8Error::{valid_up_to,error_len}` (`feature(const_str_from_utf8)`)
2021-11-18 00:50:42 +03:00
John Kugelman
cf2bcd10ed Add #[must_use] to from_value conversions 2021-10-10 19:00:33 -04:00
Mark Rousskov
b4e7649d6d Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
Jacob Pratt
36f02f3523 Stabilize const_fn_transmute 2021-07-27 16:03:09 -04:00
Jacob Pratt
fe7487a79e Stabilize str::from_utf8_unchecked as const 2021-06-11 01:55:47 -04:00
Joshua Nelson
9a75f4fed1 Convert primitives to use intra-doc links 2021-02-25 20:31:53 -05:00
Jake Goulding
dcef5ff372 Bump bootstrap compiler version 2020-11-19 19:23:36 -05:00
Florian Warzecha
05f4a9a42a switch allow_internal_unstable const fns to rustc_allow_const_fn_unstable 2020-10-21 20:54:20 +02:00
Lzu Tao
653b5bf18c Move functions converting bytes to str to new mod 2020-09-26 05:20:53 +00:00