Skip to content

Commit f337e28

Browse files
authored
Rollup merge of #147773 - timvisee:docs-empty-is-ascii, r=Noratrieb
`is_ascii` on an empty string or slice returns true Update the description of the [`is_ascii`](https://doc.rust-lang.org/std/primitive.str.html#method.is_ascii) functions - an empty string or slice also returns `true`. This follows the pattern of [`all()`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.all). Clippy currently suggests to change `string.chars().all(|c| c.is_ascii())` into `string.is_ascii()`. This suggestion therefore seems fitting. I've already questioned the behavior for this multiple times. I've always had to check the internals to conclude how it works. That's why I'm opening this PR to add it directly in the documentation.
2 parents 3a993f7 + 7a11c72 commit f337e28

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

library/core/src/slice/ascii.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use crate::{ascii, iter, ops};
99

1010
impl [u8] {
1111
/// Checks if all bytes in this slice are within the ASCII range.
12+
///
13+
/// An empty slice returns `true`.
1214
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
1315
#[rustc_const_stable(feature = "const_slice_is_ascii", since = "1.74.0")]
1416
#[must_use]

library/core/src/str/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,8 @@ impl str {
27042704

27052705
/// Checks if all characters in this string are within the ASCII range.
27062706
///
2707+
/// An empty string returns `true`.
2708+
///
27072709
/// # Examples
27082710
///
27092711
/// ```

library/std/src/ffi/os_str.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,8 @@ impl OsStr {
12151215

12161216
/// Checks if all characters in this string are within the ASCII range.
12171217
///
1218+
/// An empty string returns `true`.
1219+
///
12181220
/// # Examples
12191221
///
12201222
/// ```

0 commit comments

Comments
 (0)