diff --git a/Cargo.toml b/Cargo.toml index c3cb7c56..7cee4146 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -188,47 +188,52 @@ codegen-units=1 workspace = true [workspace.lints.rust] -# missing_abi = "warn" +missing_abi = "warn" # missing_docs = "warn" -# noop_method_call = "warn" -# pointer_structural_match = "warn" +noop_method_call = "warn" +pointer_structural_match = "warn" # unreachable_pub = "warn" -# unused_extern_crates = "warn" -# unused_import_braces = "warn" +unused_extern_crates = "warn" +unused_import_braces = "warn" # unused_lifetimes = "warn" unused_qualifications = "warn" -# unused_tuple_struct_fields = "warn" +unused_tuple_struct_fields = "warn" [workspace.lints.clippy] suspicious = "warn" # assume deny in practice perf = "warn" # assume deny in practice -# redundant_clone = "warn" -# cloned_instead_of_copied = "warn" +redundant_clone = "warn" +cloned_instead_of_copied = "warn" expl_impl_clone_on_copy = "warn" # pedantic = "warn" -# as_conversions = "warn" +unnecessary_cast = "warn" +cast_lossless = "warn" +ptr_as_ptr = "warn" +ref_to_mut = "warn" +char_lit_as_u8 = "warn" dbg_macro = "warn" -# empty_structs_with_brackets = "warn" +empty_structs_with_brackets = "warn" # get_unwrap = "warn" # if_then_some_else_none = "warn" # let_underscore_must_use = "warn" # map_err_ignore = "warn" # missing_docs_in_private_items = "warn" -# negative_feature_names = "warn" -# pub_without_shorthand = "warn" +negative_feature_names = "warn" +pub_without_shorthand = "warn" rc_buffer = "warn" rc_mutex = "warn" -# redundant_feature_names = "warn" -# redundant_type_annotations = "warn" +redundant_feature_names = "warn" +redundant_type_annotations = "warn" # ref_patterns = "warn" -# rest_pat_in_fully_bound_structs = "warn" -# str_to_string = "warn" +rest_pat_in_fully_bound_structs = "warn" +str_to_string = "warn" # string_add = "warn" # string_slice = "warn" # string_to_string = "warn" tests_outside_test_module = "warn" undocumented_unsafe_blocks = "warn" -# unneeded_field_pattern = "warn" -# unseparated_literal_suffix = "warn" +unneeded_field_pattern = "warn" +unseparated_literal_suffix = "warn" # unwrap_used = "warn" -# wildcard_dependencies = "warn" \ No newline at end of file +# expect_used = "warn" +wildcard_dependencies = "warn" \ No newline at end of file diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index 2c34a24e..d114cf67 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -132,9 +132,7 @@ pub async fn get_content_as_filename_route( let mxc = format!("mxc://{}/{}", body.server_name, body.media_id); if let Some(FileMeta { - content_disposition: _, - content_type, - file, + content_type, file, .. }) = services().media.get(mxc.clone()).await? { Ok(get_content_as_filename::v3::Response { diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 5c297948..df7980ff 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -1221,7 +1221,7 @@ fn validate_and_add_event_id( Ok((event_id, value)) } -pub(crate) async fn invite_helper<'a>( +pub(crate) async fn invite_helper( sender_user: &UserId, user_id: &UserId, room_id: &RoomId, diff --git a/src/api/client_server/report.rs b/src/api/client_server/report.rs index 19b76c49..412590ba 100644 --- a/src/api/client_server/report.rs +++ b/src/api/client_server/report.rs @@ -41,7 +41,7 @@ pub async fn report_event_route( services().admin .send_message(message::RoomMessageEventContent::text_html( format!( - "Report received from: {}\n\n\ + "@room Report received from: {}\n\n\ Event ID: {:?}\n\ Room ID: {:?}\n\ Sent By: {:?}\n\n\ diff --git a/src/api/server_server.rs b/src/api/server_server.rs index cbd511b7..1570b541 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -95,7 +95,7 @@ impl FedDest { fn into_uri_string(self) -> String { match self { Self::Literal(addr) => addr.to_string(), - Self::Named(host, ref port) => host + port, + Self::Named(host, port) => host + &port, } } diff --git a/src/config/mod.rs b/src/config/mod.rs index d1550728..567870a8 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -218,10 +218,7 @@ impl fmt::Display for Config { "Allow device name federation", &self.allow_device_name_federation.to_string(), ), - ( - "Notification push path", - &self.notification_push_path.to_string(), - ), + ("Notification push path", &self.notification_push_path), ("Allow room creation", &self.allow_room_creation.to_string()), ( "Allow public room directory over federation", @@ -280,10 +277,7 @@ impl fmt::Display for Config { "zstd Response Body Compression", &self.zstd_compression.to_string(), ), - ( - "RocksDB database log level", - &self.rocksdb_log_level.to_string(), - ), + ("RocksDB database log level", &self.rocksdb_log_level), ( "RocksDB database log time-to-roll", &self.rocksdb_log_time_to_roll.to_string(), @@ -393,11 +387,11 @@ fn default_rocksdb_log_time_to_roll() -> usize { } // I know, it's a great name -pub fn default_default_room_version() -> RoomVersionId { +pub(crate) fn default_default_room_version() -> RoomVersionId { RoomVersionId::V10 } -pub fn default_rocksdb_max_log_file_size() -> usize { +fn default_rocksdb_max_log_file_size() -> usize { // 4 megabytes 4 * 1024 * 1024 } diff --git a/src/config/proxy.rs b/src/config/proxy.rs index 28ffada4..715d59f2 100644 --- a/src/config/proxy.rs +++ b/src/config/proxy.rs @@ -95,20 +95,20 @@ impl PartialProxyConfig { /// A domain name, that optionally allows a * as its first subdomain. #[derive(Clone, Debug)] -pub enum WildCardedDomain { +enum WildCardedDomain { WildCard, WildCarded(String), Exact(String), } impl WildCardedDomain { - pub fn matches(&self, domain: &str) -> bool { + fn matches(&self, domain: &str) -> bool { match self { WildCardedDomain::WildCard => true, WildCardedDomain::WildCarded(d) => domain.ends_with(d), WildCardedDomain::Exact(d) => domain == d, } } - pub fn more_specific_than(&self, other: &Self) -> bool { + fn more_specific_than(&self, other: &Self) -> bool { match (self, other) { (WildCardedDomain::WildCard, WildCardedDomain::WildCard) => false, (_, WildCardedDomain::WildCard) => true, diff --git a/src/database/abstraction.rs b/src/database/abstraction.rs index 83e82314..5056de8f 100644 --- a/src/database/abstraction.rs +++ b/src/database/abstraction.rs @@ -7,12 +7,12 @@ use std::{future::Future, pin::Pin, sync::Arc}; pub mod sqlite; #[cfg(feature = "rocksdb")] -pub mod rocksdb; +pub(crate) mod rocksdb; #[cfg(any(feature = "sqlite", feature = "rocksdb"))] -pub mod watchers; +pub(crate) mod watchers; -pub trait KeyValueDatabaseEngine: Send + Sync { +pub(crate) trait KeyValueDatabaseEngine: Send + Sync { fn open(config: &Config) -> Result where Self: Sized; @@ -27,7 +27,7 @@ pub trait KeyValueDatabaseEngine: Send + Sync { fn clear_caches(&self) {} } -pub trait KvTree: Send + Sync { +pub(crate) trait KvTree: Send + Sync { fn get(&self, key: &[u8]) -> Result>>; fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>; diff --git a/src/database/abstraction/rocksdb.rs b/src/database/abstraction/rocksdb.rs index 47203f08..7aca3fad 100644 --- a/src/database/abstraction/rocksdb.rs +++ b/src/database/abstraction/rocksdb.rs @@ -8,14 +8,14 @@ use std::{ use rocksdb::LogLevel::{Debug, Error, Fatal, Info, Warn}; -pub struct Engine { +pub(crate) struct Engine { rocks: rocksdb::DBWithThreadMode, cache: rocksdb::Cache, old_cfs: Vec, config: Config, } -pub struct RocksDbEngineTree<'a> { +struct RocksDbEngineTree<'a> { db: Arc, name: &'a str, watchers: Watchers, diff --git a/src/database/key_value/globals.rs b/src/database/key_value/globals.rs index 7a70af18..3cc1663b 100644 --- a/src/database/key_value/globals.rs +++ b/src/database/key_value/globals.rs @@ -11,8 +11,8 @@ use ruma::{ use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; -pub const COUNTER: &[u8] = b"c"; -pub const LAST_CHECK_FOR_UPDATES_COUNT: &[u8] = b"u"; +const COUNTER: &[u8] = b"c"; +const LAST_CHECK_FOR_UPDATES_COUNT: &[u8] = b"u"; #[async_trait] impl service::globals::Data for KeyValueDatabase { diff --git a/src/database/mod.rs b/src/database/mod.rs index 7234f8b8..9b53785f 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -1,5 +1,5 @@ -pub mod abstraction; -pub mod key_value; +pub(crate) mod abstraction; +pub(crate) mod key_value; use crate::{ service::rooms::{edus::presence::presence_handler, timeline::PduCount}, @@ -1094,7 +1094,7 @@ impl KeyValueDatabase { use tokio::time::Instant; let timer_interval = - Duration::from_secs(services().globals.config.cleanup_second_interval as u64); + Duration::from_secs(u64::from(services().globals.config.cleanup_second_interval)); fn perform_cleanup() { let start = Instant::now(); diff --git a/src/main.rs b/src/main.rs index cce432fd..49ceb1b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,7 @@ static GLOBAL: Jemalloc = Jemalloc; #[derive(Parser)] #[clap(version, about, long_about = None)] -struct Args {} +struct Args; #[tokio::main] async fn main() { diff --git a/src/service/account_data/mod.rs b/src/service/account_data/mod.rs index f9c49b1a..bfdbd5f5 100644 --- a/src/service/account_data/mod.rs +++ b/src/service/account_data/mod.rs @@ -1,6 +1,6 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use ruma::{ events::{AnyEphemeralRoomEvent, RoomAccountDataEventType}, diff --git a/src/service/appservice/mod.rs b/src/service/appservice/mod.rs index 3052964d..7789968c 100644 --- a/src/service/appservice/mod.rs +++ b/src/service/appservice/mod.rs @@ -1,6 +1,6 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use crate::Result; diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 78d913e7..46d83206 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -75,7 +75,7 @@ pub struct Service<'a> { pub roomid_mutex_federation: RwLock>>>, // this lock will be held longer pub roomid_federationhandletime: RwLock>, pub stateres_mutex: Arc>, - pub rotate: RotationHandler, + pub(crate) rotate: RotationHandler, pub shutdown: AtomicBool, pub argon: Argon2<'a>, @@ -84,12 +84,12 @@ pub struct Service<'a> { /// Handles "rotation" of long-polling requests. "Rotation" in this context is similar to "rotation" of log files and the like. /// /// This is utilized to have sync workers return early and release read locks on the database. -pub struct RotationHandler(broadcast::Sender<()>, broadcast::Receiver<()>); +pub(crate) struct RotationHandler(broadcast::Sender<()>, ()); impl RotationHandler { pub fn new() -> Self { - let (s, r) = broadcast::channel(1); - Self(s, r) + let (s, _r) = broadcast::channel(1); + Self(s, ()) } pub fn watch(&self) -> impl Future { @@ -113,13 +113,13 @@ impl Default for RotationHandler { type DnsOverrides = Box Option + Send + Sync>; -pub struct Resolver { +struct Resolver { inner: GaiResolver, overrides: DnsOverrides, } impl Resolver { - pub fn new(overrides: DnsOverrides) -> Resolver { + fn new(overrides: DnsOverrides) -> Resolver { Resolver { inner: GaiResolver::new(), overrides, diff --git a/src/service/key_backups/mod.rs b/src/service/key_backups/mod.rs index 5fc52ced..50eca0b6 100644 --- a/src/service/key_backups/mod.rs +++ b/src/service/key_backups/mod.rs @@ -1,5 +1,5 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use crate::Result; use ruma::{ diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index 327abd86..4a016bda 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -1,7 +1,7 @@ mod data; use std::io::Cursor; -pub use data::Data; +pub(crate) use data::Data; use crate::{services, Result}; use image::imageops::FilterType; diff --git a/src/service/mod.rs b/src/service/mod.rs index 883c567c..0597c211 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -7,19 +7,19 @@ use lru_cache::LruCache; use crate::{Config, Result}; -pub mod account_data; -pub mod admin; -pub mod appservice; -pub mod globals; -pub mod key_backups; -pub mod media; -pub mod pdu; -pub mod pusher; -pub mod rooms; -pub mod sending; -pub mod transaction_ids; -pub mod uiaa; -pub mod users; +pub(crate) mod account_data; +pub(crate) mod admin; +pub(crate) mod appservice; +pub(crate) mod globals; +pub(crate) mod key_backups; +pub(crate) mod media; +pub(crate) mod pdu; +pub(crate) mod pusher; +pub(crate) mod rooms; +pub(crate) mod sending; +pub(crate) mod transaction_ids; +pub(crate) mod uiaa; +pub(crate) mod users; pub struct Services<'a> { pub appservice: appservice::Service, diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 79e83f97..e737df17 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,4 +1,4 @@ -pub mod error; +pub(crate) mod error; use crate::{services, Error, Result}; use argon2::{password_hash::SaltString, PasswordHasher}; @@ -14,14 +14,14 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; -pub fn millis_since_unix_epoch() -> u64 { +pub(crate) fn millis_since_unix_epoch() -> u64 { SystemTime::now() .duration_since(UNIX_EPOCH) .expect("time is valid") .as_millis() as u64 } -pub fn increment(old: Option<&[u8]>) -> Option> { +pub(crate) fn increment(old: Option<&[u8]>) -> Option> { let number = match old.map(|bytes| bytes.try_into()) { Some(Ok(bytes)) => { let number = u64::from_be_bytes(bytes); @@ -89,7 +89,7 @@ pub fn calculate_hash(keys: &[&[u8]]) -> Vec { hash.as_ref().to_owned() } -pub fn common_elements( +pub(crate) fn common_elements( mut iterators: impl Iterator>>, check_order: impl Fn(&[u8], &[u8]) -> Ordering, ) -> Option>> { @@ -116,7 +116,7 @@ pub fn common_elements( /// Fallible conversion from any value that implements `Serialize` to a `CanonicalJsonObject`. /// /// `value` must serialize to an `serde_json::Value::Object`. -pub fn to_canonical_object( +pub(crate) fn to_canonical_object( value: T, ) -> Result { use serde::ser::Error; @@ -129,7 +129,7 @@ pub fn to_canonical_object( } } -pub fn deserialize_from_str< +pub(crate) fn deserialize_from_str< 'de, D: serde::de::Deserializer<'de>, T: FromStr, @@ -160,7 +160,7 @@ pub fn deserialize_from_str< /// Wrapper struct which will emit the HTML-escaped version of the contained /// string when passed to a format string. -pub struct HtmlEscape<'a>(pub &'a str); +pub(crate) struct HtmlEscape<'a>(pub(crate) &'a str); impl<'a> fmt::Display for HtmlEscape<'a> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {