Skip to content

Commit

Permalink
Merge pull request #154 from Alexhuszagh/clippy
Browse files Browse the repository at this point in the history
Make our clippy lints much more stringent.
  • Loading branch information
Alexhuszagh authored Sep 17, 2024
2 parents 47bac73 + 045ce56 commit e2454cb
Show file tree
Hide file tree
Showing 52 changed files with 1,181 additions and 824 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 28 additions & 3 deletions lexical-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
//!
Expand Down Expand Up @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions lexical-parse-float/etc/limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {')
Expand All @@ -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 {')
Expand Down
2 changes: 1 addition & 1 deletion lexical-parse-float/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions lexical-parse-float/src/bellerophon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ use crate::table::bellerophon_powers;
/// This has been modified to return a biased, rather than unbiased exponent.
pub fn bellerophon<F: RawFloat, const FORMAT: u128>(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,
Expand Down Expand Up @@ -181,7 +187,7 @@ const fn error_halfscale() -> u32 {
#[cfg_attr(not(feature = "compact"), inline(always))]
fn error_is_accurate<F: RawFloat>(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
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit e2454cb

Please sign in to comment.