Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make clippy happy #276

Merged
merged 7 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cc;
use cmake;



use std::env;
use std::path::PathBuf;
Expand Down Expand Up @@ -31,7 +31,7 @@ fn main() {
.with_header("namespace litehtml_rust {struct Callbacks;}")
.generate()
.expect("Unable to generate bindings")
.write_to_file(&litehtml_callbacks_header_file);
.write_to_file(litehtml_callbacks_header_file);

let clang_include_path = format!("{}/include", clang_lib_path);
let include_path = format!("{}/include", out_path);
Expand Down
11 changes: 4 additions & 7 deletions app/src/backends/imap/imap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use crate::models;

use diesel::Connection;
use futures::Future;
use melib;
use melib::backends::imap::{
Expand Down Expand Up @@ -327,7 +326,7 @@ impl ImapBackend {
if !l.starts_with(b"*") {
continue;
}
if let Ok(mut mailbox) = list_mailbox_result(&l).map(|(_, v)| v) {
if let Ok(mut mailbox) = list_mailbox_result(l).map(|(_, v)| v) {
if let Some(parent) = mailbox.parent {
if mailboxes.contains_key(&parent) {
mailboxes.entry(parent).and_modify(|e| e.children.push(mailbox.hash));
Expand All @@ -351,7 +350,7 @@ impl ImapBackend {
} else {
mailboxes.insert(mailbox.hash, mailbox);
}
} else if let Ok(status) = status_response(&l).map(|(_, v)| v) {
} else if let Ok(status) = status_response(l).map(|(_, v)| v) {
if let Some(mailbox_hash) = status.mailbox {
if mailboxes.contains_key(&mailbox_hash) {
let entry = mailboxes.entry(mailbox_hash).or_default();
Expand All @@ -363,7 +362,6 @@ impl ImapBackend {
}
}
}
} else {
}
}
mailboxes.retain(|_, v| v.hash != 0);
Expand All @@ -374,7 +372,7 @@ impl ImapBackend {
if !l.starts_with(b"*") {
continue;
}
if let Ok(subscription) = list_mailbox_result(&l).map(|(_, v)| v) {
if let Ok(subscription) = list_mailbox_result(l).map(|(_, v)| v) {
if let Some(f) = mailboxes.get_mut(&subscription.hash()) {
if f.special_usage() == melib::backends::SpecialUsageMailbox::Normal
&& subscription.special_usage() != melib::backends::SpecialUsageMailbox::Normal
Expand All @@ -383,7 +381,6 @@ impl ImapBackend {
}
f.is_subscribed = true;
}
} else {
}
}

Expand All @@ -403,7 +400,7 @@ impl ImapBackend {

let mut response = Vec::with_capacity(8 * 1024);

let mut messages = connection
let messages = connection
.uid_fetch(format!("{}", uid), "(BODY.PEEK[])".to_string(), &mut response)
.await?;

Expand Down
12 changes: 6 additions & 6 deletions app/src/backends/imap/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ImapBackend {

let now = Instant::now();

let new_messages = fetch_messages_overview_in_uid_range(&mut *connection, 1, select_response.uidnext - 1).await?;
let new_messages = fetch_messages_overview_in_uid_range(&mut connection, 1, select_response.uidnext - 1).await?;

debug!(
"Finished fresh fetch. Found {} new messages with UID validity {}. Took {} seconds.",
Expand Down Expand Up @@ -79,10 +79,10 @@ impl ImapBackend {
} else {
debug!("Fetching new messages");
let new_messages =
fetch_messages_overview_in_uid_range(&mut *connection, max_uid + 1, select_response.uidnext - 1).await?;
fetch_messages_overview_in_uid_range(&mut connection, max_uid + 1, select_response.uidnext - 1).await?;

debug!("Found {} new messages. Fetching flag updates", new_messages.len());
let flag_updates = fetch_flags_updates_in_uid_range(&mut *connection, 1, max_uid).await?;
let flag_updates = fetch_flags_updates_in_uid_range(&mut connection, 1, max_uid).await?;

debug!("Finished in {} seconds.", now.elapsed().as_secs());

Expand Down Expand Up @@ -136,9 +136,9 @@ async fn fetch_messages_overview_in_uid_range(
let mut response = Vec::with_capacity(8 * 1024);
let mut messages_list = Vec::new();

let mut iterator = UidFetchIterator::new(uid_range_start, uid_range_end);
let iterator = UidFetchIterator::new(uid_range_start, uid_range_end);

while let Some((fetch_range_start, fetch_range_end)) = iterator.next() {
for (fetch_range_start, fetch_range_end) in iterator {
let mut messages = connection
.uid_fetch(
format!("{}:{}", fetch_range_start, fetch_range_end),
Expand Down Expand Up @@ -181,7 +181,7 @@ async fn fetch_messages_overview_in_uid_range(
.map(|modseq| TryInto::<i64>::try_into(u64::from(modseq.0)))
.transpose()
// Abusing the types a little bit to coerce into a valid MeliError
.or_else(|_| Err(Cow::from("Unable to convert modification sequence type")))?;
.map_err(|_| Cow::from("Unable to convert modification sequence type"))?;

messages_list.push(new_message);
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/backends/imap/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub enum UntaggedResponse {
}

fn process_untagged_line(line: &[u8]) -> Result<Option<UntaggedResponse>, String> {
debug!("Processing untagged line: {}", std::str::from_utf8(&line).unwrap().trim());
debug!("Processing untagged line: {}", std::str::from_utf8(line).unwrap().trim());
match melib::backends::imap::untagged_responses(line).map(|(_, v, _)| v) {
Ok(None) => Ok(None),
Err(_) => {
Expand Down Expand Up @@ -189,7 +189,7 @@ async fn idle(
if should_drop {
debug!(
"Dropping command confirmation or continuation: {}",
std::str::from_utf8(&line).unwrap().trim()
std::str::from_utf8(line).unwrap().trim()
);
}

Expand Down
6 changes: 3 additions & 3 deletions app/src/controllers/application.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use adw::subclass::prelude::*;
use gtk::gio::{prelude::*, SimpleAction};
use gtk::prelude::*;
use gtk::subclass::prelude::*;

use gtk::{gdk, gio, glib};

use chrono::prelude::*;
Expand Down Expand Up @@ -174,7 +174,7 @@ mod imp {
fn activate(&self) {
debug!("Application activate");

let mut application_message;
let application_message;
if self.should_set_up_test_server() {
debug!("Test server setup not found. Configuring");

Expand Down Expand Up @@ -222,7 +222,7 @@ mod imp {
}

fn command_line(&self, command_line: &gio::ApplicationCommandLine) -> glib::ExitCode {
if command_line.options_dict().contains(&"with-test-server") {
if command_line.options_dict().contains("with-test-server") {
debug!("Enabling test server setup");
self.enable_test_server_setup();
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/google_oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub async fn refresh_access_token(refresh_token: &String) -> Result<GoogleTokenR
let client = HttpClient::new().unwrap();

let request = GoogleAccessTokenRefreshRequest {
refresh_token: &refresh_token,
refresh_token,
client_id: &CLIENT_ID.to_string(),
client_secret: &CLIENT_SECRET.to_string(),
grant_type: &"refresh_token".to_string(),
Expand Down
24 changes: 11 additions & 13 deletions app/src/litehtml_callbacks.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use gtk::prelude::*;
use gtk::{gdk, graphene, gsk, pango};
use pangocairo;

use libc;
use log::debug;
use std::ffi::{CStr, CString};

Expand Down Expand Up @@ -62,7 +60,7 @@ impl Callbacks {
}

pub fn nodes(&self) -> &Vec<gsk::RenderNode> {
return &self.render_nodes;
&self.render_nodes
}

pub fn clear_nodes(&mut self) {
Expand All @@ -75,7 +73,7 @@ impl Callbacks {

let text = c_str.to_str().unwrap();

if text.trim().len() == 0 {
if text.trim().is_empty() {
debug!("Skipping drawing whitespace");

return;
Expand All @@ -89,7 +87,7 @@ impl Callbacks {
let font_map = pangocairo::FontMap::default();
let context = font_map.create_context();

let font = context.load_font(&font_description).unwrap();
let font = context.load_font(font_description).unwrap();

let layout = pango::Layout::new(&context);

Expand Down Expand Up @@ -126,9 +124,9 @@ impl Callbacks {

let font_map = pangocairo::FontMap::default();
let context = font_map.create_context();
context.set_font_description(Some(&font_description));
context.set_font_description(Some(font_description));

let font = context.load_font(&font_description).unwrap();
let font = context.load_font(font_description).unwrap();

let (ink_rect, logical_rect) = font.glyph_extents(0 as pango::Glyph);

Expand Down Expand Up @@ -167,7 +165,7 @@ impl Callbacks {

self.populate_font_metrics(font_description_key, font_metrics);

return font_description_key.clone();
return *font_description_key;
}

let font_description_key = self.next_font_key;
Expand All @@ -191,12 +189,12 @@ impl Callbacks {

self.populate_font_metrics(&font_description_key, font_metrics);

return font_description_key;
font_description_key
}

#[no_mangle]
pub extern "C" fn get_default_font_name(&self) -> *const libc::c_char {
return self.default_font.as_ptr();
self.default_font.as_ptr()
}

#[no_mangle]
Expand All @@ -213,8 +211,8 @@ impl Callbacks {

let layout = pango::Layout::new(&context);

layout.set_text(&text);
layout.set_font_description(Some(&font_description));
layout.set_text(text);
layout.set_font_description(Some(font_description));

let (width, _) = layout.size();

Expand All @@ -223,6 +221,6 @@ impl Callbacks {
return width;
}

return 0;
0
}
}
2 changes: 1 addition & 1 deletion app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use controllers::ApplicationProfile;
use gettextrs::{gettext, LocaleCategory};
use gtk::{gio, glib};

use adw;

use adw::prelude::*;

use self::config::{GETTEXT_PACKAGE, LOCALEDIR, PROFILE, RESOURCES_FILE};
Expand Down
2 changes: 1 addition & 1 deletion app/src/models/conversation_messages_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub mod model {
}

pub fn load_message(&self, id: i32) {
let self_ = imp::ConversationModel::from_obj(&self);
let self_ = imp::ConversationModel::from_obj(self);

let previous_count = self_.n_items();

Expand Down
2 changes: 1 addition & 1 deletion app/src/models/database.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::schema::{folders, identities, messages};
use chrono;


#[derive(Identifiable, Queryable, Associations, Debug, Clone)]
#[diesel(belongs_to(BareIdentity, foreign_key = identity_id))]
Expand Down
18 changes: 9 additions & 9 deletions app/src/models/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use log::{debug, error, info};

use gtk::glib;

use melib::{backends::BackendMailbox, BackendEventConsumer};
use melib::backends::BackendMailbox;

use std::boxed::Box;
use std::collections::HashMap;
use std::convert::TryInto;
use std::rc::Rc;
use std::sync::Arc;

use std::time::Instant;

use crate::backends::imap;
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Identity {
.expect("Unable to find IMAP password for IMAP account type"),
};

if bare_identity.identity_type == IdentityType::Gmail {}
bare_identity.identity_type == IdentityType::Gmail;

let imap_backend = imap::ImapBackend::new(
bare_identity.imap_server_hostname.clone(),
Expand All @@ -79,12 +79,12 @@ impl Identity {
.unwrap();

info!("Identity for {} created", bare_identity.email_address);
return Identity {
Identity {
bare_identity: Rc::new(bare_identity),
backend: Rc::new(imap_backend),
store,
application_message_sender,
};
}
}

pub async fn initialize(self: Rc<Self>) -> Result<(), String> {
Expand Down Expand Up @@ -173,9 +173,9 @@ impl Identity {
for folder in folders.iter().filter(|x| x.folder_name != "INBOX") {
// @TODO if the folders changed in the meanwhile and the last sync somehow
// failed, we need to check if the folder actually exists
let sync_result = self.clone().sync_messages_for_folder(&folder, SyncType::Update).await;
let sync_result = self.clone().sync_messages_for_folder(folder, SyncType::Update).await;

self.clone().handle_sync_messages_for_folder_result(&folder, sync_result);
self.clone().handle_sync_messages_for_folder_result(folder, sync_result);
}

Ok(())
Expand Down Expand Up @@ -270,7 +270,7 @@ impl Identity {
&mailbox_path,
self.bare_identity.as_ref().email_address
);
self.store.store_folder_for_mailbox(self.bare_identity.as_ref(), &mailbox_value)?;
self.store.store_folder_for_mailbox(self.bare_identity.as_ref(), mailbox_value)?;
}
}
}
Expand All @@ -281,7 +281,7 @@ impl Identity {
&folder_path,
self.bare_identity.as_ref().email_address
);
self.store.remove_folder(self.bare_identity.as_ref(), &folder_value)?;
self.store.remove_folder(self.bare_identity.as_ref(), folder_value)?;
}

//@TODO trigger application event to reload folders
Expand Down
2 changes: 1 addition & 1 deletion app/src/services/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ impl Store {
let connection = &mut self.database_connection_pool.get().map_err(|e| e.to_string())?;

// The key is the UID and the value is the database primary key
let mut store_folder_uids: HashMap<_, _> = schema::messages::table
let store_folder_uids: HashMap<_, _> = schema::messages::table
.select((schema::messages::uid, schema::messages::id))
.filter(schema::messages::folder_id.eq(folder.id))
.load::<(i64, i32)>(connection)
Expand Down
4 changes: 2 additions & 2 deletions app/src/ui/welcome_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gtk;


use gtk::gio;
use gtk::glib;
Expand Down Expand Up @@ -35,7 +35,7 @@ pub struct WelcomeDialog {
impl WelcomeDialog {
pub fn new(sender: glib::Sender<ApplicationMessage>) -> WelcomeDialog {
let dialog = Self {
sender: sender,
sender,
// Workaround for the desktop manager seemingly taking over headerbars?
gtk_dialog: gtk::Dialog::with_buttons(
Some(""),
Expand Down
Loading