From 045ce56a92ebf485cae7609f804368b196ea15b0 Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Tue, 17 Sep 2024 17:08:48 -0500 Subject: [PATCH] Make our clippy lints much more stringent. --- CHANGELOG | 10 +- lexical-core/src/lib.rs | 31 +- lexical-parse-float/etc/limits.py | 2 + lexical-parse-float/src/api.rs | 2 +- lexical-parse-float/src/bellerophon.rs | 16 +- lexical-parse-float/src/bigint.rs | 118 ++++-- lexical-parse-float/src/binary.rs | 13 +- lexical-parse-float/src/float.rs | 5 + lexical-parse-float/src/fpu.rs | 3 +- lexical-parse-float/src/lemire.rs | 17 +- lexical-parse-float/src/lib.rs | 27 ++ lexical-parse-float/src/limits.rs | 28 +- lexical-parse-float/src/mask.rs | 11 +- lexical-parse-float/src/number.rs | 41 +- lexical-parse-float/src/options.rs | 165 ++++---- lexical-parse-float/src/parse.rs | 52 ++- lexical-parse-float/src/shared.rs | 7 +- lexical-parse-float/src/slow.rs | 34 +- lexical-parse-float/src/table_decimal.rs | 17 +- lexical-parse-float/src/table_lemire.rs | 1 + lexical-parse-float/src/table_radix.rs | 2 +- lexical-parse-float/tests/stackvec_tests.rs | 12 +- lexical-parse-integer/src/api.rs | 2 +- lexical-parse-integer/src/lib.rs | 27 ++ lexical-parse-integer/src/options.rs | 5 +- lexical-util/src/api.rs | 8 +- lexical-util/src/div128.rs | 12 +- lexical-util/src/feature_format.rs | 292 +++++++------- lexical-util/src/format.rs | 414 ++++++++++---------- lexical-util/src/format_builder.rs | 6 +- lexical-util/src/format_flags.rs | 99 ++--- lexical-util/src/iterator.rs | 28 +- lexical-util/src/lib.rs | 27 ++ lexical-util/src/noskip.rs | 14 +- lexical-util/src/num.rs | 66 ++-- lexical-util/src/skip.rs | 12 +- lexical-util/src/step.rs | 4 +- lexical-write-float/src/algorithm.rs | 21 +- lexical-write-float/src/binary.rs | 4 +- lexical-write-float/src/compact.rs | 4 +- lexical-write-float/src/hex.rs | 7 +- lexical-write-float/src/lib.rs | 24 ++ lexical-write-float/src/options.rs | 166 ++++---- lexical-write-float/src/radix.rs | 17 +- lexical-write-float/src/shared.rs | 8 +- lexical-write-float/src/write.rs | 3 - lexical-write-integer/src/algorithm.rs | 22 +- lexical-write-integer/src/api.rs | 4 +- lexical-write-integer/src/decimal.rs | 2 +- lexical-write-integer/src/lib.rs | 54 ++- lexical-write-integer/src/options.rs | 8 +- lexical/src/lib.rs | 31 +- 52 files changed, 1181 insertions(+), 824 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 78b53391..0201481a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,11 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [1.0.0] 2024-09-16 +### Fixed -### Changed +- Inlining inconsistency between public API methods (credit to @zheland) + +## [1.0.1] 2024-09-16 + +### Fixed -- Fixes a correctness regression +- A correctness regression. ## [1.0.0] 2024-09-14 diff --git a/lexical-core/src/lib.rs b/lexical-core/src/lib.rs index a7f9c7fc..9dee2357 100644 --- a/lexical-core/src/lib.rs +++ b/lexical-core/src/lib.rs @@ -1,4 +1,4 @@ -//! Fast lexical conversion routines for a no_std environment. +//! Fast lexical conversion routines for a `no_std` environment. //! //! lexical-core is a low-level API for number-to-string and //! string-to-number conversions, without requiring a system @@ -219,8 +219,9 @@ //! //! Many pre-defined constants therefore exist to simplify common use-cases, //! including: -//! - JSON, XML, TOML, YAML, SQLite, and many more. -//! - Rust, Python, C#, FORTRAN, COBOL literals and strings, and many more. +//! - `JSON`, `XML`, `TOML`, `YAML`, `SQLite`, and many more. +//! - `Rust`, `Python`, `C#`, `FORTRAN`, `COBOL` literals and strings, and many +//! more. //! //! ## Options API //! @@ -339,6 +340,30 @@ #![allow(unused_unsafe)] #![cfg_attr(feature = "lint", warn(unsafe_op_in_unsafe_fn))] #![cfg_attr(not(feature = "std"), no_std)] +#![deny( + clippy::doc_markdown, + clippy::unnecessary_safety_comment, + clippy::semicolon_if_nothing_returned, + clippy::unwrap_used, + clippy::as_underscore, + clippy::doc_markdown +)] +#![allow( + // used when concepts are logically separate + clippy::match_same_arms, + // loss of precision is intentional + clippy::integer_division, + // mathematical names use 1-character identifiers + clippy::min_ident_chars, + // these are not cryptographically secure contexts + clippy::integer_division_remainder_used, + // this can be intentional + clippy::module_name_repetitions, + // this is intentional: already passing a pointer and need performance + clippy::needless_pass_by_value, + // we use this for inline formatting for unsafe blocks + clippy::semicolon_inside_block, +)] // Re-exports #[cfg(feature = "parse-floats")] diff --git a/lexical-parse-float/etc/limits.py b/lexical-parse-float/etc/limits.py index cd4cfb75..248fa151 100644 --- a/lexical-parse-float/etc/limits.py +++ b/lexical-parse-float/etc/limits.py @@ -87,6 +87,7 @@ def all_limits(mantissa_size, exponent_size, type_name): max_exp = 2**(exponent_size - 1) - 1 print('/// Get the exponent limit as a const fn.') + print('#[must_use]') print('#[inline(always)]') print(f'pub const fn {type_name}_exponent_limit(radix: u32) -> (i64, i64) {{') print(' match radix {') @@ -99,6 +100,7 @@ def all_limits(mantissa_size, exponent_size, type_name): print('') print('/// Get the mantissa limit as a const fn.') + print('#[must_use]') print('#[inline(always)]') print(f'pub const fn {type_name}_mantissa_limit(radix: u32) -> i64 {{') print(' match radix {') diff --git a/lexical-parse-float/src/api.rs b/lexical-parse-float/src/api.rs index a282768d..dbffa7d4 100644 --- a/lexical-parse-float/src/api.rs +++ b/lexical-parse-float/src/api.rs @@ -17,7 +17,7 @@ use crate::parse::ParseFloat; const DEFAULT_OPTIONS: Options = Options::new(); -/// Implement FromLexical for numeric type. +/// Implement `FromLexical` for numeric type. /// /// Need to inline these, otherwise codegen is suboptimal. /// For some reason, it can't determine some of the const evaluations diff --git a/lexical-parse-float/src/bellerophon.rs b/lexical-parse-float/src/bellerophon.rs index 35a26be2..812c4a3e 100644 --- a/lexical-parse-float/src/bellerophon.rs +++ b/lexical-parse-float/src/bellerophon.rs @@ -39,8 +39,14 @@ use crate::table::bellerophon_powers; /// This has been modified to return a biased, rather than unbiased exponent. pub fn bellerophon(num: &Number, lossy: bool) -> ExtendedFloat80 { let format = NumberFormat::<{ FORMAT }> {}; - debug_assert!(!matches!(format.radix(), 2 | 4 | 8 | 16 | 32)); - debug_assert!(format.mantissa_radix() == format.exponent_base()); + debug_assert!( + !matches!(format.radix(), 2 | 4 | 8 | 16 | 32), + "performance slow for non-pow2 cases" + ); + debug_assert!( + format.mantissa_radix() == format.exponent_base(), + "only works if digits and exponent have same base" + ); let fp_zero = ExtendedFloat80 { mant: 0, @@ -181,7 +187,7 @@ const fn error_halfscale() -> u32 { #[cfg_attr(not(feature = "compact"), inline(always))] fn error_is_accurate(errors: u32, fp: &ExtendedFloat80) -> bool { // Check we can't have a literal 0 denormal float. - debug_assert!(fp.exp >= -64); + debug_assert!(fp.exp >= -64, "cannot have a literal 0 float"); // Determine if extended-precision float is a good approximation. // If the error has affected too many units, the float will be @@ -323,8 +329,8 @@ pub fn normalize(fp: &mut ExtendedFloat80) -> i32 { #[cfg_attr(not(feature = "compact"), inline(always))] pub fn mul(x: &ExtendedFloat80, y: &ExtendedFloat80) -> ExtendedFloat80 { // Logic check, values must be decently normalized prior to multiplication. - debug_assert!(x.mant >> 32 != 0); - debug_assert!(y.mant >> 32 != 0); + debug_assert!(x.mant >> 32 != 0, "cannot have a literal 0 float"); + debug_assert!(y.mant >> 32 != 0, "cannot have a literal 0 float"); // Extract high-and-low masks. const LOMASK: u64 = u32::MAX as u64; diff --git a/lexical-parse-float/src/bigint.rs b/lexical-parse-float/src/bigint.rs index 0738f0a0..d6f59e44 100644 --- a/lexical-parse-float/src/bigint.rs +++ b/lexical-parse-float/src/bigint.rs @@ -246,7 +246,8 @@ impl Bigfloat { #[cfg(feature = "radix")] impl ops::MulAssign<&Bigfloat> for Bigfloat { #[inline(always)] - #[allow(clippy::suspicious_op_assign_impl)] + #[allow(clippy::suspicious_op_assign_impl)] // reason="intended increment" + #[allow(clippy::unwrap_used)] // reason="exceeding the bounds is a developper error" fn mul_assign(&mut self, rhs: &Bigfloat) { large_mul(&mut self.data, &rhs.data).unwrap(); self.exp += rhs.exp; @@ -268,7 +269,8 @@ impl Default for Bigfloat { pub struct StackVec { /// The raw buffer for the elements. data: [mem::MaybeUninit; SIZE], - /// The number of elements in the array (we never need more than u16::MAX). + /// The number of elements in the array (we never need more than + /// `u16::MAX`). length: u16, } @@ -322,6 +324,7 @@ macro_rules! hi { impl StackVec { /// Construct an empty vector. + #[must_use] #[inline(always)] pub const fn new() -> Self { Self { @@ -331,18 +334,21 @@ impl StackVec { } /// Get a mutable ptr to the current start of the big integer. + #[must_use] #[inline(always)] pub fn as_mut_ptr(&mut self) -> *mut Limb { self.data.as_mut_ptr().cast::() } /// Get a ptr to the current start of the big integer. + #[must_use] #[inline(always)] pub fn as_ptr(&self) -> *const Limb { self.data.as_ptr().cast::() } /// Construct a vector from an existing slice. + #[must_use] #[inline(always)] pub fn try_from(x: &[Limb]) -> Option { let mut vec = Self::new(); @@ -361,24 +367,27 @@ impl StackVec { /// Safe as long as `len` is less than `SIZE`. #[inline(always)] pub unsafe fn set_len(&mut self, len: usize) { - debug_assert!(len <= u16::MAX as usize); - debug_assert!(len <= SIZE); + debug_assert!(len <= u16::MAX as usize, "indexing must fit in 16 bits"); + debug_assert!(len <= SIZE, "cannot exceed our array bounds"); self.length = len as u16; } /// Get the number of elements stored in the vector. + #[must_use] #[inline(always)] pub const fn len(&self) -> usize { self.length as usize } /// If the vector is empty. + #[must_use] #[inline(always)] pub const fn is_empty(&self) -> bool { self.len() == 0 } /// The number of items the vector can hold. + #[must_use] #[inline(always)] pub const fn capacity(&self) -> usize { SIZE @@ -391,7 +400,7 @@ impl StackVec { /// Safe if `self.len() < self.capacity()`. #[inline(always)] unsafe fn push_unchecked(&mut self, value: Limb) { - debug_assert!(self.len() < self.capacity()); + debug_assert!(self.len() < self.capacity(), "cannot exceed our array bounds"); // SAFETY: safe, capacity is less than the current size. unsafe { let len = self.len(); @@ -420,10 +429,10 @@ impl StackVec { /// Safe if `self.len() > 0`. #[inline(always)] unsafe fn pop_unchecked(&mut self) -> Limb { - debug_assert!(!self.is_empty()); + debug_assert!(!self.is_empty(), "cannot pop a value if none exists"); + self.length -= 1; // SAFETY: safe if `self.length > 0`. // We have a trivial drop and copy, so this is safe. - self.length -= 1; unsafe { ptr::read(self.as_mut_ptr().add(self.len())) } } @@ -448,7 +457,7 @@ impl StackVec { unsafe fn extend_unchecked(&mut self, slc: &[Limb]) { let index = self.len(); let new_len = index + slc.len(); - debug_assert!(self.len() + slc.len() <= self.capacity()); + debug_assert!(self.len() + slc.len() <= self.capacity(), "cannot exceed our array bounds"); let src = slc.as_ptr(); // SAFETY: safe if `self.len() + slc.len() <= self.capacity()`. unsafe { @@ -476,7 +485,7 @@ impl StackVec { /// /// Safe as long as `len <= self.capacity()`. unsafe fn truncate_unchecked(&mut self, len: usize) { - debug_assert!(len <= self.capacity()); + debug_assert!(len <= self.capacity(), "cannot exceed our array bounds"); self.length = len as u16; } @@ -487,16 +496,16 @@ impl StackVec { /// Safe as long as `len <= self.capacity()`. #[inline(always)] pub unsafe fn resize_unchecked(&mut self, len: usize, value: Limb) { - debug_assert!(len <= self.capacity()); + debug_assert!(len <= self.capacity(), "cannot exceed our array bounds"); let old_len = self.len(); if len > old_len { // We have a trivial drop, so there's no worry here. // Just, don't set the length until all values have been written, // so we don't accidentally read uninitialized memory. - // SAFETY: safe if `len < self.capacity()`. let count = len - old_len; for index in 0..count { + // SAFETY: safe if `len < self.capacity()`. unsafe { let dst = self.as_mut_ptr().add(old_len + index); ptr::write(dst, value); @@ -581,33 +590,36 @@ impl StackVec { // FROM - /// Create StackVec from u16 value. + /// Create `StackVec` from u16 value. + #[must_use] #[inline(always)] pub fn from_u16(x: u16) -> Self { let mut vec = Self::new(); - assert!(1 <= vec.capacity()); + assert!(1 <= vec.capacity(), "cannot exceed our array bounds"); _ = vec.try_push(x as Limb); vec.normalize(); vec } - /// Create StackVec from u32 value. + /// Create `StackVec` from u32 value. + #[must_use] #[inline(always)] pub fn from_u32(x: u32) -> Self { let mut vec = Self::new(); - debug_assert!(1 <= vec.capacity()); - assert!(1 <= SIZE); + debug_assert!(1 <= vec.capacity(), "cannot exceed our array bounds"); + assert!(1 <= SIZE, "cannot exceed our array bounds"); _ = vec.try_push(x as Limb); vec.normalize(); vec } - /// Create StackVec from u64 value. + /// Create `StackVec` from u64 value. + #[must_use] #[inline(always)] pub fn from_u64(x: u64) -> Self { let mut vec = Self::new(); - debug_assert!(2 <= vec.capacity()); - assert!(2 <= SIZE); + debug_assert!(2 <= vec.capacity(), "cannot exceed our array bounds"); + assert!(2 <= SIZE, "cannot exceed our array bounds"); if LIMB_BITS == 32 { _ = vec.try_push(x as Limb); _ = vec.try_push((x >> 32) as Limb); @@ -621,6 +633,7 @@ impl StackVec { // INDEX /// Create a reverse view of the vector for indexing. + #[must_use] #[inline(always)] pub fn rview(&self) -> ReverseView { ReverseView { @@ -644,14 +657,11 @@ impl StackVec { } /// Get if the big integer is normalized. + #[must_use] #[inline(always)] - #[allow(clippy::match_like_matches_macro)] pub fn is_normalized(&self) -> bool { // We don't care if this wraps: the index is bounds-checked. - match self.get(self.len().wrapping_sub(1)) { - Some(&0) => false, - _ => true, - } + self.get(self.len().wrapping_sub(1)) != Some(&0) } /// Calculate the fast quotient for a single limb-bit quotient. @@ -668,13 +678,13 @@ impl StackVec { large_quorem(self, y) } - /// AddAssign small integer. + /// `AddAssign` small integer. #[inline(always)] pub fn add_small(&mut self, y: Limb) -> Option<()> { small_add(self, y) } - /// MulAssign small integer. + /// `MulAssign` small integer. #[inline(always)] pub fn mul_small(&mut self, y: Limb) -> Option<()> { small_mul(self, y) @@ -683,7 +693,7 @@ impl StackVec { impl PartialEq for StackVec { #[inline(always)] - #[allow(clippy::op_ref)] + #[allow(clippy::op_ref)] // reason="need to convert to slice for equality" fn eq(&self, other: &Self) -> bool { use core::ops::Deref; self.len() == other.len() && self.deref() == other.deref() @@ -711,7 +721,7 @@ impl ops::Deref for StackVec { type Target = [Limb]; #[inline(always)] fn deref(&self) -> &[Limb] { - debug_assert!(self.len() <= self.capacity()); + debug_assert!(self.len() <= self.capacity(), "cannot exceed our array bounds"); // SAFETY: safe since `self.data[..self.len()]` must be initialized // and `self.len() <= self.capacity()`. unsafe { @@ -724,7 +734,7 @@ impl ops::Deref for StackVec { impl ops::DerefMut for StackVec { #[inline(always)] fn deref_mut(&mut self) -> &mut [Limb] { - debug_assert!(self.len() <= self.capacity()); + debug_assert!(self.len() <= self.capacity(), "cannot exceed our array bounds"); // SAFETY: safe since `self.data[..self.len()]` must be initialized // and `self.len() <= self.capacity()`. unsafe { @@ -736,6 +746,7 @@ impl ops::DerefMut for StackVec { impl ops::MulAssign<&[Limb]> for StackVec { #[inline(always)] + #[allow(clippy::unwrap_used)] // reason="exceeding the bounds is a developper error" fn mul_assign(&mut self, rhs: &[Limb]) { large_mul(self, rhs).unwrap(); } @@ -763,7 +774,7 @@ impl<'a, T: 'a> ReverseView<'a, T> { /// or `index < self.inner.len()`. #[inline(always)] pub unsafe fn get_unchecked(&self, index: usize) -> &T { - debug_assert!(index < self.inner.len()); + debug_assert!(index < self.inner.len(), "cannot exceed our array bounds"); let len = self.inner.len(); // SAFETY: Safe as long as the index < length, so len - index - 1 >= 0 and <= // len. @@ -811,9 +822,10 @@ impl<'a, T> ops::Index for ReverseView<'a, T> { /// Safe as long as `rindex <= x.len()`. This is only called /// where the type size is directly from the caller, and removing /// it leads to a ~20% degradation in performance. +#[must_use] #[inline(always)] pub unsafe fn nonzero(x: &[Limb], rindex: usize) -> bool { - debug_assert!(rindex <= x.len()); + debug_assert!(rindex <= x.len(), "cannot exceed our array bounds"); let len = x.len(); // SAFETY: safe if `rindex < x.len()`, since then `x.len() - rindex < x.len()`. let slc = unsafe { &index_unchecked!(x[..len - rindex]) }; @@ -823,6 +835,7 @@ pub unsafe fn nonzero(x: &[Limb], rindex: usize) -> bool { // These return the high X bits and if the bits were truncated. /// Shift 32-bit integer to high 16-bits. +#[must_use] #[inline(always)] pub const fn u32_to_hi16_1(r0: u32) -> (u16, bool) { let r0 = u32_to_hi32_1(r0).0; @@ -830,6 +843,7 @@ pub const fn u32_to_hi16_1(r0: u32) -> (u16, bool) { } /// Shift 2 32-bit integers to high 16-bits. +#[must_use] #[inline(always)] pub const fn u32_to_hi16_2(r0: u32, r1: u32) -> (u16, bool) { let (r0, n) = u32_to_hi32_2(r0, r1); @@ -837,6 +851,7 @@ pub const fn u32_to_hi16_2(r0: u32, r1: u32) -> (u16, bool) { } /// Shift 32-bit integer to high 32-bits. +#[must_use] #[inline(always)] pub const fn u32_to_hi32_1(r0: u32) -> (u32, bool) { let ls = r0.leading_zeros(); @@ -844,6 +859,7 @@ pub const fn u32_to_hi32_1(r0: u32) -> (u32, bool) { } /// Shift 2 32-bit integers to high 32-bits. +#[must_use] #[inline(always)] pub const fn u32_to_hi32_2(r0: u32, r1: u32) -> (u32, bool) { let ls = r0.leading_zeros(); @@ -857,12 +873,14 @@ pub const fn u32_to_hi32_2(r0: u32, r1: u32) -> (u32, bool) { } /// Shift 32-bit integer to high 64-bits. +#[must_use] #[inline(always)] pub const fn u32_to_hi64_1(r0: u32) -> (u64, bool) { u64_to_hi64_1(r0 as u64) } /// Shift 2 32-bit integers to high 64-bits. +#[must_use] #[inline(always)] pub const fn u32_to_hi64_2(r0: u32, r1: u32) -> (u64, bool) { let r0 = (r0 as u64) << 32; @@ -871,6 +889,7 @@ pub const fn u32_to_hi64_2(r0: u32, r1: u32) -> (u64, bool) { } /// Shift 3 32-bit integers to high 64-bits. +#[must_use] #[inline(always)] pub const fn u32_to_hi64_3(r0: u32, r1: u32, r2: u32) -> (u64, bool) { let r0 = r0 as u64; @@ -880,6 +899,7 @@ pub const fn u32_to_hi64_3(r0: u32, r1: u32, r2: u32) -> (u64, bool) { } /// Shift 64-bit integer to high 16-bits. +#[must_use] #[inline(always)] pub const fn u64_to_hi16_1(r0: u64) -> (u16, bool) { let r0 = u64_to_hi64_1(r0).0; @@ -887,6 +907,7 @@ pub const fn u64_to_hi16_1(r0: u64) -> (u16, bool) { } /// Shift 2 64-bit integers to high 16-bits. +#[must_use] #[inline(always)] pub const fn u64_to_hi16_2(r0: u64, r1: u64) -> (u16, bool) { let (r0, n) = u64_to_hi64_2(r0, r1); @@ -894,6 +915,7 @@ pub const fn u64_to_hi16_2(r0: u64, r1: u64) -> (u16, bool) { } /// Shift 64-bit integer to high 32-bits. +#[must_use] #[inline(always)] pub const fn u64_to_hi32_1(r0: u64) -> (u32, bool) { let r0 = u64_to_hi64_1(r0).0; @@ -901,6 +923,7 @@ pub const fn u64_to_hi32_1(r0: u64) -> (u32, bool) { } /// Shift 2 64-bit integers to high 32-bits. +#[must_use] #[inline(always)] pub const fn u64_to_hi32_2(r0: u64, r1: u64) -> (u32, bool) { let (r0, n) = u64_to_hi64_2(r0, r1); @@ -908,6 +931,7 @@ pub const fn u64_to_hi32_2(r0: u64, r1: u64) -> (u32, bool) { } /// Shift 64-bit integer to high 64-bits. +#[must_use] #[inline(always)] pub const fn u64_to_hi64_1(r0: u64) -> (u64, bool) { let ls = r0.leading_zeros(); @@ -915,6 +939,7 @@ pub const fn u64_to_hi64_1(r0: u64) -> (u64, bool) { } /// Shift 2 64-bit integers to high 64-bits. +#[must_use] #[inline(always)] pub const fn u64_to_hi64_2(r0: u64, r1: u64) -> (u64, bool) { let ls = r0.leading_zeros(); @@ -976,6 +1001,8 @@ pub const fn u64_to_hi64_2(r0: u64, r1: u64) -> (u64, bool) { /// Furthermore, using sufficiently big large powers is also crucial for /// performance. This is a tradeoff of binary size and performance, and /// using a single value at ~`5^(5 * max_exp)` seems optimal. +#[allow(clippy::doc_markdown)] // reason="not attempted to be referencing items" +#[allow(clippy::missing_inline_in_public_items)] // reason="only public for testing" pub fn pow(x: &mut StackVec, base: u32, mut exp: u32) -> Option<()> { // Minimize the number of iterations for large exponents: just // do a few steps with a large powers. @@ -1011,8 +1038,9 @@ pub fn pow(x: &mut StackVec, base: u32, mut exp: u32) - /// Add two small integers and return the resulting value and if overflow /// happens. +#[must_use] #[inline(always)] -pub fn scalar_add(x: Limb, y: Limb) -> (Limb, bool) { +pub const fn scalar_add(x: Limb, y: Limb) -> (Limb, bool) { x.overflowing_add(y) } @@ -1020,8 +1048,9 @@ pub fn scalar_add(x: Limb, y: Limb) -> (Limb, bool) { /// contribution). /// /// Returns the (low, high) components. +#[must_use] #[inline(always)] -pub fn scalar_mul(x: Limb, y: Limb, carry: Limb) -> (Limb, Limb) { +pub const fn scalar_mul(x: Limb, y: Limb, carry: Limb) -> (Limb, Limb) { // Cannot overflow, as long as wide is 2x as wide. This is because // the following is always true: // `Wide::MAX - (Narrow::MAX * Narrow::MAX) >= Narrow::MAX` @@ -1081,6 +1110,7 @@ pub fn small_mul(x: &mut StackVec, y: Limb) -> Option<( // ----- /// Add bigint to bigint starting from offset. +#[allow(clippy::missing_inline_in_public_items)] // reason="only public for testing" pub fn large_add_from( x: &mut StackVec, y: &[Limb], @@ -1190,7 +1220,9 @@ pub fn large_add(x: &mut StackVec, y: &[Limb]) -> Optio /// ``` /// /// In short, Karatsuba multiplication is never worthwhile for out use-case. -#[allow(clippy::needless_range_loop)] +#[must_use] +#[allow(clippy::needless_range_loop)] // reason="required for performance, see benches" +#[allow(clippy::missing_inline_in_public_items)] // reason="only public for testing" pub fn long_mul(x: &[Limb], y: &[Limb]) -> Option> { // Using the immutable value, multiply by all the scalars in y, using // the algorithm defined above. Use a single buffer to avoid @@ -1245,7 +1277,7 @@ pub fn large_mul(x: &mut StackVec, y: &[Limb]) -> Optio /// Adapted from David M. Gay's dtoa, and therefore under an MIT license: /// www.netlib.org/fp/dtoa.c #[cfg(feature = "radix")] -#[allow(clippy::many_single_char_names)] +#[allow(clippy::many_single_char_names)] // reason = "mathematical names of variables" pub fn large_quorem(x: &mut StackVec, y: &[Limb]) -> Limb { // If we have an empty divisor, error out early. assert!(!y.is_empty(), "large_quorem:: division by zero error."); @@ -1302,6 +1334,7 @@ pub fn large_quorem(x: &mut StackVec, y: &[Limb]) -> Li // ------- /// Compare `x` to `y`, in little-endian order. +#[must_use] #[inline(always)] pub fn compare(x: &[Limb], y: &[Limb]) -> cmp::Ordering { match x.len().cmp(&y.len()) { @@ -1326,14 +1359,14 @@ pub fn compare(x: &[Limb], y: &[Limb]) -> cmp::Ordering { /// Shift-left `n` bits inside a buffer. #[inline(always)] pub fn shl_bits(x: &mut StackVec, n: usize) -> Option<()> { - debug_assert!(n != 0); + debug_assert!(n != 0, "cannot shift left by 0 bits"); // Internally, for each item, we shift left by n, and add the previous // right shifted limb-bits. // For example, we transform (for u8) shifted left 2, to: // b10100100 b01000010 // b10 b10010001 b00001000 - debug_assert!(n < LIMB_BITS); + debug_assert!(n < LIMB_BITS, "cannot shift left more bits than in our limb"); let rshift = LIMB_BITS - n; let lshift = n; let mut prev: Limb = 0; @@ -1356,7 +1389,7 @@ pub fn shl_bits(x: &mut StackVec, n: usize) -> Option<( /// Shift-left `n` limbs inside a buffer. #[inline(always)] pub fn shl_limbs(x: &mut StackVec, n: usize) -> Option<()> { - debug_assert!(n != 0); + debug_assert!(n != 0, "cannot shift left by 0 bits"); if n + x.len() > x.capacity() { None } else if !x.is_empty() { @@ -1364,8 +1397,7 @@ pub fn shl_limbs(x: &mut StackVec, n: usize) -> Option< let x_len = x.len(); let ptr = x.as_mut_ptr(); let src = ptr; - // FIXME: Change to `split_at_mut` and `clone_from_slice`? - // SAFE: since x is not empty, and `x.len() + n <= x.capacity()`. + // SAFETY: since x is not empty, and `x.len() + n <= x.capacity()`. unsafe { // Move the elements. let dst = ptr.add(n); @@ -1381,6 +1413,7 @@ pub fn shl_limbs(x: &mut StackVec, n: usize) -> Option< } /// Shift-left buffer by n bits. +#[must_use] #[inline(always)] pub fn shl(x: &mut StackVec, n: usize) -> Option<()> { let rem = n % LIMB_BITS; @@ -1395,6 +1428,7 @@ pub fn shl(x: &mut StackVec, n: usize) -> Option<()> { } /// Get number of leading zero bits in the storage. +#[must_use] #[inline(always)] pub fn leading_zeros(x: &[Limb]) -> u32 { let length = x.len(); @@ -1407,6 +1441,7 @@ pub fn leading_zeros(x: &[Limb]) -> u32 { } /// Calculate the bit-length of the big-integer. +#[must_use] #[inline(always)] pub fn bit_length(x: &[Limb]) -> u32 { let nlz = leading_zeros(x); @@ -1417,6 +1452,7 @@ pub fn bit_length(x: &[Limb]) -> u32 { // ----- /// Get the base, odd radix, and the power-of-two for the type. +#[must_use] #[inline(always)] #[cfg(feature = "radix")] pub const fn split_radix(radix: u32) -> (u32, u32) { @@ -1462,6 +1498,7 @@ pub const fn split_radix(radix: u32) -> (u32, u32) { } /// Get the base, odd radix, and the power-of-two for the type. +#[must_use] #[inline(always)] #[cfg(all(feature = "power-of-two", not(feature = "radix")))] pub const fn split_radix(radix: u32) -> (u32, u32) { @@ -1481,6 +1518,7 @@ pub const fn split_radix(radix: u32) -> (u32, u32) { } /// Get the base, odd radix, and the power-of-two for the type. +#[must_use] #[inline(always)] #[cfg(not(feature = "power-of-two"))] pub const fn split_radix(radix: u32) -> (u32, u32) { diff --git a/lexical-parse-float/src/binary.rs b/lexical-parse-float/src/binary.rs index 1c92e7c1..bf695ebb 100644 --- a/lexical-parse-float/src/binary.rs +++ b/lexical-parse-float/src/binary.rs @@ -25,7 +25,10 @@ use crate::shared; #[cfg_attr(not(feature = "compact"), inline(always))] pub fn binary(num: &Number, lossy: bool) -> ExtendedFloat80 { let format = NumberFormat::<{ FORMAT }> {}; - debug_assert!(matches!(format.radix(), 2 | 4 | 8 | 16 | 32)); + debug_assert!( + matches!(format.radix(), 2 | 4 | 8 | 16 | 32), + "algorithm requires a power-of-two" + ); let fp_zero = ExtendedFloat80 { mant: 0, @@ -112,7 +115,7 @@ pub fn parse_u64_digits<'a, Iter, const FORMAT: u128>( // Try to parse 8 digits at a time, if we can. #[cfg(not(feature = "compact"))] if can_try_parse_multidigit!(iter, radix) { - debug_assert!(radix < 16); + debug_assert!(radix < 16, "larger radices will wrap on radix^8"); let radix8 = format.radix8() as u64; while *step > 8 { if let Some(v) = algorithm::try_parse_8digits::(&mut iter) { @@ -126,9 +129,9 @@ pub fn parse_u64_digits<'a, Iter, const FORMAT: u128>( // Parse single digits at a time. for &c in iter { - let digit = char_to_valid_digit_const(c, radix as _); + let digit = char_to_valid_digit_const(c, radix as u32); if !*overflowed { - let result = mantissa.checked_mul(radix as _).and_then(|x| x.checked_add(digit as _)); + let result = mantissa.checked_mul(radix).and_then(|x| x.checked_add(digit as u64)); if let Some(mant) = result { *mantissa = mant; } else { @@ -150,7 +153,7 @@ pub fn parse_u64_digits<'a, Iter, const FORMAT: u128>( pub fn slow_binary(num: Number) -> ExtendedFloat80 { let format = NumberFormat::<{ FORMAT }> {}; let radix = format.radix(); - debug_assert!(matches!(radix, 2 | 4 | 8 | 16 | 32)); + debug_assert!(matches!(radix, 2 | 4 | 8 | 16 | 32), "algorithm requires a power-of-two"); // This assumes the sign bit has already been parsed, and we're // starting with the integer digits, and the float format has been diff --git a/lexical-parse-float/src/float.rs b/lexical-parse-float/src/float.rs index bae429e4..83da8600 100644 --- a/lexical-parse-float/src/float.rs +++ b/lexical-parse-float/src/float.rs @@ -34,6 +34,7 @@ pub trait RawFloat: Float + ExactFloat + MaxDigits { /// Minimum exponent that for a fast path case, or /// `-⌊(MANTISSA_SIZE+1)/log2(r)⌋` where `r` is the radix with /// powers-of-two removed. + #[must_use] #[inline(always)] fn min_exponent_fast_path(radix: u32) -> i64 { Self::exponent_limit(radix).0 @@ -42,6 +43,7 @@ pub trait RawFloat: Float + ExactFloat + MaxDigits { /// Maximum exponent that for a fast path case, or /// `⌊(MANTISSA_SIZE+1)/log2(r)⌋` where `r` is the radix with /// powers-of-two removed. + #[must_use] #[inline(always)] fn max_exponent_fast_path(radix: u32) -> i64 { Self::exponent_limit(radix).1 @@ -49,6 +51,7 @@ pub trait RawFloat: Float + ExactFloat + MaxDigits { // Maximum exponent that can be represented for a disguised-fast path case. // This is `max_exponent_fast_path(radix) + ⌊(MANTISSA_SIZE+1)/log2(radix)⌋` + #[must_use] #[inline(always)] fn max_exponent_disguised_fast_path(radix: u32) -> i64 { Self::max_exponent_fast_path(radix) + Self::mantissa_limit(radix) @@ -58,6 +61,7 @@ pub trait RawFloat: Float + ExactFloat + MaxDigits { fn pow_fast_path(exponent: usize, radix: u32) -> Self; /// Get a small, integral power-of-radix for fast-path multiplication. + #[must_use] #[inline(always)] fn int_pow_fast_path(exponent: usize, radix: u32) -> u64 { // SAFETY: safe as long as the exponent is smaller than the radix table. @@ -190,6 +194,7 @@ pub fn powd(x: f64, y: f64) -> f64 { } /// Converts an `ExtendedFloat` to the closest machine float type. +#[must_use] #[inline(always)] pub fn extended_to_float(x: ExtendedFloat80) -> F { let mut word = x.mant; diff --git a/lexical-parse-float/src/fpu.rs b/lexical-parse-float/src/fpu.rs index 657eaee1..1795eeeb 100644 --- a/lexical-parse-float/src/fpu.rs +++ b/lexical-parse-float/src/fpu.rs @@ -101,6 +101,7 @@ mod fpu_precision { // basis. #[cfg(any(not(target_arch = "x86"), target_feature = "sse2"))] mod fpu_precision { - pub fn set_precision() { + #[inline] + pub const fn set_precision() { } } diff --git a/lexical-parse-float/src/lemire.rs b/lexical-parse-float/src/lemire.rs index 0ace5909..03d8e8ff 100644 --- a/lexical-parse-float/src/lemire.rs +++ b/lexical-parse-float/src/lemire.rs @@ -13,6 +13,7 @@ use crate::table::{LARGEST_POWER_OF_FIVE, POWER_OF_FIVE_128, SMALLEST_POWER_OF_F /// Ensure truncation of digits doesn't affect our computation, by doing 2 /// passes. +#[must_use] #[inline(always)] pub fn lemire(num: &Number, lossy: bool) -> ExtendedFloat80 { // If significant digits were truncated, then we can have rounding error @@ -50,6 +51,8 @@ pub fn lemire(num: &Number, lossy: bool) -> ExtendedFloat80 { /// at a Gigabyte per Second" in section 5, "Fast Algorithm", and /// section 6, "Exact Numbers And Ties", available online: /// . +#[must_use] +#[allow(clippy::missing_inline_in_public_items)] // reason="public for testing only" pub fn compute_float(q: i64, mut w: u64, lossy: bool) -> ExtendedFloat80 { let fp_zero = ExtendedFloat80 { mant: 0, @@ -154,6 +157,7 @@ pub fn compute_float(q: i64, mut w: u64, lossy: bool) -> Extende /// Fallback algorithm to calculate the non-rounded representation. /// This calculates the extended representation, and then normalizes /// the resulting representation, so the high bit is set. +#[must_use] #[inline(always)] pub fn compute_error(q: i64, mut w: u64) -> ExtendedFloat80 { let lz = w.leading_zeros() as i32; @@ -163,8 +167,9 @@ pub fn compute_error(q: i64, mut w: u64) -> ExtendedFloat80 { } /// Compute the error from a mantissa scaled to the exponent. +#[must_use] #[inline(always)] -pub fn compute_error_scaled(q: i64, mut w: u64, lz: i32) -> ExtendedFloat80 { +pub const fn compute_error_scaled(q: i64, mut w: u64, lz: i32) -> ExtendedFloat80 { // Want to normalize the float, but this is faster than ctlz on most // architectures. let hilz = (w >> 63) as i32 ^ 1; @@ -182,12 +187,12 @@ pub fn compute_error_scaled(q: i64, mut w: u64, lz: i32) -> Exte /// log2(10), where 217706 / 2^16 is accurate for the /// entire range of non-finite decimal exponents. #[inline(always)] -fn power(q: i32) -> i32 { +const fn power(q: i32) -> i32 { (q.wrapping_mul(152_170 + 65536) >> 16) + 63 } #[inline(always)] -fn full_multiplication(a: u64, b: u64) -> (u64, u64) { +const fn full_multiplication(a: u64, b: u64) -> (u64, u64) { let r = (a as u128) * (b as u128); (r as u64, (r >> 64) as u64) } @@ -197,9 +202,9 @@ fn full_multiplication(a: u64, b: u64) -> (u64, u64) { // most significant bits and the low part corresponding to the least significant // bits. fn compute_product_approx(q: i64, w: u64, precision: usize) -> (u64, u64) { - debug_assert!(q >= SMALLEST_POWER_OF_FIVE as i64); - debug_assert!(q <= LARGEST_POWER_OF_FIVE as i64); - debug_assert!(precision <= 64); + debug_assert!(q >= SMALLEST_POWER_OF_FIVE as i64, "must be within our required pow5 range"); + debug_assert!(q <= LARGEST_POWER_OF_FIVE as i64, "must be within our required pow5 range"); + debug_assert!(precision <= 64, "requires a 64-bit or smaller float"); let mask = if precision < 64 { 0xFFFF_FFFF_FFFF_FFFF_u64 >> precision diff --git a/lexical-parse-float/src/lib.rs b/lexical-parse-float/src/lib.rs index 7f0e8049..208501e8 100644 --- a/lexical-parse-float/src/lib.rs +++ b/lexical-parse-float/src/lib.rs @@ -92,11 +92,38 @@ //! [longbits]: //! [push_unchecked]: +// FIXME: Implement clippy/allow reasons once we drop support for 1.80.0 and below +// Clippy reasons were stabilized in 1.81.0. + // We want to have the same safety guarantees as Rust core, // so we allow unused unsafe to clearly document safety guarantees. #![allow(unused_unsafe)] #![cfg_attr(feature = "lint", warn(unsafe_op_in_unsafe_fn))] #![cfg_attr(not(feature = "std"), no_std)] +#![deny( + clippy::doc_markdown, + clippy::unnecessary_safety_comment, + clippy::semicolon_if_nothing_returned, + clippy::unwrap_used, + clippy::as_underscore, + clippy::doc_markdown +)] +#![allow( + // used when concepts are logically separate + clippy::match_same_arms, + // loss of precision is intentional + clippy::integer_division, + // mathematical names use 1-character identifiers + clippy::min_ident_chars, + // these are not cryptographically secure contexts + clippy::integer_division_remainder_used, + // this can be intentional + clippy::module_name_repetitions, + // this is intentional: already passing a pointer and need performance + clippy::needless_pass_by_value, + // we use this for inline formatting for unsafe blocks + clippy::semicolon_inside_block, +)] #[macro_use] pub mod shared; diff --git a/lexical-parse-float/src/limits.rs b/lexical-parse-float/src/limits.rs index b3d1a64a..20d452d9 100644 --- a/lexical-parse-float/src/limits.rs +++ b/lexical-parse-float/src/limits.rs @@ -116,6 +116,7 @@ impl ExactFloat for bf16 { // -------- /// Get the exponent limit as a const fn. +#[must_use] #[inline(always)] #[cfg(feature = "radix")] pub const fn f32_exponent_limit(radix: u32) -> (i64, i64) { @@ -160,6 +161,7 @@ pub const fn f32_exponent_limit(radix: u32) -> (i64, i64) { } /// Get the exponent limit as a const fn. +#[must_use] #[inline(always)] #[cfg(all(feature = "power-of-two", not(feature = "radix")))] pub const fn f32_exponent_limit(radix: u32) -> (i64, i64) { @@ -175,6 +177,7 @@ pub const fn f32_exponent_limit(radix: u32) -> (i64, i64) { } /// Get the exponent limit as a const fn. +#[must_use] #[inline(always)] #[cfg(not(feature = "power-of-two"))] pub const fn f32_exponent_limit(radix: u32) -> (i64, i64) { @@ -185,6 +188,7 @@ pub const fn f32_exponent_limit(radix: u32) -> (i64, i64) { } /// Get the mantissa limit as a const fn. +#[must_use] #[inline(always)] #[cfg(feature = "radix")] pub const fn f32_mantissa_limit(radix: u32) -> i64 { @@ -229,6 +233,7 @@ pub const fn f32_mantissa_limit(radix: u32) -> i64 { } /// Get the mantissa limit as a const fn. +#[must_use] #[inline(always)] #[cfg(all(feature = "power-of-two", not(feature = "radix")))] pub const fn f32_mantissa_limit(radix: u32) -> i64 { @@ -244,6 +249,7 @@ pub const fn f32_mantissa_limit(radix: u32) -> i64 { } /// Get the mantissa limit as a const fn. +#[must_use] #[inline(always)] #[cfg(not(feature = "power-of-two"))] pub const fn f32_mantissa_limit(radix: u32) -> i64 { @@ -254,6 +260,7 @@ pub const fn f32_mantissa_limit(radix: u32) -> i64 { } /// Get the exponent limit as a const fn. +#[must_use] #[inline(always)] #[cfg(feature = "radix")] pub const fn f64_exponent_limit(radix: u32) -> (i64, i64) { @@ -298,6 +305,7 @@ pub const fn f64_exponent_limit(radix: u32) -> (i64, i64) { } // Get the exponent limit as a const fn. +#[must_use] #[inline(always)] #[cfg(all(feature = "power-of-two", not(feature = "radix")))] pub const fn f64_exponent_limit(radix: u32) -> (i64, i64) { @@ -313,8 +321,9 @@ pub const fn f64_exponent_limit(radix: u32) -> (i64, i64) { } /// Get the exponent limit as a const fn. -#[cfg(not(feature = "power-of-two"))] +#[must_use] #[inline(always)] +#[cfg(not(feature = "power-of-two"))] pub const fn f64_exponent_limit(radix: u32) -> (i64, i64) { match radix { 10 => (-22, 22), @@ -323,6 +332,7 @@ pub const fn f64_exponent_limit(radix: u32) -> (i64, i64) { } /// Get the mantissa limit as a const fn. +#[must_use] #[inline(always)] #[cfg(feature = "radix")] pub const fn f64_mantissa_limit(radix: u32) -> i64 { @@ -367,6 +377,7 @@ pub const fn f64_mantissa_limit(radix: u32) -> i64 { } /// Get the mantissa limit as a const fn. +#[must_use] #[inline(always)] #[cfg(all(feature = "power-of-two", not(feature = "radix")))] pub const fn f64_mantissa_limit(radix: u32) -> i64 { @@ -382,6 +393,7 @@ pub const fn f64_mantissa_limit(radix: u32) -> i64 { } /// Get the mantissa limit as a const fn. +#[must_use] #[inline(always)] #[cfg(not(feature = "power-of-two"))] pub const fn f64_mantissa_limit(radix: u32) -> i64 { @@ -392,6 +404,7 @@ pub const fn f64_mantissa_limit(radix: u32) -> i64 { } /// Get the exponent limit as a const fn. +#[must_use] #[inline(always)] #[cfg(feature = "f128")] #[cfg(feature = "radix")] @@ -455,6 +468,7 @@ pub const fn f128_exponent_limit(radix: u32) -> (i64, i64) { } /// Get the exponent limit as a const fn. +#[must_use] #[inline(always)] #[cfg(feature = "f128")] #[cfg(not(feature = "power-of-two"))] @@ -467,6 +481,7 @@ pub const fn f128_exponent_limit(radix: u32) -> (i64, i64) { } /// Get the mantissa limit as a const fn. +#[must_use] #[inline(always)] #[cfg(feature = "f128")] #[cfg(feature = "radix")] @@ -513,6 +528,7 @@ pub const fn f128_mantissa_limit(radix: u32) -> i64 { } /// Get the mantissa limit as a const fn. +#[must_use] #[inline(always)] #[cfg(feature = "f128")] #[cfg(all(feature = "power-of-two", not(feature = "radix")))] @@ -530,6 +546,7 @@ pub const fn f128_mantissa_limit(radix: u32) -> i64 { } /// Get the mantissa limit as a const fn. +#[must_use] #[inline(always)] #[cfg(feature = "f128")] #[cfg(not(feature = "power-of-two"))] @@ -577,6 +594,7 @@ pub const fn f128_mantissa_limit(radix: u32) -> i64 { /// Get the maximum value for `radix^N` that can be represented in a u32. /// This is calculated as `⌊log(2^32 - 1, b)⌋`. +#[must_use] #[inline(always)] #[cfg(feature = "radix")] pub const fn u32_power_limit(radix: u32) -> u32 { @@ -622,6 +640,7 @@ pub const fn u32_power_limit(radix: u32) -> u32 { } /// This is calculated as `⌊log(2^32 - 1, b)⌋`. +#[must_use] #[inline(always)] #[cfg(all(feature = "power-of-two", not(feature = "radix")))] pub const fn u32_power_limit(radix: u32) -> u32 { @@ -639,6 +658,7 @@ pub const fn u32_power_limit(radix: u32) -> u32 { } /// This is calculated as `⌊log(2^32 - 1, b)⌋`. +#[must_use] #[inline(always)] #[cfg(not(feature = "power-of-two"))] pub const fn u32_power_limit(radix: u32) -> u32 { @@ -652,6 +672,7 @@ pub const fn u32_power_limit(radix: u32) -> u32 { /// Get the maximum value for `radix^N` that can be represented in a u64. /// This is calculated as `⌊log(2^64 - 1, b)⌋`. +#[must_use] #[inline(always)] #[cfg(feature = "radix")] pub const fn u64_power_limit(radix: u32) -> u32 { @@ -698,6 +719,7 @@ pub const fn u64_power_limit(radix: u32) -> u32 { /// Get the maximum value for `radix^N` that can be represented in a u64. /// This is calculated as `⌊log(2^64 - 1, b)⌋`. +#[must_use] #[inline(always)] #[cfg(all(feature = "power-of-two", not(feature = "radix")))] pub const fn u64_power_limit(radix: u32) -> u32 { @@ -714,6 +736,7 @@ pub const fn u64_power_limit(radix: u32) -> u32 { } } +#[must_use] #[inline(always)] #[cfg(not(feature = "power-of-two"))] pub const fn u64_power_limit(radix: u32) -> u32 { @@ -836,6 +859,7 @@ pub const fn u64_power_limit(radix: u32) -> u32 { /// print(' _ => None,') /// print('}') /// ``` +#[allow(clippy::doc_markdown)] // reason="not meant to be function parameters" pub trait MaxDigits { fn max_digits(radix: u32) -> Option; } @@ -907,6 +931,7 @@ impl MaxDigits for bf16 { // -------- /// Get the maximum number of significant digits as a const fn. +#[must_use] #[inline(always)] pub const fn f32_max_digits(radix: u32) -> Option { match radix { @@ -930,6 +955,7 @@ pub const fn f32_max_digits(radix: u32) -> Option { } /// Get the maximum number of significant digits as a const fn. +#[must_use] #[inline(always)] pub const fn f64_max_digits(radix: u32) -> Option { match radix { diff --git a/lexical-parse-float/src/mask.rs b/lexical-parse-float/src/mask.rs index 6db6c33d..a8362505 100644 --- a/lexical-parse-float/src/mask.rs +++ b/lexical-parse-float/src/mask.rs @@ -12,8 +12,10 @@ /// assert_eq!(lower_n_mask(2), 0b11); /// # } /// ``` +#[must_use] #[inline(always)] -pub fn lower_n_mask(n: u64) -> u64 { +#[allow(clippy::match_bool)] // reason="easier to visualize logic" +pub const fn lower_n_mask(n: u64) -> u64 { debug_assert!(n <= 64, "lower_n_mask() overflow in shl."); match n == 64 { @@ -32,8 +34,10 @@ pub fn lower_n_mask(n: u64) -> u64 { /// assert_eq!(lower_n_halfway(2), 0b10); /// # } /// ``` +#[must_use] #[inline(always)] -pub fn lower_n_halfway(n: u64) -> u64 { +#[allow(clippy::match_bool)] // reason="easier to visualize logic" +pub const fn lower_n_halfway(n: u64) -> u64 { debug_assert!(n <= 64, "lower_n_halfway() overflow in shl."); match n == 0 { @@ -52,8 +56,9 @@ pub fn lower_n_halfway(n: u64) -> u64 { /// assert_eq!(nth_bit(2), 0b100); /// # } /// ``` +#[must_use] #[inline(always)] -pub fn nth_bit(n: u64) -> u64 { +pub const fn nth_bit(n: u64) -> u64 { debug_assert!(n < 64, "nth_bit() overflow in shl."); 1 << n } diff --git a/lexical-parse-float/src/number.rs b/lexical-parse-float/src/number.rs index 6152e962..5973d3dc 100644 --- a/lexical-parse-float/src/number.rs +++ b/lexical-parse-float/src/number.rs @@ -4,6 +4,7 @@ //! a port of [fast_float](https://github.com/fastfloat/fast_float) to Rust. #![doc(hidden)] +#![allow(clippy::exhaustive_structs)] // reason = "only public for testing" use lexical_util::format::NumberFormat; @@ -33,10 +34,14 @@ pub struct Number<'a> { impl<'a> Number<'a> { /// Detect if the float can be accurately reconstructed from native floats. + #[must_use] #[inline(always)] pub fn is_fast_path(&self) -> bool { let format = NumberFormat:: {}; - debug_assert!(format.mantissa_radix() == format.exponent_base()); + debug_assert!( + format.mantissa_radix() == format.exponent_base(), + "fast path requires same radix" + ); F::min_exponent_fast_path(format.radix()) <= self.exponent && self.exponent <= F::max_exponent_disguised_fast_path(format.radix()) && self.mantissa <= F::MAX_MANTISSA_FAST_PATH @@ -53,10 +58,15 @@ impl<'a> Number<'a> { /// There is an exception: disguised fast-path cases, where we can shift /// powers-of-10 from the exponent to the significant digits. // `set_precision` doesn't return a unit value on x87 FPUs. - #[allow(clippy::let_unit_value)] + #[must_use] + #[allow(clippy::missing_inline_in_public_items)] // reason = "only public for testing" + #[allow(clippy::let_unit_value)] // reason = "untentional ASM drop for X87 FPUs" pub fn try_fast_path(&self) -> Option { let format = NumberFormat:: {}; - debug_assert!(format.mantissa_radix() == format.exponent_base()); + debug_assert!( + format.mantissa_radix() == format.exponent_base(), + "fast path requires same radix" + ); // The fast path crucially depends on arithmetic being rounded to the correct // number of bits without any intermediate rounding. On x86 (without SSE // or SSE2) this requires the precision of the x87 FPU stack to be @@ -64,7 +74,7 @@ impl<'a> Number<'a> { // function takes care of setting the precision on architectures which // require setting it by changing the global state (like the control word of the // x87 FPU). - let _cw = set_precision::(); + let _cw: () = set_precision::(); if self.is_fast_path::() { let radix = format.radix(); @@ -73,9 +83,9 @@ impl<'a> Number<'a> { // normal fast path let value = F::as_cast(self.mantissa); if self.exponent < 0 { - value / F::pow_fast_path((-self.exponent) as _, radix) + value / F::pow_fast_path((-self.exponent) as usize, radix) } else { - value * F::pow_fast_path(self.exponent as _, radix) + value * F::pow_fast_path(self.exponent as usize, radix) } } else { // disguised fast path @@ -85,7 +95,7 @@ impl<'a> Number<'a> { if mantissa > F::MAX_MANTISSA_FAST_PATH { return None; } - F::as_cast(mantissa) * F::pow_fast_path(max_exponent as _, radix) + F::as_cast(mantissa) * F::pow_fast_path(max_exponent as usize, radix) }; if self.is_negative { value = -value; @@ -98,10 +108,15 @@ impl<'a> Number<'a> { /// Force a fast-path algorithm, even when it may not be accurate. // `set_precision` doesn't return a unit value on x87 FPUs. - #[allow(clippy::let_unit_value)] + #[must_use] + #[allow(clippy::missing_inline_in_public_items)] // reason = "only public for testing" + #[allow(clippy::let_unit_value)] // reason = "untentional ASM drop for X87 FPUs" pub fn force_fast_path(&self) -> F { let format = NumberFormat:: {}; - debug_assert!(format.mantissa_radix() == format.exponent_base()); + debug_assert!( + format.mantissa_radix() == format.exponent_base(), + "fast path requires same radix" + ); let _cw = set_precision::(); @@ -111,16 +126,16 @@ impl<'a> Number<'a> { let mut exponent = self.exponent.abs(); if self.exponent < 0 { while exponent > max_exponent { - value /= F::pow_fast_path(max_exponent as _, radix); + value /= F::pow_fast_path(max_exponent as usize, radix); exponent -= max_exponent; } - value /= F::pow_fast_path(exponent as _, radix); + value /= F::pow_fast_path(exponent as usize, radix); } else { while exponent > max_exponent { - value *= F::pow_fast_path(max_exponent as _, radix); + value *= F::pow_fast_path(max_exponent as usize, radix); exponent -= max_exponent; } - value *= F::pow_fast_path(exponent as _, radix); + value *= F::pow_fast_path(exponent as usize, radix); } if self.is_negative { value = -value; diff --git a/lexical-parse-float/src/options.rs b/lexical-parse-float/src/options.rs index 75efb6a8..a3910cd3 100644 --- a/lexical-parse-float/src/options.rs +++ b/lexical-parse-float/src/options.rs @@ -1,5 +1,7 @@ //! Configuration options for parsing floats. +#![allow(clippy::must_use_candidate)] + use lexical_util::ascii::{is_valid_ascii, is_valid_letter_slice}; use lexical_util::error::Error; use lexical_util::options::{self, ParseOptions}; @@ -82,6 +84,7 @@ impl OptionsBuilder { // SETTERS /// Set if we disable the use of arbitrary-precision arithmetic. + #[must_use] #[inline(always)] pub const fn lossy(mut self, lossy: bool) -> Self { self.lossy = lossy; @@ -89,6 +92,7 @@ impl OptionsBuilder { } /// Set the character to designate the exponent component of a float. + #[must_use] #[inline(always)] pub const fn exponent(mut self, exponent: u8) -> Self { self.exponent = exponent; @@ -96,6 +100,7 @@ impl OptionsBuilder { } /// Set the character to separate the integer from the fraction components. + #[must_use] #[inline(always)] pub const fn decimal_point(mut self, decimal_point: u8) -> Self { self.decimal_point = decimal_point; @@ -103,6 +108,7 @@ impl OptionsBuilder { } /// Set the string representation for `NaN`. + #[must_use] #[inline(always)] pub const fn nan_string(mut self, nan_string: Option<&'static [u8]>) -> Self { self.nan_string = nan_string; @@ -110,6 +116,7 @@ impl OptionsBuilder { } /// Set the short string representation for `Infinity`. + #[must_use] #[inline(always)] pub const fn inf_string(mut self, inf_string: Option<&'static [u8]>) -> Self { self.inf_string = inf_string; @@ -117,6 +124,7 @@ impl OptionsBuilder { } /// Set the long string representation for `Infinity`. + #[must_use] #[inline(always)] pub const fn infinity_string(mut self, infinity_string: Option<&'static [u8]>) -> Self { self.infinity_string = infinity_string; @@ -127,7 +135,7 @@ impl OptionsBuilder { /// Determine if `nan_str` is valid. #[inline(always)] - #[allow(clippy::if_same_then_else, clippy::needless_bool)] + #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason = "more idiomatic" pub const fn nan_str_is_valid(&self) -> bool { if self.nan_string.is_none() { return true; @@ -148,7 +156,7 @@ impl OptionsBuilder { /// Determine if `inf_str` is valid. #[inline(always)] - #[allow(clippy::if_same_then_else, clippy::needless_bool)] + #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason = "more idiomatic" pub const fn inf_str_is_valid(&self) -> bool { if self.infinity_string.is_none() && self.inf_string.is_some() { return false; @@ -174,7 +182,7 @@ impl OptionsBuilder { /// Determine if `infinity_string` is valid. #[inline(always)] - #[allow(clippy::if_same_then_else, clippy::needless_bool)] + #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason = "more idiomatic" pub const fn infinity_string_is_valid(&self) -> bool { if self.infinity_string.is_none() && self.inf_string.is_some() { return false; @@ -199,7 +207,7 @@ impl OptionsBuilder { /// Check if the builder state is valid. #[inline(always)] - #[allow(clippy::if_same_then_else, clippy::needless_bool)] + #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason = "more idiomatic" pub const fn is_valid(&self) -> bool { if !is_valid_ascii(self.exponent) { false @@ -222,8 +230,8 @@ impl OptionsBuilder { /// /// This is completely safe, however, misusing this, especially /// the `nan_string`, `inf_string`, and `infinity_string` could - /// panic at runtime. Always use [MAX_SPECIAL_STRING_LENGTH] and - /// check if [Self::is_valid] prior to using a created format string. + /// panic at runtime. Always use [`MAX_SPECIAL_STRING_LENGTH`] and + /// check if [`Self::is_valid`] prior to using a created format string. #[inline(always)] pub const fn build_unchecked(&self) -> Options { Options { @@ -237,8 +245,13 @@ impl OptionsBuilder { } /// Build the Options struct. + /// + /// # Errors + /// + /// If the NaN, Inf, or Infinity strings are too long or invalid + /// digits/characters are provided for some numerical formats. #[inline(always)] - #[allow(clippy::if_same_then_else)] + #[allow(clippy::if_same_then_else)] // reason = "more idiomatic" pub const fn build(&self) -> Result { if !is_valid_ascii(self.exponent) { return Err(Error::InvalidExponentSymbol); @@ -403,7 +416,7 @@ impl Options { /// Set if we disable the use of arbitrary-precision arithmetic. #[inline(always)] pub fn set_lossy(&mut self, lossy: bool) { - self.lossy = lossy + self.lossy = lossy; } /// Set the character to designate the exponent component of a float. @@ -421,30 +434,32 @@ impl Options { /// Set the string representation for `NaN`. #[inline(always)] pub fn set_nan_string(&mut self, nan_string: Option<&'static [u8]>) { - self.nan_string = nan_string + self.nan_string = nan_string; } /// Set the short string representation for `Infinity` #[inline(always)] pub fn set_inf_string(&mut self, inf_string: Option<&'static [u8]>) { - self.inf_string = inf_string + self.inf_string = inf_string; } /// Set the long string representation for `Infinity` #[inline(always)] pub fn set_infinity_string(&mut self, infinity_string: Option<&'static [u8]>) { - self.infinity_string = infinity_string + self.infinity_string = infinity_string; } // BUILDERS - /// Get OptionsBuilder as a static function. + /// Get `OptionsBuilder` as a static function. + #[must_use] #[inline(always)] pub const fn builder() -> OptionsBuilder { OptionsBuilder::new() } - /// Create OptionsBuilder using existing values. + /// Create `OptionsBuilder` using existing values. + #[must_use] #[inline(always)] pub const fn rebuild(&self) -> OptionsBuilder { OptionsBuilder { @@ -514,7 +529,7 @@ pub const CARAT_EXPONENT: Options = Options::builder() .build_unchecked(); const_assert!(CARAT_EXPONENT.is_valid()); -/// Number format for a Rust literal floating-point number. +/// Number format for a `Rust` literal floating-point number. #[rustfmt::skip] pub const RUST_LITERAL: Options = Options::builder() .nan_string(options::RUST_LITERAL) @@ -523,7 +538,7 @@ pub const RUST_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(RUST_LITERAL.is_valid()); -/// Number format for a Python literal floating-point number. +/// Number format for a `Python` literal floating-point number. #[rustfmt::skip] pub const PYTHON_LITERAL: Options = Options::builder() .nan_string(options::PYTHON_LITERAL) @@ -532,7 +547,7 @@ pub const PYTHON_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(PYTHON_LITERAL.is_valid()); -/// Number format for a C++ literal floating-point number. +/// Number format for a `C++` literal floating-point number. #[rustfmt::skip] pub const CXX_LITERAL: Options = Options::builder() .nan_string(options::CXX_LITERAL_NAN) @@ -541,7 +556,7 @@ pub const CXX_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(CXX_LITERAL.is_valid()); -/// Number format for a C literal floating-point number. +/// Number format for a `C` literal floating-point number. #[rustfmt::skip] pub const C_LITERAL: Options = Options::builder() .nan_string(options::C_LITERAL_NAN) @@ -550,7 +565,7 @@ pub const C_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(CXX_LITERAL.is_valid()); -/// Number format for a Ruby literal floating-point number. +/// Number format for a `Ruby` literal floating-point number. #[rustfmt::skip] pub const RUBY_LITERAL: Options = Options::builder() .nan_string(options::RUBY_LITERAL_NAN) @@ -559,8 +574,8 @@ pub const RUBY_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(RUBY_LITERAL.is_valid()); -/// Number format to parse a Ruby float from string. -/// Ruby can write NaN and Infinity as strings, but won't roundtrip them back to floats. +/// Number format to parse a `Ruby` float from string. +/// `Ruby` can write NaN and Infinity as strings, but won't roundtrip them back to floats. #[rustfmt::skip] pub const RUBY_STRING: Options = Options::builder() .nan_string(options::RUBY_STRING_NONE) @@ -569,7 +584,7 @@ pub const RUBY_STRING: Options = Options::builder() .build_unchecked(); const_assert!(RUBY_STRING.is_valid()); -/// Number format for a Swift literal floating-point number. +/// Number format for a `Swift` literal floating-point number. #[rustfmt::skip] pub const SWIFT_LITERAL: Options = Options::builder() .nan_string(options::SWIFT_LITERAL) @@ -578,7 +593,7 @@ pub const SWIFT_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(SWIFT_LITERAL.is_valid()); -/// Number format for a Go literal floating-point number. +/// Number format for a `Go` literal floating-point number. #[rustfmt::skip] pub const GO_LITERAL: Options = Options::builder() .nan_string(options::GO_LITERAL) @@ -587,7 +602,7 @@ pub const GO_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(GO_LITERAL.is_valid()); -/// Number format for a Haskell literal floating-point number. +/// Number format for a `Haskell` literal floating-point number. #[rustfmt::skip] pub const HASKELL_LITERAL: Options = Options::builder() .nan_string(options::HASKELL_LITERAL) @@ -596,7 +611,7 @@ pub const HASKELL_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(HASKELL_LITERAL.is_valid()); -/// Number format to parse a Haskell float from string. +/// Number format to parse a `Haskell` float from string. #[rustfmt::skip] pub const HASKELL_STRING: Options = Options::builder() .inf_string(options::HASKELL_STRING_INF) @@ -604,7 +619,7 @@ pub const HASKELL_STRING: Options = Options::builder() .build_unchecked(); const_assert!(HASKELL_STRING.is_valid()); -/// Number format for a Javascript literal floating-point number. +/// Number format for a `Javascript` literal floating-point number. #[rustfmt::skip] pub const JAVASCRIPT_LITERAL: Options = Options::builder() .inf_string(options::JAVASCRIPT_INF) @@ -612,7 +627,7 @@ pub const JAVASCRIPT_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(JAVASCRIPT_LITERAL.is_valid()); -/// Number format to parse a Javascript float from string. +/// Number format to parse a `Javascript` float from string. #[rustfmt::skip] pub const JAVASCRIPT_STRING: Options = Options::builder() .inf_string(options::JAVASCRIPT_INF) @@ -620,7 +635,7 @@ pub const JAVASCRIPT_STRING: Options = Options::builder() .build_unchecked(); const_assert!(JAVASCRIPT_STRING.is_valid()); -/// Number format for a Perl literal floating-point number. +/// Number format for a `Perl` literal floating-point number. #[rustfmt::skip] pub const PERL_LITERAL: Options = Options::builder() .nan_string(options::PERL_LITERAL) @@ -629,7 +644,7 @@ pub const PERL_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(PERL_LITERAL.is_valid()); -/// Number format for a PHP literal floating-point number. +/// Number format for a `PHP` literal floating-point number. #[rustfmt::skip] pub const PHP_LITERAL: Options = Options::builder() .nan_string(options::PHP_LITERAL_NAN) @@ -638,7 +653,7 @@ pub const PHP_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(PHP_LITERAL.is_valid()); -/// Number format for a Java literal floating-point number. +/// Number format for a `Java` literal floating-point number. #[rustfmt::skip] pub const JAVA_LITERAL: Options = Options::builder() .nan_string(options::JAVA_LITERAL) @@ -647,7 +662,7 @@ pub const JAVA_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(JAVA_LITERAL.is_valid()); -/// Number format to parse a Java float from string. +/// Number format to parse a `Java` float from string. #[rustfmt::skip] pub const JAVA_STRING: Options = Options::builder() .inf_string(options::JAVA_STRING_INF) @@ -655,7 +670,7 @@ pub const JAVA_STRING: Options = Options::builder() .build_unchecked(); const_assert!(JAVA_STRING.is_valid()); -/// Number format for an R literal floating-point number. +/// Number format for an `R` literal floating-point number. #[rustfmt::skip] pub const R_LITERAL: Options = Options::builder() .inf_string(options::R_LITERAL_INF) @@ -663,7 +678,7 @@ pub const R_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(R_LITERAL.is_valid()); -/// Number format for a Kotlin literal floating-point number. +/// Number format for a `Kotlin` literal floating-point number. #[rustfmt::skip] pub const KOTLIN_LITERAL: Options = Options::builder() .nan_string(options::KOTLIN_LITERAL) @@ -672,7 +687,7 @@ pub const KOTLIN_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(KOTLIN_LITERAL.is_valid()); -/// Number format to parse a Kotlin float from string. +/// Number format to parse a `Kotlin` float from string. #[rustfmt::skip] pub const KOTLIN_STRING: Options = Options::builder() .inf_string(options::KOTLIN_STRING_INF) @@ -680,7 +695,7 @@ pub const KOTLIN_STRING: Options = Options::builder() .build_unchecked(); const_assert!(KOTLIN_STRING.is_valid()); -/// Number format for a Julia literal floating-point number. +/// Number format for a `Julia` literal floating-point number. #[rustfmt::skip] pub const JULIA_LITERAL: Options = Options::builder() .inf_string(options::JULIA_LITERAL_INF) @@ -688,7 +703,7 @@ pub const JULIA_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(JULIA_LITERAL.is_valid()); -/// Number format for a C# literal floating-point number. +/// Number format for a `C#` literal floating-point number. #[rustfmt::skip] pub const CSHARP_LITERAL: Options = Options::builder() .nan_string(options::CSHARP_LITERAL) @@ -697,7 +712,7 @@ pub const CSHARP_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(CSHARP_LITERAL.is_valid()); -/// Number format to parse a C# float from string. +/// Number format to parse a `C#` float from string. #[rustfmt::skip] pub const CSHARP_STRING: Options = Options::builder() .inf_string(options::CSHARP_STRING_INF) @@ -705,7 +720,7 @@ pub const CSHARP_STRING: Options = Options::builder() .build_unchecked(); const_assert!(CSHARP_STRING.is_valid()); -/// Number format for a Kawa literal floating-point number. +/// Number format for a `Kawa` literal floating-point number. #[rustfmt::skip] pub const KAWA_LITERAL: Options = Options::builder() .nan_string(options::KAWA) @@ -714,7 +729,7 @@ pub const KAWA_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(KAWA_LITERAL.is_valid()); -/// Number format to parse a Kawa float from string. +/// Number format to parse a `Kawa` float from string. #[rustfmt::skip] pub const KAWA_STRING: Options = Options::builder() .nan_string(options::KAWA) @@ -723,7 +738,7 @@ pub const KAWA_STRING: Options = Options::builder() .build_unchecked(); const_assert!(KAWA_STRING.is_valid()); -/// Number format for a Gambit-C literal floating-point number. +/// Number format for a `Gambit-C` literal floating-point number. #[rustfmt::skip] pub const GAMBITC_LITERAL: Options = Options::builder() .nan_string(options::GAMBITC) @@ -732,7 +747,7 @@ pub const GAMBITC_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(GAMBITC_LITERAL.is_valid()); -/// Number format to parse a Gambit-C float from string. +/// Number format to parse a `Gambit-C` float from string. #[rustfmt::skip] pub const GAMBITC_STRING: Options = Options::builder() .nan_string(options::GAMBITC) @@ -741,7 +756,7 @@ pub const GAMBITC_STRING: Options = Options::builder() .build_unchecked(); const_assert!(GAMBITC_STRING.is_valid()); -/// Number format for a Guile literal floating-point number. +/// Number format for a `Guile` literal floating-point number. #[rustfmt::skip] pub const GUILE_LITERAL: Options = Options::builder() .nan_string(options::GUILE) @@ -750,7 +765,7 @@ pub const GUILE_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(GUILE_LITERAL.is_valid()); -/// Number format to parse a Guile float from string. +/// Number format to parse a `Guile` float from string. #[rustfmt::skip] pub const GUILE_STRING: Options = Options::builder() .nan_string(options::GUILE) @@ -759,7 +774,7 @@ pub const GUILE_STRING: Options = Options::builder() .build_unchecked(); const_assert!(GUILE_STRING.is_valid()); -/// Number format for a Clojure literal floating-point number. +/// Number format for a `Clojure` literal floating-point number. #[rustfmt::skip] pub const CLOJURE_LITERAL: Options = Options::builder() .nan_string(options::CLOJURE_LITERAL) @@ -768,7 +783,7 @@ pub const CLOJURE_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(CLOJURE_LITERAL.is_valid()); -/// Number format to parse a Clojure float from string. +/// Number format to parse a `Clojure` float from string. #[rustfmt::skip] pub const CLOJURE_STRING: Options = Options::builder() .inf_string(options::CLOJURE_STRING_INF) @@ -776,14 +791,14 @@ pub const CLOJURE_STRING: Options = Options::builder() .build_unchecked(); const_assert!(CLOJURE_STRING.is_valid()); -/// Number format for an Erlang literal floating-point number. +/// Number format for an `Erlang` literal floating-point number. #[rustfmt::skip] pub const ERLANG_LITERAL: Options = Options::builder() .nan_string(options::ERLANG_LITERAL_NAN) .build_unchecked(); const_assert!(ERLANG_LITERAL.is_valid()); -/// Number format to parse an Erlang float from string. +/// Number format to parse an `Erlang` float from string. #[rustfmt::skip] pub const ERLANG_STRING: Options = Options::builder() .nan_string(options::ERLANG_STRING) @@ -792,7 +807,7 @@ pub const ERLANG_STRING: Options = Options::builder() .build_unchecked(); const_assert!(ERLANG_STRING.is_valid()); -/// Number format for an Elm literal floating-point number. +/// Number format for an `Elm` literal floating-point number. #[rustfmt::skip] pub const ELM_LITERAL: Options = Options::builder() .nan_string(options::ELM_LITERAL) @@ -801,7 +816,7 @@ pub const ELM_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(ELM_LITERAL.is_valid()); -/// Number format to parse an Elm float from string. +/// Number format to parse an `Elm` float from string. #[rustfmt::skip] pub const ELM_STRING: Options = Options::builder() .nan_string(options::ELM_STRING_NAN) @@ -810,7 +825,7 @@ pub const ELM_STRING: Options = Options::builder() .build_unchecked(); const_assert!(ELM_STRING.is_valid()); -/// Number format for a Scala literal floating-point number. +/// Number format for a `Scala` literal floating-point number. #[rustfmt::skip] pub const SCALA_LITERAL: Options = Options::builder() .nan_string(options::SCALA_LITERAL) @@ -819,7 +834,7 @@ pub const SCALA_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(SCALA_LITERAL.is_valid()); -/// Number format to parse a Scala float from string. +/// Number format to parse a `Scala` float from string. #[rustfmt::skip] pub const SCALA_STRING: Options = Options::builder() .inf_string(options::SCALA_STRING_INF) @@ -827,7 +842,7 @@ pub const SCALA_STRING: Options = Options::builder() .build_unchecked(); const_assert!(SCALA_STRING.is_valid()); -/// Number format for an Elixir literal floating-point number. +/// Number format for an `Elixir` literal floating-point number. #[rustfmt::skip] pub const ELIXIR_LITERAL: Options = Options::builder() .nan_string(options::ELIXIR) @@ -836,7 +851,7 @@ pub const ELIXIR_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(ELIXIR_LITERAL.is_valid()); -/// Number format to parse an Elixir float from string. +/// Number format to parse an `Elixir` float from string. #[rustfmt::skip] pub const ELIXIR_STRING: Options = Options::builder() .nan_string(options::ELIXIR) @@ -845,7 +860,7 @@ pub const ELIXIR_STRING: Options = Options::builder() .build_unchecked(); const_assert!(ELIXIR_STRING.is_valid()); -/// Number format for a FORTRAN literal floating-point number. +/// Number format for a `FORTRAN` literal floating-point number. #[rustfmt::skip] pub const FORTRAN_LITERAL: Options = Options::builder() .nan_string(options::FORTRAN_LITERAL) @@ -854,7 +869,7 @@ pub const FORTRAN_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(FORTRAN_LITERAL.is_valid()); -/// Number format for a D literal floating-point number. +/// Number format for a `D` literal floating-point number. #[rustfmt::skip] pub const D_LITERAL: Options = Options::builder() .nan_string(options::D_LITERAL) @@ -863,7 +878,7 @@ pub const D_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(D_LITERAL.is_valid()); -/// Number format for a Coffeescript literal floating-point number. +/// Number format for a `Coffeescript` literal floating-point number. #[rustfmt::skip] pub const COFFEESCRIPT_LITERAL: Options = Options::builder() .inf_string(options::COFFEESCRIPT_INF) @@ -871,7 +886,7 @@ pub const COFFEESCRIPT_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(COFFEESCRIPT_LITERAL.is_valid()); -/// Number format to parse a Coffeescript float from string. +/// Number format to parse a `Coffeescript` float from string. #[rustfmt::skip] pub const COFFEESCRIPT_STRING: Options = Options::builder() .inf_string(options::COFFEESCRIPT_INF) @@ -879,7 +894,7 @@ pub const COFFEESCRIPT_STRING: Options = Options::builder() .build_unchecked(); const_assert!(COFFEESCRIPT_STRING.is_valid()); -/// Number format for a COBOL literal floating-point number. +/// Number format for a `COBOL` literal floating-point number. #[rustfmt::skip] pub const COBOL_LITERAL: Options = Options::builder() .nan_string(options::COBOL) @@ -888,7 +903,7 @@ pub const COBOL_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(COBOL_LITERAL.is_valid()); -/// Number format to parse a COBOL float from string. +/// Number format to parse a `COBOL` float from string. #[rustfmt::skip] pub const COBOL_STRING: Options = Options::builder() .nan_string(options::COBOL) @@ -897,7 +912,7 @@ pub const COBOL_STRING: Options = Options::builder() .build_unchecked(); const_assert!(COBOL_STRING.is_valid()); -/// Number format for an F# literal floating-point number. +/// Number format for an `F#` literal floating-point number. #[rustfmt::skip] pub const FSHARP_LITERAL: Options = Options::builder() .nan_string(options::FSHARP_LITERAL_NAN) @@ -915,7 +930,7 @@ pub const VB_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(VB_LITERAL.is_valid()); -/// Number format to parse a Visual Basic float from string. +/// Number format to parse a `Visual Basic` float from string. #[rustfmt::skip] pub const VB_STRING: Options = Options::builder() .inf_string(options::VB_STRING_INF) @@ -923,7 +938,7 @@ pub const VB_STRING: Options = Options::builder() .build_unchecked(); const_assert!(VB_STRING.is_valid()); -/// Number format for an OCaml literal floating-point number. +/// Number format for an `OCaml` literal floating-point number. #[rustfmt::skip] pub const OCAML_LITERAL: Options = Options::builder() .nan_string(options::OCAML_LITERAL_NAN) @@ -932,7 +947,7 @@ pub const OCAML_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(OCAML_LITERAL.is_valid()); -/// Number format for an Objective-C literal floating-point number. +/// Number format for an `Objective-C` literal floating-point number. #[rustfmt::skip] pub const OBJECTIVEC_LITERAL: Options = Options::builder() .nan_string(options::OBJECTIVEC) @@ -941,7 +956,7 @@ pub const OBJECTIVEC_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(OBJECTIVEC_LITERAL.is_valid()); -/// Number format to parse an Objective-C float from string. +/// Number format to parse an `Objective-C` float from string. #[rustfmt::skip] pub const OBJECTIVEC_STRING: Options = Options::builder() .nan_string(options::OBJECTIVEC) @@ -950,7 +965,7 @@ pub const OBJECTIVEC_STRING: Options = Options::builder() .build_unchecked(); const_assert!(OBJECTIVEC_STRING.is_valid()); -/// Number format for an ReasonML literal floating-point number. +/// Number format for an `ReasonML` literal floating-point number. #[rustfmt::skip] pub const REASONML_LITERAL: Options = Options::builder() .nan_string(options::REASONML_LITERAL_NAN) @@ -959,7 +974,7 @@ pub const REASONML_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(REASONML_LITERAL.is_valid()); -/// Number format for a MATLAB literal floating-point number. +/// Number format for a `MATLAB` literal floating-point number. #[rustfmt::skip] pub const MATLAB_LITERAL: Options = Options::builder() .inf_string(options::MATLAB_LITERAL_INF) @@ -967,7 +982,7 @@ pub const MATLAB_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(MATLAB_LITERAL.is_valid()); -/// Number format for a Zig literal floating-point number. +/// Number format for a `Zig` literal floating-point number. #[rustfmt::skip] pub const ZIG_LITERAL: Options = Options::builder() .nan_string(options::ZIG_LITERAL) @@ -976,7 +991,7 @@ pub const ZIG_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(ZIG_LITERAL.is_valid()); -/// Number format for a Safe literal floating-point number. +/// Number format for a `Sage` literal floating-point number. #[rustfmt::skip] pub const SAGE_LITERAL: Options = Options::builder() .inf_string(options::SAGE_LITERAL_INF) @@ -984,7 +999,7 @@ pub const SAGE_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(SAGE_LITERAL.is_valid()); -/// Number format for a JSON literal floating-point number. +/// Number format for a `JSON` literal floating-point number. #[rustfmt::skip] pub const JSON: Options = Options::builder() .nan_string(options::JSON) @@ -993,7 +1008,7 @@ pub const JSON: Options = Options::builder() .build_unchecked(); const_assert!(JSON.is_valid()); -/// Number format for a TOML literal floating-point number. +/// Number format for a `TOML` literal floating-point number. #[rustfmt::skip] pub const TOML: Options = Options::builder() .nan_string(options::TOML) @@ -1002,11 +1017,11 @@ pub const TOML: Options = Options::builder() .build_unchecked(); const_assert!(TOML.is_valid()); -/// Number format for a YAML literal floating-point number. +/// Number format for a `YAML` literal floating-point number. #[rustfmt::skip] pub const YAML: Options = JSON; -/// Number format for an XML literal floating-point number. +/// Number format for an `XML` literal floating-point number. #[rustfmt::skip] pub const XML: Options = Options::builder() .inf_string(options::XML_INF) @@ -1014,7 +1029,7 @@ pub const XML: Options = Options::builder() .build_unchecked(); const_assert!(XML.is_valid()); -/// Number format for a SQLite literal floating-point number. +/// Number format for a `SQLite` literal floating-point number. #[rustfmt::skip] pub const SQLITE: Options = Options::builder() .nan_string(options::SQLITE) @@ -1023,7 +1038,7 @@ pub const SQLITE: Options = Options::builder() .build_unchecked(); const_assert!(SQLITE.is_valid()); -/// Number format for a PostgreSQL literal floating-point number. +/// Number format for a `PostgreSQL` literal floating-point number. #[rustfmt::skip] pub const POSTGRESQL: Options = Options::builder() .nan_string(options::POSTGRESQL) @@ -1032,7 +1047,7 @@ pub const POSTGRESQL: Options = Options::builder() .build_unchecked(); const_assert!(POSTGRESQL.is_valid()); -/// Number format for a MySQL literal floating-point number. +/// Number format for a `MySQL` literal floating-point number. #[rustfmt::skip] pub const MYSQL: Options = Options::builder() .nan_string(options::MYSQL) @@ -1041,7 +1056,7 @@ pub const MYSQL: Options = Options::builder() .build_unchecked(); const_assert!(MYSQL.is_valid()); -/// Number format for a MongoDB literal floating-point number. +/// Number format for a `MongoDB` literal floating-point number. #[rustfmt::skip] pub const MONGODB: Options = Options::builder() .inf_string(options::MONGODB_INF) diff --git a/lexical-parse-float/src/parse.rs b/lexical-parse-float/src/parse.rs index cc704c03..e4acbb0d 100644 --- a/lexical-parse-float/src/parse.rs +++ b/lexical-parse-float/src/parse.rs @@ -195,7 +195,7 @@ pub fn parse_exponent_sign(byte: &mut Bytes<'_, FORMAT>) -> /// Utility to extract the result and handle any errors from parsing a `Number`. /// /// - `format` - The numberical format as a packed integer -/// - `byte` - The DigitsIter iterator +/// - `byte` - The `DigitsIter` iterator /// - `is_negative` - If the final value is negative /// - `parse_normal` - The function to parse non-special numbers with /// - `parse_special` - The function to parse special numbers with @@ -238,6 +238,7 @@ macro_rules! to_native { } /// Parse a float from bytes using a complete parser. +#[allow(clippy::missing_inline_in_public_items)] // reason = "only public for testing" pub fn parse_complete( bytes: &[u8], options: &Options, @@ -261,7 +262,7 @@ pub fn parse_complete( // Fallback to a slower, but always correct algorithm. If we have // lossy, we can't be here. if fp.exp < 0 { - debug_assert!(!options.lossy()); + debug_assert!(!options.lossy(), "lossy algorithms never use slow algorithms"); // Undo the invalid extended float biasing. fp.exp -= shared::INVALID_FP; fp = slow_path::(num, fp); @@ -272,6 +273,7 @@ pub fn parse_complete( } /// Parse a float using only the fast path as a complete parser. +#[allow(clippy::missing_inline_in_public_items)] // reason = "only public for testing" pub fn fast_path_complete( bytes: &[u8], options: &Options, @@ -288,6 +290,7 @@ pub fn fast_path_complete( } /// Parse a float from bytes using a partial parser. +#[allow(clippy::missing_inline_in_public_items)] // reason = "only public for testing" pub fn parse_partial( bytes: &[u8], options: &Options, @@ -318,7 +321,7 @@ pub fn parse_partial( // Fallback to a slower, but always correct algorithm. If we have // lossy, we can't be here. if fp.exp < 0 { - debug_assert!(!options.lossy()); + debug_assert!(!options.lossy(), "lossy algorithms never use slow algorithms"); // Undo the invalid extended float biasing. fp.exp -= shared::INVALID_FP; fp = slow_path::(num, fp); @@ -329,6 +332,7 @@ pub fn parse_partial( } /// Parse a float using only the fast path as a partial parser. +#[allow(clippy::missing_inline_in_public_items)] // reason = "only public for testing" pub fn fast_path_partial( bytes: &[u8], options: &Options, @@ -356,6 +360,7 @@ pub fn fast_path_partial( /// Wrapper for different moderate-path algorithms. /// A return exponent of `-1` indicates an invalid value. +#[must_use] #[inline(always)] pub fn moderate_path( num: &Number, @@ -418,6 +423,7 @@ pub fn moderate_path( /// Invoke the slow path. /// At this point, the float string has already been validated. +#[must_use] #[inline(always)] pub fn slow_path( num: Number, @@ -447,7 +453,11 @@ pub fn slow_path( /// This creates a representation of the float as the /// significant digits and the decimal exponent. #[cfg_attr(not(feature = "compact"), inline(always))] -#[allow(clippy::collapsible_if, unused_mut)] +#[allow(unused_mut)] // reason = "used when format is enabled" +#[allow(clippy::unwrap_used)] // reason = "developper error if we incorrectly assume an overflow" +#[allow(clippy::collapsible_if)] // reason = "more readable uncollapsed" +#[allow(clippy::cast_possible_wrap)] // reason = "no hardware supports buffers >= i64::MAX" +#[allow(clippy::too_many_lines)] // reason = "function is one logical entity" pub fn parse_partial_number<'a, const FORMAT: u128>( mut byte: Bytes<'a, FORMAT>, is_negative: bool, @@ -484,8 +494,8 @@ pub fn parse_partial_number<'a, const FORMAT: u128>( let format = NumberFormat::<{ FORMAT }> {}; let decimal_point = options.decimal_point(); let exponent_character = options.exponent(); - debug_assert!(format.is_valid()); - debug_assert!(!byte.is_buffer_empty()); + debug_assert!(format.is_valid(), "should have already checked for an invalid number format"); + debug_assert!(!byte.is_buffer_empty(), "should have previously checked for empty input"); let bits_per_digit = shared::log2(format.mantissa_radix()) as i64; let bits_per_base = shared::log2(format.exponent_base()) as i64; @@ -516,7 +526,7 @@ pub fn parse_partial_number<'a, const FORMAT: u128>( #[cfg(not(feature = "compact"))] parse_8digits::<_, FORMAT>(byte.integer_iter(), &mut mantissa); parse_digits::<_, _, FORMAT>(byte.integer_iter(), |digit| { - mantissa = mantissa.wrapping_mul(format.radix() as _).wrapping_add(digit as _); + mantissa = mantissa.wrapping_mul(format.radix() as u64).wrapping_add(digit as u64); }); let mut n_digits = byte.current_count() - start.current_count(); #[cfg(feature = "format")] @@ -525,6 +535,10 @@ pub fn parse_partial_number<'a, const FORMAT: u128>( } // Store the integer digits for slow-path algorithms. + debug_assert!( + n_digits <= start.as_slice().len(), + "number of digits parsed must <= buffer length" + ); // SAFETY: safe, since `n_digits <= start.as_slice().len()`. // This is since `byte.len() >= start.len()` but has to have // the same end bounds (that is, `start = byte.clone()`), so @@ -534,7 +548,6 @@ pub fn parse_partial_number<'a, const FORMAT: u128>( // NOTE: Removing this code leads to ~10% reduction in parsing // that triggers the Eisell-Lemire algorithm or the digit comp // algorithms, so don't remove the unsafe indexing. - debug_assert!(n_digits <= start.as_slice().len()); let integer_digits = unsafe { start.as_slice().get_unchecked(..n_digits) }; // Check if integer leading zeros are disabled. @@ -560,13 +573,16 @@ pub fn parse_partial_number<'a, const FORMAT: u128>( #[cfg(not(feature = "compact"))] parse_8digits::<_, FORMAT>(byte.fraction_iter(), &mut mantissa); parse_digits::<_, _, FORMAT>(byte.fraction_iter(), |digit| { - mantissa = mantissa.wrapping_mul(format.radix() as _).wrapping_add(digit as _); + mantissa = mantissa.wrapping_mul(format.radix() as u64).wrapping_add(digit as u64); }); n_after_dot = byte.current_count() - before.current_count(); // Store the fraction digits for slow-path algorithms. + debug_assert!( + n_after_dot <= before.as_slice().len(), + "digits after dot must be smaller than buffer" + ); // SAFETY: safe, since `n_after_dot <= before.as_slice().len()`. - debug_assert!(n_after_dot <= before.as_slice().len()); fraction_digits = Some(unsafe { before.as_slice().get_unchecked(..n_after_dot) }); // Calculate the implicit exponent: the number of digits after the dot. @@ -574,7 +590,7 @@ pub fn parse_partial_number<'a, const FORMAT: u128>( if format.mantissa_radix() == format.exponent_base() { exponent = implicit_exponent; } else { - debug_assert!(bits_per_digit % bits_per_base == 0); + debug_assert!(bits_per_digit % bits_per_base == 0, "exponent must be a power of base"); exponent = implicit_exponent * bits_per_digit / bits_per_base; }; #[cfg(feature = "format")] @@ -611,7 +627,7 @@ pub fn parse_partial_number<'a, const FORMAT: u128>( } } - let is_negative = parse_exponent_sign(&mut byte)?; + let is_negative_exponent = parse_exponent_sign(&mut byte)?; let before = byte.current_count(); parse_digits::<_, _, FORMAT>(byte.exponent_iter(), |digit| { if explicit_exponent < 0x10000000 { @@ -623,7 +639,7 @@ pub fn parse_partial_number<'a, const FORMAT: u128>( return Err(Error::EmptyExponent(byte.cursor())); } // Handle our sign, and get the explicit part of the exponent. - explicit_exponent = if is_negative { + explicit_exponent = if is_negative_exponent { -explicit_exponent } else { explicit_exponent @@ -719,7 +735,7 @@ pub fn parse_partial_number<'a, const FORMAT: u128>( if format.mantissa_radix() == format.exponent_base() { exponent = implicit_exponent; } else { - debug_assert!(bits_per_digit % bits_per_base == 0); + debug_assert!(bits_per_digit % bits_per_base == 0, "exponent must be a power of base"); exponent = implicit_exponent * bits_per_digit / bits_per_base; }; // Add back the explicit exponent. @@ -789,7 +805,7 @@ where let format = NumberFormat::<{ FORMAT }> {}; let radix: u64 = format.radix() as u64; if can_try_parse_multidigit!(iter, radix) { - debug_assert!(radix < 16); + debug_assert!(radix < 16, "radices over 16 will overflow with radix^8"); let radix8 = format.radix8() as u64; // Can do up to 2 iterations without overflowing, however, for large // inputs, this is much faster than any other alternative. @@ -818,7 +834,7 @@ pub fn parse_u64_digits<'a, Iter, const FORMAT: u128>( // Try to parse 8 digits at a time, if we can. #[cfg(not(feature = "compact"))] if can_try_parse_multidigit!(iter, radix) { - debug_assert!(radix < 16); + debug_assert!(radix < 16, "radices over 16 will overflow with radix^8"); let radix8 = format.radix8() as u64; while *step > 8 { if let Some(v) = algorithm::try_parse_8digits::(&mut iter) { @@ -849,6 +865,7 @@ pub fn parse_u64_digits<'a, Iter, const FORMAT: u128>( /// Determine if the input data matches the special string. /// If there's no match, returns 0. Otherwise, returns the byte's cursor. +#[must_use] #[inline(always)] pub fn is_special_eq(mut byte: Bytes, string: &'static [u8]) -> usize { let format = NumberFormat::<{ FORMAT }> {}; @@ -867,6 +884,7 @@ pub fn is_special_eq(mut byte: Bytes, string: &'stat } /// Parse a positive representation of a special, non-finite float. +#[must_use] #[cfg_attr(not(feature = "compact"), inline(always))] pub fn parse_positive_special( byte: Bytes, @@ -911,6 +929,7 @@ where } /// Parse a partial representation of a special, non-finite float. +#[must_use] #[inline(always)] pub fn parse_partial_special( byte: Bytes, @@ -928,6 +947,7 @@ where } /// Try to parse a special, non-finite float. +#[must_use] #[inline(always)] pub fn parse_special( byte: Bytes, diff --git a/lexical-parse-float/src/shared.rs b/lexical-parse-float/src/shared.rs index 9933c832..29f64fd6 100644 --- a/lexical-parse-float/src/shared.rs +++ b/lexical-parse-float/src/shared.rs @@ -134,6 +134,7 @@ where /// ret /// ``` #[cfg_attr(not(feature = "compact"), inline(always))] +#[allow(clippy::unwrap_used)] // reason="yi cannot be none due to previous check" pub fn starts_with_uncased<'a, 'b, Iter1, Iter2>(mut x: Iter1, mut y: Iter2) -> bool where Iter1: Iterator, @@ -224,9 +225,9 @@ where /// Shift right N-bytes and round towards a direction. /// /// Callback should take the following parameters: -/// 1. is_odd -/// 1. is_halfway -/// 1. is_above +/// 1. `is_odd` +/// 1. `is_halfway` +/// 1. `is_above` #[cfg_attr(not(feature = "compact"), inline(always))] pub fn round_nearest_tie_even(fp: &mut ExtendedFloat80, shift: i32, cb: Cb) where diff --git a/lexical-parse-float/src/slow.rs b/lexical-parse-float/src/slow.rs index f614afa8..db57e209 100644 --- a/lexical-parse-float/src/slow.rs +++ b/lexical-parse-float/src/slow.rs @@ -44,14 +44,16 @@ use crate::shared; /// any value before or equal to `16777217.0` must be rounded down /// to `16777216.0`. These near-halfway conversions therefore may require /// a large number of digits to unambiguously determine how to round. +#[must_use] #[inline(always)] +#[allow(clippy::unwrap_used)] // reason = "none is a developper error" pub fn slow_radix( num: Number, fp: ExtendedFloat80, ) -> ExtendedFloat80 { // Ensure our preconditions are valid: // 1. The significant digits are not shifted into place. - debug_assert!(fp.mant & (1 << 63) != 0); + debug_assert!(fp.mant & (1 << 63) != 0, "number must be normalized"); let format = NumberFormat::<{ FORMAT }> {}; @@ -95,7 +97,9 @@ pub fn slow_radix( /// exponent relative to the significant digits, we scale the real /// digits to the theoretical digits for `b` and determine if we /// need to round-up. +#[must_use] #[inline(always)] +#[allow(clippy::cast_possible_wrap)] // reason = "the value range is [-324, 308]" pub fn digit_comp( num: Number, fp: ExtendedFloat80, @@ -114,6 +118,10 @@ pub fn digit_comp( /// Generate the significant digits with a positive exponent relative to /// mantissa. +#[must_use] +#[allow(clippy::unwrap_used)] // reason = "none is a developper error" +#[allow(clippy::cast_possible_wrap)] // reason = "can't wrap in practice: max is ~1000 limbs" +#[allow(clippy::missing_inline_in_public_items)] // reason = "only public for testing" pub fn positive_digit_comp( mut bigmant: Bigint, exponent: i32, @@ -166,7 +174,10 @@ pub fn positive_digit_comp( /// /// This allows us to compare both floats using integers efficiently /// without any loss of precision. -#[allow(clippy::comparison_chain)] +#[allow(clippy::match_bool)] // reason = "simplifies documentation" +#[allow(clippy::unwrap_used)] // reason = "unwrap panics if a developer error" +#[allow(clippy::comparison_chain)] // reason = "logically different conditions for algorithm" +#[allow(clippy::missing_inline_in_public_items)] // reason = "only exposed for unittesting" pub fn negative_digit_comp( bigmant: Bigint, mut fp: ExtendedFloat80, @@ -174,7 +185,7 @@ pub fn negative_digit_comp( ) -> ExtendedFloat80 { // Ensure our preconditions are valid: // 1. The significant digits are not shifted into place. - debug_assert!(fp.mant & (1 << 63) != 0); + debug_assert!(fp.mant & (1 << 63) != 0, "the significant digits must be normalized"); let format = NumberFormat:: {}; let radix = format.radix(); @@ -182,7 +193,7 @@ pub fn negative_digit_comp( // Get the significant digits and radix exponent for the real digits. let mut real_digits = bigmant; let real_exp = exponent; - debug_assert!(real_exp < 0); + debug_assert!(real_exp < 0, "algorithm only works with negative numbers"); // Round down our extended-precision float and calculate `b`. let mut b = fp; @@ -320,7 +331,6 @@ macro_rules! add_temporary { // Add a temporary where we won't read the counter results internally. (@end $format:ident, $result:ident, $counter:ident, $value:ident) => { if $counter != 0 { - // SAFETY: safe, since `counter <= step`, or smaller than the table size. let small_power = f64::int_pow_fast_path($counter, $format.radix()); add_temporary!(@mul $result, small_power as Limb, $value); } @@ -386,6 +396,9 @@ macro_rules! round_up_nonzero { /// /// Returns the parsed mantissa and the number of digits in the mantissa. /// The max digits is the maximum number of digits plus one. +#[must_use] +#[allow(clippy::cognitive_complexity)] // reason = "complexity broken into macros" +#[allow(clippy::missing_inline_in_public_items)] // reason = "only public for testing" pub fn parse_mantissa(num: Number, max_digits: usize) -> (Bigint, usize) { let format = NumberFormat:: {}; let radix = format.radix(); @@ -432,7 +445,7 @@ pub fn parse_mantissa(num: Number, max_digits: usize) -> (Bi round_up_nonzero!(format, integer_iter, result, count); if let Some(fraction) = num.fraction { let mut fraction = fraction.bytes::(); - round_up_nonzero!(format, fraction.fraction_iter(), result, count) + round_up_nonzero!(format, fraction.fraction_iter(), result, count); } return (result, count); } else { @@ -574,7 +587,8 @@ macro_rules! fraction_compare { /// Adapted from "Bigcomp: Deciding Truncated, Near Halfway Conversions", /// available [here](https://www.exploringbinary.com/bigcomp-deciding-truncated-near-halfway-conversions/). #[cfg(feature = "radix")] -#[allow(clippy::comparison_chain)] +#[allow(clippy::unwrap_used)] // reason = "none is a developper error due to shl overflow" +#[allow(clippy::comparison_chain)] // reason = "logically different conditions for algorithm" pub fn byte_comp( number: Number, mut fp: ExtendedFloat80, @@ -672,6 +686,7 @@ pub fn byte_comp( /// - `den` - The theoretical digits created by `b+h` to determine if `b` or /// `b+1` #[cfg(feature = "radix")] +#[allow(clippy::unwrap_used)] // reason = "none is a developper error due to a missing fraction" pub fn compare_bytes( number: Number, mut num: Bigfloat, @@ -712,6 +727,7 @@ pub fn compare_bytes( /// Calculate the scientific exponent from a `Number` value. /// Any other attempts would require slowdowns for faster algorithms. +#[must_use] #[inline(always)] pub fn scientific_exponent(num: &Number) -> i32 { // This has the significant digits and exponent relative to those @@ -744,6 +760,7 @@ pub fn scientific_exponent(num: &Number) -> i32 { } /// Calculate `b` from a a representation of `b` as a float. +#[must_use] #[inline(always)] pub fn b(float: F) -> ExtendedFloat80 { ExtendedFloat80 { @@ -753,6 +770,7 @@ pub fn b(float: F) -> ExtendedFloat80 { } /// Calculate `b+h` from a a representation of `b` as a float. +#[must_use] #[inline(always)] pub fn bh(float: F) -> ExtendedFloat80 { let fp = b(float); @@ -765,6 +783,7 @@ pub fn bh(float: F) -> ExtendedFloat80 { // NOTE: There will never be binary factors here. /// Calculate the integral ceiling of the binary factor from a basen number. +#[must_use] #[inline(always)] #[cfg(feature = "radix")] pub const fn integral_binary_factor(radix: u32) -> u32 { @@ -805,6 +824,7 @@ pub const fn integral_binary_factor(radix: u32) -> u32 { } /// Calculate the integral ceiling of the binary factor from a basen number. +#[must_use] #[inline(always)] #[cfg(not(feature = "radix"))] pub const fn integral_binary_factor(radix: u32) -> u32 { diff --git a/lexical-parse-float/src/table_decimal.rs b/lexical-parse-float/src/table_decimal.rs index 173430cd..39505f1f 100644 --- a/lexical-parse-float/src/table_decimal.rs +++ b/lexical-parse-float/src/table_decimal.rs @@ -13,6 +13,7 @@ use crate::limits::{f32_exponent_limit, f64_exponent_limit, f64_mantissa_limit, // ------- /// Get lookup table for small int powers. +#[must_use] #[inline(always)] #[cfg(not(feature = "power-of-two"))] pub const fn get_small_int_power(exponent: usize, radix: u32) -> u64 { @@ -25,48 +26,56 @@ pub const fn get_small_int_power(exponent: usize, radix: u32) -> u64 { } /// Get lookup table for small f32 powers. +#[must_use] #[inline(always)] #[cfg(not(feature = "power-of-two"))] -pub fn get_small_f32_power(exponent: usize, radix: u32) -> f32 { +pub const fn get_small_f32_power(exponent: usize, radix: u32) -> f32 { _ = radix; get_small_f32_power10(exponent) } /// Get lookup table for small f64 powers. +#[must_use] #[inline(always)] #[cfg(not(feature = "power-of-two"))] -pub fn get_small_f64_power(exponent: usize, radix: u32) -> f64 { +pub const fn get_small_f64_power(exponent: usize, radix: u32) -> f64 { _ = radix; get_small_f64_power10(exponent) } /// Get pre-computed power for a large power of radix. +#[must_use] +#[inline(always)] #[cfg(not(feature = "radix"))] pub const fn get_large_int_power(_: u32) -> (&'static [Limb], u32) { (&LARGE_POW5, LARGE_POW5_STEP) } /// Get pre-computed int power of 5. +#[must_use] #[inline(always)] pub const fn get_small_int_power5(exponent: usize) -> u64 { SMALL_INT_POW5[exponent] } /// Get pre-computed int power of 10. +#[must_use] #[inline(always)] pub const fn get_small_int_power10(exponent: usize) -> u64 { SMALL_INT_POW10[exponent] } /// Get pre-computed f32 power of 10. +#[must_use] #[inline(always)] -pub fn get_small_f32_power10(exponent: usize) -> f32 { +pub const fn get_small_f32_power10(exponent: usize) -> f32 { SMALL_F32_POW10[exponent] } /// Get pre-computed f64 power of 10. +#[must_use] #[inline(always)] -pub fn get_small_f64_power10(exponent: usize) -> f64 { +pub const fn get_small_f64_power10(exponent: usize) -> f64 { SMALL_F64_POW10[exponent] } diff --git a/lexical-parse-float/src/table_lemire.rs b/lexical-parse-float/src/table_lemire.rs index 110e1dab..7d2f8e01 100644 --- a/lexical-parse-float/src/table_lemire.rs +++ b/lexical-parse-float/src/table_lemire.rs @@ -11,6 +11,7 @@ #![doc(hidden)] #![cfg(not(feature = "compact"))] +#![allow(clippy::unreadable_literal)] // reason="these are auto-generated" pub const SMALLEST_POWER_OF_FIVE: i32 = -342; pub const LARGEST_POWER_OF_FIVE: i32 = 308; diff --git a/lexical-parse-float/src/table_radix.rs b/lexical-parse-float/src/table_radix.rs index 32e84cd2..58cbac81 100644 --- a/lexical-parse-float/src/table_radix.rs +++ b/lexical-parse-float/src/table_radix.rs @@ -3,7 +3,7 @@ #![cfg(feature = "radix")] #![cfg(not(feature = "compact"))] #![doc(hidden)] -#![allow(clippy::excessive_precision)] +#![allow(clippy::excessive_precision)] // reason = "auto-generated values that need to be exact" use lexical_util::assert::debug_assert_radix; use static_assertions::const_assert; diff --git a/lexical-parse-float/tests/stackvec_tests.rs b/lexical-parse-float/tests/stackvec_tests.rs index 11876c81..40fff904 100644 --- a/lexical-parse-float/tests/stackvec_tests.rs +++ b/lexical-parse-float/tests/stackvec_tests.rs @@ -431,29 +431,29 @@ fn shl_limbs_test() { fn shl_test() { // Pattern generated via `''.join(["1" +"0"*i for i in range(20)])` let mut x = VecType::from_u32(0xD2210408); - bigint::shl(&mut x, 5); + bigint::shl(&mut x, 5).unwrap(); let expected: VecType = vec_from_u32(&[0x44208100, 0x1A]); assert_eq!(&*x, &*expected); - bigint::shl(&mut x, 32); + bigint::shl(&mut x, 32).unwrap(); let expected: VecType = vec_from_u32(&[0, 0x44208100, 0x1A]); assert_eq!(&*x, &*expected); - bigint::shl(&mut x, 27); + bigint::shl(&mut x, 27).unwrap(); let expected: VecType = vec_from_u32(&[0, 0, 0xD2210408]); assert_eq!(&*x, &*expected); // 96-bits of previous pattern let mut x: VecType = vec_from_u32(&[0x20020010, 0x8040100, 0xD2210408]); - bigint::shl(&mut x, 5); + bigint::shl(&mut x, 5).unwrap(); let expected: VecType = vec_from_u32(&[0x400200, 0x802004, 0x44208101, 0x1A]); assert_eq!(&*x, &*expected); - bigint::shl(&mut x, 32); + bigint::shl(&mut x, 32).unwrap(); let expected: VecType = vec_from_u32(&[0, 0x400200, 0x802004, 0x44208101, 0x1A]); assert_eq!(&*x, &*expected); - bigint::shl(&mut x, 27); + bigint::shl(&mut x, 27).unwrap(); let expected: VecType = vec_from_u32(&[0, 0, 0x20020010, 0x8040100, 0xD2210408]); assert_eq!(&*x, &*expected); } diff --git a/lexical-parse-integer/src/api.rs b/lexical-parse-integer/src/api.rs index 5cc08ebb..98dda514 100644 --- a/lexical-parse-integer/src/api.rs +++ b/lexical-parse-integer/src/api.rs @@ -8,7 +8,7 @@ use lexical_util::{from_lexical, from_lexical_with_options}; use crate::options::{Options, STANDARD as DEFAULT_OPTIONS}; use crate::parse::ParseInteger; -/// Implement FromLexical for numeric type. +/// Implement `FromLexical` for numeric type. /// /// Need to inline these, otherwise codegen is suboptimal. /// For some reason, it can't determine some of the const evaluations diff --git a/lexical-parse-integer/src/lib.rs b/lexical-parse-integer/src/lib.rs index a046192f..a89b59e4 100644 --- a/lexical-parse-integer/src/lib.rs +++ b/lexical-parse-integer/src/lib.rs @@ -55,11 +55,38 @@ //! - [Benchmarks](https://github.com/Alexhuszagh/rust-lexical/blob/main/lexical-parse-integer/docs/Benchmarks.md) //! - [Comprehensive Benchmarks](https://github.com/Alexhuszagh/lexical-benchmarks) +// FIXME: Implement clippy/allow reasons once we drop support for 1.80.0 and below +// Clippy reasons were stabilized in 1.81.0. + // We want to have the same safety guarantees as Rust core, // so we allow unused unsafe to clearly document safety guarantees. #![allow(unused_unsafe)] #![cfg_attr(feature = "lint", warn(unsafe_op_in_unsafe_fn))] #![cfg_attr(not(feature = "std"), no_std)] +#![deny( + clippy::doc_markdown, + clippy::unnecessary_safety_comment, + clippy::semicolon_if_nothing_returned, + clippy::unwrap_used, + clippy::as_underscore, + clippy::doc_markdown +)] +#![allow( + // used when concepts are logically separate + clippy::match_same_arms, + // loss of precision is intentional + clippy::integer_division, + // mathematical names use 1-character identifiers + clippy::min_ident_chars, + // these are not cryptographically secure contexts + clippy::integer_division_remainder_used, + // this can be intentional + clippy::module_name_repetitions, + // this is intentional: already passing a pointer and need performance + clippy::needless_pass_by_value, + // we use this for inline formatting for unsafe blocks + clippy::semicolon_inside_block, +)] pub mod algorithm; pub mod options; diff --git a/lexical-parse-integer/src/options.rs b/lexical-parse-integer/src/options.rs index 34cb45eb..6015a427 100644 --- a/lexical-parse-integer/src/options.rs +++ b/lexical-parse-integer/src/options.rs @@ -100,6 +100,7 @@ pub struct Options { impl Options { /// Create options with default values. + #[must_use] #[inline(always)] pub const fn new() -> Self { Self::builder().build_unchecked() @@ -129,13 +130,13 @@ impl Options { // BUILDERS - /// Get OptionsBuilder as a static function. + /// Get `OptionsBuilder` as a static function. #[inline(always)] pub const fn builder() -> OptionsBuilder { OptionsBuilder::new() } - /// Create OptionsBuilder using existing values. + /// Create `OptionsBuilder` using existing values. #[inline(always)] pub const fn rebuild(&self) -> OptionsBuilder { OptionsBuilder { diff --git a/lexical-util/src/api.rs b/lexical-util/src/api.rs index 5e510a17..771285bf 100644 --- a/lexical-util/src/api.rs +++ b/lexical-util/src/api.rs @@ -7,7 +7,7 @@ // FROM LEXICAL -/// Define FromLexical trait. +/// Define `FromLexical` trait. #[macro_export] #[cfg(feature = "parse")] macro_rules! from_lexical { @@ -39,7 +39,7 @@ macro_rules! from_lexical { }; } -/// Define FromLexicalWithOptions trait. +/// Define `FromLexicalWithOptions` trait. #[macro_export] #[cfg(feature = "parse")] macro_rules! from_lexical_with_options { @@ -107,7 +107,7 @@ macro_rules! from_lexical_with_options { // TO LEXICAL -/// Define ToLexical trait. +/// Define `ToLexical` trait. #[macro_export] #[cfg(feature = "write")] macro_rules! to_lexical { @@ -145,7 +145,7 @@ macro_rules! to_lexical { }; } -/// Define ToLexicalWithOptions trait. +/// Define `ToLexicalWithOptions` trait. #[macro_export] #[cfg(feature = "write")] macro_rules! to_lexical_with_options { diff --git a/lexical-util/src/div128.rs b/lexical-util/src/div128.rs index aed2caf8..7922ba36 100644 --- a/lexical-util/src/div128.rs +++ b/lexical-util/src/div128.rs @@ -52,7 +52,7 @@ use crate::mul::mulhi; /// Therefore, the `shr` is `log2(radix) * digits`, and the mask is just the /// lower `shr` bits of the digits. #[inline(always)] -#[allow(clippy::many_single_char_names)] +#[allow(clippy::many_single_char_names)] // reason="mathematical names" pub const fn pow2_u128_divrem(n: u128, mask: u64, shr: u32) -> (u128, u64) { let quot = n >> shr; let rem = mask & n as u64; @@ -62,7 +62,7 @@ pub const fn pow2_u128_divrem(n: u128, mask: u64, shr: u32) -> (u128, u64) { /// Fast division/remainder algorithm for u128, without a fast native /// approximation. #[inline(always)] -#[allow(clippy::many_single_char_names)] +#[allow(clippy::many_single_char_names)] // reason="mathematical names" pub fn fast_u128_divrem( n: u128, d: u64, @@ -83,7 +83,7 @@ pub fn fast_u128_divrem( /// Fast division/remainder algorithm for u128, without a fast native /// approximation. #[inline(always)] -#[allow(clippy::many_single_char_names)] +#[allow(clippy::many_single_char_names)] // reason="mathematical names" pub fn moderate_u128_divrem(n: u128, d: u64, factor: u128, factor_shr: u32) -> (u128, u64) { let quot = mulhi::(n, factor) >> factor_shr; let rem = (n - quot * d as u128) as u64; @@ -99,7 +99,7 @@ pub fn moderate_u128_divrem(n: u128, d: u64, factor: u128, factor_shr: u32) -> ( /// in the above paper, but this is a suitable fallback when we cannot use /// the faster algorithm. #[cfg_attr(not(feature = "compact"), inline(always))] -#[allow(clippy::many_single_char_names)] +#[allow(clippy::many_single_char_names)] // reason="mathematical names" pub fn slow_u128_divrem(n: u128, d: u64, d_ctlz: u32) -> (u128, u64) { // Ensure we have the correct number of leading zeros passed. debug_assert_eq!(d_ctlz, d.leading_zeros()); @@ -154,9 +154,9 @@ pub fn slow_u128_divrem(n: u128, d: u64, d_ctlz: u32) -> (u128, u64) { /// /// This returns the quotient and the remainder. /// For the number of digits processed, see -/// [min_step](crate::step::min_step). +/// [`min_step`](crate::step::min_step). #[inline(always)] -#[allow(clippy::needless_return)] +#[allow(clippy::needless_return)] // reason="required based on radix configuration" pub fn u128_divrem(n: u128, radix: u32) -> (u128, u64) { debug_assert_radix(radix); diff --git a/lexical-util/src/feature_format.rs b/lexical-util/src/feature_format.rs index 256bf0fc..350eac50 100644 --- a/lexical-util/src/feature_format.rs +++ b/lexical-util/src/feature_format.rs @@ -703,7 +703,7 @@ use crate::error::Error; use crate::format_builder::NumberFormatBuilder; use crate::format_flags as flags; -/// Add multiple flags to SyntaxFormat. +/// Add multiple flags to `SyntaxFormat`. macro_rules! from_flag { ($format:ident, $flag:ident) => {{ $format & flags::$flag != 0 @@ -734,7 +734,7 @@ impl NumberFormat { } /// Get the error type from the format. - #[allow(clippy::if_same_then_else)] + #[allow(clippy::if_same_then_else)] // reason="all are different logic conditions" pub const fn error(&self) -> Error { if !flags::is_valid_radix(self.mantissa_radix()) { Error::InvalidMantissaRadix @@ -1281,7 +1281,7 @@ impl Default for NumberFormat { // passes test 0, and has no digit separator. // RUST LITERAL [4569ABFGHIJKMN-_] -/// Number format for a Rust literal floating-point number. +/// Number format for a `Rust` literal floating-point number. #[rustfmt::skip] pub const RUST_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -1296,28 +1296,28 @@ pub const RUST_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ RUST_LITERAL }> {}.is_valid()); // RUST STRING [0134567MN] -/// Number format to parse a Rust float from string. +/// Number format to parse a `Rust` float from string. #[rustfmt::skip] pub const RUST_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ RUST_STRING }> {}.is_valid()); -/// Number format for a Python literal floating-point number. +/// Number format for a `Python` literal floating-point number. pub const PYTHON_LITERAL: u128 = PYTHON3_LITERAL; -/// Number format to parse a Python float from string. +/// Number format to parse a `Python` float from string. pub const PYTHON_STRING: u128 = PYTHON3_STRING; -/// Number format for a Python3 literal floating-point number. +/// Number format for a `Python3` literal floating-point number. pub const PYTHON3_LITERAL: u128 = PYTHON36_LITERAL; // PYTHON3 STRING [0134567MN] -/// Number format to parse a Python3 float from string. +/// Number format to parse a `Python3` float from string. #[rustfmt::skip] pub const PYTHON3_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ PYTHON3_STRING }> {}.is_valid()); // PYTHON3.6+ LITERAL [013456N-_] -/// Number format for a Python3.6 or higher literal floating-point number. +/// Number format for a `Python3.6` or higher literal floating-point number. #[rustfmt::skip] pub const PYTHON36_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -1329,7 +1329,7 @@ pub const PYTHON36_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ PYTHON36_LITERAL }> {}.is_valid()); // PYTHON3.5- LITERAL [013456N] -/// Number format for a Python3.5 or lower literal floating-point number. +/// Number format for a `Python3.5` or lower literal floating-point number. #[rustfmt::skip] pub const PYTHON35_LITERAL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -1339,7 +1339,7 @@ pub const PYTHON35_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ PYTHON35_LITERAL }> {}.is_valid()); // PYTHON2 LITERAL [013456MN] -/// Number format for a Python2 literal floating-point number. +/// Number format for a `Python2` literal floating-point number. #[rustfmt::skip] pub const PYTHON2_LITERAL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -1348,27 +1348,27 @@ pub const PYTHON2_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ PYTHON2_LITERAL }> {}.is_valid()); // PYTHON2 STRING [0134567MN] -/// Number format to parse a Python2 float from string. +/// Number format to parse a `Python2` float from string. #[rustfmt::skip] pub const PYTHON2_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ PYTHON2_STRING }> {}.is_valid()); -/// Number format for a C++ literal floating-point number. +/// Number format for a `C++` literal floating-point number. pub const CXX_LITERAL: u128 = CXX20_LITERAL; -/// Number format to parse a C++ float from string. +/// Number format to parse a `C++` float from string. pub const CXX_STRING: u128 = CXX20_STRING; -/// Number format for a C++ literal hexadecimal floating-point number. +/// Number format for a `C++` literal hexadecimal floating-point number. #[cfg(feature = "power-of-two")] pub const CXX_HEX_LITERAL: u128 = CXX20_HEX_LITERAL; -/// Number format to parse a C++ hexadecimal float from string. +/// Number format to parse a `C++` hexadecimal float from string. #[cfg(feature = "power-of-two")] pub const CXX_HEX_STRING: u128 = CXX20_HEX_STRING; // C++20 LITERAL [013456789ABMN-'] -/// Number format for a C++20 literal floating-point number. +/// Number format for a `C++20` literal floating-point number. #[rustfmt::skip] pub const CXX20_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'\'')) @@ -1379,13 +1379,13 @@ pub const CXX20_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX20_LITERAL }> {}.is_valid()); // C++20 STRING [0134567MN] -/// Number format for a C++20 string floating-point number. +/// Number format for a `C++20` string floating-point number. #[rustfmt::skip] pub const CXX20_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ CXX20_STRING }> {}.is_valid()); // C++20 HEX LITERAL [013456789ABMN-'] -/// Number format for a C++20 literal hexadecimal floating-point number. +/// Number format for a `C++20` literal hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const CXX20_HEX_LITERAL: u128 = NumberFormatBuilder::new() @@ -1402,7 +1402,7 @@ pub const CXX20_HEX_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX20_HEX_LITERAL }> {}.is_valid()); // C++20 HEX STRING [0134567MN] -/// Number format for a C++20 string hexadecimal floating-point number. +/// Number format for a `C++20` string hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const CXX20_HEX_STRING: u128 = NumberFormatBuilder::new() @@ -1415,7 +1415,7 @@ pub const CXX20_HEX_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX20_HEX_STRING }> {}.is_valid()); // C++17 LITERAL [013456789ABMN-'] -/// Number format for a C++17 literal floating-point number. +/// Number format for a `C++17` literal floating-point number. #[rustfmt::skip] pub const CXX17_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'\'')) @@ -1426,13 +1426,13 @@ pub const CXX17_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX17_LITERAL }> {}.is_valid()); // C++17 STRING [0134567MN] -/// Number format for a C++17 string floating-point number. +/// Number format for a `C++17` string floating-point number. #[rustfmt::skip] pub const CXX17_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ CXX17_STRING }> {}.is_valid()); // C++17 HEX LITERAL [013456789ABMN-'] -/// Number format for a C++17 literal hexadecimal floating-point number. +/// Number format for a `C++17` literal hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const CXX17_HEX_LITERAL: u128 = NumberFormatBuilder::new() @@ -1449,7 +1449,7 @@ pub const CXX17_HEX_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX17_HEX_LITERAL }> {}.is_valid()); // C++17 HEX STRING [0134567MN] -/// Number format for a C++17 string hexadecimal floating-point number. +/// Number format for a `C++17` string hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const CXX17_HEX_STRING: u128 = NumberFormatBuilder::new() @@ -1462,7 +1462,7 @@ pub const CXX17_HEX_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX17_HEX_STRING }> {}.is_valid()); // C++14 LITERAL [013456789ABMN-'] -/// Number format for a C++14 literal floating-point number. +/// Number format for a `C++14` literal floating-point number. #[rustfmt::skip] pub const CXX14_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'\'')) @@ -1473,13 +1473,13 @@ pub const CXX14_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX14_LITERAL }> {}.is_valid()); // C++14 STRING [0134567MN] -/// Number format for a C++14 string floating-point number. +/// Number format for a `C++14` string floating-point number. #[rustfmt::skip] pub const CXX14_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ CXX14_STRING }> {}.is_valid()); // C++14 HEX STRING [0134567MN] -/// Number format for a C++14 string hexadecimal floating-point number. +/// Number format for a `C++14` string hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const CXX14_HEX_STRING: u128 = NumberFormatBuilder::new() @@ -1492,7 +1492,7 @@ pub const CXX14_HEX_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX14_HEX_STRING }> {}.is_valid()); // C++11 LITERAL [01345678MN] -/// Number format for a C++11 literal floating-point number. +/// Number format for a `C++11` literal floating-point number. #[rustfmt::skip] pub const CXX11_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1501,13 +1501,13 @@ pub const CXX11_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX11_LITERAL }> {}.is_valid()); // C++11 STRING [0134567MN] -/// Number format for a C++11 string floating-point number. +/// Number format for a `C++11` string floating-point number. #[rustfmt::skip] pub const CXX11_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ CXX11_STRING }> {}.is_valid()); // C++11 HEX STRING [0134567MN] -/// Number format for a C++11 string hexadecimal floating-point number. +/// Number format for a `C++11` string hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const CXX11_HEX_STRING: u128 = NumberFormatBuilder::new() @@ -1520,7 +1520,7 @@ pub const CXX11_HEX_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX11_HEX_STRING }> {}.is_valid()); // C++03 LITERAL [01345678MN] -/// Number format for a C++03 literal floating-point number. +/// Number format for a `C++03` literal floating-point number. #[rustfmt::skip] pub const CXX03_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1529,13 +1529,13 @@ pub const CXX03_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX03_LITERAL }> {}.is_valid()); // C++03 STRING [0134567MN] -/// Number format for a C++03 string floating-point number. +/// Number format for a `C++03` string floating-point number. #[rustfmt::skip] pub const CXX03_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ CXX03_STRING }> {}.is_valid()); // C++98 LITERAL [01345678MN] -/// Number format for a C++98 literal floating-point number. +/// Number format for a `C++98` literal floating-point number. #[rustfmt::skip] pub const CXX98_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1544,7 +1544,7 @@ pub const CXX98_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CXX98_LITERAL }> {}.is_valid()); // C++98 STRING [0134567MN] -/// Number format for a C++98 string floating-point number. +/// Number format for a `C++98` string floating-point number. #[rustfmt::skip] pub const CXX98_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ CXX98_STRING }> {}.is_valid()); @@ -1552,19 +1552,19 @@ const_assert!(NumberFormat::<{ CXX98_STRING }> {}.is_valid()); /// Number format for a C literal floating-point number. pub const C_LITERAL: u128 = C18_LITERAL; -/// Number format to parse a C float from string. +/// Number format to parse a `C` float from string. pub const C_STRING: u128 = C18_STRING; -/// Number format for a C literal hexadecimal floating-point number. +/// Number format for a `C` literal hexadecimal floating-point number. #[cfg(feature = "power-of-two")] pub const C_HEX_LITERAL: u128 = C18_HEX_LITERAL; -/// Number format to parse a C hexadecimal float from string. +/// Number format to parse a `C` hexadecimal float from string. #[cfg(feature = "power-of-two")] pub const C_HEX_STRING: u128 = C18_HEX_STRING; // C18 LITERAL [01345678MN] -/// Number format for a C++98 literal floating-point number. +/// Number format for a `C18` literal floating-point number. #[rustfmt::skip] pub const C18_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1573,13 +1573,13 @@ pub const C18_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C18_LITERAL }> {}.is_valid()); // C18 STRING [0134567MN] -/// Number format for a C++98 string floating-point number. +/// Number format for a `C18` string floating-point number. #[rustfmt::skip] pub const C18_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ C18_STRING }> {}.is_valid()); // C18 HEX LITERAL [01345678MN] -/// Number format for a C++98 literal hexadecimal floating-point number. +/// Number format for a `C18` literal hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const C18_HEX_LITERAL: u128 = NumberFormatBuilder::new() @@ -1594,7 +1594,7 @@ pub const C18_HEX_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C18_HEX_LITERAL }> {}.is_valid()); // C18 HEX STRING [0134567MN] -/// Number format for a C18 string hexadecimal floating-point number. +/// Number format for a `C18` string hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const C18_HEX_STRING: u128 = NumberFormatBuilder::new() @@ -1607,7 +1607,7 @@ pub const C18_HEX_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C18_HEX_STRING }> {}.is_valid()); // C11 LITERAL [01345678MN] -/// Number format for a C++98 literal floating-point number. +/// Number format for a `C11` literal floating-point number. #[rustfmt::skip] pub const C11_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1616,13 +1616,13 @@ pub const C11_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C11_LITERAL }> {}.is_valid()); // C11 STRING [0134567MN] -/// Number format for a C++98 string floating-point number. +/// Number format for a `C11` string floating-point number. #[rustfmt::skip] pub const C11_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ C11_STRING }> {}.is_valid()); // C11 HEX LITERAL [01345678MN] -/// Number format for a C++98 literal hexadecimal floating-point number. +/// Number format for a `C11` literal hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const C11_HEX_LITERAL: u128 = NumberFormatBuilder::new() @@ -1637,7 +1637,7 @@ pub const C11_HEX_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C11_HEX_LITERAL }> {}.is_valid()); // C11 HEX STRING [0134567MN] -/// Number format for a C11 string hexadecimal floating-point number. +/// Number format for a `C11` string hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const C11_HEX_STRING: u128 = NumberFormatBuilder::new() @@ -1650,7 +1650,7 @@ pub const C11_HEX_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C11_HEX_STRING }> {}.is_valid()); // C99 LITERAL [01345678MN] -/// Number format for a C++98 literal floating-point number. +/// Number format for a `C99` literal floating-point number. #[rustfmt::skip] pub const C99_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1659,13 +1659,13 @@ pub const C99_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C99_LITERAL }> {}.is_valid()); // C99 STRING [0134567MN] -/// Number format for a C++98 string floating-point number. +/// Number format for a `C99` string floating-point number. #[rustfmt::skip] pub const C99_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ C99_STRING }> {}.is_valid()); // C99 HEX LITERAL [01345678MN] -/// Number format for a C++98 literal hexadecimal floating-point number. +/// Number format for a `C99` literal hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const C99_HEX_LITERAL: u128 = NumberFormatBuilder::new() @@ -1680,7 +1680,7 @@ pub const C99_HEX_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C99_HEX_LITERAL }> {}.is_valid()); // C99 HEX STRING [0134567MN] -/// Number format for a C99 string hexadecimal floating-point number. +/// Number format for a `C99` string hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const C99_HEX_STRING: u128 = NumberFormatBuilder::new() @@ -1693,7 +1693,7 @@ pub const C99_HEX_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C99_HEX_STRING }> {}.is_valid()); // C90 LITERAL [013456MN] -/// Number format for a C++98 literal floating-point number. +/// Number format for a `C90` literal floating-point number. #[rustfmt::skip] pub const C90_LITERAL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -1702,13 +1702,13 @@ pub const C90_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C90_LITERAL }> {}.is_valid()); // C90 STRING [0134567MN] -/// Number format for a C++98 string floating-point number. +/// Number format for a `C90` string floating-point number. #[rustfmt::skip] pub const C90_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ C90_STRING }> {}.is_valid()); // C90 HEX STRING [0134567MN] -/// Number format for a C90 string hexadecimal floating-point number. +/// Number format for a `C90` string hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const C90_HEX_STRING: u128 = NumberFormatBuilder::new() @@ -1721,7 +1721,7 @@ pub const C90_HEX_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C90_HEX_STRING }> {}.is_valid()); // C89 LITERAL [013456MN] -/// Number format for a C++98 literal floating-point number. +/// Number format for a `C89` literal floating-point number. #[rustfmt::skip] pub const C89_LITERAL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -1730,13 +1730,13 @@ pub const C89_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C89_LITERAL }> {}.is_valid()); // C89 STRING [0134567MN] -/// Number format for a C++98 string floating-point number. +/// Number format for a `C89` string floating-point number. #[rustfmt::skip] pub const C89_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ C89_STRING }> {}.is_valid()); // C89 HEX STRING [0134567MN] -/// Number format for a C89 string hexadecimal floating-point number. +/// Number format for a `C89` string hexadecimal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const C89_HEX_STRING: u128 = NumberFormatBuilder::new() @@ -1749,7 +1749,7 @@ pub const C89_HEX_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ C89_HEX_STRING }> {}.is_valid()); // RUBY LITERAL [345689AMN-_] -/// Number format for a Ruby literal floating-point number. +/// Number format for a `Ruby` literal floating-point number. #[rustfmt::skip] pub const RUBY_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -1764,7 +1764,7 @@ pub const RUBY_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ RUBY_LITERAL }> {}.is_valid()); // RUBY OCTAL LITERAL [345689AN-_] -/// Number format for a Ruby literal floating-point number. +/// Number format for a `Ruby` literal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const RUBY_OCTAL_LITERAL: u128 = NumberFormatBuilder::new() @@ -1780,7 +1780,7 @@ const_assert!(NumberFormat::<{ RUBY_OCTAL_LITERAL }> {}.is_valid()); // RUBY STRING [01234569ABMN-_] // Note: Amazingly, Ruby 1.8+ do not allow parsing special values. -/// Number format to parse a Ruby float from string. +/// Number format to parse a `Ruby` float from string. #[rustfmt::skip] pub const RUBY_STRING: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -1791,7 +1791,7 @@ pub const RUBY_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ RUBY_STRING }> {}.is_valid()); // SWIFT LITERAL [34569ABFGHIJKMN-_] -/// Number format for a Swift literal floating-point number. +/// Number format for a `Swift` literal floating-point number. #[rustfmt::skip] pub const SWIFT_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -1805,7 +1805,7 @@ pub const SWIFT_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ SWIFT_LITERAL }> {}.is_valid()); // SWIFT STRING [134567MN] -/// Number format to parse a Swift float from string. +/// Number format to parse a `Swift` float from string. #[rustfmt::skip] pub const SWIFT_STRING: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -1814,7 +1814,7 @@ pub const SWIFT_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ SWIFT_STRING }> {}.is_valid()); // GO LITERAL [13456MN] -/// Number format for a Golang literal floating-point number. +/// Number format for a `Golang` literal floating-point number. #[rustfmt::skip] pub const GO_LITERAL: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -1824,7 +1824,7 @@ pub const GO_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ GO_LITERAL }> {}.is_valid()); // GO STRING [134567MN] -/// Number format to parse a Golang float from string. +/// Number format to parse a `Golang` float from string. #[rustfmt::skip] pub const GO_STRING: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -1833,7 +1833,7 @@ pub const GO_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ GO_STRING }> {}.is_valid()); // HASKELL LITERAL [456MN] -/// Number format for a Haskell literal floating-point number. +/// Number format for a `Haskell` literal floating-point number. #[rustfmt::skip] pub const HASKELL_LITERAL: u128 = NumberFormatBuilder::new() .required_digits(true) @@ -1844,7 +1844,7 @@ pub const HASKELL_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ HASKELL_LITERAL }> {}.is_valid()); // HASKELL STRING [45678MN] -/// Number format to parse a Haskell float from string. +/// Number format to parse a `Haskell` float from string. #[rustfmt::skip] pub const HASKELL_STRING: u128 = NumberFormatBuilder::new() .required_digits(true) @@ -1855,7 +1855,7 @@ pub const HASKELL_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ HASKELL_STRING }> {}.is_valid()); // JAVASCRIPT LITERAL [01345678M] -/// Number format for a Javascript literal floating-point number. +/// Number format for a `Javascript` literal floating-point number. #[rustfmt::skip] pub const JAVASCRIPT_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1865,7 +1865,7 @@ pub const JAVASCRIPT_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ JAVASCRIPT_LITERAL }> {}.is_valid()); // JAVASCRIPT STRING [012345678MN] -/// Number format to parse a Javascript float from string. +/// Number format to parse a `Javascript` float from string. #[rustfmt::skip] pub const JAVASCRIPT_STRING: u128 = NumberFormatBuilder::new() .required_exponent_digits(false) @@ -1875,7 +1875,7 @@ pub const JAVASCRIPT_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ JAVASCRIPT_STRING }> {}.is_valid()); // PERL LITERAL [0134569ABDEFGHIJKMN-_] -/// Number format for a Perl literal floating-point number. +/// Number format for a `Perl` literal floating-point number. #[rustfmt::skip] pub const PERL_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -1890,11 +1890,11 @@ pub const PERL_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ PERL_LITERAL }> {}.is_valid()); // PERL STRING [01234567MN] -/// Number format to parse a Perl float from string. +/// Number format to parse a `Perl` float from string. pub const PERL_STRING: u128 = PERMISSIVE; // PHP LITERAL [01345678MN] -/// Number format for a PHP literal floating-point number. +/// Number format for a `PHP` literal floating-point number. #[rustfmt::skip] pub const PHP_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1903,7 +1903,7 @@ pub const PHP_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ PHP_LITERAL }> {}.is_valid()); // PHP STRING [0123456MN] -/// Number format to parse a PHP float from string. +/// Number format to parse a `PHP` float from string. #[rustfmt::skip] pub const PHP_STRING: u128 = NumberFormatBuilder::new() .required_exponent_digits(false) @@ -1913,7 +1913,7 @@ pub const PHP_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ PHP_STRING }> {}.is_valid()); // JAVA LITERAL [0134569ABIJKMN-_] -/// Number format for a Java literal floating-point number. +/// Number format for a `Java` literal floating-point number. #[rustfmt::skip] pub const JAVA_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -1925,7 +1925,7 @@ pub const JAVA_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ JAVA_LITERAL }> {}.is_valid()); // JAVA STRING [01345678MN] -/// Number format to parse a Java float from string. +/// Number format to parse a `Java` float from string. #[rustfmt::skip] pub const JAVA_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1934,7 +1934,7 @@ pub const JAVA_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ JAVA_STRING }> {}.is_valid()); // R LITERAL [01345678MN] -/// Number format for a R literal floating-point number. +/// Number format for a `R` literal floating-point number. #[rustfmt::skip] pub const R_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1943,11 +1943,11 @@ pub const R_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ R_LITERAL }> {}.is_valid()); // R STRING [01234567MN] -/// Number format to parse a R float from string. +/// Number format to parse a `R` float from string. pub const R_STRING: u128 = PERMISSIVE; // KOTLIN LITERAL [0134569ABIJKN-_] -/// Number format for a Kotlin literal floating-point number. +/// Number format for a `Kotlin` literal floating-point number. #[rustfmt::skip] pub const KOTLIN_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -1960,7 +1960,7 @@ pub const KOTLIN_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ KOTLIN_LITERAL }> {}.is_valid()); // KOTLIN STRING [0134568MN] -/// Number format to parse a Kotlin float from string. +/// Number format to parse a `Kotlin` float from string. #[rustfmt::skip] pub const KOTLIN_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -1969,7 +1969,7 @@ pub const KOTLIN_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ KOTLIN_STRING }> {}.is_valid()); // JULIA LITERAL [01345689AMN-_] -/// Number format for a Julia literal floating-point number. +/// Number format for a `Julia` literal floating-point number. #[rustfmt::skip] pub const JULIA_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -1981,13 +1981,13 @@ pub const JULIA_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ JULIA_LITERAL }> {}.is_valid()); // JULIA STRING [01345678MN] -/// Number format to parse a Julia float from string. +/// Number format to parse a `Julia` float from string. #[rustfmt::skip] pub const JULIA_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ JULIA_STRING }> {}.is_valid()); // JULIA HEX LITERAL [01345689AMN-_] -/// Number format for a Julia literal floating-point number. +/// Number format for a `Julia` literal floating-point number. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const JULIA_HEX_LITERAL: u128 = NumberFormatBuilder::new() @@ -2004,7 +2004,7 @@ pub const JULIA_HEX_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ JULIA_HEX_LITERAL }> {}.is_valid()); // JULIA HEX STRING [01345678MN] -/// Number format to parse a Julia float from string. +/// Number format to parse a `Julia` float from string. #[rustfmt::skip] #[cfg(feature = "power-of-two")] pub const JULIA_HEX_STRING: u128 = NumberFormatBuilder::new() @@ -2016,14 +2016,14 @@ pub const JULIA_HEX_STRING: u128 = NumberFormatBuilder::new() #[cfg(feature = "power-of-two")] const_assert!(NumberFormat::<{ JULIA_HEX_STRING }> {}.is_valid()); -/// Number format for a C# literal floating-point number. +/// Number format for a `C#` literal floating-point number. pub const CSHARP_LITERAL: u128 = CSHARP7_LITERAL; -/// Number format to parse a C# float from string. +/// Number format to parse a `C#` float from string. pub const CSHARP_STRING: u128 = CSHARP7_STRING; // CSHARP7 LITERAL [034569ABIJKMN-_] -/// Number format for a C#7 literal floating-point number. +/// Number format for a `C#7` literal floating-point number. #[rustfmt::skip] pub const CSHARP7_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2036,7 +2036,7 @@ pub const CSHARP7_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP7_LITERAL }> {}.is_valid()); // CSHARP7 STRING [0134568MN] -/// Number format to parse a C#7 float from string. +/// Number format to parse a `C#7` float from string. #[rustfmt::skip] pub const CSHARP7_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2045,7 +2045,7 @@ pub const CSHARP7_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP7_STRING }> {}.is_valid()); // CSHARP6 LITERAL [03456MN] -/// Number format for a C#6 literal floating-point number. +/// Number format for a `C#6` literal floating-point number. #[rustfmt::skip] pub const CSHARP6_LITERAL: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -2055,7 +2055,7 @@ pub const CSHARP6_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP6_LITERAL }> {}.is_valid()); // CSHARP6 STRING [0134568MN] -/// Number format to parse a C#6 float from string. +/// Number format to parse a `C#6` float from string. #[rustfmt::skip] pub const CSHARP6_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2064,7 +2064,7 @@ pub const CSHARP6_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP6_STRING }> {}.is_valid()); // CSHARP5 LITERAL [03456MN] -/// Number format for a C#5 literal floating-point number. +/// Number format for a `C#5` literal floating-point number. #[rustfmt::skip] pub const CSHARP5_LITERAL: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -2074,7 +2074,7 @@ pub const CSHARP5_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP5_LITERAL }> {}.is_valid()); // CSHARP5 STRING [0134568MN] -/// Number format to parse a C#5 float from string. +/// Number format to parse a `C#5` float from string. #[rustfmt::skip] pub const CSHARP5_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2083,7 +2083,7 @@ pub const CSHARP5_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP5_STRING }> {}.is_valid()); // CSHARP4 LITERAL [03456MN] -/// Number format for a C#4 literal floating-point number. +/// Number format for a `C#4` literal floating-point number. #[rustfmt::skip] pub const CSHARP4_LITERAL: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -2093,7 +2093,7 @@ pub const CSHARP4_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP4_LITERAL }> {}.is_valid()); // CSHARP4 STRING [0134568MN] -/// Number format to parse a C#4 float from string. +/// Number format to parse a `C#4` float from string. #[rustfmt::skip] pub const CSHARP4_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2102,7 +2102,7 @@ pub const CSHARP4_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP4_STRING }> {}.is_valid()); // CSHARP3 LITERAL [03456MN] -/// Number format for a C#3 literal floating-point number. +/// Number format for a `C#3` literal floating-point number. #[rustfmt::skip] pub const CSHARP3_LITERAL: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -2112,7 +2112,7 @@ pub const CSHARP3_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP3_LITERAL }> {}.is_valid()); // CSHARP3 STRING [0134568MN] -/// Number format to parse a C#3 float from string. +/// Number format to parse a `C#3` float from string. #[rustfmt::skip] pub const CSHARP3_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2121,7 +2121,7 @@ pub const CSHARP3_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP3_STRING }> {}.is_valid()); // CSHARP2 LITERAL [03456MN] -/// Number format for a C#2 literal floating-point number. +/// Number format for a `C#2` literal floating-point number. #[rustfmt::skip] pub const CSHARP2_LITERAL: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -2131,7 +2131,7 @@ pub const CSHARP2_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP2_LITERAL }> {}.is_valid()); // CSHARP2 STRING [0134568MN] -/// Number format to parse a C#2 float from string. +/// Number format to parse a `C#2` float from string. #[rustfmt::skip] pub const CSHARP2_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2140,7 +2140,7 @@ pub const CSHARP2_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP2_STRING }> {}.is_valid()); // CSHARP1 LITERAL [03456MN] -/// Number format for a C#1 literal floating-point number. +/// Number format for a `C#1` literal floating-point number. #[rustfmt::skip] pub const CSHARP1_LITERAL: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -2150,7 +2150,7 @@ pub const CSHARP1_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP1_LITERAL }> {}.is_valid()); // CSHARP1 STRING [0134568MN] -/// Number format to parse a C#1 float from string. +/// Number format to parse a `C#1` float from string. #[rustfmt::skip] pub const CSHARP1_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2159,7 +2159,7 @@ pub const CSHARP1_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CSHARP1_STRING }> {}.is_valid()); // KAWA LITERAL [013456MN] -/// Number format for a Kawa literal floating-point number. +/// Number format for a `Kawa` literal floating-point number. #[rustfmt::skip] pub const KAWA_LITERAL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2168,7 +2168,7 @@ pub const KAWA_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ KAWA_LITERAL }> {}.is_valid()); // KAWA STRING [013456MN] -/// Number format to parse a Kawa float from string. +/// Number format to parse a `Kawa` float from string. #[rustfmt::skip] pub const KAWA_STRING: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2177,7 +2177,7 @@ pub const KAWA_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ KAWA_STRING }> {}.is_valid()); // GAMBITC LITERAL [013456MN] -/// Number format for a Gambit-C literal floating-point number. +/// Number format for a `Gambit-C` literal floating-point number. #[rustfmt::skip] pub const GAMBITC_LITERAL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2186,7 +2186,7 @@ pub const GAMBITC_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ GAMBITC_LITERAL }> {}.is_valid()); // GAMBITC STRING [013456MN] -/// Number format to parse a Gambit-C float from string. +/// Number format to parse a `Gambit-C` float from string. #[rustfmt::skip] pub const GAMBITC_STRING: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2195,7 +2195,7 @@ pub const GAMBITC_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ GAMBITC_STRING }> {}.is_valid()); // GUILE LITERAL [013456MN] -/// Number format for a Guile literal floating-point number. +/// Number format for a `Guile` literal floating-point number. #[rustfmt::skip] pub const GUILE_LITERAL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2204,7 +2204,7 @@ pub const GUILE_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ GUILE_LITERAL }> {}.is_valid()); // GUILE STRING [013456MN] -/// Number format to parse a Guile float from string. +/// Number format to parse a `Guile` float from string. #[rustfmt::skip] pub const GUILE_STRING: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2213,7 +2213,7 @@ pub const GUILE_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ GUILE_STRING }> {}.is_valid()); // CLOJURE LITERAL [13456MN] -/// Number format for a Clojure literal floating-point number. +/// Number format for a `Clojure` literal floating-point number. #[rustfmt::skip] pub const CLOJURE_LITERAL: u128 = NumberFormatBuilder::new() .required_integer_digits(true) @@ -2223,7 +2223,7 @@ pub const CLOJURE_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CLOJURE_LITERAL }> {}.is_valid()); // CLOJURE STRING [01345678MN] -/// Number format to parse a Clojure float from string. +/// Number format to parse a `Clojure` float from string. #[rustfmt::skip] pub const CLOJURE_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2232,7 +2232,7 @@ pub const CLOJURE_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ CLOJURE_STRING }> {}.is_valid()); // ERLANG LITERAL [34578MN] -/// Number format for an Erlang literal floating-point number. +/// Number format for an `Erlang` literal floating-point number. #[rustfmt::skip] pub const ERLANG_LITERAL: u128 = NumberFormatBuilder::new() .required_digits(true) @@ -2243,7 +2243,7 @@ pub const ERLANG_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ ERLANG_LITERAL }> {}.is_valid()); // ERLANG STRING [345MN] -/// Number format to parse an Erlang float from string. +/// Number format to parse an `Erlang` float from string. #[rustfmt::skip] pub const ERLANG_STRING: u128 = NumberFormatBuilder::new() .required_digits(true) @@ -2254,7 +2254,7 @@ pub const ERLANG_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ ERLANG_STRING }> {}.is_valid()); // ELM LITERAL [456] -/// Number format for an Elm literal floating-point number. +/// Number format for an `Elm` literal floating-point number. #[rustfmt::skip] pub const ELM_LITERAL: u128 = NumberFormatBuilder::new() .required_digits(true) @@ -2268,7 +2268,7 @@ const_assert!(NumberFormat::<{ ELM_LITERAL }> {}.is_valid()); // ELM STRING [01345678MN] // Note: There is no valid representation of NaN, just Infinity. -/// Number format to parse an Elm float from string. +/// Number format to parse an `Elm` float from string. #[rustfmt::skip] pub const ELM_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2277,7 +2277,7 @@ pub const ELM_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ ELM_STRING }> {}.is_valid()); // SCALA LITERAL [3456] -/// Number format for a Scala literal floating-point number. +/// Number format for a `Scala` literal floating-point number. #[rustfmt::skip] pub const SCALA_LITERAL: u128 = NumberFormatBuilder::new() .required_digits(true) @@ -2289,7 +2289,7 @@ pub const SCALA_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ SCALA_LITERAL }> {}.is_valid()); // SCALA STRING [01345678MN] -/// Number format to parse a Scala float from string. +/// Number format to parse a `Scala` float from string. #[rustfmt::skip] pub const SCALA_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2298,7 +2298,7 @@ pub const SCALA_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ SCALA_STRING }> {}.is_valid()); // ELIXIR LITERAL [3459ABMN-_] -/// Number format for an Elixir literal floating-point number. +/// Number format for an `Elixir` literal floating-point number. #[rustfmt::skip] pub const ELIXIR_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2311,7 +2311,7 @@ pub const ELIXIR_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ ELIXIR_LITERAL }> {}.is_valid()); // ELIXIR STRING [345MN] -/// Number format to parse an Elixir float from string. +/// Number format to parse an `Elixir` float from string. #[rustfmt::skip] pub const ELIXIR_STRING: u128 = NumberFormatBuilder::new() .required_digits(true) @@ -2322,7 +2322,7 @@ pub const ELIXIR_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ ELIXIR_STRING }> {}.is_valid()); // FORTRAN LITERAL [013456MN] -/// Number format for a FORTRAN literal floating-point number. +/// Number format for a `FORTRAN` literal floating-point number. #[rustfmt::skip] pub const FORTRAN_LITERAL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2331,13 +2331,13 @@ pub const FORTRAN_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ FORTRAN_LITERAL }> {}.is_valid()); // FORTRAN STRING [0134567MN] -/// Number format to parse a FORTRAN float from string. +/// Number format to parse a `FORTRAN` float from string. #[rustfmt::skip] pub const FORTRAN_STRING: u128 = NumberFormatBuilder::new().build(); const_assert!(NumberFormat::<{ FORTRAN_STRING }> {}.is_valid()); // D LITERAL [0134569ABFGHIJKN-_] -/// Number format for a D literal floating-point number. +/// Number format for a `D` literal floating-point number. #[rustfmt::skip] pub const D_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2351,7 +2351,7 @@ pub const D_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ D_LITERAL }> {}.is_valid()); // D STRING [01345679AFGMN-_] -/// Number format to parse a D float from string. +/// Number format to parse a `D` float from string. #[rustfmt::skip] pub const D_STRING: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2364,7 +2364,7 @@ pub const D_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ D_STRING }> {}.is_valid()); // COFFEESCRIPT LITERAL [01345678] -/// Number format for a Coffeescript literal floating-point number. +/// Number format for a `Coffeescript` literal floating-point number. #[rustfmt::skip] pub const COFFEESCRIPT_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2375,7 +2375,7 @@ pub const COFFEESCRIPT_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ COFFEESCRIPT_LITERAL }> {}.is_valid()); // COFFEESCRIPT STRING [012345678MN] -/// Number format to parse a Coffeescript float from string. +/// Number format to parse a `Coffeescript` float from string. #[rustfmt::skip] pub const COFFEESCRIPT_STRING: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2384,7 +2384,7 @@ pub const COFFEESCRIPT_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ COFFEESCRIPT_STRING }> {}.is_valid()); // COBOL LITERAL [0345MN] -/// Number format for a Cobol literal floating-point number. +/// Number format for a `Cobol` literal floating-point number. #[rustfmt::skip] pub const COBOL_LITERAL: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -2395,7 +2395,7 @@ pub const COBOL_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ COBOL_LITERAL }> {}.is_valid()); // COBOL STRING [012356MN] -/// Number format to parse a Cobol float from string. +/// Number format to parse a `Cobol` float from string. #[rustfmt::skip] pub const COBOL_STRING: u128 = NumberFormatBuilder::new() .required_exponent_sign(true) @@ -2405,7 +2405,7 @@ pub const COBOL_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ COBOL_STRING }> {}.is_valid()); // FSHARP LITERAL [13456789ABIJKMN-_] -/// Number format for a F# literal floating-point number. +/// Number format for a `F#` literal floating-point number. #[rustfmt::skip] pub const FSHARP_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2419,7 +2419,7 @@ pub const FSHARP_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ FSHARP_LITERAL }> {}.is_valid()); // FSHARP STRING [013456789ABCDEFGHIJKLMN-_] -/// Number format to parse a F# float from string. +/// Number format to parse a `F#` float from string. #[rustfmt::skip] pub const FSHARP_STRING: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2433,7 +2433,7 @@ pub const FSHARP_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ FSHARP_STRING }> {}.is_valid()); // VB LITERAL [03456MN] -/// Number format for a Visual Basic literal floating-point number. +/// Number format for a `Visual Basic` literal floating-point number. #[rustfmt::skip] pub const VB_LITERAL: u128 = NumberFormatBuilder::new() .required_fraction_digits(true) @@ -2443,7 +2443,7 @@ pub const VB_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ VB_LITERAL }> {}.is_valid()); // VB STRING [01345678MN] -/// Number format to parse a Visual Basic float from string. +/// Number format to parse a `Visual Basic` float from string. // Note: To my knowledge, Visual Basic cannot parse infinity. #[rustfmt::skip] pub const VB_STRING: u128 = NumberFormatBuilder::new() @@ -2453,7 +2453,7 @@ pub const VB_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ VB_STRING }> {}.is_valid()); // OCAML LITERAL [1456789ABDFGHIJKMN-_] -/// Number format for an OCaml literal floating-point number. +/// Number format for an `OCaml` literal floating-point number. #[rustfmt::skip] pub const OCAML_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2470,7 +2470,7 @@ pub const OCAML_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ OCAML_LITERAL }> {}.is_valid()); // OCAML STRING [01345679ABCDEFGHIJKLMN-_] -/// Number format to parse an OCaml float from string. +/// Number format to parse an `OCaml` float from string. #[rustfmt::skip] pub const OCAML_STRING: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2484,7 +2484,7 @@ pub const OCAML_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ OCAML_STRING }> {}.is_valid()); // OBJECTIVEC LITERAL [013456MN] -/// Number format for an Objective-C literal floating-point number. +/// Number format for an `Objective-C` literal floating-point number. #[rustfmt::skip] pub const OBJECTIVEC_LITERAL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2493,7 +2493,7 @@ pub const OBJECTIVEC_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ OBJECTIVEC_LITERAL }> {}.is_valid()); // OBJECTIVEC STRING [013456MN] -/// Number format to parse an Objective-C float from string. +/// Number format to parse an `Objective-C` float from string. #[rustfmt::skip] pub const OBJECTIVEC_STRING: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2502,7 +2502,7 @@ pub const OBJECTIVEC_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ OBJECTIVEC_STRING }> {}.is_valid()); // REASONML LITERAL [13456789ABDFGHIJKMN-_] -/// Number format for a ReasonML literal floating-point number. +/// Number format for a `ReasonML` literal floating-point number. #[rustfmt::skip] pub const REASONML_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2518,7 +2518,7 @@ pub const REASONML_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ REASONML_LITERAL }> {}.is_valid()); // REASONML STRING [01345679ABCDEFGHIJKLMN-_] -/// Number format to parse a ReasonML float from string. +/// Number format to parse a `ReasonML` float from string. #[rustfmt::skip] pub const REASONML_STRING: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2533,7 +2533,7 @@ const_assert!(NumberFormat::<{ REASONML_STRING }> {}.is_valid()); // OCTAVE LITERAL [013456789ABDFGHIJKMN-_] // Note: Octave accepts both NaN and nan, Inf and inf. -/// Number format for an Octave literal floating-point number. +/// Number format for an `Octave` literal floating-point number. #[rustfmt::skip] pub const OCTAVE_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2547,7 +2547,7 @@ pub const OCTAVE_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ OCTAVE_LITERAL }> {}.is_valid()); // OCTAVE STRING [01345679ABCDEFGHIJKMN-,] -/// Number format to parse an Octave float from string. +/// Number format to parse an `Octave` float from string. #[rustfmt::skip] pub const OCTAVE_STRING: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b',')) @@ -2561,7 +2561,7 @@ const_assert!(NumberFormat::<{ OCTAVE_STRING }> {}.is_valid()); // MATLAB LITERAL [013456789ABDFGHIJKMN-_] // Note: Matlab accepts both NaN and nan, Inf and inf. -/// Number format for an Matlab literal floating-point number. +/// Number format for an `Matlab` literal floating-point number. #[rustfmt::skip] pub const MATLAB_LITERAL: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2575,7 +2575,7 @@ pub const MATLAB_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ MATLAB_LITERAL }> {}.is_valid()); // MATLAB STRING [01345679ABCDEFGHIJKMN-,] -/// Number format to parse an Matlab float from string. +/// Number format to parse an `Matlab` float from string. #[rustfmt::skip] pub const MATLAB_STRING: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b',')) @@ -2588,7 +2588,7 @@ pub const MATLAB_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ MATLAB_STRING }> {}.is_valid()); // ZIG LITERAL [1456MN] -/// Number format for a Zig literal floating-point number. +/// Number format for a `Zig` literal floating-point number. #[rustfmt::skip] pub const ZIG_LITERAL: u128 = NumberFormatBuilder::new() .required_integer_digits(true) @@ -2599,12 +2599,12 @@ pub const ZIG_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ ZIG_LITERAL }> {}.is_valid()); // ZIG STRING [01234567MN] -/// Number format to parse a Zig float from string. +/// Number format to parse a `Zig` float from string. pub const ZIG_STRING: u128 = PERMISSIVE; // SAGE LITERAL [012345678MN] // Note: Both Infinity and infinity are accepted. -/// Number format for a Sage literal floating-point number. +/// Number format for a `Sage` literal floating-point number. #[rustfmt::skip] pub const SAGE_LITERAL: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) @@ -2613,7 +2613,7 @@ pub const SAGE_LITERAL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ SAGE_LITERAL }> {}.is_valid()); // SAGE STRING [01345679ABMN-_] -/// Number format to parse a Sage float from string. +/// Number format to parse a `Sage` float from string. #[rustfmt::skip] pub const SAGE_STRING: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2623,7 +2623,7 @@ pub const SAGE_STRING: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ SAGE_STRING }> {}.is_valid()); // JSON [456] -/// Number format for a JSON literal floating-point number. +/// Number format for a `JSON` literal floating-point number. #[rustfmt::skip] pub const JSON: u128 = NumberFormatBuilder::new() .required_digits(true) @@ -2636,7 +2636,7 @@ pub const JSON: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ JSON }> {}.is_valid()); // TOML [34569AB] -/// Number format for a TOML literal floating-point number. +/// Number format for a `TOML` literal floating-point number. #[rustfmt::skip] pub const TOML: u128 = NumberFormatBuilder::new() .digit_separator(num::NonZeroU8::new(b'_')) @@ -2650,11 +2650,11 @@ pub const TOML: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ TOML }> {}.is_valid()); // YAML (defined in-terms of JSON schema). -/// Number format for a YAML literal floating-point number. +/// Number format for a `YAML` literal floating-point number. pub const YAML: u128 = JSON; // XML [01234578MN] -/// Number format for a XML literal floating-point number. +/// Number format for a `XML` literal floating-point number. #[rustfmt::skip] pub const XML: u128 = NumberFormatBuilder::new() .required_exponent_digits(false) @@ -2664,7 +2664,7 @@ pub const XML: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ XML }> {}.is_valid()); // SQLITE [013456MN] -/// Number format for a SQLite literal floating-point number. +/// Number format for a `SQLite` literal floating-point number. #[rustfmt::skip] pub const SQLITE: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2673,7 +2673,7 @@ pub const SQLITE: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ SQLITE }> {}.is_valid()); // POSTGRESQL [013456MN] -/// Number format for a PostgreSQL literal floating-point number. +/// Number format for a `PostgreSQL` literal floating-point number. #[rustfmt::skip] pub const POSTGRESQL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2682,7 +2682,7 @@ pub const POSTGRESQL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ POSTGRESQL }> {}.is_valid()); // MYSQL [013456MN] -/// Number format for a MySQL literal floating-point number. +/// Number format for a `MySQL` literal floating-point number. #[rustfmt::skip] pub const MYSQL: u128 = NumberFormatBuilder::new() .no_special(true) @@ -2691,7 +2691,7 @@ pub const MYSQL: u128 = NumberFormatBuilder::new() const_assert!(NumberFormat::<{ MYSQL }> {}.is_valid()); // MONGODB [01345678M] -/// Number format for a MongoDB literal floating-point number. +/// Number format for a `MongoDB` literal floating-point number. #[rustfmt::skip] pub const MONGODB: u128 = NumberFormatBuilder::new() .case_sensitive_special(true) diff --git a/lexical-util/src/format.rs b/lexical-util/src/format.rs index f0265409..87efe079 100644 --- a/lexical-util/src/format.rs +++ b/lexical-util/src/format.rs @@ -10,240 +10,240 @@ //! programming, markup, and data languages. //! //! - [STANDARD] -#![cfg_attr(feature = "format", doc = " - [RUST_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [RUST_STRING]")] -#![cfg_attr(feature = "format", doc = " - [PYTHON_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [PYTHON_STRING]")] -#![cfg_attr(feature = "format", doc = " - [PYTHON3_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [PYTHON3_STRING]")] -#![cfg_attr(feature = "format", doc = " - [PYTHON36_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [PYTHON35_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [PYTHON2_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [PYTHON2_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CXX_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CXX_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [CXX_HEX_LITERAL]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [CXX_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CXX20_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CXX20_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [CXX20_HEX_LITERAL]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [CXX20_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CXX17_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CXX17_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [CXX17_HEX_LITERAL]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [CXX17_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CXX14_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CXX14_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [CXX14_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CXX11_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CXX11_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [CXX11_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CXX03_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CXX03_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CXX98_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CXX98_STRING]")] -#![cfg_attr(feature = "format", doc = " - [C_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [C_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [C_HEX_LITERAL]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [C_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [C18_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [C18_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [C18_HEX_LITERAL]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [C18_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [C11_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [C11_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [C11_HEX_LITERAL]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [C11_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [C99_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [C99_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [C99_HEX_LITERAL]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [C99_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [C90_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [C90_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [C90_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [C89_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [C89_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [C89_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [RUBY_LITERAL]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [RUBY_OCTAL_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [RUBY_STRING]")] -#![cfg_attr(feature = "format", doc = " - [SWIFT_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [SWIFT_STRING]")] -#![cfg_attr(feature = "format", doc = " - [GO_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [GO_STRING]")] -#![cfg_attr(feature = "format", doc = " - [HASKELL_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [HASKELL_STRING]")] -#![cfg_attr(feature = "format", doc = " - [JAVASCRIPT_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [JAVASCRIPT_STRING]")] -#![cfg_attr(feature = "format", doc = " - [PERL_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [PERL_STRING]")] -#![cfg_attr(feature = "format", doc = " - [PHP_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [PHP_STRING]")] -#![cfg_attr(feature = "format", doc = " - [JAVA_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [JAVA_STRING]")] -#![cfg_attr(feature = "format", doc = " - [R_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [R_STRING]")] -#![cfg_attr(feature = "format", doc = " - [KOTLIN_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [KOTLIN_STRING]")] -#![cfg_attr(feature = "format", doc = " - [JULIA_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [JULIA_STRING]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [JULIA_HEX_LITERAL]")] -#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [JULIA_HEX_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP7_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP7_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP6_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP6_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP5_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP5_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP4_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP4_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP3_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP3_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP2_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP2_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP1_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CSHARP1_STRING]")] -#![cfg_attr(feature = "format", doc = " - [KAWA_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [KAWA_STRING]")] -#![cfg_attr(feature = "format", doc = " - [GAMBITC_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [GAMBITC_STRING]")] -#![cfg_attr(feature = "format", doc = " - [GUILE_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [GUILE_STRING]")] -#![cfg_attr(feature = "format", doc = " - [CLOJURE_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [CLOJURE_STRING]")] -#![cfg_attr(feature = "format", doc = " - [ERLANG_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [ERLANG_STRING]")] -#![cfg_attr(feature = "format", doc = " - [ELM_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [ELM_STRING]")] -#![cfg_attr(feature = "format", doc = " - [SCALA_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [SCALA_STRING]")] -#![cfg_attr(feature = "format", doc = " - [ELIXIR_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [ELIXIR_STRING]")] -#![cfg_attr(feature = "format", doc = " - [FORTRAN_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [FORTRAN_STRING]")] -#![cfg_attr(feature = "format", doc = " - [D_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [D_STRING]")] -#![cfg_attr(feature = "format", doc = " - [COFFEESCRIPT_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [COFFEESCRIPT_STRING]")] -#![cfg_attr(feature = "format", doc = " - [COBOL_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [COBOL_STRING]")] -#![cfg_attr(feature = "format", doc = " - [FSHARP_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [FSHARP_STRING]")] -#![cfg_attr(feature = "format", doc = " - [VB_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [VB_STRING]")] -#![cfg_attr(feature = "format", doc = " - [OCAML_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [OCAML_STRING]")] -#![cfg_attr(feature = "format", doc = " - [OBJECTIVEC_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [OBJECTIVEC_STRING]")] -#![cfg_attr(feature = "format", doc = " - [REASONML_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [REASONML_STRING]")] -#![cfg_attr(feature = "format", doc = " - [OCTAVE_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [OCTAVE_STRING]")] -#![cfg_attr(feature = "format", doc = " - [MATLAB_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [MATLAB_STRING]")] -#![cfg_attr(feature = "format", doc = " - [ZIG_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [ZIG_STRING]")] -#![cfg_attr(feature = "format", doc = " - [SAGE_LITERAL]")] -#![cfg_attr(feature = "format", doc = " - [SAGE_STRING]")] -#![cfg_attr(feature = "format", doc = " - [JSON]")] -#![cfg_attr(feature = "format", doc = " - [TOML]")] -#![cfg_attr(feature = "format", doc = " - [YAML]")] -#![cfg_attr(feature = "format", doc = " - [XML]")] -#![cfg_attr(feature = "format", doc = " - [SQLITE]")] -#![cfg_attr(feature = "format", doc = " - [POSTGRESQL]")] -#![cfg_attr(feature = "format", doc = " - [MYSQL]")] -#![cfg_attr(feature = "format", doc = " - [MONGODB]")] +#![cfg_attr(feature = "format", doc = " - [`RUST_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`RUST_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`PYTHON_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`PYTHON_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`PYTHON3_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`PYTHON3_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`PYTHON36_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`PYTHON35_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`PYTHON2_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`PYTHON2_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`CXX_HEX_LITERAL`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`CXX_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX20_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX20_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`CXX20_HEX_LITERAL`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`CXX20_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX17_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX17_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`CXX17_HEX_LITERAL`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`CXX17_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX14_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX14_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`CXX14_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX11_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX11_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`CXX11_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX03_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX03_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX98_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CXX98_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`C_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`C_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`C_HEX_LITERAL`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`C_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`C18_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`C18_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`C18_HEX_LITERAL`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`C18_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`C11_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`C11_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`C11_HEX_LITERAL`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`C11_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`C99_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`C99_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`C99_HEX_LITERAL`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`C99_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`C90_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`C90_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`C90_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`C89_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`C89_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`C89_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`RUBY_LITERAL`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`RUBY_OCTAL_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`RUBY_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`SWIFT_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`SWIFT_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`GO_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`GO_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`HASKELL_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`HASKELL_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`JAVASCRIPT_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`JAVASCRIPT_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`PERL_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`PERL_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`PHP_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`PHP_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`JAVA_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`JAVA_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`R_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`R_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`KOTLIN_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`KOTLIN_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`JULIA_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`JULIA_STRING`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`JULIA_HEX_LITERAL`]")] +#![cfg_attr(all(feature = "format", feature = "power-of-two"), doc = " - [`JULIA_HEX_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP7_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP7_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP6_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP6_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP5_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP5_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP4_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP4_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP3_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP3_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP2_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP2_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP1_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CSHARP1_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`KAWA_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`KAWA_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`GAMBITC_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`GAMBITC_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`GUILE_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`GUILE_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`CLOJURE_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`CLOJURE_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`ERLANG_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`ERLANG_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`ELM_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`ELM_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`SCALA_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`SCALA_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`ELIXIR_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`ELIXIR_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`FORTRAN_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`FORTRAN_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`D_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`D_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`COFFEESCRIPT_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`COFFEESCRIPT_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`COBOL_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`COBOL_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`FSHARP_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`FSHARP_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`VB_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`VB_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`OCAML_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`OCAML_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`OBJECTIVEC_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`OBJECTIVEC_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`REASONML_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`REASONML_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`OCTAVE_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`OCTAVE_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`MATLAB_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`MATLAB_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`ZIG_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`ZIG_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`SAGE_LITERAL`]")] +#![cfg_attr(feature = "format", doc = " - [`SAGE_STRING`]")] +#![cfg_attr(feature = "format", doc = " - [`JSON`]")] +#![cfg_attr(feature = "format", doc = " - [`TOML`]")] +#![cfg_attr(feature = "format", doc = " - [`YAML`]")] +#![cfg_attr(feature = "format", doc = " - [`XML`]")] +#![cfg_attr(feature = "format", doc = " - [`SQLITE`]")] +#![cfg_attr(feature = "format", doc = " - [`POSTGRESQL`]")] +#![cfg_attr(feature = "format", doc = " - [`MYSQL`]")] +#![cfg_attr(feature = "format", doc = " - [`MONGODB`]")] //! //! # Syntax Flags //! //! Bitflags to get and set syntax flags for the format packed struct. //! -//! - [REQUIRED_INTEGER_DIGITS] -//! - [REQUIRED_FRACTION_DIGITS] -//! - [REQUIRED_EXPONENT_DIGITS] -//! - [REQUIRED_MANTISSA_DIGITS] -//! - [REQUIRED_DIGITS] -//! - [NO_POSITIVE_MANTISSA_SIGN] -//! - [REQUIRED_MANTISSA_SIGN] -//! - [NO_EXPONENT_NOTATION] -//! - [NO_POSITIVE_EXPONENT_SIGN] -//! - [REQUIRED_EXPONENT_SIGN] -//! - [NO_EXPONENT_WITHOUT_FRACTION] -//! - [NO_SPECIAL] -//! - [CASE_SENSITIVE_SPECIAL] -//! - [NO_INTEGER_LEADING_ZEROS] -//! - [NO_FLOAT_LEADING_ZEROS] -//! - [REQUIRED_EXPONENT_NOTATION] -//! - [CASE_SENSITIVE_EXPONENT] -//! - [CASE_SENSITIVE_BASE_PREFIX] -//! - [CASE_SENSITIVE_BASE_SUFFIX] +//! - [`REQUIRED_INTEGER_DIGITS`] +//! - [`REQUIRED_FRACTION_DIGITS`] +//! - [`REQUIRED_EXPONENT_DIGITS`] +//! - [`REQUIRED_MANTISSA_DIGITS`] +//! - [`REQUIRED_DIGITS`] +//! - [`NO_POSITIVE_MANTISSA_SIGN`] +//! - [`REQUIRED_MANTISSA_SIGN`] +//! - [`NO_EXPONENT_NOTATION`] +//! - [`NO_POSITIVE_EXPONENT_SIGN`] +//! - [`REQUIRED_EXPONENT_SIGN`] +//! - [`NO_EXPONENT_WITHOUT_FRACTION`] +//! - [`NO_SPECIAL`] +//! - [`CASE_SENSITIVE_SPECIAL`] +//! - [`NO_INTEGER_LEADING_ZEROS`] +//! - [`NO_FLOAT_LEADING_ZEROS`] +//! - [`REQUIRED_EXPONENT_NOTATION`] +//! - [`CASE_SENSITIVE_EXPONENT`] +//! - [`CASE_SENSITIVE_BASE_PREFIX`] +//! - [`CASE_SENSITIVE_BASE_SUFFIX`] //! //! # Digit Separator Flags //! //! Bitflags to get and set digit separators flags for the format //! packed struct. //! -//! - [INTEGER_INTERNAL_DIGIT_SEPARATOR] -//! - [FRACTION_INTERNAL_DIGIT_SEPARATOR] -//! - [EXPONENT_INTERNAL_DIGIT_SEPARATOR] -//! - [INTEGER_LEADING_DIGIT_SEPARATOR] -//! - [FRACTION_LEADING_DIGIT_SEPARATOR] -//! - [EXPONENT_LEADING_DIGIT_SEPARATOR] -//! - [INTEGER_TRAILING_DIGIT_SEPARATOR] -//! - [FRACTION_TRAILING_DIGIT_SEPARATOR] -//! - [EXPONENT_TRAILING_DIGIT_SEPARATOR] -//! - [INTEGER_CONSECUTIVE_DIGIT_SEPARATOR] -//! - [FRACTION_CONSECUTIVE_DIGIT_SEPARATOR] -//! - [EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR] -//! - [INTERNAL_DIGIT_SEPARATOR] -//! - [LEADING_DIGIT_SEPARATOR] -//! - [TRAILING_DIGIT_SEPARATOR] -//! - [CONSECUTIVE_DIGIT_SEPARATOR] -//! - [SPECIAL_DIGIT_SEPARATOR] +//! - [`INTEGER_INTERNAL_DIGIT_SEPARATOR`] +//! - [`FRACTION_INTERNAL_DIGIT_SEPARATOR`] +//! - [`EXPONENT_INTERNAL_DIGIT_SEPARATOR`] +//! - [`INTEGER_LEADING_DIGIT_SEPARATOR`] +//! - [`FRACTION_LEADING_DIGIT_SEPARATOR`] +//! - [`EXPONENT_LEADING_DIGIT_SEPARATOR`] +//! - [`INTEGER_TRAILING_DIGIT_SEPARATOR`] +//! - [`FRACTION_TRAILING_DIGIT_SEPARATOR`] +//! - [`EXPONENT_TRAILING_DIGIT_SEPARATOR`] +//! - [`INTEGER_CONSECUTIVE_DIGIT_SEPARATOR`] +//! - [`FRACTION_CONSECUTIVE_DIGIT_SEPARATOR`] +//! - [`EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR`] +//! - [`INTERNAL_DIGIT_SEPARATOR`] +//! - [`LEADING_DIGIT_SEPARATOR`] +//! - [`TRAILING_DIGIT_SEPARATOR`] +//! - [`CONSECUTIVE_DIGIT_SEPARATOR`] +//! - [`SPECIAL_DIGIT_SEPARATOR`] //! //! # Character Shifts and Masks //! //! Bitmasks and bitshifts to get and set control characters for the format //! packed struct. //! -//! - [DIGIT_SEPARATOR_SHIFT] -//! - [DIGIT_SEPARATOR] -//! - [BASE_PREFIX_SHIFT] -//! - [BASE_PREFIX] -//! - [BASE_SUFFIX_SHIFT] -//! - [BASE_SUFFIX] -//! - [MANTISSA_RADIX_SHIFT] -//! - [MANTISSA_RADIX] -//! - [RADIX_SHIFT] -//! - [RADIX] -//! - [EXPONENT_BASE_SHIFT] -//! - [EXPONENT_BASE] -//! - [EXPONENT_RADIX_SHIFT] -//! - [EXPONENT_RADIX] +//! - [`DIGIT_SEPARATOR_SHIFT`] +//! - [`DIGIT_SEPARATOR`] +//! - [`BASE_PREFIX_SHIFT`] +//! - [`BASE_PREFIX`] +//! - [`BASE_SUFFIX_SHIFT`] +//! - [`BASE_SUFFIX`] +//! - [`MANTISSA_RADIX_SHIFT`] +//! - [`MANTISSA_RADIX`] +//! - [`RADIX_SHIFT`] +//! - [`RADIX`] +//! - [`EXPONENT_BASE_SHIFT`] +//! - [`EXPONENT_BASE`] +//! - [`EXPONENT_RADIX_SHIFT`] +//! - [`EXPONENT_RADIX`] //! //! # Character Functions //! //! Functions to get control characters from the format packed struct. //! -//! - [digit_separator] -//! - [base_prefix] -//! - [base_suffix] -//! - [mantissa_radix] -//! - [exponent_base] -//! - [exponent_radix] -//! - [radix_from_flags] +//! - [`digit_separator`] +//! - [`base_prefix`] +//! - [`base_suffix`] +//! - [`mantissa_radix`] +//! - [`exponent_base`] +//! - [`exponent_radix`] +//! - [`radix_from_flags`] //! //! # Validators //! //! Functions to validate control characters for the format packed struct. //! -//! - [is_valid_digit_separator] -//! - [is_valid_base_prefix] -//! - [is_valid_base_suffix] -//! - [is_valid_punctuation] -//! - [is_valid_radix] +//! - [`is_valid_digit_separator`] +//! - [`is_valid_base_prefix`] +//! - [`is_valid_base_suffix`] +//! - [`is_valid_punctuation`] +//! - [`is_valid_radix`] use static_assertions::const_assert; diff --git a/lexical-util/src/format_builder.rs b/lexical-util/src/format_builder.rs index 441f175b..706eace0 100644 --- a/lexical-util/src/format_builder.rs +++ b/lexical-util/src/format_builder.rs @@ -12,7 +12,7 @@ pub type OptionU8 = Option; // Ensure the sizes are identical. const_assert!(mem::size_of::() == mem::size_of::()); -/// Add single flag to SyntaxFormat. +/// Add single flag to `SyntaxFormat`. macro_rules! add_flag { ($format:ident, $bool:expr, $flag:ident) => { if $bool { @@ -21,7 +21,7 @@ macro_rules! add_flag { }; } -/// Add multiple flags to SyntaxFormat. +/// Add multiple flags to `SyntaxFormat`. macro_rules! add_flags { ($format:ident ; $($bool:expr, $flag:ident ;)*) => {{ $(add_flag!($format, $bool, $flag);)* @@ -236,7 +236,7 @@ pub struct NumberFormatBuilder { impl NumberFormatBuilder { // CONSTRUCTORS - /// Create new NumberFormatBuilder with default arguments. + /// Create new `NumberFormatBuilder` with default arguments. #[inline(always)] pub const fn new() -> Self { Self { diff --git a/lexical-util/src/format_flags.rs b/lexical-util/src/format_flags.rs index df26404b..c55a36fc 100644 --- a/lexical-util/src/format_flags.rs +++ b/lexical-util/src/format_flags.rs @@ -108,7 +108,7 @@ //! In order to limit the format specification and avoid parsing //! non-numerical data, all number formats require some significant //! digits. Examples of always invalid numbers include: -//! - `` +//! - ` ` //! - `.` //! - `e` //! - `e7` @@ -158,50 +158,50 @@ //! Currently Supported Programming and Data Languages: //! --------------------------------------------------- //! -//! 1. Rust -//! 2. Python -//! 3. C++ (98, 03, 11, 14, 17) -//! 4. C (89, 90, 99, 11, 18) -//! 5. Ruby -//! 6. Swift -//! 7. Go -//! 8. Haskell -//! 9. Javascript -//! 10. Perl -//! 11. PHP -//! 12. Java -//! 13. R -//! 14. Kotlin -//! 15. Julia -//! 16. C# (ISO-1, ISO-2, 3, 4, 5, 6, 7) -//! 17. Kawa -//! 18. Gambit-C -//! 19. Guile -//! 20. Clojure -//! 21. Erlang -//! 22. Elm -//! 23. Scala -//! 24. Elixir -//! 25. FORTRAN -//! 26. D -//! 27. Coffeescript -//! 28. Cobol -//! 29. F# -//! 30. Visual Basic -//! 31. OCaml -//! 32. Objective-C -//! 33. ReasonML -//! 34. Octave -//! 35. Matlab -//! 36. Zig -//! 37. SageMath -//! 38. JSON -//! 39. TOML -//! 40. XML -//! 41. SQLite -//! 42. PostgreSQL -//! 43. MySQL -//! 44. MongoDB +//! 1. `Rust` +//! 2. `Python` +//! 3. `C++` (98, 03, 11, 14, 17) +//! 4. `C` (89, 90, 99, 11, 18) +//! 5. `Ruby` +//! 6. `Swift` +//! 7. `Go` +//! 8. `Haskell` +//! 9. `Javascript` +//! 10. `Perl` +//! 11. `PHP` +//! 12. `Java` +//! 13. `R` +//! 14. `Kotlin` +//! 15. `Julia` +//! 16. `C#` (ISO-1, ISO-2, 3, 4, 5, 6, 7) +//! 17. `Kawa` +//! 18. `Gambit-C` +//! 19. `Guile` +//! 20. `Clojure` +//! 21. `Erlang` +//! 22. `Elm` +//! 23. `Scala` +//! 24. `Elixir` +//! 25. `FORTRAN` +//! 26. `D` +//! 27. `Coffeescript` +//! 28. `Cobol` +//! 29. `F#` +//! 30. `Visual Basic` +//! 31. `OCaml` +//! 32. `Objective-C` +//! 33. `ReasonML` +//! 34. `Octave` +//! 35. `Matlab` +//! 36. `Zig` +//! 37. `SageMath` +//! 38. `JSON` +//! 39. `TOML` +//! 40. `XML` +//! 41. `SQLite` +//! 42. `PostgreSQL` +//! 43. `MySQL` +//! 44. `MongoDB` #![cfg_attr(rustfmt, rustfmt::skip)] @@ -466,10 +466,10 @@ pub const MANTISSA_RADIX_SHIFT: i32 = 104; /// Mask to extract the mantissa radix: the radix for the significant digits. pub const MANTISSA_RADIX: u128 = 0xFF << MANTISSA_RADIX_SHIFT; -/// Alias for MANTISSA_RADIX_SHIFT. +/// Alias for `MANTISSA_RADIX_SHIFT`. pub const RADIX_SHIFT: i32 = MANTISSA_RADIX_SHIFT; -/// Alias for MANTISSA_RADIX. +/// Alias for `MANTISSA_RADIX`. pub const RADIX: u128 = MANTISSA_RADIX; /// Shift to convert to and from an exponent base as a `u32`. @@ -741,7 +741,7 @@ pub const fn is_valid_base_suffix(format: u128) -> bool { /// Determine if all of the "punctuation" characters are valid. #[inline(always)] -#[allow(clippy::if_same_then_else)] +#[allow(clippy::if_same_then_else)] // reason="all are different logic conditions" pub const fn is_valid_punctuation(format: u128) -> bool { // All the checks against optional characters with mandatory are fine: // if they're not 0, then they can't overlap, and mandatory can't be 0. @@ -766,7 +766,8 @@ pub const fn is_valid_punctuation(format: u128) -> bool { /// Determine if all of the "punctuation" characters for the options API are valid. #[inline(always)] -#[allow(clippy::if_same_then_else, clippy::needless_bool)] +#[allow(clippy::if_same_then_else)] // reason="all are different logic conditions" +#[allow(clippy::needless_bool)] // reason="not needless depending on the format condition" pub const fn is_valid_options_punctuation(format: u128, exponent: u8, decimal_point: u8) -> bool { // All the checks against optional characters with mandatory are fine: // if they're not 0, then they can't overlap, and mandatory can't be 0. diff --git a/lexical-util/src/iterator.rs b/lexical-util/src/iterator.rs index 9db4b2ee..7f4cb98e 100644 --- a/lexical-util/src/iterator.rs +++ b/lexical-util/src/iterator.rs @@ -23,18 +23,18 @@ pub use crate::skip::{AsBytes, Bytes}; /// /// # Safety /// -/// Safe if [set_cursor] is set to an index <= [buffer_length], so no -/// out-of-bounds reads can occur. Also, [get_buffer] must return a slice of +/// Safe if [`set_cursor`] is set to an index <= [`buffer_length`], so no +/// out-of-bounds reads can occur. Also, [`get_buffer`] must return a slice of /// initialized bytes. The caller must also ensure that any calls that increment -/// the cursor, such as [step_by_unchecked], [step_unchecked], and -/// [peek_many_unchecked] never exceed [buffer_length] as well. +/// the cursor, such as [`step_by_unchecked`], [`step_unchecked`], and +/// [`peek_many_unchecked`] never exceed [`buffer_length`] as well. /// -/// [set_cursor] Iter::set_cursor -/// [buffer_length] Iter::buffer_length -/// [get_buffer]: Iter::get_buffer -/// [step_by_unchecked]: Iter::step_by_unchecked -/// [step_unchecked]: Iter::step_unchecked -/// [peek_many_unchecked]: Iter::peek_many_unchecked +/// [`set_cursor`]: `Iter::set_cursor` +/// [`buffer_length`]: `Iter::buffer_length` +/// [`get_buffer`]: `Iter::get_buffer` +/// [`step_by_unchecked`]: `Iter::step_by_unchecked` +/// [`step_unchecked`]: `Iter::step_unchecked` +/// [`peek_many_unchecked`]: `Iter::peek_many_unchecked` #[cfg(feature = "parse")] pub unsafe trait Iter<'a> { /// Determine if the buffer is contiguous in memory. @@ -69,7 +69,7 @@ pub unsafe trait Iter<'a> { /// Get if no bytes are available in the buffer. /// /// This operators on the underlying buffer: that is, - /// it returns if [as_slice] would return an empty slice. + /// it returns if [`as_slice`] would return an empty slice. /// /// [as_slice]: Iter::as_slice #[inline(always)] @@ -264,15 +264,15 @@ pub trait DigitsIter<'a>: Iterator + Iter<'a> { /// non-contiguous iterators you **MUST** advance to the next element /// to be returned, then check to see if a value exists. The safest /// implementation is always to check if `self.peek().is_none()` and - /// ensure [peek] is always safe. + /// ensure [`peek`] is always safe. /// /// If you would like to see if the cursor is at the end of the buffer, - /// see [is_buffer_empty] instead. + /// see [`is_buffer_empty`] instead. /// /// [is_buffer_empty]: Iter::is_buffer_empty /// [peek]: DigitsIter::peek #[inline(always)] - #[allow(clippy::wrong_self_convention)] + #[allow(clippy::wrong_self_convention)] // reason="required for peeking next item" fn is_consumed(&mut self) -> bool { self.peek().is_none() } diff --git a/lexical-util/src/lib.rs b/lexical-util/src/lib.rs index fe3af037..756a87df 100644 --- a/lexical-util/src/lib.rs +++ b/lexical-util/src/lib.rs @@ -99,11 +99,38 @@ //! [is_consumed]: //! [peek]: +// FIXME: Implement clippy/allow reasons once we drop support for 1.80.0 and below +// Clippy reasons were stabilized in 1.81.0. + // We want to have the same safety guarantees as Rust core, // so we allow unused unsafe to clearly document safety guarantees. #![allow(unused_unsafe)] #![cfg_attr(feature = "lint", warn(unsafe_op_in_unsafe_fn))] #![cfg_attr(not(feature = "std"), no_std)] +#![deny( + clippy::doc_markdown, + clippy::unnecessary_safety_comment, + clippy::semicolon_if_nothing_returned, + clippy::unwrap_used, + clippy::as_underscore, + clippy::doc_markdown +)] +#![allow( + // used when concepts are logically separate + clippy::match_same_arms, + // loss of precision is intentional + clippy::integer_division, + // mathematical names use 1-character identifiers + clippy::min_ident_chars, + // these are not cryptographically secure contexts + clippy::integer_division_remainder_used, + // this can be intentional + clippy::module_name_repetitions, + // this is intentional: already passing a pointer and need performance + clippy::needless_pass_by_value, + // we use this for inline formatting for unsafe blocks + clippy::semicolon_inside_block, +)] pub mod algorithm; pub mod ascii; diff --git a/lexical-util/src/noskip.rs b/lexical-util/src/noskip.rs index e71d5e0b..e8209a77 100644 --- a/lexical-util/src/noskip.rs +++ b/lexical-util/src/noskip.rs @@ -53,11 +53,11 @@ impl<'a, const __: u128> Bytes<'a, __> { /// /// # Safety /// - /// This is safe if and only if the index is <= slc.len(). + /// This is safe if and only if the index is <= `slc.len()`. /// For this reason, since it's easy to get wrong, we only /// expose it to `DigitsIterator` and nothing else. #[inline(always)] - #[allow(clippy::assertions_on_constants)] + #[allow(clippy::assertions_on_constants)] // reason="ensuring safety invariants are valid" const unsafe fn from_parts(slc: &'a [u8], index: usize) -> Self { debug_assert!(index <= slc.len()); debug_assert!(Self::IS_CONTIGUOUS); @@ -122,7 +122,7 @@ unsafe impl<'a, const __: u128> Iter<'a> for Bytes<'a, __> { #[inline(always)] unsafe fn set_cursor(&mut self, index: usize) { debug_assert!(index <= self.buffer_length()); - self.index = index + self.index = index; } /// Get the current number of values returned by the iterator. @@ -137,7 +137,7 @@ unsafe impl<'a, const __: u128> Iter<'a> for Bytes<'a, __> { } #[inline(always)] - #[allow(clippy::assertions_on_constants)] + #[allow(clippy::assertions_on_constants)] // reason="ensuring safety invariants are valid" unsafe fn step_by_unchecked(&mut self, count: usize) { assert!(Self::IS_CONTIGUOUS); debug_assert!(self.as_slice().len() >= count); @@ -145,7 +145,7 @@ unsafe impl<'a, const __: u128> Iter<'a> for Bytes<'a, __> { } #[inline(always)] - #[allow(clippy::assertions_on_constants)] + #[allow(clippy::assertions_on_constants)] // reason="ensuring safety invariants are valid" unsafe fn peek_many_unchecked(&self) -> V { debug_assert!(Self::IS_CONTIGUOUS); debug_assert!(self.as_slice().len() >= mem::size_of::()); @@ -173,15 +173,13 @@ impl<'a: 'b, 'b, const __: u128> DigitsIterator<'a, 'b, __> { } } - // TODO: Move as a trait - /// Take the first N digits from the iterator. /// /// This only takes the digits if we have a contiguous iterator. /// It takes the digits, validating the bounds, and then advanced /// the iterators state. #[cfg_attr(not(feature = "compact"), inline(always))] - #[allow(clippy::assertions_on_constants)] + #[allow(clippy::assertions_on_constants)] // reason="ensuring safety invariants are valid" pub fn take_n(&mut self, n: usize) -> Option> { debug_assert!(Self::IS_CONTIGUOUS); let end = self.byte.slc.len().min(n + self.cursor()); diff --git a/lexical-util/src/num.rs b/lexical-util/src/num.rs index 522ba0b6..ca310d13 100644 --- a/lexical-util/src/num.rs +++ b/lexical-util/src/num.rs @@ -47,82 +47,82 @@ macro_rules! as_primitive { impl AsPrimitive for $t { #[inline(always)] fn as_u8(self) -> u8 { - self as _ + self as u8 } #[inline(always)] fn as_u16(self) -> u16 { - self as _ + self as u16 } #[inline(always)] fn as_u32(self) -> u32 { - self as _ + self as u32 } #[inline(always)] fn as_u64(self) -> u64 { - self as _ + self as u64 } #[inline(always)] fn as_u128(self) -> u128 { - self as _ + self as u128 } #[inline(always)] fn as_usize(self) -> usize { - self as _ + self as usize } #[inline(always)] fn as_i8(self) -> i8 { - self as _ + self as i8 } #[inline(always)] fn as_i16(self) -> i16 { - self as _ + self as i16 } #[inline(always)] fn as_i32(self) -> i32 { - self as _ + self as i32 } #[inline(always)] fn as_i64(self) -> i64 { - self as _ + self as i64 } #[inline(always)] fn as_i128(self) -> i128 { - self as _ + self as i128 } #[inline(always)] fn as_isize(self) -> isize { - self as _ + self as isize } #[inline(always)] fn as_f32(self) -> f32 { - self as _ + self as f32 } #[inline(always)] fn as_f64(self) -> f64 { - self as _ + self as f64 } #[inline(always)] fn from_u32(value: u32) -> Self { - value as _ + value as Self } #[inline(always)] fn from_u64(value: u64) -> Self { - value as _ + value as Self } #[cfg(feature = "f16")] @@ -148,75 +148,76 @@ macro_rules! half_as_primitive { impl AsPrimitive for $t { #[inline(always)] fn as_u8(self) -> u8 { - self.as_f32() as _ + self.as_f32() as u8 } #[inline(always)] fn as_u16(self) -> u16 { - self.as_f32() as _ + self.as_f32() as u16 } #[inline(always)] fn as_u32(self) -> u32 { - self.as_f32() as _ + self.as_f32() as u32 } #[inline(always)] fn as_u64(self) -> u64 { - self.as_f32() as _ + self.as_f32() as u64 } #[inline(always)] fn as_u128(self) -> u128 { - self.as_f32() as _ + self.as_f32() as u128 } #[inline(always)] fn as_usize(self) -> usize { - self.as_f32() as _ + self.as_f32() as usize } #[inline(always)] fn as_i8(self) -> i8 { - self.as_f32() as _ + self.as_f32() as i8 } #[inline(always)] fn as_i16(self) -> i16 { - self.as_f32() as _ + self.as_f32() as i16 } #[inline(always)] fn as_i32(self) -> i32 { - self.as_f32() as _ + self.as_f32() as i32 } #[inline(always)] fn as_i64(self) -> i64 { - self.as_f32() as _ + self.as_f32() as i64 } #[inline(always)] fn as_i128(self) -> i128 { - self.as_f32() as _ + self.as_f32() as i128 } #[inline(always)] fn as_isize(self) -> isize { - self.as_f32() as _ + self.as_f32() as isize } #[inline(always)] fn as_f32(self) -> f32 { - self.as_f32() as _ + self.as_f32() as f32 } #[inline(always)] fn as_f64(self) -> f64 { - self.as_f32() as _ + self.as_f32() as f64 } #[inline(always)] + #[allow(clippy::as_underscore)] // reason="intentionally used in a generic sense" fn from_u32(value: u32) -> Self { Self::from_f32(value as _) } @@ -263,6 +264,7 @@ macro_rules! as_cast { ($($t:ty, $meth:ident ; )*) => ($( impl AsCast for $t { #[inline(always)] + #[allow(clippy::as_underscore)] // reason="intentional due to generic API" fn as_cast(n: N) -> $t { n.$meth() as _ } @@ -1301,7 +1303,7 @@ fn floorf(x: f32) -> f32 { * to produce the hexadecimal values shown. */ -#[allow(clippy::eq_op, clippy::excessive_precision)] +#[allow(clippy::eq_op, clippy::excessive_precision)] // reason="values need to be exact under all conditions" #[cfg(all(not(feature = "std"), feature = "floats"))] fn logd(mut x: f64) -> f64 { const LN2_HI: f64 = 6.93147180369123816490e-01; /* 3fe62e42 fee00000 */ @@ -1373,7 +1375,7 @@ fn logd(mut x: f64) -> f64 { * ==================================================== */ -#[allow(clippy::eq_op, clippy::excessive_precision)] +#[allow(clippy::eq_op, clippy::excessive_precision)] // reason="values need to be exact under all conditions" #[cfg(all(not(feature = "std"), feature = "floats"))] fn logf(mut x: f32) -> f32 { const LN2_HI: f32 = 6.9313812256e-01; /* 0x3f317180 */ diff --git a/lexical-util/src/skip.rs b/lexical-util/src/skip.rs index 8337e26c..88a1023e 100644 --- a/lexical-util/src/skip.rs +++ b/lexical-util/src/skip.rs @@ -340,7 +340,7 @@ impl<'a> AsBytes<'a> for [u8] { /// `FORMAT` is required to tell us what the digit separator is, and where /// the digit separators are allowed, as well tell us the radix. /// The radix is required to allow us to differentiate digit from -/// non-digit characters (see [DigitSeparators](/docs/DigitSeparators.md) +/// non-digit characters (see [`DigitSeparators`](/docs/DigitSeparators.md) /// for a detailed explanation on why). #[derive(Clone)] pub struct Bytes<'a, const FORMAT: u128> { @@ -367,7 +367,7 @@ impl<'a, const FORMAT: u128> Bytes<'a, FORMAT> { /// Initialize the slice from raw parts. /// /// # Safety - /// This is safe if and only if the index is <= slc.len(). + /// This is safe if and only if the index is <= `slc.len()`. /// For this reason, since it's easy to get wrong, we only /// expose it to our `DigitsIterator`s and nothing else. /// @@ -439,7 +439,7 @@ unsafe impl<'a, const FORMAT: u128> Iter<'a> for Bytes<'a, FORMAT> { #[inline(always)] unsafe fn set_cursor(&mut self, index: usize) { debug_assert!(index <= self.buffer_length()); - self.index = index + self.index = index; } /// Get the current number of values returned by the iterator. @@ -541,7 +541,7 @@ macro_rules! skip_iterator_impl { /// the iterators state. It does not support non-contiguous iterators /// since we would lose information on the count. #[cfg_attr(not(feature = "compact"), inline(always))] - #[allow(clippy::assertions_on_constants)] + #[allow(clippy::assertions_on_constants)] // reason="ensuring safety invariants are valid" pub fn take_n(&mut self, n: usize) -> Option> { if Self::IS_CONTIGUOUS { let end = self.byte.slc.len().min(n + self.cursor()); @@ -633,7 +633,7 @@ macro_rules! skip_iterator_iter_base { }; } -/// Create base methods for the DigitsIter block of a skip iterator. +/// Create base methods for the `DigitsIter` block of a skip iterator. macro_rules! skip_iterator_digits_iter_base { () => { #[inline(always)] @@ -643,7 +643,7 @@ macro_rules! skip_iterator_digits_iter_base { }; } -/// Create impl ByteIter block for skip iterator. +/// Create impl `ByteIter` block for skip iterator. macro_rules! skip_iterator_bytesiter_impl { ($iterator:ident, $mask:ident, $i:ident, $l:ident, $t:ident, $c:ident) => { unsafe impl<'a: 'b, 'b, const FORMAT: u128> Iter<'a> for $iterator<'a, 'b, FORMAT> { diff --git a/lexical-util/src/step.rs b/lexical-util/src/step.rs index 3916a31a..8b852802 100644 --- a/lexical-util/src/step.rs +++ b/lexical-util/src/step.rs @@ -23,7 +23,7 @@ /// without overflowing for a given type. For example, 19 digits can /// always be processed for a decimal string for `u64` without overflowing. #[inline(always)] -#[allow(clippy::needless_return)] +#[allow(clippy::needless_return)] // reason="required depending on our radix configuration" pub const fn min_step(radix: u32, bits: usize, is_signed: bool) -> usize { // NOTE: to avoid branching when w don't need it, we use the compile logic @@ -96,7 +96,7 @@ pub const fn min_step(radix: u32, bits: usize, is_signed: bool) -> usize { /// be processed for a decimal string for `u64` without overflowing, but /// it may overflow. #[inline(always)] -#[allow(clippy::needless_return)] +#[allow(clippy::needless_return)] // reason="required depending on our radix configuration" pub const fn max_step(radix: u32, bits: usize, is_signed: bool) -> usize { #[cfg(feature = "radix")] { diff --git a/lexical-write-float/src/algorithm.rs b/lexical-write-float/src/algorithm.rs index c8b4e666..3e833115 100644 --- a/lexical-write-float/src/algorithm.rs +++ b/lexical-write-float/src/algorithm.rs @@ -88,7 +88,7 @@ pub fn write_float_scientific( // Write the significant digits. Write at index 1, so we can shift 1 // for the decimal point without intermediate buffers. - // SAFETY: safe, if we have enough bytes to write the significant digits. + // Won't panic if we have enough bytes to write the significant digits. let digits = &mut bytes[1..]; let digit_count = F::write_digits(digits, fp.mant); @@ -119,7 +119,7 @@ pub fn write_float_scientific( } // Now, write our scientific notation. - // SAFETY: safe since bytes must be large enough to store all digits. + // Won't panic since bytes must be large enough to store all digits. shared::write_exponent::(bytes, &mut cursor, sci_exp, options.exponent()); cursor @@ -152,7 +152,7 @@ pub fn write_float_negative_exponent( bytes[..cursor].fill(b'0'); // Write out our significant digits. - // SAFETY: safe, if we have enough bytes to write the significant digits. + // Won't panic: we have enough bytes to write the significant digits. let digits = &mut bytes[cursor..]; let digit_count = F::write_digits(digits, fp.mant); @@ -439,7 +439,7 @@ pub fn compute_nearest_shorter(float: F) -> ExtendedFloat80 { /// Compute the interval I = [m−w,m+w] if even, otherwise, (m−w,m+w). /// This is the normal case for a finite number with non-zero significant /// digits. -#[allow(clippy::comparison_chain)] +#[allow(clippy::comparison_chain)] // reason="logical approach for algorithm" pub fn compute_nearest_normal(float: F) -> ExtendedFloat80 { let mantissa = float.mantissa().as_u64(); let exponent = float.exponent(); @@ -524,7 +524,7 @@ pub fn compute_nearest_normal(float: F) -> ExtendedFloat80 { } else { let (xi_parity, x_is_integer) = F::compute_mul_parity(two_fl, &pow5, beta); if !xi_parity && !x_is_integer { - should_short_circuit = false + should_short_circuit = false; } } } @@ -575,7 +575,7 @@ pub fn compute_nearest_normal(float: F) -> ExtendedFloat80 { } /// Compute the interval I = [w,w+). -#[allow(clippy::comparison_chain)] +#[allow(clippy::comparison_chain)] // reason="logical approach for algorithm" pub fn compute_left_closed_directed(float: F) -> ExtendedFloat80 { let mantissa = float.mantissa().as_u64(); let exponent = float.exponent(); @@ -664,7 +664,7 @@ pub fn compute_left_closed_directed(float: F) -> ExtendedFloat80 { } /// Compute the interval I = (w−,w].. -#[allow(clippy::comparison_chain, clippy::if_same_then_else)] +#[allow(clippy::comparison_chain, clippy::if_same_then_else)] // reason="logical approach for algorithm" pub fn compute_right_closed_directed(float: F, shorter: bool) -> ExtendedFloat80 { // ensure our floats have a maximum exp in the range [-324, 308]. assert!(F::BITS <= 64, "cannot guarantee safety invariants with 128-bit floats"); @@ -757,6 +757,7 @@ pub fn compute_right_closed_directed(float: F, shorter: bool) -> Ex /// Returns the number of digits written. This assumes any trailing zeros have /// been removed. #[inline(always)] +#[allow(clippy::branches_sharing_code)] // reason="could differentiate later" pub fn write_digits_u32(bytes: &mut [u8], mantissa: u32) -> usize { debug_assert!(bytes.len() >= 10); mantissa.write_mantissa::(bytes) @@ -769,7 +770,7 @@ pub fn write_digits_u32(bytes: &mut [u8], mantissa: u32) -> usize { /// same as the number of digits in the mantissa, since trailing zeros will /// be removed. `log10(2**64-1) < 20`, so 20 digits is always enough. #[inline(always)] -#[allow(clippy::branches_sharing_code)] +#[allow(clippy::branches_sharing_code)] // reason="could differentiate later" pub fn write_digits_u64(bytes: &mut [u8], mantissa: u64) -> usize { debug_assert!(bytes.len() >= 20); mantissa.write_mantissa::(bytes) @@ -1145,7 +1146,7 @@ pub trait DragonboxFloat: Float { /// Constant derived in Section 4.5 of the Dragonbox algorithm. const KAPPA: u32; /// Ceiling of the maximum number of float decimal digits + 1. - /// Or, ceil((MANTISSA_SIZE + 1) / log2(10)) + 1. + /// Or, `ceil((MANTISSA_SIZE + 1) / log2(10)) + 1`. const DECIMAL_DIGITS: usize; const FC_PM_HALF_LOWER: i32 = -(Self::KAPPA as i32) - floor_log5_pow2(Self::KAPPA as i32); const DIV_BY_5_THRESHOLD: i32 = floor_log2_pow10(Self::KAPPA as i32 + 1); @@ -1186,7 +1187,7 @@ pub trait DragonboxFloat: Float { /// Remove trailing zeros from the float. fn remove_trailing_zeros(mantissa: u64) -> (u64, i32); - /// Determine if two_f is divisible by 2^exp. + /// Determine if `two_f` is divisible by 2^exp. #[inline(always)] fn divisible_by_pow2(x: u64, exp: u32) -> bool { // Preconditions: exp >= 1 && x != 0 diff --git a/lexical-write-float/src/binary.rs b/lexical-write-float/src/binary.rs index 2dc30de7..63ad4ba6 100644 --- a/lexical-write-float/src/binary.rs +++ b/lexical-write-float/src/binary.rs @@ -219,7 +219,7 @@ where let shl = calculate_shl(exp, bits_per_digit); let value = mantissa << shl; - // SAFETY: both are safe, if the buffer is large enough to hold the significant + // Won't panic, if the buffer is large enough to hold the significant // digits. let count = value.write_mantissa::(&mut bytes[cursor..]); let zeros = rtrim_char_count(&bytes[cursor..cursor + count], b'0'); @@ -697,7 +697,7 @@ pub fn calculate_shl(exp: i32, bits_per_digit: i32) -> i32 { /// If we have a negative exp, then when scaling that, /// we need to consider that an exp of -1 with 5 bits /// per base is still <0, IE, the sci exp we write has -/// to be: ⌊sci_exp / bits_per_base⌋, where ceil is +/// to be: `⌊sci_exp / bits_per_base⌋`, where ceil is /// wrapping towards greatest magnitude. /// /// If we have a positive exp, we just need the floor of the diff --git a/lexical-write-float/src/compact.rs b/lexical-write-float/src/compact.rs index 12c93ffc..574499bd 100644 --- a/lexical-write-float/src/compact.rs +++ b/lexical-write-float/src/compact.rs @@ -85,7 +85,7 @@ pub fn write_float( } /// Write float to string in scientific notation. -#[allow(clippy::comparison_chain)] +#[allow(clippy::comparison_chain)] // reason="logical approach for the algorithm" pub fn write_float_scientific( bytes: &mut [u8], digits: &mut [u8], @@ -143,7 +143,7 @@ pub fn write_float_scientific( /// Write negative float to string without scientific notation. /// /// Has a negative exponent (shift right) and no scientific notation. -#[allow(clippy::comparison_chain)] +#[allow(clippy::comparison_chain)] // reason="logical approach for the algorithm" pub fn write_float_negative_exponent( bytes: &mut [u8], digits: &mut [u8], diff --git a/lexical-write-float/src/hex.rs b/lexical-write-float/src/hex.rs index 8966fbfe..e85387fd 100644 --- a/lexical-write-float/src/hex.rs +++ b/lexical-write-float/src/hex.rs @@ -175,7 +175,8 @@ where let exact_count = shared::min_exact_digits(digit_count, options); // Write any trailing digits to the output. - // SAFETY: safe if the buffer is large enough to hold the significant digits. + // Won't panic safe if the buffer is large enough to hold the significant + // digits. if !format.no_exponent_without_fraction() && cursor == 2 && options.trim_floats() { // Need to trim floats from trailing zeros, and we have only a decimal. cursor -= 1; @@ -193,7 +194,7 @@ where } // Now, write our scientific notation. - // SAFETY: safe if bytes is large enough to store all digits. + // Won't panic safe if bytes is large enough to store all digits. let scaled_sci_exp = scale_sci_exp(sci_exp, bits_per_digit, bits_per_base); shared::write_exponent::(bytes, &mut cursor, scaled_sci_exp, options.exponent()); @@ -205,7 +206,7 @@ where /// We need to scale the scientific exponent for writing. /// -/// This is similar to [binary::scale_sci_exp](crate::binary::scale_sci_exp), +/// This is similar to [`binary::scale_sci_exp`](crate::binary::scale_sci_exp), /// however, we need to effectively have the same algorithm with `bits_per_base` /// instead of `bits_per_digit`. However, `bits_per_base` is smaller, and /// will not properly floor the values, so we add in an extra step. diff --git a/lexical-write-float/src/lib.rs b/lexical-write-float/src/lib.rs index c90160aa..c5860791 100644 --- a/lexical-write-float/src/lib.rs +++ b/lexical-write-float/src/lib.rs @@ -78,6 +78,30 @@ #![allow(unused_unsafe)] #![cfg_attr(feature = "lint", warn(unsafe_op_in_unsafe_fn))] #![cfg_attr(not(feature = "std"), no_std)] +#![deny( + clippy::doc_markdown, + clippy::unnecessary_safety_comment, + clippy::semicolon_if_nothing_returned, + clippy::unwrap_used, + clippy::as_underscore, + clippy::doc_markdown +)] +#![allow( + // used when concepts are logically separate + clippy::match_same_arms, + // loss of precision is intentional + clippy::integer_division, + // mathematical names use 1-character identifiers + clippy::min_ident_chars, + // these are not cryptographically secure contexts + clippy::integer_division_remainder_used, + // this can be intentional + clippy::module_name_repetitions, + // this is intentional: already passing a pointer and need performance + clippy::needless_pass_by_value, + // we use this for inline formatting for unsafe blocks + clippy::semicolon_inside_block, +)] #[macro_use] mod index; diff --git a/lexical-write-float/src/options.rs b/lexical-write-float/src/options.rs index e041bfe5..2f0ead6a 100644 --- a/lexical-write-float/src/options.rs +++ b/lexical-write-float/src/options.rs @@ -212,10 +212,10 @@ impl OptionsBuilder { /// /// Panics /// - /// Setting a value too large may cause a panic even if [FORMATTED_SIZE] + /// Setting a value too large may cause a panic even if [`FORMATTED_SIZE`] /// elements are provided. /// - /// [FORMATTED_SIZE]: lexical_util::constants::FormattedSize::FORMATTED_SIZE + /// [`FORMATTED_SIZE`]: `lexical_util::constants::FormattedSize::FORMATTED_SIZE` #[inline(always)] pub const fn nan_string(mut self, nan_string: Option<&'static [u8]>) -> Self { self.nan_string = nan_string; @@ -226,10 +226,10 @@ impl OptionsBuilder { /// /// Panics /// - /// Setting a value too large may cause a panic even if [FORMATTED_SIZE] + /// Setting a value too large may cause a panic even if [`FORMATTED_SIZE`] /// elements are provided. /// - /// [FORMATTED_SIZE]: lexical_util::constants::FormattedSize::FORMATTED_SIZE + /// [`FORMATTED_SIZE`]: `lexical_util::constants::FormattedSize::FORMATTED_SIZE` #[inline(always)] pub const fn inf_string(mut self, inf_string: Option<&'static [u8]>) -> Self { self.inf_string = inf_string; @@ -240,7 +240,7 @@ impl OptionsBuilder { /// Determine if `nan_str` is valid. #[inline(always)] - #[allow(clippy::if_same_then_else, clippy::needless_bool)] + #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason="more logical" pub const fn nan_str_is_valid(&self) -> bool { if self.nan_string.is_none() { return true; @@ -261,7 +261,7 @@ impl OptionsBuilder { /// Determine if `inf_str` is valid. #[inline(always)] - #[allow(clippy::if_same_then_else, clippy::needless_bool)] + #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason="more logical" pub const fn inf_str_is_valid(&self) -> bool { if self.inf_string.is_none() { return true; @@ -282,7 +282,7 @@ impl OptionsBuilder { /// Check if the builder state is valid. #[inline(always)] - #[allow(clippy::if_same_then_else, clippy::needless_bool)] + #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason="more logical" pub const fn is_valid(&self) -> bool { if !is_valid_ascii(self.exponent) { false @@ -303,8 +303,8 @@ impl OptionsBuilder { /// /// This is completely safe, however, misusing this, especially /// the `nan_string` and `inf_string` representations could cause - /// panics at runtime. Always use [MAX_SPECIAL_STRING_LENGTH] and - /// check if [Self::is_valid] prior to using a created format string. + /// panics at runtime. Always use [`MAX_SPECIAL_STRING_LENGTH`] and + /// check if [`Self::is_valid`] prior to using a created format string. #[inline(always)] pub const fn build_unchecked(&self) -> Options { Options { @@ -323,7 +323,7 @@ impl OptionsBuilder { /// Build the Options struct. #[inline(always)] - #[allow(clippy::if_same_then_else)] + #[allow(clippy::if_same_then_else)] // reason="more logical" pub const fn build(&self) -> Result { if self.nan_string.is_some() { let nan = unwrap_str(self.nan_string); @@ -515,13 +515,13 @@ impl Options { /// Set the maximum number of significant digits to write. #[inline(always)] pub fn set_max_significant_digits(&mut self, max_significant_digits: OptionUsize) { - self.max_significant_digits = max_significant_digits + self.max_significant_digits = max_significant_digits; } /// Set the minimum number of significant digits to write. #[inline(always)] pub fn set_min_significant_digits(&mut self, min_significant_digits: OptionUsize) { - self.min_significant_digits = min_significant_digits + self.min_significant_digits = min_significant_digits; } /// Set the maximum exponent prior to using scientific notation. @@ -574,37 +574,37 @@ impl Options { /// /// Panics /// - /// Setting a value too large may cause a panic even if [FORMATTED_SIZE] + /// Setting a value too large may cause a panic even if [`FORMATTED_SIZE`] /// elements are provided. /// - /// [FORMATTED_SIZE]: lexical_util::constants::FormattedSize::FORMATTED_SIZE + /// [`FORMATTED_SIZE`]: `lexical_util::constants::FormattedSize::FORMATTED_SIZE` #[inline(always)] pub fn set_nan_string(&mut self, nan_string: Option<&'static [u8]>) { - self.nan_string = nan_string + self.nan_string = nan_string; } /// Set the short string representation for `Infinity` /// /// Panics /// - /// Setting a value too large may cause a panic even if [FORMATTED_SIZE] + /// Setting a value too large may cause a panic even if [`FORMATTED_SIZE`] /// elements are provided. /// - /// [FORMATTED_SIZE]: lexical_util::constants::FormattedSize::FORMATTED_SIZE + /// [`FORMATTED_SIZE`]: `lexical_util::constants::FormattedSize::FORMATTED_SIZE` #[inline(always)] pub fn set_inf_string(&mut self, inf_string: Option<&'static [u8]>) { - self.inf_string = inf_string + self.inf_string = inf_string; } // BUILDERS - /// Get WriteFloatOptionsBuilder as a static function. + /// Get `WriteFloatOptionsBuilder` as a static function. #[inline(always)] pub const fn builder() -> OptionsBuilder { OptionsBuilder::new() } - /// Create OptionsBuilder using existing values. + /// Create `OptionsBuilder` using existing values. #[inline(always)] pub const fn rebuild(&self) -> OptionsBuilder { OptionsBuilder { @@ -700,7 +700,7 @@ impl WriteOptions for Options { } } -/// Define unwrap_or_zero for a custom type. +/// Define `unwrap_or_zero` for a custom type. macro_rules! unwrap_or_zero { ($name:ident, $opt:ident, $t:ident) => { /// Unwrap `Option` as a const fn. @@ -768,7 +768,7 @@ pub const CARAT_EXPONENT: Options = Options::builder() .build_unchecked(); const_assert!(CARAT_EXPONENT.is_valid()); -/// Number format for a Rust literal floating-point number. +/// Number format for a `Rust` literal floating-point number. #[rustfmt::skip] pub const RUST_LITERAL: Options = Options::builder() .nan_string(options::RUST_LITERAL) @@ -776,7 +776,7 @@ pub const RUST_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(RUST_LITERAL.is_valid()); -/// Number format for a Python literal floating-point number. +/// Number format for a `Python` literal floating-point number. #[rustfmt::skip] pub const PYTHON_LITERAL: Options = Options::builder() .nan_string(options::PYTHON_LITERAL) @@ -784,7 +784,7 @@ pub const PYTHON_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(PYTHON_LITERAL.is_valid()); -/// Number format for a C++ literal floating-point number. +/// Number format for a `C++` literal floating-point number. #[rustfmt::skip] pub const CXX_LITERAL: Options = Options::builder() .nan_string(options::CXX_LITERAL_NAN) @@ -792,7 +792,7 @@ pub const CXX_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(CXX_LITERAL.is_valid()); -/// Number format for a C literal floating-point number. +/// Number format for a `C` literal floating-point number. #[rustfmt::skip] pub const C_LITERAL: Options = Options::builder() .nan_string(options::C_LITERAL_NAN) @@ -800,7 +800,7 @@ pub const C_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(CXX_LITERAL.is_valid()); -/// Number format for a Ruby literal floating-point number. +/// Number format for a `Ruby` literal floating-point number. #[rustfmt::skip] pub const RUBY_LITERAL: Options = Options::builder() .positive_exponent_break(num::NonZeroI32::new(14)) @@ -810,7 +810,7 @@ pub const RUBY_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(RUBY_LITERAL.is_valid()); -/// Number format to parse a Ruby float from string. +/// Number format to parse a `Ruby` float from string. #[rustfmt::skip] pub const RUBY_STRING: Options = Options::builder() .nan_string(options::RUBY_LITERAL_NAN) @@ -818,7 +818,7 @@ pub const RUBY_STRING: Options = Options::builder() .build_unchecked(); const_assert!(RUBY_STRING.is_valid()); -/// Number format for a Swift literal floating-point number. +/// Number format for a `Swift` literal floating-point number. #[rustfmt::skip] pub const SWIFT_LITERAL: Options = Options::builder() .nan_string(options::SWIFT_LITERAL) @@ -826,7 +826,7 @@ pub const SWIFT_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(SWIFT_LITERAL.is_valid()); -/// Number format for a Go literal floating-point number. +/// Number format for a `Go` literal floating-point number. #[rustfmt::skip] pub const GO_LITERAL: Options = Options::builder() .nan_string(options::GO_LITERAL) @@ -834,7 +834,7 @@ pub const GO_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(GO_LITERAL.is_valid()); -/// Number format for a Haskell literal floating-point number. +/// Number format for a `Haskell` literal floating-point number. #[rustfmt::skip] pub const HASKELL_LITERAL: Options = Options::builder() .nan_string(options::HASKELL_LITERAL) @@ -842,28 +842,28 @@ pub const HASKELL_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(HASKELL_LITERAL.is_valid()); -/// Number format to parse a Haskell float from string. +/// Number format to parse a `Haskell` float from string. #[rustfmt::skip] pub const HASKELL_STRING: Options = Options::builder() .inf_string(options::HASKELL_STRING_INF) .build_unchecked(); const_assert!(HASKELL_STRING.is_valid()); -/// Number format for a Javascript literal floating-point number. +/// Number format for a `Javascript` literal floating-point number. #[rustfmt::skip] pub const JAVASCRIPT_LITERAL: Options = Options::builder() .inf_string(options::JAVASCRIPT_INF) .build_unchecked(); const_assert!(JAVASCRIPT_LITERAL.is_valid()); -/// Number format to parse a Javascript float from string. +/// Number format to parse a `Javascript` float from string. #[rustfmt::skip] pub const JAVASCRIPT_STRING: Options = Options::builder() .inf_string(options::JAVASCRIPT_INF) .build_unchecked(); const_assert!(JAVASCRIPT_STRING.is_valid()); -/// Number format for a Perl literal floating-point number. +/// Number format for a `Perl` literal floating-point number. #[rustfmt::skip] pub const PERL_LITERAL: Options = Options::builder() .nan_string(options::PERL_LITERAL) @@ -871,7 +871,7 @@ pub const PERL_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(PERL_LITERAL.is_valid()); -/// Number format for a PHP literal floating-point number. +/// Number format for a `PHP` literal floating-point number. #[rustfmt::skip] pub const PHP_LITERAL: Options = Options::builder() .nan_string(options::PHP_LITERAL_NAN) @@ -879,7 +879,7 @@ pub const PHP_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(PHP_LITERAL.is_valid()); -/// Number format for a Java literal floating-point number. +/// Number format for a `Java` literal floating-point number. #[rustfmt::skip] pub const JAVA_LITERAL: Options = Options::builder() .nan_string(options::JAVA_LITERAL) @@ -887,21 +887,21 @@ pub const JAVA_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(JAVA_LITERAL.is_valid()); -/// Number format to parse a Java float from string. +/// Number format to parse a `Java` float from string. #[rustfmt::skip] pub const JAVA_STRING: Options = Options::builder() .inf_string(options::JAVA_STRING_INF) .build_unchecked(); const_assert!(JAVA_STRING.is_valid()); -/// Number format for an R literal floating-point number. +/// Number format for an `R` literal floating-point number. #[rustfmt::skip] pub const R_LITERAL: Options = Options::builder() .inf_string(options::R_LITERAL_INF) .build_unchecked(); const_assert!(R_LITERAL.is_valid()); -/// Number format for a Kotlin literal floating-point number. +/// Number format for a `Kotlin` literal floating-point number. #[rustfmt::skip] pub const KOTLIN_LITERAL: Options = Options::builder() .nan_string(options::KOTLIN_LITERAL) @@ -909,21 +909,21 @@ pub const KOTLIN_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(KOTLIN_LITERAL.is_valid()); -/// Number format to parse a Kotlin float from string. +/// Number format to parse a `Kotlin` float from string. #[rustfmt::skip] pub const KOTLIN_STRING: Options = Options::builder() .inf_string(options::KOTLIN_STRING_INF) .build_unchecked(); const_assert!(KOTLIN_STRING.is_valid()); -/// Number format for a Julia literal floating-point number. +/// Number format for a `Julia` literal floating-point number. #[rustfmt::skip] pub const JULIA_LITERAL: Options = Options::builder() .inf_string(options::JULIA_LITERAL_INF) .build_unchecked(); const_assert!(JULIA_LITERAL.is_valid()); -/// Number format for a C# literal floating-point number. +/// Number format for a `C#` literal floating-point number. #[rustfmt::skip] pub const CSHARP_LITERAL: Options = Options::builder() .nan_string(options::CSHARP_LITERAL) @@ -931,14 +931,14 @@ pub const CSHARP_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(CSHARP_LITERAL.is_valid()); -/// Number format to parse a C# float from string. +/// Number format to parse a `C#` float from string. #[rustfmt::skip] pub const CSHARP_STRING: Options = Options::builder() .inf_string(options::CSHARP_STRING_INF) .build_unchecked(); const_assert!(CSHARP_STRING.is_valid()); -/// Number format for a Kawa literal floating-point number. +/// Number format for a `Kawa` literal floating-point number. #[rustfmt::skip] pub const KAWA_LITERAL: Options = Options::builder() .nan_string(options::KAWA) @@ -946,7 +946,7 @@ pub const KAWA_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(KAWA_LITERAL.is_valid()); -/// Number format to parse a Kawa float from string. +/// Number format to parse a `Kawa` float from string. #[rustfmt::skip] pub const KAWA_STRING: Options = Options::builder() .nan_string(options::KAWA) @@ -954,7 +954,7 @@ pub const KAWA_STRING: Options = Options::builder() .build_unchecked(); const_assert!(KAWA_STRING.is_valid()); -/// Number format for a Gambit-C literal floating-point number. +/// Number format for a `Gambit-C` literal floating-point number. #[rustfmt::skip] pub const GAMBITC_LITERAL: Options = Options::builder() .nan_string(options::GAMBITC) @@ -962,7 +962,7 @@ pub const GAMBITC_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(GAMBITC_LITERAL.is_valid()); -/// Number format to parse a Gambit-C float from string. +/// Number format to parse a `Gambit-C` float from string. #[rustfmt::skip] pub const GAMBITC_STRING: Options = Options::builder() .nan_string(options::GAMBITC) @@ -970,7 +970,7 @@ pub const GAMBITC_STRING: Options = Options::builder() .build_unchecked(); const_assert!(GAMBITC_STRING.is_valid()); -/// Number format for a Guile literal floating-point number. +/// Number format for a `Guile` literal floating-point number. #[rustfmt::skip] pub const GUILE_LITERAL: Options = Options::builder() .nan_string(options::GUILE) @@ -978,7 +978,7 @@ pub const GUILE_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(GUILE_LITERAL.is_valid()); -/// Number format to parse a Guile float from string. +/// Number format to parse a `Guile` float from string. #[rustfmt::skip] pub const GUILE_STRING: Options = Options::builder() .nan_string(options::GUILE) @@ -986,7 +986,7 @@ pub const GUILE_STRING: Options = Options::builder() .build_unchecked(); const_assert!(GUILE_STRING.is_valid()); -/// Number format for a Clojure literal floating-point number. +/// Number format for a `Clojure` literal floating-point number. #[rustfmt::skip] pub const CLOJURE_LITERAL: Options = Options::builder() .nan_string(options::CLOJURE_LITERAL) @@ -994,21 +994,21 @@ pub const CLOJURE_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(CLOJURE_LITERAL.is_valid()); -/// Number format to parse a Clojure float from string. +/// Number format to parse a `Clojure` float from string. #[rustfmt::skip] pub const CLOJURE_STRING: Options = Options::builder() .inf_string(options::CLOJURE_STRING_INF) .build_unchecked(); const_assert!(CLOJURE_STRING.is_valid()); -/// Number format for an Erlang literal floating-point number. +/// Number format for an `Erlang` literal floating-point number. #[rustfmt::skip] pub const ERLANG_LITERAL: Options = Options::builder() .nan_string(options::ERLANG_LITERAL_NAN) .build_unchecked(); const_assert!(ERLANG_LITERAL.is_valid()); -/// Number format to parse an Erlang float from string. +/// Number format to parse an `Erlang` float from string. #[rustfmt::skip] pub const ERLANG_STRING: Options = Options::builder() .nan_string(options::ERLANG_STRING) @@ -1016,7 +1016,7 @@ pub const ERLANG_STRING: Options = Options::builder() .build_unchecked(); const_assert!(ERLANG_STRING.is_valid()); -/// Number format for an Elm literal floating-point number. +/// Number format for an `Elm` literal floating-point number. #[rustfmt::skip] pub const ELM_LITERAL: Options = Options::builder() .nan_string(options::ELM_LITERAL) @@ -1024,7 +1024,7 @@ pub const ELM_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(ELM_LITERAL.is_valid()); -/// Number format to parse an Elm float from string. +/// Number format to parse an `Elm` float from string. #[rustfmt::skip] pub const ELM_STRING: Options = Options::builder() .nan_string(options::ELM_STRING_NAN) @@ -1032,7 +1032,7 @@ pub const ELM_STRING: Options = Options::builder() .build_unchecked(); const_assert!(ELM_STRING.is_valid()); -/// Number format for a Scala literal floating-point number. +/// Number format for a `Scala` literal floating-point number. #[rustfmt::skip] pub const SCALA_LITERAL: Options = Options::builder() .nan_string(options::SCALA_LITERAL) @@ -1040,14 +1040,14 @@ pub const SCALA_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(SCALA_LITERAL.is_valid()); -/// Number format to parse a Scala float from string. +/// Number format to parse a `Scala` float from string. #[rustfmt::skip] pub const SCALA_STRING: Options = Options::builder() .inf_string(options::SCALA_STRING_INF) .build_unchecked(); const_assert!(SCALA_STRING.is_valid()); -/// Number format for an Elixir literal floating-point number. +/// Number format for an `Elixir` literal floating-point number. #[rustfmt::skip] pub const ELIXIR_LITERAL: Options = Options::builder() .nan_string(options::ELIXIR) @@ -1055,7 +1055,7 @@ pub const ELIXIR_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(ELIXIR_LITERAL.is_valid()); -/// Number format to parse an Elixir float from string. +/// Number format to parse an `Elixir` float from string. #[rustfmt::skip] pub const ELIXIR_STRING: Options = Options::builder() .nan_string(options::ELIXIR) @@ -1063,7 +1063,7 @@ pub const ELIXIR_STRING: Options = Options::builder() .build_unchecked(); const_assert!(ELIXIR_STRING.is_valid()); -/// Number format for a FORTRAN literal floating-point number. +/// Number format for a `FORTRAN` literal floating-point number. #[rustfmt::skip] pub const FORTRAN_LITERAL: Options = Options::builder() .nan_string(options::FORTRAN_LITERAL) @@ -1071,7 +1071,7 @@ pub const FORTRAN_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(FORTRAN_LITERAL.is_valid()); -/// Number format for a D literal floating-point number. +/// Number format for a `D` literal floating-point number. #[rustfmt::skip] pub const D_LITERAL: Options = Options::builder() .nan_string(options::D_LITERAL) @@ -1079,21 +1079,21 @@ pub const D_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(D_LITERAL.is_valid()); -/// Number format for a Coffeescript literal floating-point number. +/// Number format for a `Coffeescript` literal floating-point number. #[rustfmt::skip] pub const COFFEESCRIPT_LITERAL: Options = Options::builder() .inf_string(options::COFFEESCRIPT_INF) .build_unchecked(); const_assert!(COFFEESCRIPT_LITERAL.is_valid()); -/// Number format to parse a Coffeescript float from string. +/// Number format to parse a `Coffeescript` float from string. #[rustfmt::skip] pub const COFFEESCRIPT_STRING: Options = Options::builder() .inf_string(options::COFFEESCRIPT_INF) .build_unchecked(); const_assert!(COFFEESCRIPT_STRING.is_valid()); -/// Number format for a COBOL literal floating-point number. +/// Number format for a `COBOL` literal floating-point number. #[rustfmt::skip] pub const COBOL_LITERAL: Options = Options::builder() .nan_string(options::COBOL) @@ -1101,7 +1101,7 @@ pub const COBOL_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(COBOL_LITERAL.is_valid()); -/// Number format to parse a COBOL float from string. +/// Number format to parse a `COBOL` float from string. #[rustfmt::skip] pub const COBOL_STRING: Options = Options::builder() .nan_string(options::COBOL) @@ -1109,7 +1109,7 @@ pub const COBOL_STRING: Options = Options::builder() .build_unchecked(); const_assert!(COBOL_STRING.is_valid()); -/// Number format for an F# literal floating-point number. +/// Number format for an `F#` literal floating-point number. #[rustfmt::skip] pub const FSHARP_LITERAL: Options = Options::builder() .nan_string(options::FSHARP_LITERAL_NAN) @@ -1117,7 +1117,7 @@ pub const FSHARP_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(FSHARP_LITERAL.is_valid()); -/// Number format for a Visual Basic literal floating-point number. +/// Number format for a `Visual Basic` literal floating-point number. #[rustfmt::skip] pub const VB_LITERAL: Options = Options::builder() .nan_string(options::VB_LITERAL) @@ -1125,14 +1125,14 @@ pub const VB_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(VB_LITERAL.is_valid()); -/// Number format to parse a Visual Basic float from string. +/// Number format to parse a `Visual Basic` float from string. #[rustfmt::skip] pub const VB_STRING: Options = Options::builder() .inf_string(options::VB_STRING_INF) .build_unchecked(); const_assert!(VB_STRING.is_valid()); -/// Number format for an OCaml literal floating-point number. +/// Number format for an `OCaml` literal floating-point number. #[rustfmt::skip] pub const OCAML_LITERAL: Options = Options::builder() .nan_string(options::OCAML_LITERAL_NAN) @@ -1140,7 +1140,7 @@ pub const OCAML_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(OCAML_LITERAL.is_valid()); -/// Number format for an Objective-C literal floating-point number. +/// Number format for an `Objective-C` literal floating-point number. #[rustfmt::skip] pub const OBJECTIVEC_LITERAL: Options = Options::builder() .nan_string(options::OBJECTIVEC) @@ -1148,7 +1148,7 @@ pub const OBJECTIVEC_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(OBJECTIVEC_LITERAL.is_valid()); -/// Number format to parse an Objective-C float from string. +/// Number format to parse an `Objective-C` float from string. #[rustfmt::skip] pub const OBJECTIVEC_STRING: Options = Options::builder() .nan_string(options::OBJECTIVEC) @@ -1156,7 +1156,7 @@ pub const OBJECTIVEC_STRING: Options = Options::builder() .build_unchecked(); const_assert!(OBJECTIVEC_STRING.is_valid()); -/// Number format for an ReasonML literal floating-point number. +/// Number format for an `ReasonML` literal floating-point number. #[rustfmt::skip] pub const REASONML_LITERAL: Options = Options::builder() .nan_string(options::REASONML_LITERAL_NAN) @@ -1164,14 +1164,14 @@ pub const REASONML_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(REASONML_LITERAL.is_valid()); -/// Number format for a MATLAB literal floating-point number. +/// Number format for a `MATLAB` literal floating-point number. #[rustfmt::skip] pub const MATLAB_LITERAL: Options = Options::builder() .inf_string(options::MATLAB_LITERAL_INF) .build_unchecked(); const_assert!(MATLAB_LITERAL.is_valid()); -/// Number format for a Zig literal floating-point number. +/// Number format for a `Zig` literal floating-point number. #[rustfmt::skip] pub const ZIG_LITERAL: Options = Options::builder() .nan_string(options::ZIG_LITERAL) @@ -1179,14 +1179,14 @@ pub const ZIG_LITERAL: Options = Options::builder() .build_unchecked(); const_assert!(ZIG_LITERAL.is_valid()); -/// Number format for a Safe literal floating-point number. +/// Number format for a `Safe` literal floating-point number. #[rustfmt::skip] pub const SAGE_LITERAL: Options = Options::builder() .inf_string(options::SAGE_LITERAL_INF) .build_unchecked(); const_assert!(SAGE_LITERAL.is_valid()); -/// Number format for a JSON literal floating-point number. +/// Number format for a `JSON` literal floating-point number. #[rustfmt::skip] pub const JSON: Options = Options::builder() .nan_string(options::JSON) @@ -1194,7 +1194,7 @@ pub const JSON: Options = Options::builder() .build_unchecked(); const_assert!(JSON.is_valid()); -/// Number format for a TOML literal floating-point number. +/// Number format for a `TOML` literal floating-point number. #[rustfmt::skip] pub const TOML: Options = Options::builder() .nan_string(options::TOML) @@ -1202,18 +1202,18 @@ pub const TOML: Options = Options::builder() .build_unchecked(); const_assert!(TOML.is_valid()); -/// Number format for a YAML literal floating-point number. +/// Number format for a `YAML` literal floating-point number. #[rustfmt::skip] pub const YAML: Options = JSON; -/// Number format for an XML literal floating-point number. +/// Number format for an `XML` literal floating-point number. #[rustfmt::skip] pub const XML: Options = Options::builder() .inf_string(options::XML_INF) .build_unchecked(); const_assert!(XML.is_valid()); -/// Number format for a SQLite literal floating-point number. +/// Number format for a `SQLite` literal floating-point number. #[rustfmt::skip] pub const SQLITE: Options = Options::builder() .nan_string(options::SQLITE) @@ -1221,7 +1221,7 @@ pub const SQLITE: Options = Options::builder() .build_unchecked(); const_assert!(SQLITE.is_valid()); -/// Number format for a PostgreSQL literal floating-point number. +/// Number format for a `PostgreSQL` literal floating-point number. #[rustfmt::skip] pub const POSTGRESQL: Options = Options::builder() .nan_string(options::POSTGRESQL) @@ -1229,7 +1229,7 @@ pub const POSTGRESQL: Options = Options::builder() .build_unchecked(); const_assert!(POSTGRESQL.is_valid()); -/// Number format for a MySQL literal floating-point number. +/// Number format for a `MySQL` literal floating-point number. #[rustfmt::skip] pub const MYSQL: Options = Options::builder() .nan_string(options::MYSQL) @@ -1237,7 +1237,7 @@ pub const MYSQL: Options = Options::builder() .build_unchecked(); const_assert!(MYSQL.is_valid()); -/// Number format for a MongoDB literal floating-point number. +/// Number format for a `MongoDB` literal floating-point number. #[rustfmt::skip] pub const MONGODB: Options = Options::builder() .inf_string(options::MONGODB_INF) diff --git a/lexical-write-float/src/radix.rs b/lexical-write-float/src/radix.rs index aa34eb94..e41ab23c 100644 --- a/lexical-write-float/src/radix.rs +++ b/lexical-write-float/src/radix.rs @@ -34,7 +34,7 @@ use crate::shared; /// # Panics /// /// Panics if exponent notation is used. -#[allow(clippy::collapsible_if)] +#[allow(clippy::collapsible_if)] // reason="conditions are different logical concepts" pub fn write_float( float: F, bytes: &mut [u8], @@ -84,7 +84,8 @@ where debug_assert!(delta > F::ZERO); // Write our fraction digits. - // SAFETY: we have 1100 digits, which is enough for any float f64 or smaller. + // Won't panic since we have 1100 digits, which is enough for any float f64 or + // smaller. if fraction > delta { loop { // Shift up by one digit. @@ -129,8 +130,8 @@ where } // Compute integer digits. Fill unrepresented digits with zero. - // SAFETY: we have 1100 digits, which is enough for any float f64 or smaller. - // We do this first, so we can do extended precision control later. + // Won't panic we have 1100 digits, which is enough for any float f64 or + // smaller. We do this first, so we can do extended precision control later. while (integer / base).exponent() > 0 { integer /= base; integer_cursor -= 1; @@ -232,7 +233,7 @@ pub fn write_float_scientific( let exact_count = shared::min_exact_digits(digit_count, options); // Write any trailing digits to the output. - // SAFETY: bytes cannot be empty. + // Won't panic since bytes cannot be empty. if !format.no_exponent_without_fraction() && cursor == 2 && options.trim_floats() { // Need to trim floats from trailing zeros, and we have only a decimal. cursor -= 1; @@ -309,7 +310,7 @@ pub fn write_float_nonscientific( // Write the fraction component. // We've only consumed `integer_count` digits, since this input // may have been truncated. - // SAFETY: safe since `integer_count < digits.len()` since `digit_count < + // Won't panic since `integer_count < digits.len()` since `digit_count < // digits.len()`. let digits = &digits[integer_count..]; let fraction_count = digit_count.saturating_sub(integer_length); @@ -334,7 +335,7 @@ pub fn write_float_nonscientific( let exact_count = shared::min_exact_digits(digit_count, options); // Write any trailing digits to the output. - // SAFETY: bytes cannot be empty. + // Won't panic since bytes cannot be empty. if (fraction_count > 0 || !options.trim_floats()) && exact_count > digit_count { // NOTE: Neither `exact_count >= digit_count >= 2`. // We need to write `exact_count - (cursor - 1)` digits, since @@ -369,7 +370,7 @@ const MAX_DIGIT_LENGTH: usize = BUFFER_SIZE - MAX_NONDIGIT_LENGTH; /// of significant digits. Returns the number of digits of the mantissa, /// and if the rounding did a full carry. #[cfg_attr(not(feature = "compact"), inline(always))] -#[allow(clippy::comparison_chain)] +#[allow(clippy::comparison_chain)] // reason="conditions are different logical concepts" pub fn truncate_and_round( buffer: &mut [u8], start: usize, diff --git a/lexical-write-float/src/shared.rs b/lexical-write-float/src/shared.rs index 0a6559ea..42cab65a 100644 --- a/lexical-write-float/src/shared.rs +++ b/lexical-write-float/src/shared.rs @@ -29,9 +29,9 @@ pub fn round_up(digits: &mut [u8], count: usize, radix: u32) -> (usize, bool) { while index != 0 { let c = digits[index - 1]; if c < max_char { - // SAFETY: safe since `index > 0 && index <= digits.len()`. let digit = char_to_valid_digit_const(c, radix); let rounded = digit_to_char_const(digit + 1, radix); + // Won't panic since `index > 0 && index <= digits.len()`. digits[index - 1] = rounded; return (index, false); } @@ -52,8 +52,8 @@ pub fn round_up(digits: &mut [u8], count: usize, radix: u32) -> (usize, bool) { /// length of the written digits in `digits`, and `exp` is the decimal exponent /// relative to the digits. Returns the digit count, resulting exp, and if /// the input carried to the next digit. -#[allow(clippy::comparison_chain)] #[cfg_attr(not(feature = "compact"), inline(always))] +#[allow(clippy::comparison_chain)] // reason="conditions are different logical concepts" pub fn truncate_and_round_decimal( digits: &mut [u8], digit_count: usize, @@ -81,7 +81,7 @@ pub fn truncate_and_round_decimal( // halfway at all, we need to round up, even if 1 digit. // Get the last non-truncated digit, and the remaining ones. - // SAFETY: safe if `digit_count < digits.len()`, since `max_digits < + // Won't panic if `digit_count < digits.len()`, since `max_digits < // digit_count`. let truncated = digits[max_digits]; let (digits, carried) = if truncated < b'5' { @@ -96,7 +96,7 @@ pub fn truncate_and_round_decimal( let is_odd = to_round[0] % 2 == 1; let is_above = to_round[2..].iter().any(|&x| x != b'0'); if is_odd || is_above { - // SAFETY: safe if `digit_count <= digits.len()`, because `max_digits < + // Won't panic `digit_count <= digits.len()`, because `max_digits < // digit_count`. round_up(digits, max_digits, 10) } else { diff --git a/lexical-write-float/src/write.rs b/lexical-write-float/src/write.rs index 3a680ee5..8b3c54fa 100644 --- a/lexical-write-float/src/write.rs +++ b/lexical-write-float/src/write.rs @@ -122,7 +122,6 @@ pub trait WriteFloat: RawFloat + FormattedSize { if !self.is_special() { #[cfg(all(feature = "power-of-two", not(feature = "radix")))] { - // SAFETY: safe if the buffer can hold the significant digits let radix = format.radix(); let exponent_base = format.exponent_base(); count @@ -137,7 +136,6 @@ pub trait WriteFloat: RawFloat + FormattedSize { #[cfg(feature = "radix")] { - // SAFETY: safe if the buffer can hold the significant digits let radix = format.radix(); let exponent_base = format.exponent_base(); count @@ -179,7 +177,6 @@ macro_rules! write_float_as_f32 { #[inline(always)] fn write_float(self, bytes: &mut [u8], options: &Options) -> usize { - // SAFETY: safe if `bytes` is large enough to hold the written bytes. self.as_f32().write_float::(bytes, options) } } diff --git a/lexical-write-integer/src/algorithm.rs b/lexical-write-integer/src/algorithm.rs index 9c8f88cf..9737c3ac 100644 --- a/lexical-write-integer/src/algorithm.rs +++ b/lexical-write-integer/src/algorithm.rs @@ -132,8 +132,8 @@ unsafe fn write_digits( // Decode last 2 digits. if value < radix { - // SAFETY: this is always safe, since value < radix, so it must be < 36. let r = u32::as_cast(value); + // SAFETY: this is always safe, since value < radix, so it must be < 36. write_digit!(buffer, index, r); } else { let r = usize::as_cast(T::TWO * value); @@ -167,8 +167,8 @@ unsafe fn write_step_digits( // SAFETY: safe as long as the call to write_step_digits is safe. let index = unsafe { write_digits(value, radix, table, buffer, index) }; // Write the remaining 0 bytes. - // SAFETY: this is always safe since `end < index && index < start`. let end = start.saturating_sub(step); + // SAFETY: this is always safe since `end < index && index < start`. let zeros = unsafe { &mut index_unchecked_mut!(buffer[end..index]) }; zeros.fill(b'0'); @@ -181,12 +181,12 @@ unsafe fn write_step_digits( /// /// Safe as long as the buffer is large enough to hold as many digits /// that can be in the largest value of `T`, in radix `N`. For decimal -/// values, it's supposed to be exactly [digit_count] to avoid copies, +/// values, it's supposed to be exactly [`digit_count`] to avoid copies, /// since we write from the end to the front. /// -/// See the crate [crate] documentation for more security considerations. +/// See the crate [`crate`] documentation for more security considerations. /// -/// [digit_count]: crate::decimal::DigitCount +/// [`digit_count`]: `crate::decimal::DigitCount` #[inline(always)] pub fn algorithm(value: T, radix: u32, table: &[u8], buffer: &mut [u8]) -> usize where @@ -216,12 +216,12 @@ where /// /// Safe as long as the buffer is large enough to hold as many digits /// that can be in the largest value of `T`, in radix `N`. For decimal -/// values, it's supposed to be exactly [digit_count] to avoid copies, +/// values, it's supposed to be exactly [`digit_count`] to avoid copies, /// since we write from the end to the front. /// -/// See the crate [crate] documentation for more security considerations. +/// See the crate [`crate`] documentation for more security considerations. /// -/// [digit_count]: crate::decimal::DigitCount +/// [`digit_count`]: `crate::decimal::DigitCount` #[inline(always)] pub fn algorithm_u128( value: u128, @@ -242,12 +242,12 @@ pub fn algorithm_u128( let radix = radix_from_flags(FORMAT, MASK, SHIFT); assert!(radix <= 36, "radix must be <= 36"); assert!(table.len() >= (radix * radix * 2) as usize, "table must be 2 * radix^2 long"); - if value <= u64::MAX as _ { + if value <= u64::MAX as u128 { // SAFETY: safe if the buffer is large enough to hold the significant digits. return unsafe { algorithm(value as u64, radix, table, buffer) }; } - // SAFETY: Both forms of unchecked indexing cannot overflow. + // LOGIC: Both forms of unchecked indexing cannot overflow. // The table always has 2*radix^2 elements, so it must be a legal index. // The buffer is ensured to have at least `FORMATTED_SIZE` or // `FORMATTED_SIZE_DECIMAL` characters, which is the maximum number of @@ -264,7 +264,7 @@ pub fn algorithm_u128( let (value, low) = u128_divrem(value, radix_from_flags(FORMAT, MASK, SHIFT)); let mut index = buffer.len(); index = unsafe { write_step_digits(low, radix, table, buffer, index, step) }; - if value <= u64::MAX as _ { + if value <= u64::MAX as u128 { unsafe { write_digits(value as u64, radix, table, buffer, index) }; return count; } diff --git a/lexical-write-integer/src/api.rs b/lexical-write-integer/src/api.rs index 11d34d15..d6070d1a 100644 --- a/lexical-write-integer/src/api.rs +++ b/lexical-write-integer/src/api.rs @@ -72,7 +72,7 @@ where // API -// Implement ToLexical for numeric type. +// Implement `ToLexical` for numeric type. macro_rules! unsigned_to_lexical { ($($narrow:tt $wide:tt ; )*) => ($( impl ToLexical for $narrow { @@ -120,7 +120,7 @@ unsigned_to_lexical! { usize u32 ; } #[cfg(target_pointer_width = "64")] unsigned_to_lexical! { usize u64 ; } -// Implement ToLexical for numeric type. +// Implement `ToLexical` for numeric type. macro_rules! signed_to_lexical { ($($narrow:tt $wide:tt $unsigned:tt ; )*) => ($( impl ToLexical for $narrow { diff --git a/lexical-write-integer/src/decimal.rs b/lexical-write-integer/src/decimal.rs index 790efa6c..2ec3a576 100644 --- a/lexical-write-integer/src/decimal.rs +++ b/lexical-write-integer/src/decimal.rs @@ -99,7 +99,7 @@ pub fn fast_digit_count(x: u32) -> usize { 42949672960, 42949672960, ]; - // SAFETY: always safe, since fast_log2 will always return a value + // This always safe, since fast_log2 will always return a value // <= 32. This is because the range of values from `ctlz(x | 1)` is // `[0, 31]`, so `32 - 1 - ctlz(x | 1)` must be in the range `[0, 31]`. let shift = TABLE[fast_log2(x)]; diff --git a/lexical-write-integer/src/lib.rs b/lexical-write-integer/src/lib.rs index ec0d0874..ea9e0e95 100644 --- a/lexical-write-integer/src/lib.rs +++ b/lexical-write-integer/src/lib.rs @@ -52,15 +52,15 @@ //! as an intermediate. //! //! The decimal writer relies on pre-computed tables and an exact calculation -//! of the digit count ([digit_count]) to avoid any overhead. Avoid intermediary -//! copies is **CRITICAL** for fast performance so the entire buffer must be -//! known but assigned to use algorithms the compiler cannot easily verify. This -//! is because we use multi-digit optimizations with our pre-computed tables, -//! so we cannot just iterate over the slice and assign iteratively. Using -//! checked indexing can lead to 30%+ decreases in performance. However, with -//! careful analysis and factoring of the code, it's fairly easy to demonstrate -//! the safety as long as the caller enusres at least the required number of -//! digits are provided. +//! of the digit count ([`digit_count`]) to avoid any overhead. Avoid +//! intermediary copies is **CRITICAL** for fast performance so the entire +//! buffer must be known but assigned to use algorithms the compiler cannot +//! easily verify. This is because we use multi-digit optimizations with our +//! pre-computed tables, so we cannot just iterate over the slice and assign +//! iteratively. Using checked indexing can lead to 30%+ decreases in +//! performance. However, with careful analysis and factoring of the code, it's +//! fairly easy to demonstrate the safety as long as the caller enusres at least +//! the required number of digits are provided. //! //! Our algorithms work like this, carving off the lower digits and writing them //! to the back of the buffer. @@ -100,27 +100,51 @@ //! We can efficiently determine at compile time if the pre-computed //! tables are large enough so there are no non-local safety considerations //! there. The current logic call stack is: -//! 1. [to_lexical] +//! 1. [`to_lexical`] //! 2. [decimal][dec], compact, or radix (gts the correct tables and calls //! algorithm) //! 3. [algorithm] //! //! [decimal][dec], compact, and radix therefore **MUST** be safe and do type //! check of the bounds to avoid too much expoosure to unsafety. Only -//! [algorithm] should have any unsafety associated with it. That is, as long as -//! the direct caller has ensure the proper buffer is allocated, there are +//! [`algorithm`] should have any unsafety associated with it. That is, as long +//! as the direct caller has ensure the proper buffer is allocated, there are //! non-local safety invariants. //! -//! [digit_count]: crate::decimal::DigitCount -//! [to_lexical]: crate::ToLexical::to_lexical +//! [`digit_count`]: crate::decimal::DigitCount +//! [`to_lexical`]: crate::ToLexical::to_lexical //! [dec]: crate::decimal::Decimal::decimal -//! [algorithm]: crate::algorithm::algorithm +//! [`algorithm`]: crate::algorithm::algorithm // We want to have the same safety guarantees as Rust core, // so we allow unused unsafe to clearly document safety guarantees. #![allow(unused_unsafe)] #![cfg_attr(feature = "lint", warn(unsafe_op_in_unsafe_fn))] #![cfg_attr(not(feature = "std"), no_std)] +#![deny( + clippy::doc_markdown, + clippy::unnecessary_safety_comment, + clippy::semicolon_if_nothing_returned, + clippy::unwrap_used, + clippy::as_underscore, + clippy::doc_markdown +)] +#![allow( + // used when concepts are logically separate + clippy::match_same_arms, + // loss of precision is intentional + clippy::integer_division, + // mathematical names use 1-character identifiers + clippy::min_ident_chars, + // these are not cryptographically secure contexts + clippy::integer_division_remainder_used, + // this can be intentional + clippy::module_name_repetitions, + // this is intentional: already passing a pointer and need performance + clippy::needless_pass_by_value, + // we use this for inline formatting for unsafe blocks + clippy::semicolon_inside_block, +)] #[macro_use] mod index; diff --git a/lexical-write-integer/src/options.rs b/lexical-write-integer/src/options.rs index b3ff7cd6..fd5b3c5e 100644 --- a/lexical-write-integer/src/options.rs +++ b/lexical-write-integer/src/options.rs @@ -26,13 +26,13 @@ impl OptionsBuilder { true } - /// Build the Options struct with bounds validation. + /// Build the `Options` struct with bounds validation. #[inline(always)] pub const fn build_unchecked(&self) -> Options { Options {} } - /// Build the Options struct. + /// Build the `Options` struct. #[inline(always)] pub const fn build(&self) -> Result { Ok(self.build_unchecked()) @@ -77,13 +77,13 @@ impl Options { // BUILDERS - /// Get OptionsBuilder as a static function. + /// Get `OptionsBuilder` as a static function. #[inline(always)] pub const fn builder() -> OptionsBuilder { OptionsBuilder::new() } - /// Create OptionsBuilder using existing values. + /// Create `OptionsBuilder` using existing values. #[inline(always)] pub const fn rebuild(&self) -> OptionsBuilder { OptionsBuilder {} diff --git a/lexical/src/lib.rs b/lexical/src/lib.rs index fc4913d1..161cacab 100644 --- a/lexical/src/lib.rs +++ b/lexical/src/lib.rs @@ -1,6 +1,6 @@ //! Fast lexical conversion routines. //! -//! Fast lexical conversion routines for both std and no_std environments. +//! Fast lexical conversion routines for both `std` and `no_std` environments. //! lexical provides routines to convert numbers to and from decimal //! strings. lexical also supports non-base 10 numbers, with the `radix` //! feature, for both integers and floats. lexical is customizable @@ -178,8 +178,9 @@ //! //! Many pre-defined constants therefore exist to simplify common use-cases, //! including: -//! - JSON, XML, TOML, YAML, SQLite, and many more. -//! - Rust, Python, C#, FORTRAN, COBOL literals and strings, and many more. +//! - `JSON`, `XML`, `TOML`, `YAML`, `SQLite`, and many more. +//! - `Rust`, `Python`, `C#`, `FORTRAN`, `COBOL` literals and strings, and many +//! more. //! //! ## Options API //! @@ -275,6 +276,30 @@ #![allow(unused_unsafe)] #![cfg_attr(feature = "lint", warn(unsafe_op_in_unsafe_fn))] #![cfg_attr(not(feature = "std"), no_std)] +#![deny( + clippy::doc_markdown, + clippy::unnecessary_safety_comment, + clippy::semicolon_if_nothing_returned, + clippy::unwrap_used, + clippy::as_underscore, + clippy::doc_markdown +)] +#![allow( + // used when concepts are logically separate + clippy::match_same_arms, + // loss of precision is intentional + clippy::integer_division, + // mathematical names use 1-character identifiers + clippy::min_ident_chars, + // these are not cryptographically secure contexts + clippy::integer_division_remainder_used, + // this can be intentional + clippy::module_name_repetitions, + // this is intentional: already passing a pointer and need performance + clippy::needless_pass_by_value, + // we use this for inline formatting for unsafe blocks + clippy::semicolon_inside_block, +)] // Need an allocator for String/Vec. #[cfg(feature = "write")]