about summary refs log tree commit diff
path: root/library/std/src/sys/unix/stack_overflow.rs
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-04-11 20:00:44 +0200
committerGitHub <noreply@github.com>2022-04-11 20:00:44 +0200
commitae6f75a0c35ae7067015828a6408ccba871ab763 (patch)
treedd4c5154ad84cfcc65b350c06ac634af1827f2fe /library/std/src/sys/unix/stack_overflow.rs
parent82a6463b1cc005b7f14b15288dcc6ede965ec5c0 (diff)
parentb92cd1a32c842e82575e59374545dda5f9b9f77a (diff)
downloadrust-ae6f75a0c35ae7067015828a6408ccba871ab763.tar.gz
rust-ae6f75a0c35ae7067015828a6408ccba871ab763.zip
Rollup merge of #95895 - CAD97:patch-2, r=Dylan-DPC
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.

Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/str.3A.3Afrom_utf8_unchecked.20Safety.20requirement
Diffstat (limited to 'library/std/src/sys/unix/stack_overflow.rs')
0 files changed, 0 insertions, 0 deletions