diff options
| author | sam skeoch <djscythe@noreply.codeberg.org> | 2025-05-13 14:55:03 +0100 |
|---|---|---|
| committer | sam skeoch <djscythe@noreply.codeberg.org> | 2025-05-16 13:54:02 +0100 |
| commit | 101e24a223f818e17d2c68298d48d4e6008c02aa (patch) | |
| tree | aa544b24f193f39f97b4f610a0487740b620bc55 /library/core/src/char | |
| parent | 7d9f437f993e213c1f9aeb9c07454f6fd1648821 (diff) | |
Add assert_unsafe_precondition!()s to as_ascii_unchecked() methods
Diffstat (limited to 'library/core/src/char')
| -rw-r--r-- | library/core/src/char/methods.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 3c25ab4fdd7..af2edf141b2 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -4,6 +4,7 @@ use super::*; use crate::panic::const_panic; use crate::slice; use crate::str::from_utf8_unchecked_mut; +use crate::ub_checks::assert_unsafe_precondition; use crate::unicode::printable::is_printable; use crate::unicode::{self, conversions}; @@ -1212,6 +1213,12 @@ impl char { #[unstable(feature = "ascii_char", issue = "110998")] #[inline] pub const unsafe fn as_ascii_unchecked(&self) -> ascii::Char { + assert_unsafe_precondition!( + check_library_ub, + "as_ascii_unchecked requires that the char is valid ASCII", + (it: &char = self) => it.is_ascii() + ); + // SAFETY: the caller promised that this char is ASCII. unsafe { ascii::Char::from_u8_unchecked(*self as u8) } } |
