Skip to content

Fix unused-import warnings under PG18 test builds - #41

Open
SferaDev wants to merge 2 commits into
mainfrom
fix/pg18-test-warnings
Open

Fix unused-import warnings under PG18 test builds#41
SferaDev wants to merge 2 commits into
mainfrom
fix/pg18-test-warnings

Conversation

@SferaDev

Copy link
Copy Markdown
Member

What

Compiling with the pg_test feature (e.g. make test PG_MAJOR=18) produced ~24 pre-existing warnings: 12 unused import and 12 never 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 the pg_test feature is on. But rustc strips #[test] functions outside --test builds, 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:3778super::*
  • src/scan/exec/agg/extract.rs:170super::*
  • src/scan/exec/agg/state.rs:711-717new_cd_set_int, StringArena, AggAccumulator/AggType/GroupKey*/hash_group_key*/keys_match, pgrx::pg_sys
  • src/scan/exec/count_minmax.rs:885,887super::*, PG_EPOCH_OFFSET_*/encode_f*_to_i64
  • src/scan/exec/decompress.rs:4330-4331super::*, std::cmp::Ordering
  • src/scan/hook.rs:4766, src/scan/path.rs:2949super::*

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)

  • 13 modules containing only plain #[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.rs mixes #[test] and #[pg_test], so the module keeps any(test, pg_test) (the #[pg_test] fns must ship in the cdylib); only the #[test]-only helper assert_simple_matches_regex is gated #[cfg(test)].
  • Left untouched: modules with #[pg_test] fns (timeparse.rs, json_extract.rs, exec/mod.rs, agg/metadata.rs, agg/compact.rs, agg/parser.rs, functions/*, lib.rs) and agg/test_utils.rs + its mod declaration in agg/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 warnings
  • make clippy — 0 warnings
  • make test (PG17) — 578 passed, 0 failed, 0 warnings
  • make test PG_MAJOR=18 — 578 passed, 0 failed, 0 warnings

Integration suite not run (import/cfg-only change, no runtime code touched).

SferaDev added 2 commits June 12, 2026 22:00
…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
SferaDev marked this pull request as draft June 12, 2026 22:41
@SferaDev
SferaDev requested a review from tsg June 12, 2026 22:48
@SferaDev
SferaDev marked this pull request as ready for review June 12, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant