diff --git a/crates/tor-rpccmd/src/cmd.rs b/crates/tor-rpccmd/src/cmd.rs index 25097019e..24321b5a3 100644 --- a/crates/tor-rpccmd/src/cmd.rs +++ b/crates/tor-rpccmd/src/cmd.rs @@ -1,3 +1,5 @@ +//! Command type for the RPC system. + use downcast_rs::Downcast; use crate::typeid::GetConstTypeId_; diff --git a/crates/tor-rpccmd/src/dispatch.rs b/crates/tor-rpccmd/src/dispatch.rs index 8f7a3fbbb..7828fa635 100644 --- a/crates/tor-rpccmd/src/dispatch.rs +++ b/crates/tor-rpccmd/src/dispatch.rs @@ -17,7 +17,7 @@ use crate::{Command, Context, Object, RpcError}; #[doc(hidden)] pub type RpcResult = Result, RpcError>; -// A boxed future holding the result of an RPC command. +/// A boxed future holding the result of an RPC command. type RpcResultFuture = BoxFuture<'static, RpcResult>; /// A type-erased RPC-command invocation function. @@ -146,7 +146,9 @@ macro_rules! rpc_invoke_fn { /// Actual types to use when looking up a function in our HashMap. #[derive(Eq, PartialEq, Clone, Debug, Hash)] struct FuncType { + /// The type of object to which this function applies. obj_id: ConstTypeId_, + /// The type of command to which this function applies. cmd_id: ConstTypeId_, } @@ -202,17 +204,27 @@ pub fn invoke_command( #[cfg(test)] mod test { + // @@ begin test lint list maintained by maint/add_warning @@ + #![allow(clippy::bool_assert_comparison)] + #![allow(clippy::clone_on_copy)] + #![allow(clippy::dbg_macro)] + #![allow(clippy::print_stderr)] + #![allow(clippy::print_stdout)] + #![allow(clippy::single_char_pattern)] + #![allow(clippy::unwrap_used)] + #![allow(clippy::unchecked_duration_subtraction)] + //! use futures_await_test::async_test; // Define 3 animals and one brick. #[derive(Clone)] - pub struct Swan {} + struct Swan {} #[derive(Clone)] - pub struct Wombat {} + struct Wombat {} #[derive(Clone)] - pub struct Sheep {} + struct Sheep {} #[derive(Clone)] - pub struct Brick {} + struct Brick {} impl crate::Object for Swan {} impl crate::Object for Wombat {} @@ -222,9 +234,9 @@ mod test { // Define 2 commands. #[derive(Debug, serde::Deserialize)] - pub struct GetName {} + struct GetName {} #[derive(Debug, serde::Deserialize)] - pub struct GetKids {} + struct GetKids {} #[typetag::deserialize] impl crate::Command for GetName {} #[typetag::deserialize] diff --git a/crates/tor-rpccmd/src/err.rs b/crates/tor-rpccmd/src/err.rs index 657cf7f5c..97a5b952d 100644 --- a/crates/tor-rpccmd/src/err.rs +++ b/crates/tor-rpccmd/src/err.rs @@ -34,6 +34,10 @@ where } } +/// Helper: Serialize an ErrorKind in RpcError. +/// +/// TODO RPC: This function is bogus and should probably get replaced when we +/// have more of a handle on our error format. fn ser_kind(kind: &tor_error::ErrorKind, s: S) -> Result { // TODO RPC: this format is wrong and temporary. s.serialize_str(&format!("{:?}", kind)) diff --git a/crates/tor-rpccmd/src/lib.rs b/crates/tor-rpccmd/src/lib.rs index 001edd912..74cd76786 100644 --- a/crates/tor-rpccmd/src/lib.rs +++ b/crates/tor-rpccmd/src/lib.rs @@ -1,6 +1,40 @@ #![doc = include_str!("../README.md")] // @@ begin lint list maintained by maint/add_warning @@ -// I'll run add_warning before we merge XXXX +#![cfg_attr(not(ci_arti_stable), allow(renamed_and_removed_lints))] +#![cfg_attr(not(ci_arti_nightly), allow(unknown_lints))] +#![deny(missing_docs)] +#![warn(noop_method_call)] +#![deny(unreachable_pub)] +#![warn(clippy::all)] +#![deny(clippy::await_holding_lock)] +#![deny(clippy::cargo_common_metadata)] +#![deny(clippy::cast_lossless)] +#![deny(clippy::checked_conversions)] +#![warn(clippy::cognitive_complexity)] +#![deny(clippy::debug_assert_with_mut_call)] +#![deny(clippy::exhaustive_enums)] +#![deny(clippy::exhaustive_structs)] +#![deny(clippy::expl_impl_clone_on_copy)] +#![deny(clippy::fallible_impl_from)] +#![deny(clippy::implicit_clone)] +#![deny(clippy::large_stack_arrays)] +#![warn(clippy::manual_ok_or)] +#![deny(clippy::missing_docs_in_private_items)] +#![deny(clippy::missing_panics_doc)] +#![warn(clippy::needless_borrow)] +#![warn(clippy::needless_pass_by_value)] +#![warn(clippy::option_option)] +#![warn(clippy::rc_buffer)] +#![deny(clippy::ref_option_ref)] +#![warn(clippy::semicolon_if_nothing_returned)] +#![warn(clippy::trait_duplication_in_bounds)] +#![deny(clippy::unnecessary_wraps)] +#![warn(clippy::unseparated_literal_suffix)] +#![deny(clippy::unwrap_used)] +#![allow(clippy::let_unit_value)] // This can reasonably be done for explicitness +#![allow(clippy::uninlined_format_args)] +#![allow(clippy::significant_drop_in_scrutinee)] // arti/-/merge_requests/588/#note_2812945 +#![allow(clippy::result_large_err)] // temporary workaround for arti#587 //! mod cmd; @@ -65,10 +99,15 @@ pub trait Context: Send + Sync { ) -> Result<(), SendUpdateError>; } +/// An error caused while trying to send an update to a command. #[derive(Debug, Clone, thiserror::Error)] +#[non_exhaustive] pub enum SendUpdateError { + /// The application didn't ask for any updates for this request. #[error("Application did not request updates")] NoUpdatesWanted, + + /// The request was cancelled, or the connection was closed. #[error("Request cancelled")] RequestCancelled, } diff --git a/crates/tor-rpccmd/src/obj.rs b/crates/tor-rpccmd/src/obj.rs index 3856e176a..99afaff00 100644 --- a/crates/tor-rpccmd/src/obj.rs +++ b/crates/tor-rpccmd/src/obj.rs @@ -1,8 +1,11 @@ +//! Object type for our RPC system. + use downcast_rs::DowncastSync; use serde::{Deserialize, Serialize}; use crate::typeid::GetConstTypeId_; +/// An object to which commands can be addressed by our RPC system. pub trait Object: GetConstTypeId_ + DowncastSync {} downcast_rs::impl_downcast!(sync Object); diff --git a/crates/tor-rpccmd/src/typeid.rs b/crates/tor-rpccmd/src/typeid.rs index 6050f0f38..28981cd08 100644 --- a/crates/tor-rpccmd/src/typeid.rs +++ b/crates/tor-rpccmd/src/typeid.rs @@ -21,6 +21,7 @@ /// /// [relevant Rust feature]: https://github.com/rust-lang/rust/issues/77125 #[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)] +#[allow(clippy::exhaustive_structs)] pub struct ConstTypeId_( /// Sadly this has to be `pub` so we can construct these from other crates. /// @@ -77,6 +78,17 @@ pub use impl_const_type_id; #[cfg(test)] mod test { + // @@ begin test lint list maintained by maint/add_warning @@ + #![allow(clippy::bool_assert_comparison)] + #![allow(clippy::clone_on_copy)] + #![allow(clippy::dbg_macro)] + #![allow(clippy::print_stderr)] + #![allow(clippy::print_stdout)] + #![allow(clippy::single_char_pattern)] + #![allow(clippy::unwrap_used)] + #![allow(clippy::unchecked_duration_subtraction)] + //! + use assert_impl::assert_impl; struct Foo(usize);