From 7a11c72db032257b709707f08d008e20dae7e8e9 Mon Sep 17 00:00:00 2001 From: timvisee Date: Thu, 16 Oct 2025 10:52:51 +0200 Subject: [PATCH] is_ascii on an empty string or slice returns true --- library/core/src/slice/ascii.rs | 2 ++ library/core/src/str/mod.rs | 2 ++ library/std/src/ffi/os_str.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index e17a2e03d2dc4..42916558b5fc4 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -9,6 +9,8 @@ use crate::{ascii, iter, ops}; impl [u8] { /// Checks if all bytes in this slice are within the ASCII range. + /// + /// An empty slice returns `true`. #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[rustc_const_stable(feature = "const_slice_is_ascii", since = "1.74.0")] #[must_use] diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 3a5efa7d83511..82019b9b3afe5 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -2704,6 +2704,8 @@ impl str { /// Checks if all characters in this string are within the ASCII range. /// + /// An empty string returns `true`. + /// /// # Examples /// /// ``` diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 6c098034eea3b..09bd911aa769a 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1215,6 +1215,8 @@ impl OsStr { /// Checks if all characters in this string are within the ASCII range. /// + /// An empty string returns `true`. + /// /// # Examples /// /// ```