Modern Apps git

← Modern-Apps.git

networklocation: clippy hygiene in wpsdb and geocoder

Commit
46de6f279a5c98e7da806534e7144a3e49cc6d28
Author
Vayun Mathur <[email protected]>
When
2026-12-01 21:57 UTC (4 days ago)
Parents
18c8fbb
Workspace clippy flagged: unused jni imports in jni.rs and
wpsdb.rs (only JClass/EnvUnowned are referenced, including from
the include!d part files), inconsistent digit grouping on the
coordinate bias constants and fixture literals (regrouped to
threes, same values), a manual !RangeInclusive::contains on
sample_log2, a manual div-ceil in the zero_samples binary
search (now div_ceil), and a useless usize cast in the
geocoder's string-array length.

Two fields flagged dead (EstimatedPosition::inliers_size,
Reader::universe_bits) are read by the crate's tests, just not
by production code: they keep per-field #[allow(dead_code)]
with comments saying so rather than deletion, which would have
removed real assertions.

Left standing: the two deprecated Env array calls in jni.rs
(the typed-array migration is a separate JNI change) and
items_after_test_module (moving the inline test module is
pure layout churn).

Verified: cargo clippy -p
network_location_position_estimation_rust --all-targets shows
only those three items, cargo test (67 passed), fmt clean.

Diff

networklocation/src/main/rust/src/geocoder_part1.rs
diff --git a/networklocation/src/main/rust/src/geocoder_part1.rs b/networklocation/src/main/rust/src/geocoder_part1.rsindex a467e07468..cc6b8d7bfb 100644--- a/networklocation/src/main/rust/src/geocoder_part1.rs+++ b/networklocation/src/main/rust/src/geocoder_part1.rs@@ -295,7 +295,7 @@ type Handle = Mutex<Reader>;  fn build_string_array(env: &mut Env, reader: &mut Reader, recs: &[i32]) -> jobjectArray {     let arr: JObjectArray<JString> =-        match env.new_object_type_array::<JString>((recs.len() * FIELDS) as usize, JString::null()) {+        match env.new_object_type_array::<JString>(recs.len() * FIELDS, JString::null()) {             Ok(a) => a,             Err(_) => return std::ptr::null_mut(),         };
networklocation/src/main/rust/src/jni.rs
diff --git a/networklocation/src/main/rust/src/jni.rs b/networklocation/src/main/rust/src/jni.rsindex 5e6498d8b0..92065397a0 100644--- a/networklocation/src/main/rust/src/jni.rs+++ b/networklocation/src/main/rust/src/jni.rs@@ -14,7 +14,7 @@ use crate::position::Position;  use jni::objects::{JClass, JDoubleArray}; use jni::sys::jdoubleArray;-use jni::{Env, EnvUnowned};+use jni::EnvUnowned;  /// Metres per degree of latitude (WGS-84 mean). Longitude scales this by /// `cos(lat)`.
networklocation/src/main/rust/src/lib.rs
diff --git a/networklocation/src/main/rust/src/lib.rs b/networklocation/src/main/rust/src/lib.rsindex fa509b01d0..a7f90b1147 100644--- a/networklocation/src/main/rust/src/lib.rs+++ b/networklocation/src/main/rust/src/lib.rs@@ -32,6 +32,9 @@ pub struct EstimatedPosition {     /// estimated position     position: Position,     /// inliers size+    // Read by the estimator tests; the JNI surface returns only+    // the position, so production code never reads this.+    #[allow(dead_code)]     inliers_size: usize, } 
networklocation/src/main/rust/src/wpsdb.rs
diff --git a/networklocation/src/main/rust/src/wpsdb.rs b/networklocation/src/main/rust/src/wpsdb.rsindex 2b56a910d8..a68a54c503 100644--- a/networklocation/src/main/rust/src/wpsdb.rs+++ b/networklocation/src/main/rust/src/wpsdb.rs@@ -50,9 +50,9 @@ use std::fs::File; #[cfg(unix)] use std::os::unix::io::FromRawFd; -use jni::objects::{JByteArray, JClass, JDoubleArray, JObjectArray, JString};+use jni::objects::JClass; use jni::sys::{jdoubleArray, jint, jlong};-use jni::{jni_str, Env, EnvUnowned};+use jni::EnvUnowned;  const MAGIC: &[u8; 8] = b"WPSDB2\x00\x00"; @@ -71,9 +71,9 @@ const ALT_BITS: u32 = 16; const ALT_BIAS: i64 = 32768;  /// Bias that maps `lat * 1e8` from [-90, 90] onto [0, 180e8], which fits 35 bits.-const LAT_BIAS: i64 = 90_00_000_000;+const LAT_BIAS: i64 = 9_000_000_000; /// Bias that maps `lon * 1e8` from [-180, 180] onto [0, 360e8], which fits 36 bits.-const LON_BIAS: i64 = 180_00_000_000;+const LON_BIAS: i64 = 18_000_000_000; const COORD_SCALE: f64 = 1e8;  /// Stored accuracy sentinel for "the source did not report one".@@ -142,6 +142,9 @@ pub struct Reader {     src: Src,     n: u64,     l: u8,+    // Read by the wpsdb tests (universe-size assertions); the+    // production lookup path derives everything it needs from `l`.+    #[allow(dead_code)]     universe_bits: u8,     high_len_bits: u64,     /// mmap of the Elias–Fano upper bitvector.@@ -206,7 +209,7 @@ impl Reader {         }         // `select0` scans at most one sample block, so an absurd stride would make lookups         // unbounded; a zero stride would divide by zero.-        if sample_log2 < 6 || sample_log2 > 20 {+        if !(6..=20).contains(&sample_log2) {             return None;         } @@ -292,7 +295,7 @@ impl Reader {         let mut lo = 0usize;         let mut hi = self.zero_samples.len() - 1;         while lo < hi {-            let mid = (lo + hi + 1) / 2;+            let mid = (lo + hi).div_ceil(2);             if self.zero_samples[mid] <= j {                 lo = mid;             } else {
networklocation/src/main/rust/src/wpsdb_part2.rs
diff --git a/networklocation/src/main/rust/src/wpsdb_part2.rs b/networklocation/src/main/rust/src/wpsdb_part2.rsindex d92f2ae406..c2bee5e4cd 100644--- a/networklocation/src/main/rust/src/wpsdb_part2.rs+++ b/networklocation/src/main/rust/src/wpsdb_part2.rs@@ -290,7 +290,7 @@ mod tests {             .map(|_| {                 let hi = (lcg(&mut state) & ((1u64 << 20) - 1)) as u128;                 let key = (hi << 64) | lcg(&mut state) as u128;-                (key, 37_77_000_000i64, -122_41_000_000i64, 250, None)+                (key, 3_777_000_000_i64, -12_241_000_000_i64, 250, None)             })             .collect();         recs.sort_by_key(|r| r.0);@@ -318,7 +318,7 @@ mod tests {             (3, 0, 0, ACC_UNKNOWN, None),             (4, 1, -1, 1, Some(0)),             (5, -LAT_BIAS + 1, LON_BIAS - 1, 12345, Some(-430)),-            (6, 45_00_000_001, -93_26_543_210, 7, Some(8848)),+            (6, 4_500_000_001, -9_326_543_210, 7, Some(8848)),         ];         write_fixture(&f.path(), 48, PAYLOAD_LATLON_E8_ACC16_ALT16, &recs, 6);         let r = Reader::open_path(f.path()).unwrap();