From 38ec9776ca32b8363f305e4985180228a18fe2d7 Mon Sep 17 00:00:00 2001 From: leynos Date: Fri, 10 Jul 2026 15:59:16 +0200 Subject: [PATCH] Make heuristics::text public so its doctests compile The three doctest examples in src/heuristics/text.rs import items via lag_complexity::heuristics::text, but the module was declared pub(crate), so the examples failed to compile under plain `cargo test --all-features`. CI never noticed because `make test` passed --all-targets, which skips doctests entirely, while the scheduled cargo-mutants workflow validates its baseline with plain `cargo test` and therefore failed before exercising any mutants. Promote heuristics::text to a public module: its functions were already `pub` with documentation written against the public path, and publishing them keeps the examples as real, runnable doctests rather than ignored prose. Add `#[must_use]` to weighted_count to satisfy the pedantic must_use_candidate lint on the newly visible function. Also run `cargo test --doc --all-features` from the `test` Makefile target so the gap between --all-targets and plain `cargo test` cannot recur unseen. Closes #66. --- Makefile | 3 +++ src/heuristics/mod.rs | 2 +- src/heuristics/text.rs | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 98626ec..437c003 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ clean: ## Remove build artifacts test: ## Run tests with warnings treated as errors RUSTFLAGS="-D warnings" $(CARGO) test --all-targets --all-features $(BUILD_JOBS) + # --all-targets skips doctests, so run them explicitly to keep CI + # aligned with the plain `cargo test` used by cargo-mutants. + RUSTFLAGS="-D warnings" $(CARGO) test --doc --all-features $(BUILD_JOBS) test-workflow-contracts: ## Validate the mutation-testing caller contract uv run --with 'pytest>=8' --with 'pyyaml>=6' pytest tests/workflow_contracts -q diff --git a/src/heuristics/mod.rs b/src/heuristics/mod.rs index 93ff2ee..b5a4da5 100644 --- a/src/heuristics/mod.rs +++ b/src/heuristics/mod.rs @@ -3,7 +3,7 @@ pub mod ambiguity; pub mod complexity; pub mod depth; -pub(crate) mod text; +pub mod text; pub use ambiguity::{AmbiguityHeuristic, AmbiguityHeuristicError}; pub use complexity::{HeuristicComplexity, HeuristicComplexityError}; diff --git a/src/heuristics/text.rs b/src/heuristics/text.rs index f4aa2af..0903954 100644 --- a/src/heuristics/text.rs +++ b/src/heuristics/text.rs @@ -40,6 +40,7 @@ pub fn normalize_tokens(input: &str) -> Vec { /// let count = weighted_count(tokens.iter().map(String::as_str), &["and"], 2); /// assert_eq!(count, 2); /// ``` +#[must_use] pub fn weighted_count>( tokens: impl Iterator, patterns: &[&str],