diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-08-22 08:17:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-22 08:17:20 +0200 |
| commit | e7df7ba1e4094b53a00f11bc24e4344dc968e12a (patch) | |
| tree | 85e7ac4b32ca11ad3c94e7d20c4e6a95b731e9a8 | |
| parent | 8f2c4d18e1491bfd50cfa4d7fe02ccb42216e064 (diff) | |
| parent | 191862d701b10f7a060d732aa6fe60c6520ae5a7 (diff) | |
| download | rust-e7df7ba1e4094b53a00f11bc24e4344dc968e12a.tar.gz rust-e7df7ba1e4094b53a00f11bc24e4344dc968e12a.zip | |
Rollup merge of #129374 - ChaiTRex:digit_unchecked_assert_unsafe_precondition, r=scottmcm
Use `assert_unsafe_precondition!` in `AsciiChar::digit_unchecked`
| -rw-r--r-- | library/core/src/ascii/ascii_char.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/library/core/src/ascii/ascii_char.rs b/library/core/src/ascii/ascii_char.rs index 375358dddf5..ce09a0b444d 100644 --- a/library/core/src/ascii/ascii_char.rs +++ b/library/core/src/ascii/ascii_char.rs @@ -3,8 +3,8 @@ //! suggestions from rustc if you get anything slightly wrong in here, and overall //! helps with clarity as we're also referring to `char` intentionally in here. -use crate::fmt; use crate::mem::transmute; +use crate::{assert_unsafe_precondition, fmt}; /// One of the 128 Unicode characters from U+0000 through U+007F, /// often known as the [ASCII] subset. @@ -497,14 +497,18 @@ impl AsciiChar { /// Notably, it should not be expected to return hex digits, or any other /// reasonable extension of the decimal digits. /// - /// (This lose safety condition is intended to simplify soundness proofs + /// (This loose safety condition is intended to simplify soundness proofs /// when writing code using this method, since the implementation doesn't /// need something really specific, not to make those other arguments do /// something useful. It might be tightened before stabilization.) #[unstable(feature = "ascii_char", issue = "110998")] #[inline] pub const unsafe fn digit_unchecked(d: u8) -> Self { - debug_assert!(d < 10); + assert_unsafe_precondition!( + check_language_ub, + "`AsciiChar::digit_unchecked` input cannot exceed 9.", + (d: u8 = d) => d < 10 + ); // SAFETY: `'0'` through `'9'` are U+00030 through U+0039, // so because `d` must be 64 or less the addition can return at most |
