Skip to content

Fix Rust 1.64 clippy warnings and tests #3613

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

Merged
merged 1 commit into from
Sep 25, 2022
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
28 changes: 15 additions & 13 deletions deltachat-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub unsafe extern "C" fn dc_context_unref(context: *mut dc_context_t) {
eprintln!("ignoring careless call to dc_context_unref()");
return;
}
Box::from_raw(context);
drop(Box::from_raw(context));
}

#[no_mangle]
Expand Down Expand Up @@ -463,7 +463,7 @@ pub unsafe extern "C" fn dc_event_unref(a: *mut dc_event_t) {
return;
}

Box::from_raw(a);
drop(Box::from_raw(a));
}

#[no_mangle]
Expand Down Expand Up @@ -687,7 +687,7 @@ pub unsafe extern "C" fn dc_event_emitter_unref(emitter: *mut dc_event_emitter_t
return;
}

Box::from_raw(emitter);
drop(Box::from_raw(emitter));
}

#[no_mangle]
Expand Down Expand Up @@ -2426,7 +2426,7 @@ pub unsafe extern "C" fn dc_array_unref(a: *mut dc_array::dc_array_t) {
return;
}

Box::from_raw(a);
drop(Box::from_raw(a));
}

#[no_mangle]
Expand Down Expand Up @@ -2607,7 +2607,7 @@ pub unsafe extern "C" fn dc_chatlist_unref(chatlist: *mut dc_chatlist_t) {
eprintln!("ignoring careless call to dc_chatlist_unref()");
return;
}
Box::from_raw(chatlist);
drop(Box::from_raw(chatlist));
}

#[no_mangle]
Expand Down Expand Up @@ -2752,7 +2752,7 @@ pub unsafe extern "C" fn dc_chat_unref(chat: *mut dc_chat_t) {
return;
}

Box::from_raw(chat);
drop(Box::from_raw(chat));
}

#[no_mangle]
Expand Down Expand Up @@ -3022,7 +3022,7 @@ pub unsafe extern "C" fn dc_msg_unref(msg: *mut dc_msg_t) {
return;
}

Box::from_raw(msg);
drop(Box::from_raw(msg));
}

#[no_mangle]
Expand Down Expand Up @@ -3744,7 +3744,7 @@ pub unsafe extern "C" fn dc_contact_unref(contact: *mut dc_contact_t) {
eprintln!("ignoring careless call to dc_contact_unref()");
return;
}
Box::from_raw(contact);
drop(Box::from_raw(contact));
}

#[no_mangle]
Expand Down Expand Up @@ -3908,7 +3908,7 @@ pub unsafe extern "C" fn dc_lot_unref(lot: *mut dc_lot_t) {
return;
}

Box::from_raw(lot);
drop(Box::from_raw(lot));
}

#[no_mangle]
Expand Down Expand Up @@ -4200,7 +4200,8 @@ pub unsafe extern "C" fn dc_accounts_get_account(
}

let accounts = &*accounts;
block_on(async move { accounts.read().await.get_account(id).await })
block_on(accounts.read())
.get_account(id)
.map(|ctx| Box::into_raw(Box::new(ctx)))
.unwrap_or_else(std::ptr::null_mut)
}
Expand All @@ -4215,7 +4216,8 @@ pub unsafe extern "C" fn dc_accounts_get_selected_account(
}

let accounts = &*accounts;
block_on(async move { accounts.read().await.get_selected_account().await })
block_on(accounts.read())
.get_selected_account()
.map(|ctx| Box::into_raw(Box::new(ctx)))
.unwrap_or_else(std::ptr::null_mut)
}
Expand Down Expand Up @@ -4360,7 +4362,7 @@ pub unsafe extern "C" fn dc_accounts_get_all(accounts: *mut dc_accounts_t) -> *m
}

let accounts = &*accounts;
let list = block_on(async move { accounts.read().await.get_all().await });
let list = block_on(accounts.read()).get_all();
let array: dc_array_t = list.into();

Box::into_raw(Box::new(array))
Expand Down Expand Up @@ -4430,7 +4432,7 @@ pub unsafe extern "C" fn dc_accounts_get_event_emitter(
}

let accounts = &*accounts;
let emitter = block_on(async move { accounts.read().await.get_event_emitter().await });
let emitter = block_on(accounts.read()).get_event_emitter();

Box::into_raw(Box::new(emitter))
}
Expand Down
11 changes: 5 additions & 6 deletions deltachat-jsonrpc/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ impl CommandApi {
.read()
.await
.get_account(id)
.await
.ok_or_else(|| anyhow!("account with id {} not found", id))?;
Ok(sc)
}
Expand Down Expand Up @@ -100,7 +99,7 @@ impl CommandApi {
}

async fn get_all_account_ids(&self) -> Vec<u32> {
self.accounts.read().await.get_all().await
self.accounts.read().await.get_all()
}

/// Select account id for internally selected state.
Expand All @@ -112,14 +111,14 @@ impl CommandApi {
/// Get the selected account id of the internal state..
/// TODO: Likely this is deprecated as all methods take an account id now.
async fn get_selected_account_id(&self) -> Option<u32> {
self.accounts.read().await.get_selected_account_id().await
self.accounts.read().await.get_selected_account_id()
}

/// Get a list of all configured accounts.
async fn get_all_accounts(&self) -> Result<Vec<Account>> {
let mut accounts = Vec::new();
for id in self.accounts.read().await.get_all().await {
let context_option = self.accounts.read().await.get_account(id).await;
for id in self.accounts.read().await.get_all() {
let context_option = self.accounts.read().await.get_account(id);
if let Some(ctx) = context_option {
accounts.push(Account::from_context(&ctx, id).await?)
} else {
Expand All @@ -135,7 +134,7 @@ impl CommandApi {

/// Get top-level info for an account.
async fn get_account_info(&self, account_id: u32) -> Result<Account> {
let context_option = self.accounts.read().await.get_account(account_id).await;
let context_option = self.accounts.read().await.get_account(account_id);
if let Some(ctx) = context_option {
Ok(Account::from_context(&ctx, account_id).await?)
} else {
Expand Down
2 changes: 1 addition & 1 deletion deltachat-jsonrpc/src/webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn handler(ws: WebSocketUpgrade, Extension(api): Extension<CommandApi>) ->
let (client, out_receiver) = RpcClient::new();
let session = RpcSession::new(client.clone(), api.clone());
tokio::spawn(async move {
let events = api.accounts.read().await.get_event_emitter().await;
let events = api.accounts.read().await.get_event_emitter();
while let Some(event) = events.recv().await {
let event = event_to_json_rpc_notification(event);
client.send_notification("event", Some(event)).await.ok();
Expand Down
Loading