From 46f89f320576dcef7ced7feb8140f7cdcd213b64 Mon Sep 17 00:00:00 2001 From: BlackDex Date: Mon, 23 Sep 2024 20:06:06 +0200 Subject: [PATCH] Adjusted according to comments Signed-off-by: BlackDex --- Cargo.lock | 12 ++++++------ Cargo.toml | 13 ++++++++++--- src/api/core/accounts.rs | 6 +++--- src/api/icons.rs | 14 +++++++------- src/config.rs | 2 -- src/db/models/emergency_access.rs | 2 +- src/error.rs | 7 ------- 7 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f07b9abd..10ed3506 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2543,9 +2543,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "polling" @@ -3573,18 +3573,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 44d985eb..63060089 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -198,6 +198,7 @@ lto = "thin" codegen-units = 16 # Linting config +# https://doc.rust-lang.org/rustc/lints/groups.html [lints.rust] # Forbid unsafe_code = "forbid" @@ -212,8 +213,8 @@ noop_method_call = "deny" refining_impl_trait = { level = "deny", priority = -1 } rust_2018_idioms = { level = "deny", priority = -1 } rust_2021_compatibility = { level = "deny", priority = -1 } -rust_2024_compatibility = { level = "deny", priority = -1 } -single_use_lifetimes = { level = "deny", priority = -1 } +# rust_2024_compatibility = { level = "deny", priority = -1 } # Enable once we are at MSRV 1.81.0 +single_use_lifetimes = "deny" trivial_casts = "deny" trivial_numeric_casts = "deny" unused = { level = "deny", priority = -1 } @@ -221,15 +222,22 @@ unused_import_braces = "deny" unused_lifetimes = "deny" unused_qualifications = "deny" variant_size_differences = "deny" +# The lints below are part of the rust_2024_compatibility group +static-mut-refs = "deny" +unsafe-op-in-unsafe-fn = "deny" +# https://rust-lang.github.io/rust-clippy/stable/index.html [lints.clippy] # Warn dbg_macro = "warn" +todo = "warn" # Deny +case_sensitive_file_extension_comparisons = "deny" cast_lossless = "deny" clone_on_ref_ptr = "deny" equatable_if_let = "deny" +filter_map_next = "deny" float_cmp_const = "deny" inefficient_to_string = "deny" iter_on_empty_collections = "deny" @@ -254,4 +262,3 @@ unused_async = "deny" unused_self = "deny" verbose_file_reads = "deny" zero_sized_map_values = "deny" -filter_map_next = "deny" diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index 2ce5d19c..f9822629 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -223,7 +223,7 @@ pub async fn _register(data: Json, mut conn: DbConn) -> JsonResult } if verified_by_invite && is_email_2fa_required(data.organization_user_id, &mut conn).await { - drop(email::activate_email_2fa(&user, &mut conn).await); + email::activate_email_2fa(&user, &mut conn).await.ok(); } } @@ -232,7 +232,7 @@ pub async fn _register(data: Json, mut conn: DbConn) -> JsonResult // accept any open emergency access invitations if !CONFIG.mail_enabled() && CONFIG.emergency_access_allowed() { for mut emergency_invite in EmergencyAccess::find_all_invited_by_grantee_email(&user.email, &mut conn).await { - drop(emergency_invite.accept_invite(&user.uuid, &user.email, &mut conn).await); + emergency_invite.accept_invite(&user.uuid, &user.email, &mut conn).await.ok(); } } @@ -1038,7 +1038,7 @@ async fn put_device_token(uuid: &str, data: Json, headers: Headers, m return Ok(()); } else { // Try to unregister already registered device - drop(unregister_push_device(device.push_uuid).await); + unregister_push_device(device.push_uuid).await.ok(); } // clear the push_uuid device.push_uuid = None; diff --git a/src/api/icons.rs b/src/api/icons.rs index 47f9dde3..6afbaa9f 100644 --- a/src/api/icons.rs +++ b/src/api/icons.rs @@ -1,4 +1,5 @@ use std::{ + collections::HashMap, net::IpAddr, sync::Arc, time::{Duration, SystemTime}, @@ -446,6 +447,9 @@ async fn get_page_with_referer(url: &str, referer: &str) -> Result u8 { + static PRIORITY_MAP: Lazy> = + Lazy::new(|| [(".png", 10), (".jpg", 20), (".jpeg", 20)].into_iter().collect()); + // Check if there is a dimension set let (width, height) = parse_sizes(sizes); @@ -470,13 +474,9 @@ fn get_icon_priority(href: &str, sizes: &str) -> u8 { 200 } } else { - // Change priority by file extension - if href.ends_with(".png") { - 10 - } else if href.ends_with(".jpg") || href.ends_with(".jpeg") { - 20 - } else { - 30 + match href.rsplit_once('.') { + Some((_, extension)) => PRIORITY_MAP.get(&*extension.to_ascii_lowercase()).copied().unwrap_or(30), + None => 30, } } } diff --git a/src/config.rs b/src/config.rs index 141d311c..eb765b09 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,7 +26,6 @@ pub static CONFIG: Lazy = Lazy::new(|| { pub type Pass = String; -#[allow(edition_2024_expr_fragment_specifier)] macro_rules! make_config { ($( $(#[doc = $groupdoc:literal])? @@ -1297,7 +1296,6 @@ where hb.register_helper("case", Box::new(case_helper)); hb.register_helper("to_json", Box::new(to_json)); - #[allow(edition_2024_expr_fragment_specifier)] macro_rules! reg { ($name:expr) => {{ let template = include_str!(concat!("static/templates/", $name, ".hbs")); diff --git a/src/db/models/emergency_access.rs b/src/db/models/emergency_access.rs index f0c9e302..e1b85ec6 100644 --- a/src/db/models/emergency_access.rs +++ b/src/db/models/emergency_access.rs @@ -89,7 +89,7 @@ impl EmergencyAccess { Some(user) => user, None => { // remove outstanding invitations which should not exist - drop(Self::delete_all_by_grantee_email(email, conn).await); + Self::delete_all_by_grantee_email(email, conn).await.ok(); return None; } } diff --git a/src/error.rs b/src/error.rs index a9bc3f2b..1061a08d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,7 +5,6 @@ use crate::db::models::EventType; use crate::http_client::CustomHttpClientError; use std::error::Error as StdError; -#[allow(edition_2024_expr_fragment_specifier)] macro_rules! make_error { ( $( $name:ident ( $ty:ty ): $src_fn:expr, $usr_msg_fun:expr ),+ $(,)? ) => { const BAD_REQUEST: u16 = 400; @@ -228,7 +227,6 @@ impl Responder<'_, 'static> for Error { // Error return macros // #[macro_export] -#[allow(edition_2024_expr_fragment_specifier)] macro_rules! err { ($msg:expr) => {{ error!("{}", $msg); @@ -249,7 +247,6 @@ macro_rules! err { } #[macro_export] -#[allow(edition_2024_expr_fragment_specifier)] macro_rules! err_silent { ($msg:expr) => {{ return Err($crate::error::Error::new($msg, $msg)); @@ -260,7 +257,6 @@ macro_rules! err_silent { } #[macro_export] -#[allow(edition_2024_expr_fragment_specifier)] macro_rules! err_code { ($msg:expr, $err_code:expr) => {{ error!("{}", $msg); @@ -273,7 +269,6 @@ macro_rules! err_code { } #[macro_export] -#[allow(edition_2024_expr_fragment_specifier)] macro_rules! err_discard { ($msg:expr, $data:expr) => {{ std::io::copy(&mut $data.open(), &mut std::io::sink()).ok(); @@ -286,7 +281,6 @@ macro_rules! err_discard { } #[macro_export] -#[allow(edition_2024_expr_fragment_specifier)] macro_rules! err_json { ($expr:expr, $log_value:expr) => {{ return Err(($log_value, $expr).into()); @@ -297,7 +291,6 @@ macro_rules! err_json { } #[macro_export] -#[allow(edition_2024_expr_fragment_specifier)] macro_rules! err_handler { ($expr:expr) => {{ error!(target: "auth", "Unauthorized Error: {}", $expr);