Merge pull request #342 from djmitche/clippy-warnings

fix some clippy warnings, and make them errors for taskchampion-lib
This commit is contained in:
Dustin J. Mitchell 2022-03-10 15:35:12 -05:00 committed by GitHub
commit 889e1d1cdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 22 deletions

View file

@ -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;

View file

@ -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()?;

View file

@ -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.

View file

@ -292,7 +292,7 @@ impl<'a> RustString<'a> {
}
}
pub(crate) fn to_path_buf(&mut self) -> Result<PathBuf, std::str::Utf8Error> {
pub(crate) fn to_path_buf_mut(&mut self) -> Result<PathBuf, std::str::Utf8Error> {
#[cfg(unix)]
let path: OsString = {
// on UNIX, we can use the bytes directly, without requiring that they

View file

@ -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,

View file

@ -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.

View file

@ -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"),