The note of type.str.value uses the term "undefined behavior" for what is usually denoted as "library undefined behavior" (which is by the way not a concept in the reference):
|
r[type.str.value] |
|
A value of type `str` is represented in the same way as `[u8]`, a slice of 8-bit unsigned bytes. |
|
|
|
> [!NOTE] |
|
> The standard library makes extra assumptions about `str`: methods working on `str` assume and ensure that the data it contains is valid UTF-8. Calling a `str` method with a non-UTF-8 buffer can cause [undefined behavior] now or in the future. |
I believe this is confusing. The term "undefined behavior" in the reference should only be used for what is usually denoted as "language undefined behavior" since the reference is about the language. It is explicitly said in the introduction (under "what the reference is not") that the standard library is not documented by the reference:
|
This book also does not serve as a reference to the [standard library] included in the language distribution. |
|
Those libraries are documented separately by extracting documentation attributes from their source code. |
|
Many of the features that one might expect to be language features are library features in Rust, so what you're looking for may be there, not here. |
Unless there is already a plan to talk about library UB in the reference (which I guess would be restricted to notes), I believe it would be preferable to avoid the terminology "undefined behavior" for library UB, and use a more evasive terminology, like "calling a str method with a non-UTF-8 buffer violates assumptions and invariants of the standard library and could result in unexpected behaviors down the line".
The note of
type.str.valueuses the term "undefined behavior" for what is usually denoted as "library undefined behavior" (which is by the way not a concept in the reference):reference/src/types/str.md
Lines 15 to 19 in cf0e391
I believe this is confusing. The term "undefined behavior" in the reference should only be used for what is usually denoted as "language undefined behavior" since the reference is about the language. It is explicitly said in the introduction (under "what the reference is not") that the standard library is not documented by the reference:
reference/src/introduction.md
Lines 24 to 26 in cf0e391
Unless there is already a plan to talk about library UB in the reference (which I guess would be restricted to notes), I believe it would be preferable to avoid the terminology "undefined behavior" for library UB, and use a more evasive terminology, like "calling a
strmethod with a non-UTF-8 buffer violates assumptions and invariants of the standard library and could result in unexpected behaviors down the line".