Use #[expect(lint)] where possible

This commit is contained in:
gwenn 2024-09-05 20:51:58 +02:00
parent 5464f4f386
commit a00acd23a6
23 changed files with 44 additions and 59 deletions

View File

@ -18,7 +18,7 @@ use rusqlite::{Connection, Result};
/// sqlite> SELECT rusqlite_test_function();
/// Rusqlite extension loaded correctly!
/// ```
#[allow(clippy::not_unsafe_ptr_arg_deref)]
#[expect(clippy::not_unsafe_ptr_arg_deref)]
#[no_mangle]
pub unsafe extern "C" fn sqlite3_extension_init(
db: *mut ffi::sqlite3,

View File

@ -1,5 +1,4 @@
#![allow(non_snake_case, non_camel_case_types)]
#![cfg_attr(test, allow(deref_nullptr))] // https://github.com/rust-lang/rust-bindgen/issues/2066
#![expect(non_snake_case, non_camel_case_types)]
// force linking to openssl
#[cfg(feature = "bundled-sqlcipher-vendored-openssl")]

View File

@ -155,8 +155,9 @@ pub enum StepResult {
Locked,
}
/// Struct specifying the progress of a backup. The
/// percentage completion can be calculated as `(pagecount - remaining) /
/// Struct specifying the progress of a backup.
///
/// The percentage completion can be calculated as `(pagecount - remaining) /
/// pagecount`. The progress of a backup is as of the last call to
/// [`step`](Backup::step) - if the source database is modified after a call to
/// [`step`](Backup::step), the progress value will become outdated and

View File

@ -393,7 +393,7 @@ impl io::Seek for Blob<'_> {
}
}
#[allow(unused_must_use)]
#[expect(unused_must_use)]
impl Drop for Blob<'_> {
#[inline]
fn drop(&mut self) {

View File

@ -60,7 +60,6 @@ impl Connection {
#[derive(Debug)]
pub struct StatementCache(RefCell<LruCache<Arc<str>, RawStatement>>);
#[allow(clippy::non_send_fields_in_send_ty)]
unsafe impl Send for StatementCache {}
/// Cacheable statement.
@ -90,7 +89,6 @@ impl<'conn> DerefMut for CachedStatement<'conn> {
}
impl Drop for CachedStatement<'_> {
#[allow(unused_must_use)]
#[inline]
fn drop(&mut self) {
if let Some(stmt) = self.stmt.take() {

View File

@ -129,7 +129,7 @@ impl InnerConnection {
x_coll_needed: fn(&Connection, &str) -> Result<()>,
) -> Result<()> {
use std::mem;
#[allow(clippy::needless_return)]
#[expect(clippy::needless_return)]
unsafe extern "C" fn collation_needed_callback(
arg1: *mut c_void,
arg2: *mut ffi::sqlite3,

View File

@ -10,9 +10,8 @@ use crate::{Connection, Result};
/// See [Database Connection Configuration Options](https://sqlite.org/c3ref/c_dbconfig_enable_fkey.html) for details.
#[repr(i32)]
#[derive(Copy, Clone, Debug)]
#[allow(non_snake_case, non_camel_case_types)]
#[expect(non_camel_case_types)]
#[non_exhaustive]
#[allow(clippy::upper_case_acronyms)]
pub enum DbConfig {
//SQLITE_DBCONFIG_MAINDBNAME = 1000, /* const char* */
//SQLITE_DBCONFIG_LOOKASIDE = 1001, /* void* int int */

View File

@ -9,7 +9,6 @@ use std::str;
/// Enum listing possible errors from rusqlite.
#[derive(Debug)]
#[allow(clippy::enum_variant_names)]
#[non_exhaustive]
pub enum Error {
/// An error from an underlying SQLite call.
@ -84,7 +83,6 @@ pub enum Error {
/// [`create_scalar_function`](crate::Connection::create_scalar_function)).
#[cfg(feature = "functions")]
#[cfg_attr(docsrs, doc(cfg(feature = "functions")))]
#[allow(dead_code)]
UserFunctionError(Box<dyn error::Error + Send + Sync + 'static>),
/// Error available for the implementors of the
@ -98,7 +96,6 @@ pub enum Error {
/// [`create_module`](crate::Connection::create_module)).
#[cfg(feature = "vtab")]
#[cfg_attr(docsrs, doc(cfg(feature = "vtab")))]
#[allow(dead_code)]
ModuleError(String),
/// An unwinding panic occurs in a UDF (user-defined function).

View File

@ -707,7 +707,7 @@ unsafe extern "C" fn call_boxed_step<A, D, T>(
args: slice::from_raw_parts(argv, argc as usize),
};
#[allow(clippy::unnecessary_cast)]
#[expect(clippy::unnecessary_cast)]
if (*pac as *mut A).is_null() {
*pac = Box::into_raw(Box::new((*boxed_aggr).init(&mut ctx)?));
}
@ -778,7 +778,7 @@ where
let a: Option<A> = match aggregate_context(ctx, 0) {
Some(pac) =>
{
#[allow(clippy::unnecessary_cast)]
#[expect(clippy::unnecessary_cast)]
if (*pac as *mut A).is_null() {
None
} else {
@ -818,7 +818,7 @@ where
// Within the xValue callback, it is customary to set N=0 in calls to
// sqlite3_aggregate_context(C,N) so that no pointless memory allocations occur.
let pac = aggregate_context(ctx, 0).filter(|&pac| {
#[allow(clippy::unnecessary_cast)]
#[expect(clippy::unnecessary_cast)]
!(*pac as *mut A).is_null()
});

View File

@ -1,5 +1,5 @@
//! Commit, Data Change and Rollback Notification Callbacks
#![allow(non_camel_case_types)]
#![expect(non_camel_case_types)]
use std::os::raw::{c_char, c_int, c_void};
use std::panic::catch_unwind;
@ -19,7 +19,6 @@ mod preupdate_hook;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
#[non_exhaustive]
#[allow(clippy::upper_case_acronyms)]
pub enum Action {
/// Unsupported / unexpected action
UNKNOWN = -1,

View File

@ -23,9 +23,9 @@ pub enum PreUpdateCase {
Delete(PreUpdateOldValueAccessor),
/// Pre-update hook was triggered by an update.
Update {
#[allow(missing_docs)]
#[expect(missing_docs)]
old_value_accessor: PreUpdateOldValueAccessor,
#[allow(missing_docs)]
#[expect(missing_docs)]
new_value_accessor: PreUpdateNewValueAccessor,
},
/// This variant is not normally produced by SQLite. You may encounter it

View File

@ -41,7 +41,7 @@ pub struct InnerConnection {
unsafe impl Send for InnerConnection {}
impl InnerConnection {
#[allow(clippy::mutex_atomic, clippy::arc_with_non_send_sync)] // See unsafe impl Send / Sync for InterruptHandle
#[expect(clippy::mutex_atomic, clippy::arc_with_non_send_sync)] // See unsafe impl Send / Sync for InterruptHandle
#[inline]
pub unsafe fn new(db: *mut ffi::sqlite3, owned: bool) -> Self {
Self {
@ -146,7 +146,6 @@ impl InnerConnection {
}
}
#[allow(clippy::mutex_atomic)]
pub fn close(&mut self) -> Result<()> {
if self.db.is_null() {
return Ok(());
@ -402,7 +401,7 @@ impl InnerConnection {
}
impl Drop for InnerConnection {
#[allow(unused_must_use)]
#[expect(unused_must_use)]
#[inline]
fn drop(&mut self) {
self.close();

View File

@ -1128,7 +1128,7 @@ impl<'conn, 'sql> Batch<'conn, 'sql> {
/// Iterates on each batch statements.
///
/// Returns `Ok(None)` when batch is completed.
#[allow(clippy::should_implement_trait)] // fallible iterator
#[expect(clippy::should_implement_trait)] // fallible iterator
pub fn next(&mut self) -> Result<Option<Statement<'conn>>> {
while self.tail < self.sql.len() {
let sql = &self.sql[self.tail..];
@ -1285,21 +1285,15 @@ mod test {
// this function is never called, but is still type checked; in
// particular, calls with specific instantiations will require
// that those types are `Send`.
#[allow(
dead_code,
unconditional_recursion,
clippy::extra_unused_type_parameters
)]
#[allow(dead_code)]
#[expect(unconditional_recursion, clippy::extra_unused_type_parameters)]
fn ensure_send<T: Send>() {
ensure_send::<Connection>();
ensure_send::<InterruptHandle>();
}
#[allow(
dead_code,
unconditional_recursion,
clippy::extra_unused_type_parameters
)]
#[allow(dead_code)]
#[expect(unconditional_recursion, clippy::extra_unused_type_parameters)]
fn ensure_sync<T: Sync>() {
ensure_sync::<InterruptHandle>();
}

View File

@ -12,7 +12,7 @@ use std::os::raw::c_int;
#[derive(Copy, Clone, Debug)]
#[repr(i32)]
#[non_exhaustive]
#[allow(clippy::upper_case_acronyms, non_camel_case_types)]
#[expect(non_camel_case_types)]
#[cfg_attr(docsrs, doc(cfg(feature = "limits")))]
pub enum Limit {
/// The maximum size of any string or BLOB or table row, in bytes.

View File

@ -37,7 +37,7 @@ impl LoadExtensionGuard<'_> {
}
}
#[allow(unused_must_use)]
#[expect(unused_must_use)]
impl Drop for LoadExtensionGuard<'_> {
#[inline]
fn drop(&mut self) {

View File

@ -34,7 +34,7 @@ impl<'stmt> Rows<'stmt> {
/// consider using [`query_map`](Statement::query_map) or
/// [`query_and_then`](Statement::query_and_then) instead, which
/// return types that implement `Iterator`.
#[allow(clippy::should_implement_trait)] // cannot implement Iterator
#[expect(clippy::should_implement_trait)] // cannot implement Iterator
#[inline]
pub fn next(&mut self) -> Result<Option<&Row<'stmt>>> {
self.advance()?;
@ -107,7 +107,7 @@ impl<'stmt> Rows<'stmt> {
}
impl Drop for Rows<'_> {
#[allow(unused_must_use)]
#[expect(unused_must_use)]
#[inline]
fn drop(&mut self) {
self.reset();
@ -438,7 +438,7 @@ macro_rules! tuple_try_from_row {
fn try_from(row: &'a Row<'a>) -> Result<Self> {
let mut index = 0;
$(
#[allow(non_snake_case)]
#[expect(non_snake_case)]
let $field = row.get::<_, $field>(index)?;
index += 1;
)*

View File

@ -1,5 +1,5 @@
//! [Session Extension](https://sqlite.org/sessionintro.html)
#![allow(non_camel_case_types)]
#![expect(non_camel_case_types)]
use std::ffi::CStr;
use std::io::{Read, Write};
@ -662,11 +662,11 @@ impl Connection {
/// Constants passed to the conflict handler
/// See [here](https://sqlite.org/session.html#SQLITE_CHANGESET_CONFLICT) for details.
#[allow(missing_docs)]
#[expect(missing_docs)]
#[repr(i32)]
#[derive(Debug, PartialEq, Eq)]
#[non_exhaustive]
#[allow(clippy::upper_case_acronyms)]
#[expect(clippy::upper_case_acronyms)]
pub enum ConflictType {
UNKNOWN = -1,
SQLITE_CHANGESET_DATA = ffi::SQLITE_CHANGESET_DATA,
@ -690,11 +690,11 @@ impl From<i32> for ConflictType {
/// Constants returned by the conflict handler
/// See [here](https://sqlite.org/session.html#SQLITE_CHANGESET_ABORT) for details.
#[allow(missing_docs)]
#[expect(missing_docs)]
#[repr(i32)]
#[derive(Debug, PartialEq, Eq)]
#[non_exhaustive]
#[allow(clippy::upper_case_acronyms)]
#[expect(clippy::upper_case_acronyms)]
pub enum ConflictAction {
SQLITE_CHANGESET_OMIT = ffi::SQLITE_CHANGESET_OMIT,
SQLITE_CHANGESET_REPLACE = ffi::SQLITE_CHANGESET_REPLACE,

View File

@ -687,7 +687,7 @@ impl Statement<'_> {
#[cfg(not(feature = "extra_check"))]
#[inline]
#[allow(clippy::unnecessary_wraps)]
#[expect(clippy::unnecessary_wraps)]
fn check_update(&self) -> Result<()> {
Ok(())
}
@ -741,7 +741,7 @@ impl Statement<'_> {
#[cfg(not(feature = "extra_check"))]
#[inline]
#[allow(clippy::unnecessary_wraps)]
#[expect(clippy::unnecessary_wraps)]
pub(crate) fn check_no_tail(&self) -> Result<()> {
Ok(())
}
@ -778,7 +778,7 @@ impl fmt::Debug for Statement<'_> {
}
impl Drop for Statement<'_> {
#[allow(unused_must_use)]
#[expect(unused_must_use)]
#[inline]
fn drop(&mut self) {
self.finalize_();
@ -1020,7 +1020,7 @@ mod test {
assert_eq!(1, doubled_id);
// second row should be an `Err`
#[allow(clippy::match_wild_err_arm)]
#[expect(clippy::match_wild_err_arm)]
match rows.next().unwrap() {
Ok(_) => panic!("invalid Ok"),
Err(Error::SqliteSingleThreadedMode) => (),

View File

@ -238,7 +238,7 @@ impl Deref for Transaction<'_> {
}
}
#[allow(unused_must_use)]
#[expect(unused_must_use)]
impl Drop for Transaction<'_> {
#[inline]
fn drop(&mut self) {
@ -363,7 +363,7 @@ impl Deref for Savepoint<'_> {
}
}
#[allow(unused_must_use)]
#[expect(unused_must_use)]
impl Drop for Savepoint<'_> {
#[inline]
fn drop(&mut self) {

View File

@ -242,7 +242,7 @@ mod test {
}
#[test]
#[allow(clippy::cognitive_complexity)]
#[expect(clippy::cognitive_complexity)]
fn test_mismatched_types() -> Result<()> {
fn is_invalid_column_type(err: Error) -> bool {
matches!(err, Error::InvalidColumnType(..))
@ -388,7 +388,7 @@ mod test {
}
#[test]
#[allow(clippy::float_cmp)]
#[expect(clippy::float_cmp)]
fn test_numeric_conversions() -> Result<()> {
// Test what happens when we store an f32 and retrieve an i32 etc.
let db = Connection::open_in_memory()?;

View File

@ -12,7 +12,7 @@ struct UnlockNotification {
mutex: Mutex<bool>, // Mutex to protect structure
}
#[allow(clippy::mutex_atomic)]
#[expect(clippy::mutex_atomic)]
impl UnlockNotification {
fn new() -> Self {
Self {

View File

@ -103,7 +103,6 @@ const ZERO_MODULE: ffi::sqlite3_module = unsafe {
macro_rules! module {
($lt:lifetime, $vt:ty, $ct:ty, $xc:expr, $xd:expr, $xu:expr) => {
#[allow(clippy::needless_update)]
&Module {
base: ffi::sqlite3_module {
// We don't use V3
@ -322,8 +321,8 @@ pub trait UpdateVTab<'vtab>: CreateVTab<'vtab> {
/// Index constraint operator.
/// See [Virtual Table Constraint Operator Codes](https://sqlite.org/c3ref/c_index_constraint_eq.html) for details.
#[derive(Debug, Eq, PartialEq)]
#[allow(non_snake_case, non_camel_case_types, missing_docs)]
#[allow(clippy::upper_case_acronyms)]
#[allow(missing_docs)]
#[expect(non_camel_case_types)]
pub enum IndexConstraintOp {
SQLITE_INDEX_CONSTRAINT_EQ,
SQLITE_INDEX_CONSTRAINT_GT,

View File

@ -115,7 +115,7 @@ unsafe impl<'vtab> VTab<'vtab> for SeriesTab {
}
if idx_num.contains(QueryPlanFlags::BOTH) {
// Both start= and stop= boundaries are available.
#[allow(clippy::bool_to_int_with_if)]
#[expect(clippy::bool_to_int_with_if)]
info.set_estimated_cost(f64::from(
2 - if idx_num.contains(QueryPlanFlags::STEP) {
1
@ -193,7 +193,7 @@ impl SeriesTabCursor<'_> {
}
}
}
#[allow(clippy::comparison_chain)]
#[expect(clippy::comparison_chain)]
unsafe impl VTabCursor for SeriesTabCursor<'_> {
fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values<'_>) -> Result<()> {
let mut idx_num = QueryPlanFlags::from_bits_truncate(idx_num);