Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Jan 11, 2025
1 parent dc19f20 commit 3612d5f
Show file tree
Hide file tree
Showing 67 changed files with 131 additions and 140 deletions.
2 changes: 1 addition & 1 deletion crates/cli/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub async fn name_to_id(client: &Client, name: &str) -> String {
pub fn is_localhost(url: &str) -> bool {
url.split_once("://")
.map(|(_, url)| url.split_once('/').map_or(url, |(host, _)| host))
.map_or(false, |host| {
.is_some_and(|host| {
let host = host.rsplit_once(':').map_or(host, |(host, _)| host);
host == "localhost" || host == "127.0.0.1" || host == "[::1]"
})
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/auth/oauth/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Server {
}

// Validate grant type
if expected_grant_type.map_or(false, |g| g != grant_type) {
if expected_grant_type.is_some_and(|g| g != grant_type) {
return Err(trc::AuthEvent::Error
.into_err()
.details("Invalid grant type"));
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/auth/sasl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn extract_oauth_bearer(bytes: &[u8]) -> Option<&str> {
if is_separator || pos == eof {
if bytes
.get(start_pos..start_pos + 12)
.map_or(false, |s| s.eq_ignore_ascii_case(b"auth=Bearer "))
.is_some_and(|s| s.eq_ignore_ascii_case(b"auth=Bearer "))
{
return bytes
.get(start_pos + 12..if is_separator { pos } else { bytes.len() })
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/config/smtp/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,11 @@ fn parse_queue_quota_item(config: &mut Config, prefix: impl AsKey, id: &str) ->
keys,
size: config
.property::<Option<usize>>((prefix.as_str(), "size"))
.filter(|&v| v.as_ref().map_or(false, |v| *v > 0))
.filter(|&v| v.as_ref().is_some_and(|v| *v > 0))
.unwrap_or_default(),
messages: config
.property::<Option<usize>>((prefix.as_str(), "messages"))
.filter(|&v| v.as_ref().map_or(false, |v| *v > 0))
.filter(|&v| v.as_ref().is_some_and(|v| *v > 0))
.unwrap_or_default(),
};

Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/config/smtp/throttle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ fn parse_throttle_item(
keys,
concurrency: config
.property::<Option<u64>>((prefix.as_str(), "concurrency"))
.filter(|&v| v.as_ref().map_or(false, |v| *v > 0))
.filter(|&v| v.as_ref().is_some_and(|v| *v > 0))
.unwrap_or_default(),
rate: config
.property::<Option<Rate>>((prefix.as_str(), "rate"))
.filter(|v| v.as_ref().map_or(false, |r| r.requests > 0))
.filter(|v| v.as_ref().is_some_and(|r| r.requests > 0))
.unwrap_or_default(),
};

Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/enterprise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Core {
pub fn is_enterprise_edition(&self) -> bool {
self.enterprise
.as_ref()
.map_or(false, |e| !e.license.is_expired())
.is_some_and(|e| !e.license.is_expired())
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/common/src/expr/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ struct EvalContext<'x, 'y, V: ResolveVariable, T, C> {
session_id: u64,
}

impl<'x, 'y, V: ResolveVariable> EvalContext<'x, 'y, V, IfBlock, Vec<String>> {
impl<'x, V: ResolveVariable> EvalContext<'x, '_, V, IfBlock, Vec<String>> {
async fn eval(&mut self) -> trc::Result<Variable<'x>> {
for if_then in &self.expr.if_then {
if (EvalContext {
Expand Down Expand Up @@ -183,7 +183,7 @@ impl<'x, 'y, V: ResolveVariable> EvalContext<'x, 'y, V, IfBlock, Vec<String>> {
}
}

impl<'x, 'y, V: ResolveVariable> EvalContext<'x, 'y, V, Expression, &mut Vec<String>> {
impl<'x, V: ResolveVariable> EvalContext<'x, '_, V, Expression, &mut Vec<String>> {
async fn eval(&mut self) -> trc::Result<Variable<'x>> {
let mut stack = Vec::new();
let mut exprs = self.expr.items.iter();
Expand Down Expand Up @@ -256,7 +256,7 @@ impl<'x, 'y, V: ResolveVariable> EvalContext<'x, 'y, V, Expression, &mut Vec<Str
stack.push(result);
}
ExpressionItem::JmpIf { val, pos } => {
if stack.last().map_or(false, |v| v.to_bool()) == *val {
if stack.last().is_some_and(|v| v.to_bool()) == *val {
for _ in 0..*pos {
exprs.next();
}
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/expr/functions/asynch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Server {
if query
.as_bytes()
.get(..6)
.map_or(false, |q| q.eq_ignore_ascii_case(b"SELECT"))
.is_some_and(|q| q.eq_ignore_ascii_case(b"SELECT"))
{
let mut rows = store
.sql_query::<Rows>(&query, arguments)
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/expr/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ pub(crate) fn fn_is_ip_addr(v: Vec<Variable>) -> Variable {
pub(crate) fn fn_is_ipv4_addr(v: Vec<Variable>) -> Variable {
v[0].to_string()
.parse::<std::net::IpAddr>()
.map_or(false, |ip| matches!(ip, IpAddr::V4(_)))
.is_ok_and(|ip| matches!(ip, IpAddr::V4(_)))
.into()
}

pub(crate) fn fn_is_ipv6_addr(v: Vec<Variable>) -> Variable {
v[0].to_string()
.parse::<std::net::IpAddr>()
.map_or(false, |ip| matches!(ip, IpAddr::V6(_)))
.is_ok_and(|ip| matches!(ip, IpAddr::V6(_)))
.into()
}

Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/expr/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'x> Tokenizer<'x> {
self.is_eof = true;
break;
}
b'-' if self.buf.last().map_or(false, |c| *c == b'[') => {
b'-' if self.buf.last().is_some_and(|c| *c == b'[') => {
self.buf.push(ch);
}
b':' if self.buf.contains(&b'.') => {
Expand All @@ -85,7 +85,7 @@ impl<'x> Tokenizer<'x> {
b']' if self.buf.contains(&b'[') => {
self.buf.push(b']');
}
b'*' if self.buf.last().map_or(false, |&c| c == b'[' || c == b'.') => {
b'*' if self.buf.last().is_some_and(|&c| c == b'[' || c == b'.') => {
self.buf.push(ch);
}
_ => {
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/listener/asn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ impl Server {
if !part.is_empty() {
if idx == *index_asn {
asn = part.parse::<u32>().ok();
} else if index_asn_name.map_or(false, |i| i == idx) {
} else if index_asn_name.is_some_and(|i| i == idx) {
asn_name = Some(part.to_string());
} else if index_country.map_or(false, |i| i == idx) {
} else if index_country.is_some_and(|i| i == idx) {
country = Some(part.to_string());
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/listener/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl SessionStream for ProxiedStream<TcpStream> {
fn is_tls(&self) -> bool {
self.proxy_header()
.ssl()
.map_or(false, |ssl| ssl.client_ssl())
.is_some_and(|ssl| ssl.client_ssl())
}

fn tls_version_and_cipher(&self) -> (Cow<'static, str>, Cow<'static, str>) {
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/manager/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ impl ConfigManager {
{
let is_tls = listener
.get("tls.implicit")
.map_or(false, |tls| tls == "true");
.is_some_and(|tls| tls == "true");
let protocol = listener
.get("protocol")
.map(|s| s.as_str())
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub async fn fetch_resource(
pub fn is_localhost_url(url: &str) -> bool {
url.split_once("://")
.map(|(_, url)| url.split_once('/').map_or(url, |(host, _)| host))
.map_or(false, |host| {
.is_some_and(|host| {
let host = host.rsplit_once(':').map_or(host, |(host, _)| host);
host == "localhost" || host == "127.0.0.1" || host == "[::1]"
})
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/scripts/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ pub fn fn_is_ip_addr<'x>(_: &'x Context<'x>, v: Vec<Variable>) -> Variable {
pub fn fn_is_ipv4_addr<'x>(_: &'x Context<'x>, v: Vec<Variable>) -> Variable {
v[0].to_string()
.parse::<std::net::IpAddr>()
.map_or(false, |ip| matches!(ip, IpAddr::V4(_)))
.is_ok_and(|ip| matches!(ip, IpAddr::V4(_)))
.into()
}

pub fn fn_is_ipv6_addr<'x>(_: &'x Context<'x>, v: Vec<Variable>) -> Variable {
v[0].to_string()
.parse::<std::net::IpAddr>()
.map_or(false, |ip| matches!(ip, IpAddr::V6(_)))
.is_ok_and(|ip| matches!(ip, IpAddr::V6(_)))
.into()
}

Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/scripts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ impl<T: AsRef<str>> IsMixedCharset for T {
}
}

set.map_or(false, |set| set.is_empty())
set.is_some_and(|set| set.is_empty())
}
}
2 changes: 1 addition & 1 deletion crates/common/src/scripts/plugins/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn exec(ctx: PluginContext<'_>) -> trc::Result<Variable> {
if query
.as_bytes()
.get(..6)
.map_or(false, |q| q.eq_ignore_ascii_case(b"SELECT"))
.is_some_and(|q| q.eq_ignore_ascii_case(b"SELECT"))
{
let mut rows = store.sql_query::<Rows>(&query, arguments).await?;
Ok(match rows.rows.len().cmp(&1) {
Expand Down
2 changes: 1 addition & 1 deletion crates/directory/src/backend/internal/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl DirectoryStore for Store {
DirectoryClass::NameToId(domain.as_bytes().to_vec()),
)))
.await
.map(|p| p.map_or(false, |p| p.typ == Type::Domain))
.map(|p| p.is_some_and(|p| p.typ == Type::Domain))
}

async fn rcpt(&self, address: &str) -> trc::Result<RcptType> {
Expand Down
4 changes: 2 additions & 2 deletions crates/directory/src/backend/internal/manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ impl ManageDirectory for Store {
.filter(|v| {
v.name()
.rsplit_once('@')
.map_or(false, |(_, d)| d.eq_ignore_ascii_case(name))
.is_some_and(|(_, d)| d.eq_ignore_ascii_case(name))
})
.collect::<Vec<_>>();
let total_domain_members = domain_members.len();
Expand Down Expand Up @@ -1794,7 +1794,7 @@ impl ManageDirectory for Store {
if std::str::from_utf8(key.get(1..).unwrap_or_default())
.unwrap_or_default()
.rsplit_once('@')
.map_or(false, |(_, domain)| domain == domain_name)
.is_some_and(|(_, domain)| domain == domain_name)
{
total += 1;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/directory/src/backend/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl PrincipalInfo {

pub fn has_tenant_access(&self, tenant_id: Option<u32>) -> bool {
tenant_id.map_or(true, |tenant_id| {
self.tenant.map_or(false, |t| tenant_id == t)
self.tenant.is_some_and(|t| tenant_id == t)
|| (self.typ == Type::Tenant && self.id == tenant_id)
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/directory/src/backend/ldap/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl LdapDirectory {
&& err
.value(trc::Key::Code)
.and_then(|v| v.to_uint())
.map_or(false, |rc| [49, 50].contains(&rc)) =>
.is_some_and(|rc| [49, 50].contains(&rc)) =>
{
return Ok(None);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/directory/src/core/principal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,15 @@ impl Principal {
}

pub fn has_str_value(&self, key: PrincipalField, value: &str) -> bool {
self.fields.get(&key).map_or(false, |v| match v {
self.fields.get(&key).is_some_and(|v| match v {
PrincipalValue::String(v) => v == value,
PrincipalValue::StringList(l) => l.iter().any(|v| v == value),
PrincipalValue::Integer(_) | PrincipalValue::IntegerList(_) => false,
})
}

pub fn has_int_value(&self, key: PrincipalField, value: u64) -> bool {
self.fields.get(&key).map_or(false, |v| match v {
self.fields.get(&key).is_some_and(|v| match v {
PrincipalValue::Integer(v) => *v == value,
PrincipalValue::IntegerList(l) => l.iter().any(|v| *v == value),
PrincipalValue::String(_) | PrincipalValue::StringList(_) => false,
Expand Down
2 changes: 1 addition & 1 deletion crates/imap-proto/src/parser/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Request<Command> {
attributes.push_unique(Attribute::Uid);
} else if value.eq_ignore_ascii_case(b"RFC822") {
attributes.push_unique(
if tokens.peek().map_or(false, |token| token.is_dot()) {
if tokens.peek().is_some_and(|token| token.is_dot()) {
tokens.next();
let rfc822 = tokens
.next()
Expand Down
2 changes: 1 addition & 1 deletion crates/imap-proto/src/parser/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Request<Command> {

if tokens
.next()
.map_or(false, |token| token.eq_ignore_ascii_case(b"return"))
.is_some_and(|token| token.eq_ignore_ascii_case(b"return"))
{
if tokens
.next()
Expand Down
2 changes: 1 addition & 1 deletion crates/imap/src/op/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<T: SessionStream> SessionData<T> {
for attribute in &arguments.attributes {
match attribute {
Attribute::BodySection { sections, .. }
if sections.first().map_or(false, |s| {
if sections.first().is_some_and(|s| {
matches!(s, Section::Header | Section::HeaderFields { .. })
}) => {}
Attribute::Body | Attribute::BodyStructure | Attribute::BinarySize { .. } => {
Expand Down
2 changes: 1 addition & 1 deletion crates/imap/src/op/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<T: SessionStream> SessionData<T> {
return if mailbox_name == self.server.core.jmap.shared_folder
|| mailbox_name
.split_once('/')
.map_or(false, |(base_name, path)| {
.is_some_and(|(base_name, path)| {
base_name == self.server.core.jmap.shared_folder && !path.contains('/')
})
{
Expand Down
4 changes: 2 additions & 2 deletions crates/jmap-proto/src/method/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ impl<T> SetRequest<T> {
}

pub fn has_updates(&self) -> bool {
self.update.as_ref().map_or(false, |objs| !objs.is_empty())
self.update.as_ref().is_some_and(|objs| !objs.is_empty())
}

pub fn has_creates(&self) -> bool {
self.create.as_ref().map_or(false, |objs| !objs.is_empty())
self.create.as_ref().is_some_and(|objs| !objs.is_empty())
}

pub fn unwrap_create(&mut self) -> VecMap<String, Object<SetValue>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/jmap/src/api/autoconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl Autoconfig for Server {
if principal
.get_str_array(PrincipalField::Emails)
.and_then(|emails| emails.first())
.map_or(false, |email| email.eq_ignore_ascii_case(emailaddress))
.is_some_and(|email| email.eq_ignore_ascii_case(emailaddress))
{
account_name = principal.take_str(PrincipalField::Name).unwrap_or_default();
}
Expand Down
2 changes: 1 addition & 1 deletion crates/jmap/src/api/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl FormHandler for Server {
if form
.field_honey_pot
.as_ref()
.map_or(false, |field| form_data.has_field(field))
.is_some_and(|field| form_data.has_field(field))
{
return Err(trc::ResourceEvent::BadParameters
.into_err()
Expand Down
5 changes: 1 addition & 4 deletions crates/jmap/src/api/management/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ impl DnsManagement for Server {
name: format!("{domain_name}."),
content: format!("10 {server_name}."),
});
if server_name
.strip_prefix("mail.")
.map_or(true, |s| s != domain_name)
{
if server_name.strip_prefix("mail.") != Some(domain_name) {
records.push(DnsRecord {
typ: "CNAME".to_string(),
name: format!("mail.{domain_name}."),
Expand Down
2 changes: 1 addition & 1 deletion crates/jmap/src/api/management/enterprise/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl TelemetryApi for Server {
if (filter.is_none() && key_filters.is_empty())
|| event
.span_id()
.map_or(false, |span_id| active_span_ids.contains(&span_id))
.is_some_and(|span_id| active_span_ids.contains(&span_id))
{
events.push(event);
} else {
Expand Down
6 changes: 3 additions & 3 deletions crates/jmap/src/api/management/principal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl PrincipalManager for Server {
.into_err()
.details("Invalid type")
})?;
if params.get("confirm").map_or(true, |c| c != "true") {
if params.get("confirm") != Some("true") {
return Err(trc::EventType::Resource(trc::ResourceEvent::BadParameters)
.into_err()
.details("Missing confirmation parameter"));
Expand Down Expand Up @@ -330,7 +330,7 @@ impl PrincipalManager for Server {
.spam
.bayes
.as_ref()
.map_or(false, |c| c.account_classify);
.is_some_and(|c| c.account_classify);
for principal in principals.items {
// Delete account
if let Err(err) = server
Expand Down Expand Up @@ -478,7 +478,7 @@ impl PrincipalManager for Server {
.spam
.bayes
.as_ref()
.map_or(false, |c| c.account_classify)
.is_some_and(|c| c.account_classify)
{
let mut key = Vec::with_capacity(std::mem::size_of::<u32>() + 1);
key.push(KV_BAYES_MODEL_USER);
Expand Down
Loading

0 comments on commit 3612d5f

Please sign in to comment.