mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
|
||||
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]
|
||||
|
||||
@@ -2704,6 +2704,8 @@ pub fn parse<F: FromStr>(&self) -> Result<F, F::Err> {
|
||||
|
||||
/// Checks if all characters in this string are within the ASCII range.
|
||||
///
|
||||
/// An empty string returns `true`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
|
||||
@@ -1215,6 +1215,8 @@ pub fn to_ascii_uppercase(&self) -> OsString {
|
||||
|
||||
/// Checks if all characters in this string are within the ASCII range.
|
||||
///
|
||||
/// An empty string returns `true`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
|
||||
Reference in New Issue
Block a user