diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 4f83aaf0d..58ab5e6b1 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -7,6 +7,11 @@ // docstrings for extern "C" functions are reflected into C, and do not benefit // from safety docs. #![allow(clippy::missing_safety_doc)] +// deny some things that are typically warnings +#![deny(clippy::derivable_impls)] +#![deny(clippy::wrong_self_convention)] +#![deny(clippy::extra_unused_lifetimes)] +#![deny(clippy::unnecessary_to_owned)] mod traits; mod util; diff --git a/lib/src/replica.rs b/lib/src/replica.rs index 11fd26186..cec26ad42 100644 --- a/lib/src/replica.rs +++ b/lib/src/replica.rs @@ -149,7 +149,7 @@ pub unsafe extern "C" fn tc_replica_new_on_disk( // - caller will not use path after this call (convention) let mut path = unsafe { TCString::val_from_arg(path) }; let storage = StorageConfig::OnDisk { - taskdb_dir: path.to_path_buf()?, + taskdb_dir: path.to_path_buf_mut()?, } .into_storage()?; diff --git a/lib/src/server.rs b/lib/src/server.rs index b7247bdb6..dc1160d0c 100644 --- a/lib/src/server.rs +++ b/lib/src/server.rs @@ -72,7 +72,7 @@ pub unsafe extern "C" fn tc_server_new_local( // - caller will not use server_dir after this call (convention) let mut server_dir = unsafe { TCString::val_from_arg(server_dir) }; let server_config = ServerConfig::Local { - server_dir: server_dir.to_path_buf()?, + server_dir: server_dir.to_path_buf_mut()?, }; let server = server_config.into_server()?; // SAFETY: caller promises to free this server. diff --git a/lib/src/string.rs b/lib/src/string.rs index 86b1ac3bd..719a30563 100644 --- a/lib/src/string.rs +++ b/lib/src/string.rs @@ -292,7 +292,7 @@ impl<'a> RustString<'a> { } } - pub(crate) fn to_path_buf(&mut self) -> Result { + pub(crate) fn to_path_buf_mut(&mut self) -> Result { #[cfg(unix)] let path: OsString = { // on UNIX, we can use the bytes directly, without requiring that they diff --git a/lib/src/task.rs b/lib/src/task.rs index c3c0b896b..159553760 100644 --- a/lib/src/task.rs +++ b/lib/src/task.rs @@ -386,7 +386,7 @@ pub unsafe extern "C" fn tc_task_get_annotations(task: *mut TCTask) -> TCAnnotat /// /// Returns a TCString with NULL ptr field if the UDA does not exist. #[no_mangle] -pub unsafe extern "C" fn tc_task_get_uda<'a>( +pub unsafe extern "C" fn tc_task_get_uda( task: *mut TCTask, ns: TCString, key: TCString, @@ -413,7 +413,7 @@ pub unsafe extern "C" fn tc_task_get_uda<'a>( /// /// Returns NULL if the UDA does not exist. #[no_mangle] -pub unsafe extern "C" fn tc_task_get_legacy_uda<'a>(task: *mut TCTask, key: TCString) -> TCString { +pub unsafe extern "C" fn tc_task_get_legacy_uda(task: *mut TCTask, key: TCString) -> TCString { wrap(task, |task| { // SAFETY: // - key is valid (promised by caller) @@ -708,11 +708,7 @@ pub unsafe extern "C" fn tc_task_set_uda( wrap_mut( task, |task| { - task.set_uda( - ns.as_str()?.to_string(), - key.as_str()?.to_string(), - value.as_str()?.to_string(), - )?; + task.set_uda(ns.as_str()?, key.as_str()?, value.as_str()?.to_string())?; Ok(TCResult::Ok) }, TCResult::Error, @@ -735,7 +731,7 @@ pub unsafe extern "C" fn tc_task_remove_uda( wrap_mut( task, |task| { - task.remove_uda(ns.as_str()?.to_string(), key.as_str()?.to_string())?; + task.remove_uda(ns.as_str()?, key.as_str()?)?; Ok(TCResult::Ok) }, TCResult::Error, diff --git a/lib/src/uda.rs b/lib/src/uda.rs index 607d77e27..30607090c 100644 --- a/lib/src/uda.rs +++ b/lib/src/uda.rs @@ -3,6 +3,7 @@ use crate::types::*; /// TCUda contains the details of a UDA. #[repr(C)] +#[derive(Default)] pub struct TCUda { /// Namespace of the UDA. For legacy UDAs, this may have a NULL ptr field. pub ns: TCString, @@ -58,16 +59,6 @@ impl PassByValue for TCUda { } } -impl Default for TCUda { - fn default() -> Self { - TCUda { - ns: TCString::default(), - key: TCString::default(), - value: TCString::default(), - } - } -} - /// TCUdaList represents a list of UDAs. /// /// The content of this struct must be treated as read-only. diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 3990a4f39..6fd41b2d7 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -9,7 +9,7 @@ use std::path::PathBuf; pub fn main() -> anyhow::Result<()> { let arg = env::args().nth(1); - match arg.as_ref().map(|arg| arg.as_str()) { + match arg.as_deref() { Some("codegen") => codegen(), Some(arg) => anyhow::bail!("unknown xtask {}", arg), _ => anyhow::bail!("unknown xtask"),