diff --git a/deltachat-contact-tools/src/lib.rs b/deltachat-contact-tools/src/lib.rs index d9264ebf6..8ea7c0b6d 100644 --- a/deltachat-contact-tools/src/lib.rs +++ b/deltachat-contact-tools/src/lib.rs @@ -68,7 +68,7 @@ impl ContactAddress { pub fn new(s: &str) -> Result { let addr = addr_normalize(s); if !may_be_valid_addr(&addr) { - bail!("invalid address {:?}", s); + bail!("invalid address {s:?}"); } Ok(Self(addr.to_string())) } @@ -257,16 +257,16 @@ impl EmailAddress { .chars() .any(|c| c.is_whitespace() || c == '<' || c == '>') { - bail!("Email {:?} must not contain whitespaces, '>' or '<'", input); + bail!("Email {input:?} must not contain whitespaces, '>' or '<'"); } match &parts[..] { [domain, local] => { if local.is_empty() { - bail!("empty string is not valid for local part in {:?}", input); + bail!("empty string is not valid for local part in {input:?}"); } if domain.is_empty() { - bail!("missing domain after '@' in {:?}", input); + bail!("missing domain after '@' in {input:?}"); } if domain.ends_with('.') { bail!("Domain {domain:?} should not contain the dot in the end"); @@ -276,7 +276,7 @@ impl EmailAddress { domain: (*domain).to_string(), }) } - _ => bail!("Email {:?} must contain '@' character", input), + _ => bail!("Email {input:?} must contain '@' character"), } } } diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index 148c11285..bc2a8f285 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -126,7 +126,7 @@ impl CommandApi { .read() .await .get_account(id) - .ok_or_else(|| anyhow!("account with id {} not found", id))?; + .ok_or_else(|| anyhow!("account with id {id} not found"))?; Ok(sc) } @@ -308,8 +308,7 @@ impl CommandApi { Ok(Account::from_context(&ctx, account_id).await?) } else { Err(anyhow!( - "account with id {} doesn't exist anymore", - account_id + "account with id {account_id} doesn't exist anymore" )) } } @@ -2312,8 +2311,7 @@ impl CommandApi { let message = Message::load_from_db(&ctx, MsgId::new(msg_id)).await?; ensure!( message.get_viewtype() == Viewtype::Sticker, - "message {} is not a sticker", - msg_id + "message {msg_id} is not a sticker" ); let account_folder = ctx .get_dbfile() @@ -2533,10 +2531,7 @@ impl CommandApi { .to_u32(); Ok(msg_id) } else { - Err(anyhow!( - "chat with id {} doesn't have draft message", - chat_id - )) + Err(anyhow!("chat with id {chat_id} doesn't have draft message")) } } } diff --git a/deltachat-repl/src/cmdline.rs b/deltachat-repl/src/cmdline.rs index 93e9cc2f4..079486fb2 100644 --- a/deltachat-repl/src/cmdline.rs +++ b/deltachat-repl/src/cmdline.rs @@ -418,7 +418,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu Ok(setup_code) => { println!("Setup code for the transferred setup message: {setup_code}",) } - Err(err) => bail!("Failed to generate setup code: {}", err), + Err(err) => bail!("Failed to generate setup code: {err}"), }, "get-setupcodebegin" => { ensure!(!arg1.is_empty(), "Argument missing."); @@ -432,7 +432,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu setupcodebegin.unwrap_or_default(), ); } else { - bail!("{} is no setup message.", msg_id,); + bail!("{msg_id} is no setup message.",); } } "continue-key-transfer" => { @@ -527,7 +527,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu println!("Report written to: {file:#?}"); } Err(err) => { - bail!("Failed to get connectivity html: {}", err); + bail!("Failed to get connectivity html: {err}"); } } } @@ -1287,7 +1287,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu ); } "" => (), - _ => bail!("Unknown command: \"{}\" type ? for help.", arg0), + _ => bail!("Unknown command: \"{arg0}\" type ? for help."), } Ok(()) diff --git a/deltachat-repl/src/main.rs b/deltachat-repl/src/main.rs index 0d80cf13e..bea6bac99 100644 --- a/deltachat-repl/src/main.rs +++ b/deltachat-repl/src/main.rs @@ -466,7 +466,7 @@ async fn handle_cmd( println!("QR code svg written to: {file:#?}"); } Err(err) => { - bail!("Failed to get QR code svg: {}", err); + bail!("Failed to get QR code svg: {err}"); } } } diff --git a/deltachat-rpc-server/src/main.rs b/deltachat-rpc-server/src/main.rs index 3381f2c8d..bb3c83b84 100644 --- a/deltachat-rpc-server/src/main.rs +++ b/deltachat-rpc-server/src/main.rs @@ -41,22 +41,22 @@ async fn main_impl() -> Result<()> { if let Some(first_arg) = args.next() { if first_arg.to_str() == Some("--version") { if let Some(arg) = args.next() { - return Err(anyhow!("Unrecognized argument {:?}", arg)); + return Err(anyhow!("Unrecognized argument {arg:?}")); } eprintln!("{}", &*DC_VERSION_STR); return Ok(()); } else if first_arg.to_str() == Some("--openrpc") { if let Some(arg) = args.next() { - return Err(anyhow!("Unrecognized argument {:?}", arg)); + return Err(anyhow!("Unrecognized argument {arg:?}")); } println!("{}", CommandApi::openrpc_specification()?); return Ok(()); } else { - return Err(anyhow!("Unrecognized option {:?}", first_arg)); + return Err(anyhow!("Unrecognized option {first_arg:?}")); } } if let Some(arg) = args.next() { - return Err(anyhow!("Unrecognized argument {:?}", arg)); + return Err(anyhow!("Unrecognized argument {arg:?}")); } // Install signal handlers early so that the shutdown is graceful starting from here. diff --git a/src/accounts.rs b/src/accounts.rs index ef36ffe96..d10c7a58c 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -78,7 +78,7 @@ impl Accounts { ensure!(dir.exists(), "directory does not exist"); let config_file = dir.join(CONFIG_NAME); - ensure!(config_file.exists(), "{:?} does not exist", config_file); + ensure!(config_file.exists(), "{config_file:?} does not exist"); let config = Config::from_file(config_file, writable).await?; let events = Events::new(); @@ -724,8 +724,7 @@ impl Config { { ensure!( self.inner.accounts.iter().any(|e| e.id == id), - "invalid account id: {}", - id + "invalid account id: {id}" ); self.inner.selected_account = id; diff --git a/src/aheader.rs b/src/aheader.rs index 86941fbeb..db3ee389b 100644 --- a/src/aheader.rs +++ b/src/aheader.rs @@ -35,7 +35,7 @@ impl FromStr for EncryptPreference { match s { "mutual" => Ok(EncryptPreference::Mutual), "nopreference" => Ok(EncryptPreference::NoPreference), - _ => bail!("Cannot parse encryption preference {}", s), + _ => bail!("Cannot parse encryption preference {s}"), } } } diff --git a/src/authres.rs b/src/authres.rs index eac4a6477..ae26b3efa 100644 --- a/src/authres.rs +++ b/src/authres.rs @@ -32,7 +32,7 @@ pub(crate) async fn handle_authres( let from_domain = match EmailAddress::new(from) { Ok(email) => email.domain, Err(e) => { - return Err(anyhow::format_err!("invalid email {}: {:#}", from, e)); + return Err(anyhow::format_err!("invalid email {from}: {e:#}")); } }; diff --git a/src/blob.rs b/src/blob.rs index c3d34d406..1c1630d2d 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -170,7 +170,7 @@ impl<'a> BlobObject<'a> { false => name, }; if !BlobObject::is_acceptible_blob_name(name) { - return Err(format_err!("not an acceptable blob name: {}", name)); + return Err(format_err!("not an acceptable blob name: {name}")); } Ok(BlobObject { blobdir: context.get_blobdir(), @@ -458,8 +458,7 @@ impl<'a> BlobObject<'a> { { if img_wh < 20 { return Err(format_err!( - "Failed to scale image to below {}B.", - max_bytes, + "Failed to scale image to below {max_bytes}B.", )); } diff --git a/src/calls.rs b/src/calls.rs index 4c2ece189..c988ad5b2 100644 --- a/src/calls.rs +++ b/src/calls.rs @@ -96,7 +96,7 @@ impl CallInfo { let duration = match minutes { 0 => "<1 minute".to_string(), 1 => "1 minute".to_string(), - n => format!("{} minutes", n), + n => format!("{n} minutes"), }; if self.is_incoming() { diff --git a/src/chat.rs b/src/chat.rs index 9a1b8fddf..caf71d93a 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -373,7 +373,7 @@ impl ChatId { /// Returns true if the value was modified. pub(crate) async fn set_blocked(self, context: &Context, new_blocked: Blocked) -> Result { if self.is_special() { - bail!("ignoring setting of Block-status for {}", self); + bail!("ignoring setting of Block-status for {self}"); } let count = context .sql @@ -702,8 +702,7 @@ impl ChatId { ) -> Result<()> { ensure!( !self.is_special(), - "bad chat_id, can not be special chat: {}", - self + "bad chat_id, can not be special chat: {self}" ); context @@ -813,8 +812,7 @@ impl ChatId { pub(crate) async fn delete_ex(self, context: &Context, sync: sync::Sync) -> Result<()> { ensure!( !self.is_special(), - "bad chat_id, can not be a special chat: {}", - self + "bad chat_id, can not be a special chat: {self}" ); let chat = Chat::load_from_db(context, self).await?; @@ -3145,8 +3143,7 @@ pub async fn send_text_msg( ) -> Result { ensure!( !chat_id.is_special(), - "bad chat_id, can not be a special chat: {}", - chat_id + "bad chat_id, can not be a special chat: {chat_id}" ); let mut msg = Message::new_text(text_to_send); @@ -3914,13 +3911,11 @@ pub(crate) async fn add_contact_to_chat_ex( let mut chat = Chat::load_from_db(context, chat_id).await?; ensure!( chat.typ == Chattype::Group || chat.typ == Chattype::OutBroadcast, - "{} is not a group/broadcast where one can add members", - chat_id + "{chat_id} is not a group/broadcast where one can add members" ); ensure!( Contact::real_exists_by_id(context, contact_id).await? || contact_id == ContactId::SELF, - "invalid contact_id {} for adding to group", - contact_id + "invalid contact_id {contact_id} for adding to group" ); ensure!(!chat.is_mailing_list(), "Mailing lists can't be changed"); ensure!( @@ -4133,8 +4128,7 @@ pub async fn remove_contact_from_chat( ) -> Result<()> { ensure!( !chat_id.is_special(), - "bad chat_id, can not be special chat: {}", - chat_id + "bad chat_id, can not be special chat: {chat_id}" ); ensure!( !contact_id.is_special() || contact_id == ContactId::SELF, @@ -4148,7 +4142,7 @@ pub async fn remove_contact_from_chat( "Cannot remove contact {contact_id} from chat {chat_id}: self not in group." ); context.emit_event(EventType::ErrorSelfNotInGroup(err_msg.clone())); - bail!("{}", err_msg); + bail!("{err_msg}"); } else { let mut sync = Nosync; @@ -4390,7 +4384,7 @@ pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId) .await?; let mut chat = Chat::load_from_db(context, chat_id).await?; if let Some(reason) = chat.why_cant_send(context).await? { - bail!("cannot send to {}: {}", chat_id, reason); + bail!("cannot send to {chat_id}: {reason}"); } curr_timestamp = create_smeared_timestamps(context, msg_ids.len()); let mut msgs = Vec::with_capacity(msg_ids.len()); diff --git a/src/contact.rs b/src/contact.rs index 84750a00d..19fe5ddaa 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1742,8 +1742,7 @@ pub(crate) async fn set_blocked( ) -> Result<()> { ensure!( !contact_id.is_special(), - "Can't block special contact {}", - contact_id + "Can't block special contact {contact_id}" ); let contact = Contact::get_by_id(context, contact_id).await?; diff --git a/src/key.rs b/src/key.rs index e9ca6c595..be3c07c3e 100644 --- a/src/key.rs +++ b/src/key.rs @@ -500,7 +500,7 @@ impl std::str::FromStr for Fingerprint { .filter(|&c| c.is_ascii_hexdigit()) .collect(); let v: Vec = hex::decode(&hex_repr)?; - ensure!(v.len() == 20, "wrong fingerprint length: {}", hex_repr); + ensure!(v.len() == 20, "wrong fingerprint length: {hex_repr}"); let fp = Fingerprint::new(v); Ok(fp) } diff --git a/src/message.rs b/src/message.rs index 4c5deda70..8ae88f6bb 100644 --- a/src/message.rs +++ b/src/message.rs @@ -490,8 +490,7 @@ impl Message { pub async fn load_from_db_optional(context: &Context, id: MsgId) -> Result> { ensure!( !id.is_special(), - "Can not load special message ID {} from DB", - id + "Can not load special message ID {id} from DB" ); let msg = context .sql diff --git a/src/mimefactory.rs b/src/mimefactory.rs index cefab8476..11727bf35 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -419,10 +419,7 @@ impl MimeFactory { None } else { if keys.is_empty() && !recipients.is_empty() { - bail!( - "No recipient keys are available, cannot encrypt to {:?}.", - recipients - ); + bail!("No recipient keys are available, cannot encrypt to {recipients:?}."); } // Remove recipients for which the key is missing. diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 3640bab25..b84235180 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -2080,7 +2080,7 @@ pub(crate) fn parse_message_id(ids: &str) -> Result { if let Some(id) = parse_message_ids(ids).first() { Ok(id.to_string()) } else { - bail!("could not parse message_id: {}", ids); + bail!("could not parse message_id: {ids}"); } } diff --git a/src/param.rs b/src/param.rs index 6f8c1af24..1ea377100 100644 --- a/src/param.rs +++ b/src/param.rs @@ -284,7 +284,7 @@ impl str::FromStr for Params { inner.insert(key, value); } } else { - bail!("Not a key-value pair: {:?}", line); + bail!("Not a key-value pair: {line:?}"); } } diff --git a/src/qr.rs b/src/qr.rs index dad90a4de..ede3d33f8 100644 --- a/src/qr.rs +++ b/src/qr.rs @@ -408,7 +408,7 @@ async fn decode_openpgp(context: &Context, qr: &str) -> Result { let encoded_name = encoded_name.replace('+', "%20"); // sometimes spaces are encoded as `+` match percent_decode_str(&encoded_name).decode_utf8() { Ok(name) => name.to_string(), - Err(err) => bail!("Invalid name: {}", err), + Err(err) => bail!("Invalid name: {err}"), } } else { "".to_string() @@ -432,7 +432,7 @@ async fn decode_openpgp(context: &Context, qr: &str) -> Result { let encoded_name = encoded_name.replace('+', "%20"); // sometimes spaces are encoded as `+` match percent_decode_str(&encoded_name).decode_utf8() { Ok(name) => Some(name.to_string()), - Err(err) => bail!("Invalid group name: {}", err), + Err(err) => bail!("Invalid group name: {err}"), } } else { None @@ -581,7 +581,7 @@ fn decode_tg_socks_proxy(_context: &Context, qr: &str) -> Result { } let Some(host) = host else { - bail!("Bad t.me/socks url: {:?}", url); + bail!("Bad t.me/socks url: {url:?}"); }; let mut url = "socks5://".to_string(); @@ -684,10 +684,7 @@ pub(crate) async fn set_account_from_qr(context: &Context, qr: &str) -> Result<( context.emit_event(EventType::Error(format!( "Cannot create account, server response could not be parsed:\n{parse_error:#}\nraw response:\n{response_text}" ))); - bail!( - "Cannot create account, unexpected server response:\n{:?}", - response_text - ) + bail!("Cannot create account, unexpected server response:\n{response_text:?}") } } } diff --git a/src/qr/dclogin_scheme.rs b/src/qr/dclogin_scheme.rs index cce60f025..cdbbac352 100644 --- a/src/qr/dclogin_scheme.rs +++ b/src/qr/dclogin_scheme.rs @@ -122,7 +122,7 @@ pub(super) fn decode_login(qr: &str) -> Result { options, }) } else { - bail!("Bad scheme for account URL: {:?}.", payload); + bail!("Bad scheme for account URL: {payload:?}."); } } @@ -139,7 +139,7 @@ fn parse_socket_security(security: Option<&String>) -> Result> { Some("starttls") => Some(Socket::Starttls), Some("default") => Some(Socket::Automatic), Some("plain") => Some(Socket::Plain), - Some(other) => bail!("Unknown security level: {}", other), + Some(other) => bail!("Unknown security level: {other}"), None => None, }) } @@ -152,7 +152,7 @@ fn parse_certificate_checks( Some("1") => Some(EnteredCertificateChecks::Strict), Some("2") => Some(EnteredCertificateChecks::AcceptInvalidCertificates), Some("3") => Some(EnteredCertificateChecks::AcceptInvalidCertificates2), - Some(other) => bail!("Unknown certificatecheck level: {}", other), + Some(other) => bail!("Unknown certificatecheck level: {other}"), None => None, }) } diff --git a/src/scheduler.rs b/src/scheduler.rs index 621a799eb..bbf1ef016 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -932,7 +932,7 @@ impl Scheduler { // wait for all loops to be started if let Err(err) = try_join_all(start_recvs).await { - bail!("failed to start scheduler: {}", err); + bail!("failed to start scheduler: {err}"); } info!(ctx, "scheduler is running"); diff --git a/src/smtp.rs b/src/smtp.rs index e22f0882d..76908096b 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -242,7 +242,7 @@ pub(crate) async fn smtp_send( // Yandex error "554 5.7.1 [2] Message rejected under suspicion of SPAM; https://ya.cc/..." // should definitely go here, because user has to open the link to // resume message sending. - SendResult::Failure(format_err!("Permanent SMTP error: {}", err)) + SendResult::Failure(format_err!("Permanent SMTP error: {err}")) } } async_smtp::error::Error::Transient(ref response) => { @@ -471,7 +471,7 @@ pub(crate) async fn send_msg_to_smtp( } Ok(()) } - SendResult::Failure(err) => Err(format_err!("{}", err)), + SendResult::Failure(err) => Err(format_err!("{err}")), } } @@ -586,7 +586,7 @@ async fn send_mdn_rfc724_mid( let addr = contact.get_addr(); let recipient = async_smtp::EmailAddress::new(addr.to_string()) - .map_err(|err| format_err!("invalid recipient: {} {:?}", addr, err))?; + .map_err(|err| format_err!("invalid recipient: {addr} {err:?}"))?; let recipients = vec![recipient]; match smtp_send(context, &recipients, &body, smtp, None).await { diff --git a/src/smtp/connect.rs b/src/smtp/connect.rs index 8da6f15f0..1910b3de1 100644 --- a/src/smtp/connect.rs +++ b/src/smtp/connect.rs @@ -69,7 +69,7 @@ pub(crate) async fn connect_and_auth( .await .context("SMTP failed to get OAUTH2 access token")?; if access_token.is_none() { - bail!("SMTP OAuth 2 error {}", addr); + bail!("SMTP OAuth 2 error {addr}"); } ( async_smtp::authentication::Credentials::new( diff --git a/src/webxdc.rs b/src/webxdc.rs index fdfa5d44c..af032419f 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -279,7 +279,7 @@ impl Context { }; if !valid { - bail!("{} is not a valid webxdc file", filename); + bail!("{filename} is not a valid webxdc file"); } Ok(()) @@ -837,8 +837,8 @@ fn parse_webxdc_manifest(bytes: &[u8]) -> Result { } async fn get_blob(archive: &mut SeekZipFileReader>, name: &str) -> Result> { - let (i, _) = find_zip_entry(archive.file(), name) - .ok_or_else(|| anyhow!("no entry found for {}", name))?; + let (i, _) = + find_zip_entry(archive.file(), name).ok_or_else(|| anyhow!("no entry found for {name}"))?; let mut reader = archive.reader_with_entry(i).await?; let mut buf = Vec::new(); reader.read_to_end_checked(&mut buf).await?;