Fix unused-import warnings under PG18 test builds - #41
Open
SferaDev wants to merge 2 commits into
Open
Conversation
…ild warnings Test modules containing only plain #[test] functions were gated with #[cfg(any(test, feature = "pg_test"))]. When the cdylib is compiled with the pg_test feature (cargo pgrx test), rustc strips #[test] functions but still compiles the module body, leaving the imports and shared helpers unused — ~24 'unused import' / 'never used' warnings. - Switch 13 pure-#[test] modules to plain #[cfg(test)] (matching the existing precedent in compress.rs, catalog.rs, partition.rs, ...) and drop the now-unneeded #[pgrx::pg_schema] attribute. - In agg/regex.rs (mixed #[test] + #[pg_test] module, which must stay in the cdylib), gate the #[test]-only helper assert_simple_matches_regex with #[cfg(test)]. Modules with #[pg_test] functions, and agg/test_utils.rs (consumed by #[pg_test] modules), keep the any(test, pg_test) gate.
SferaDev
marked this pull request as draft
June 12, 2026 22:41
SferaDev
marked this pull request as ready for review
June 12, 2026 22:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Compiling with the
pg_testfeature (e.g.make test PG_MAJOR=18) produced ~24 pre-existing warnings: 12unused importand 12never used(helper fns/consts), all inside test modules.Why
These modules were gated
#[cfg(any(test, feature = "pg_test"))], so they are compiled into the cdylib whenever thepg_testfeature is on. But rustc strips#[test]functions outside--testbuilds, so in the cdylib pass the module body survives while every test is removed — leaving its imports and shared helpers dead. The warnings are version-independent; they just surfaced on PG18 because its target volume rebuilt from scratch.Warnings fixed
unused import:src/copy.rs:3778—super::*src/scan/exec/agg/extract.rs:170—super::*src/scan/exec/agg/state.rs:711-717—new_cd_set_int,StringArena,AggAccumulator/AggType/GroupKey*/hash_group_key*/keys_match,pgrx::pg_syssrc/scan/exec/count_minmax.rs:885,887—super::*,PG_EPOCH_OFFSET_*/encode_f*_to_i64src/scan/exec/decompress.rs:4330-4331—super::*,std::cmp::Orderingsrc/scan/hook.rs:4766,src/scan/path.rs:2949—super::*never used:mk_key(blob_cache/storage.rs),ranges(copy.rs),SAMPLE_USEC(agg/extract.rs),assert_simple_matches_regex(agg/regex.rs),mk_segment(append_wire.rs),assert_like_eq/datum_from_i64/datum_from_f64(batch_qual.rs),mk_filter/mk_cm(segments.rs),dict_col/lz4_col(text_col.rs)Fix (cfg-gating choices)
#[test]fns (copy.rs, blob_cache/storage.rs, scan/hook.rs, scan/path.rs, agg_wire.rs, append_wire.rs, batch_qual.rs, count_minmax.rs, decompress.rs, segments.rs, text_col.rs, agg/extract.rs, agg/state.rs): gate switched to plain#[cfg(test)]and the now-unneeded#[pgrx::pg_schema]dropped — matching existing precedent (compress.rs, catalog.rs, partition.rs, stats.rs, …). They never needed to live in the cdylib.src/scan/exec/agg/regex.rsmixes#[test]and#[pg_test], so the module keepsany(test, pg_test)(the#[pg_test]fns must ship in the cdylib); only the#[test]-only helperassert_simple_matches_regexis gated#[cfg(test)].#[pg_test]fns (timeparse.rs, json_extract.rs, exec/mod.rs, agg/metadata.rs, agg/compact.rs, agg/parser.rs, functions/*, lib.rs) andagg/test_utils.rs+ itsmoddeclaration inagg/mod.rs, since test_utils is consumed by#[pg_test]modules and must stay in pg_test builds.No production code paths changed — imports/cfg only.
Testing
make build— clean, 0 warningsmake clippy— 0 warningsmake test(PG17) — 578 passed, 0 failed, 0 warningsmake test PG_MAJOR=18— 578 passed, 0 failed, 0 warningsIntegration suite not run (import/cfg-only change, no runtime code touched).