Skip to content

chore(clippy): 5 approx_constant errors + ~26 warnings in lib/common/* and friends #22

Closed

Description

@hyperpolymath

While running cargo clippy -p my-lang --lib --tests --no-deps (during the depth-guard review in #21) the lint pass surfaces 5 errors (clippy::approx_constant, denied-by-default) and ~26 warnings in lib/common/* and a couple in src/. None of them are caused by recent work; they have been latent. Filing for separate cleanup so the parser PR stays scoped.

Errors (clippy::approx_constant -- deny-by-default)

Hardcoded approximations of pi in test asserts; clippy wants std::f64::consts::PI instead.

  • crates/my-lang/lib/common/math.rs:268 -- (abs_float(-3.14) - 3.14).abs() < f64::EPSILON (two occurrences)
  • crates/my-lang/lib/common/string.rs:300
  • crates/my-lang/lib/common/types.rs:297
  • crates/my-lang/lib/common/types.rs:304

Fix per site: replace the literal 3.14 with std::f64::consts::PI (or move to a const PI_APPROX: f64 = ...; if rounding to two decimals is intentional, and #[allow] that one site with a comment explaining why).

Warnings worth a clippy --fix sweep

Most are auto-fixable via cargo clippy --fix -p my-lang --lib --tests -- --no-deps. Grouped by category:

Redundant patterns (checker.rs): lines 419, 448, 472, 509, 544, 613 use if let Err(_) = ... where .is_err() is preferred.

length comparison to zero in parser error-recovery tests: errors.len() > 0 at parser.rs lines 2568, 2590, 2610, 2638, 2660, 2683 -- prefer !errors.is_empty().

lib/common/* style nits:

  • io.rs:41,44 -- filter_map on an Err-producing iterator (potential infinite loop).
  • string.rs:138,148 -- repeat().take() should be the dedicated method.
  • string.rs:200, types.rs:94 -- manual RangeInclusive::contains.
  • string.rs:209, types.rs:103 -- as u64 on i64::abs() result (use unsigned_abs).
  • utils.rs:98 -- manual is_multiple_of.
  • utils.rs:297,298,305 -- manual Range::contains / RangeInclusive::contains.
  • array.rs:313 -- &vec![...] where &[...] works.
  • types.rs:321,322 -- assert_eq!(x, true/false) -> assert!(...).
  • mylang/ai.rs:26 and mylang/prompt.rs:139 -- method names from_str / add shadow std trait methods.

Dead-code warnings (independent of the lint sweep):

  • parser.rs:825 -- parse_comptime_decl is unused.
  • interpreter.rs:180 -- a manual impl that could be #[derive]d.
  • checker.rs:773 -- .enumerate() with the index discarded.
  • my-pkg/src/lib.rs -- 3 unused vars (148, 176, 314) and 1 unused field (134).
  • my-mir/src/lib.rs:1019 -- unused Frame::function field.
  • my-ai/src/lib.rs:425 -- unused CachedResponse::timestamp field.

Suggested approach

  1. One PR for the 5 approx_constant errors (smallest, unblocks cargo clippy -- -D warnings in CI if/when that flips on).
  2. One PR running cargo clippy --fix across the auto-fixable warnings, with the un-fixable ones (from_str/add trait shadowing, the filter_map infinite-loop risk, the dead-code items) handled by hand.

Activity

  1. hyperpolymath commented on May 15, 2026

    @hyperpolymath
    OwnerAuthor

    All four severity-ordered PRs have landed:

    Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions