Replace .map_or(false with Option::is_some_and (#33468)

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2024-09-16 12:03:52 +02:00 committed by GitHub
parent 236cae9ce5
commit 7df30f3788
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
51 changed files with 165 additions and 171 deletions

View file

@ -93,7 +93,7 @@ impl HstsList {
pub fn is_host_secure(&self, host: &str) -> bool {
let base_domain = reg_suffix(host);
self.entries_map.get(base_domain).map_or(false, |entries| {
self.entries_map.get(base_domain).is_some_and(|entries| {
entries.iter().any(|e| {
if e.include_subdomains {
e.matches_subdomain(host) || e.matches_domain(host)
@ -105,15 +105,15 @@ impl HstsList {
}
fn has_domain(&self, host: &str, base_domain: &str) -> bool {
self.entries_map.get(base_domain).map_or(false, |entries| {
entries.iter().any(|e| e.matches_domain(host))
})
self.entries_map
.get(base_domain)
.is_some_and(|entries| entries.iter().any(|e| e.matches_domain(host)))
}
fn has_subdomain(&self, host: &str, base_domain: &str) -> bool {
self.entries_map.get(base_domain).map_or(false, |entries| {
entries.iter().any(|e| e.matches_subdomain(host))
})
self.entries_map
.get(base_domain)
.is_some_and(|entries| entries.iter().any(|e| e.matches_subdomain(host)))
}
pub fn push(&mut self, entry: HstsEntry) {
@ -153,16 +153,16 @@ impl HstsList {
}) ||
(!pref!(network.enforce_tls.onion) &&
url.domain()
.map_or(false, |domain| domain.ends_with(".onion")))
.is_some_and(|domain| domain.ends_with(".onion")))
{
url.domain()
.map_or(false, |domain| self.is_host_secure(domain))
.is_some_and(|domain| self.is_host_secure(domain))
} else {
true
}
} else {
url.domain()
.map_or(false, |domain| self.is_host_secure(domain))
.is_some_and(|domain| self.is_host_secure(domain))
};
if upgrade_scheme {

View file

@ -802,7 +802,7 @@ pub async fn http_fetch(
.actual_response()
.status
.as_ref()
.map_or(false, is_redirect_status)
.is_some_and(is_redirect_status)
{
// Substep 1.
if response
@ -992,7 +992,7 @@ pub async fn http_redirect_fetch(
.status
.as_ref()
.map_or(true, |s| s.0 != StatusCode::SEE_OTHER) &&
request.body.as_ref().map_or(false, |b| b.source_is_null())
request.body.as_ref().is_some_and(|b| b.source_is_null())
{
return Response::network_error(NetworkError::Internal("Request body is not done".into()));
}
@ -1007,7 +1007,7 @@ pub async fn http_redirect_fetch(
.actual_response()
.status
.as_ref()
.map_or(false, |(code, _)| {
.is_some_and(|(code, _)| {
((*code == StatusCode::MOVED_PERMANENTLY || *code == StatusCode::FOUND) &&
request.method == Method::POST) ||
(*code == StatusCode::SEE_OTHER &&
@ -1450,7 +1450,7 @@ async fn http_network_or_cache_fetch(
forward_response
.status
.as_ref()
.map_or(false, |s| s.0 == StatusCode::NOT_MODIFIED)
.is_some_and(|s| s.0 == StatusCode::NOT_MODIFIED)
{
if let Ok(mut http_cache) = context.state.http_cache.write() {
// Ensure done_chan is None,
@ -1989,7 +1989,7 @@ async fn cors_preflight_fetch(
response
.status
.as_ref()
.map_or(false, |(status, _)| status.is_success())
.is_some_and(|(status, _)| status.is_success())
{
// Substep 1
let mut methods = if response

View file

@ -258,7 +258,7 @@ impl StorageManager {
sender
.send(
data.get_mut(&origin)
.map_or(false, |&mut (ref mut total, ref mut entry)| {
.is_some_and(|&mut (ref mut total, ref mut entry)| {
if !entry.is_empty() {
entry.clear();
*total = 0;