@@ -358,6 +358,38 @@ use crate::vec::{self, Vec};
358
358
/// called on a `String` may assume that it is valid UTF-8, which means that a non-UTF-8 `String`
359
359
/// can lead to undefined behavior down the road.
360
360
///
361
+ /// As an exception, some functions explicitly allow invalid UTF-8, and will not immediately cause undefined
362
+ /// behavior if called on a `String` containing invalid UTF-8. In general, all of `String`'s associated
363
+ /// functions other than those listed here should be assumed to require their input be valid UTF-8.
364
+ /// Note that calling one of these functions on a `String` containing invalid UTF-8, may result in the return value
365
+ /// also containing invalid UTF-8, if relevant.
366
+ ///
367
+ /// * `String::as_bytes`
368
+ /// * `String::as_bytes_mut`
369
+ /// * `String::as_str`
370
+ /// * `String::as_mut_str`
371
+ /// * `String::as_ptr`
372
+ /// * `String::as_mut_ptr`
373
+ /// * `String::as_mut_vec`
374
+ /// * `String::capacity`
375
+ /// * `String::len`
376
+ /// * `String::clear`
377
+ /// * `<String as Drop>::drop` (i.e. dropping a `String` that contains invalid UTF-8 does not alone cause UB)
378
+ /// * `String::leak`
379
+ /// * `String::into_boxed_str`
380
+ /// * `String::reserve`
381
+ /// * `String::reserve_exact`
382
+ /// * `String::try_reserve`
383
+ /// * `String::try_reserve_exact`
384
+ /// * `<String as Deref>::deref`
385
+ /// * `<String as DerefMut>::deref_mut`
386
+ /// * `<String as AsRef<str>>::as_ref`
387
+ /// * `<String as AsMut<str>>::as_mut`
388
+ /// * `<String as Borrow<str>>::borrow`
389
+ /// * `<String as BorrowMut<str>>::borrow_mut`
390
+ /// * `<String as Clone>::clone`
391
+ /// * `<String as Clone>::clone_from`
392
+ ///
361
393
/// [str]: prim@str "str"
362
394
/// [`str`]: prim@str "str"
363
395
/// [`&str`]: prim@str "&str"
0 commit comments