Skip to content

Commit

Permalink
Explicit a few more types
Browse files Browse the repository at this point in the history
To avoid that a change in the types of the underlying called functions would result not in a compilation error but instead an incorrect `expect`.
  • Loading branch information
Ten0 authored and weiznich committed Aug 23, 2024
1 parent f0d3b08 commit b6bb500
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions diesel/src/pg/connection/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ impl PgResult {
}

pub(super) fn num_rows(&self) -> usize {
self.row_count
.try_into()
.expect("Diesel expects to run on at a least 32 bit OS")
self.row_count.try_into().expect(
"Diesel expects to run on a >= 32 bit OS \
(or libpq is giving out negative row count)",
)
}

pub(super) fn get_row(self: Rc<Self>, idx: usize) -> PgRow {
Expand Down Expand Up @@ -149,7 +150,7 @@ impl PgResult {
}

pub(in crate::pg) fn column_type(&self, col_idx: usize) -> NonZeroU32 {
let col_idx = col_idx
let col_idx: i32 = col_idx
.try_into()
.expect("Column indices are expected to fit into 32 bit");
let type_oid = unsafe { PQftype(self.internal_result.as_ptr(), col_idx) };
Expand Down Expand Up @@ -191,9 +192,10 @@ impl PgResult {
}

pub(super) fn column_count(&self) -> usize {
self.column_count
.try_into()
.expect("Diesel expects to run on a at least 32 bit OS")
self.column_count.try_into().expect(
"Diesel expects to run on a >= 32 bit OS \
(or libpq is giving out negative column count)",
)
}
}

Expand Down
4 changes: 2 additions & 2 deletions diesel/src/pg/connection/stmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Statement {
.map(|data| data.as_ref().map(|d| d.len().try_into()).unwrap_or(Ok(0)))
.collect::<Result<Vec<_>, _>>()
.map_err(|e| crate::result::Error::SerializationError(Box::new(e)))?;
let param_count = params_pointer
let param_count: libc::c_int = params_pointer
.len()
.try_into()
.map_err(|e| crate::result::Error::SerializationError(Box::new(e)))?;
Expand Down Expand Up @@ -71,7 +71,7 @@ impl Statement {
.map_err(|e| crate::result::Error::SerializationError(Box::new(e)))?;

let internal_result = unsafe {
let param_count = param_types
let param_count: libc::c_int = param_types
.len()
.try_into()
.map_err(|e| crate::result::Error::SerializationError(Box::new(e)))?;
Expand Down
4 changes: 2 additions & 2 deletions diesel/src/sqlite/connection/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ where
static NULL_CTX_ERR: &str =
"We've written the aggregator to the aggregate context, but it could not be retrieved.";

let n_bytes = std::mem::size_of::<OptionalAggregator<A>>()
let n_bytes: i32 = std::mem::size_of::<OptionalAggregator<A>>()
.try_into()
.expect("Aggregate context should be larger than 2^32");
let aggregate_context = unsafe {
Expand Down Expand Up @@ -525,7 +525,7 @@ extern "C" fn run_aggregator_final_function<ArgsSqlType, RetSqlType, Args, Ret,
}

unsafe fn context_error_str(ctx: *mut ffi::sqlite3_context, error: &str) {
let len = error
let len: i32 = error
.len()
.try_into()
.expect("Trying to set a error message with more than 2^32 byte is not supported");
Expand Down

0 comments on commit b6bb500

Please sign in to comment.