Skip to content

Commit

Permalink
chore(clippy): Version 1.84 (#4440)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbayer authored Jan 10, 2025
1 parent 0569e28 commit 4348234
Show file tree
Hide file tree
Showing 24 changed files with 31 additions and 39 deletions.
2 changes: 1 addition & 1 deletion relay-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ impl RegisterResponse {
let state = response.token.unpack(secret, max_age)?;

if let Some(header) = state.public_key().verify_meta(data, signature) {
if max_age.map_or(false, |m| header.expired(m)) {
if max_age.is_some_and(|m| header.expired(m)) {
return Err(UnpackError::SignatureExpired);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion relay-cabi/src/codeowners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn translate_codeowners_pattern(pattern: &str) -> Option<Regex> {

let anchored = pattern
.find('/')
.map_or(false, |pos| pos != pattern.len() - 1);
.is_some_and(|pos| pos != pattern.len() - 1);

if anchored {
regex += r"\A";
Expand Down
2 changes: 1 addition & 1 deletion relay-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ fn is_docker() -> bool {
return true;
}

fs::read_to_string("/proc/self/cgroup").map_or(false, |s| s.contains("/docker"))
fs::read_to_string("/proc/self/cgroup").is_ok_and(|s| s.contains("/docker"))
}

/// Default value for the "bind" configuration.
Expand Down
5 changes: 1 addition & 4 deletions relay-event-normalization/src/normalize/breakdowns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ impl EmitBreakdowns for SpanOperationsConfig {
return None;
}

let spans = match event.spans.value() {
None => return None,
Some(spans) => spans,
};
let spans = event.spans.value()?;

// Generate span operation breakdowns
let mut intervals = HashMap::new();
Expand Down
2 changes: 1 addition & 1 deletion relay-event-normalization/src/normalize/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn urlencoded_from_str(raw: &str) -> Option<Value> {
.values()
.next()
.and_then(Annotated::<Value>::as_str)
.map_or(false, |s| !matches!(s, "" | "="));
.is_some_and(|s| !matches!(s, "" | "="));

if is_valid {
Some(Value::Object(object))
Expand Down
5 changes: 2 additions & 3 deletions relay-event-normalization/src/normalize/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ impl FromUserAgentInfo for BrowserContext {
///
/// Returns None if no browser field detected.
pub fn browser_from_client_hints(s: &str) -> Option<(String, String)> {
static UA_RE: OnceLock<Regex> = OnceLock::new();
let regex = UA_RE.get_or_init(|| Regex::new(r#""([^"]*)";v="([^"]*)""#).unwrap());
for item in s.split(',') {
// if it contains one of these then we can know it isn't a browser field. atm chromium
// browsers are the only ones supporting client hints.
Expand All @@ -386,9 +388,6 @@ pub fn browser_from_client_hints(s: &str) -> Option<(String, String)> {
continue;
}

static UA_RE: OnceLock<Regex> = OnceLock::new();
let regex = UA_RE.get_or_init(|| Regex::new(r#""([^"]*)";v="([^"]*)""#).unwrap());

let captures = regex.captures(item)?;

let browser = captures.get(1)?.as_str().to_owned();
Expand Down
2 changes: 1 addition & 1 deletion relay-event-normalization/src/transactions/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'r> TransactionsProcessor<'r> {
matches!(
source,
Some(&TransactionSource::Url | &TransactionSource::Sanitized)
) || (source.is_none() && event.transaction.value().map_or(false, |t| t.contains('/')))
) || (source.is_none() && event.transaction.value().is_some_and(|t| t.contains('/')))
}

fn normalize_transaction_name(&self, event: &mut Event) {
Expand Down
2 changes: 1 addition & 1 deletion relay-filter/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn are_generic_filters_supported(
fn matches<F: Getter>(item: &F, condition: Option<&RuleCondition>) -> bool {
// TODO: the condition DSL needs to be extended to support more complex semantics, such as
// collections operations.
condition.map_or(false, |condition| condition.matches(item))
condition.is_some_and(|condition| condition.matches(item))
}

/// Filters events by any generic condition.
Expand Down
2 changes: 1 addition & 1 deletion relay-filter/src/legacy_browsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn should_filter<F: Filterable>(
}

let browsers = &config.browsers;
if item.user_agent().map_or(false, |ua| matches(ua, browsers)) {
if item.user_agent().is_some_and(|ua| matches(ua, browsers)) {
Err(FilterStatKey::LegacyBrowsers)
} else {
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion relay-filter/src/localhost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn matches<F: Filterable>(item: &F) -> bool {

fn host_matches_or_is_subdomain_of(host: &str, domain: &str) -> bool {
host.strip_suffix(domain)
.map_or(false, |s| s.is_empty() || s.ends_with('.'))
.is_some_and(|s| s.is_empty() || s.ends_with('.'))
}

/// Filters events originating from the local host.
Expand Down
2 changes: 1 addition & 1 deletion relay-filter/src/transaction_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use relay_pattern::Patterns;
use crate::{FilterStatKey, Filterable, IgnoreTransactionsFilterConfig};

fn matches(transaction: Option<&str>, patterns: &Patterns) -> bool {
transaction.map_or(false, |transaction| patterns.is_match(transaction))
transaction.is_some_and(|transaction| patterns.is_match(transaction))
}

/// Filters [Transaction](relay_event_schema::protocol::EventType::Transaction) events based on a list of provided transaction
Expand Down
6 changes: 3 additions & 3 deletions relay-profiling/src/sample/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ impl SampleProfile {

/// Checks if the last sample was recorded within the max profile duration.
fn is_above_max_duration(&self) -> bool {
self.samples.last().map_or(false, |sample| {
sample.elapsed_since_start_ns > MAX_PROFILE_DURATION_NS
})
self.samples
.last()
.is_some_and(|sample| sample.elapsed_since_start_ns > MAX_PROFILE_DURATION_NS)
}

fn remove_unreferenced_threads(&mut self) {
Expand Down
4 changes: 2 additions & 2 deletions relay-protocol/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Remark {

/// Indicates if the remark refers to an empty range
pub fn is_empty(&self) -> bool {
self.len().map_or(false, |l| l == 0)
self.len() == Some(0)
}

/// Returns the type.
Expand Down Expand Up @@ -578,7 +578,7 @@ impl Meta {

/// Indicates whether this field has errors.
pub fn has_errors(&self) -> bool {
self.0.as_ref().map_or(false, |x| !x.errors.is_empty())
self.0.as_ref().is_some_and(|x| !x.errors.is_empty())
}

/// Indicates whether this field has meta data attached.
Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/endpoints/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn parse_event(
// character substitution on the input stream but only if we detect a Python agent.
//
// This is done here so that the rest of the code can assume valid JSON.
let is_legacy_python_json = meta.client().map_or(false, |agent| {
let is_legacy_python_json = meta.client().is_some_and(|agent| {
agent.starts_with("raven-python/") || agent.starts_with("sentry-python/")
});

Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/extractors/request_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ impl FromRequestParts<ServiceState> for PartialMeta {
.config()
.static_relays()
.get(&relay_id)
.map_or(false, |ri| ri.internal);
.is_some_and(|ri| ri.internal);
}

let ReceivedAt(received_at) = ReceivedAt::from_request_parts(parts, state).await?;
Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/metrics_extraction/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl TransactionExtractor<'_> {
|| name
.strip_prefix("score.weight.")
.or_else(|| name.strip_prefix("score."))
.map_or(false, |suffix| measurement_names.contains(suffix));
.is_some_and(|suffix| measurement_names.contains(suffix));

let measurement_tags = TransactionMeasurementTags {
measurement_rating: get_measurement_rating(name, value.to_f64()),
Expand Down
4 changes: 2 additions & 2 deletions relay-server/src/services/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl EnvelopeBufferService {
}

/// Tries to pop an envelope for a ready project.
async fn try_pop<'a>(
async fn try_pop(
partition_tag: &str,
config: &Config,
buffer: &mut PolymorphicEnvelopeBuffer,
Expand Down Expand Up @@ -419,7 +419,7 @@ impl EnvelopeBufferService {
}
}

async fn pop_and_forward<'a>(
async fn pop_and_forward(
partition_tag: &str,
services: &Services,
buffer: &mut PolymorphicEnvelopeBuffer,
Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/services/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ impl ProcessingError {

fn is_unexpected(&self) -> bool {
self.to_outcome()
.map_or(false, |outcome| outcome.is_unexpected())
.is_some_and(|outcome| outcome.is_unexpected())
}
}

Expand Down
4 changes: 2 additions & 2 deletions relay-server/src/services/processor/dynamic_sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ fn compute_sampling_decision(
return SamplingResult::NoMatch;
}

if sampling_config.map_or(false, |config| config.unsupported())
|| root_sampling_config.map_or(false, |config| config.unsupported())
if sampling_config.is_some_and(|config| config.unsupported())
|| root_sampling_config.is_some_and(|config| config.unsupported())
{
if processing_enabled {
relay_log::error!("found unsupported rules even as processing relay");
Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/services/processor/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub fn finalize<Group: EventProcessing>(
let has_otel = inner_event
.contexts
.value()
.map_or(false, |contexts| contexts.contains::<OtelContext>());
.is_some_and(|contexts| contexts.contains::<OtelContext>());

if has_otel {
metric!(
Expand Down
7 changes: 2 additions & 5 deletions relay-server/src/services/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,11 +913,8 @@ impl StoreService {
span.start_timestamp_ms = (span.start_timestamp_precise * 1e3) as u64;

if let Some(measurements) = &mut span.measurements {
measurements.retain(|_, v| {
v.as_ref()
.and_then(|v| v.value)
.map_or(false, f64::is_finite)
});
measurements
.retain(|_, v| v.as_ref().and_then(|v| v.value).is_some_and(f64::is_finite));
}

self.produce(
Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/utils/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
};

let new_source = transaction_source_tag(inner);
let is_404 = extract_http_status_code(inner).map_or(false, |s| s == "404");
let is_404 = extract_http_status_code(inner).is_some_and(|s| s == "404");

relay_statsd::metric!(
counter(RelayCounters::TransactionNameChanges) += 1,
Expand Down
2 changes: 1 addition & 1 deletion tools/document-pii/src/item_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ fn is_file_declared_from_other_file(
) -> anyhow::Result<bool> {
let path = entry.path();

if path.is_file() && path.extension().map_or(false, |ext| ext == "rs") && path != *file_path {
if path.is_file() && path.extension().is_some_and(|ext| ext == "rs") && path != *file_path {
// Read the file and search for the same declaration pattern: "pub mod" and file stem.
let file = fs::File::open(path)?;
let reader = std::io::BufReader::new(file);
Expand Down
3 changes: 1 addition & 2 deletions tools/document-pii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ fn find_rs_files(dir: &PathBuf) -> Vec<std::path::PathBuf> {
if !entry.path().to_string_lossy().contains("src") {
continue;
}
if entry.file_type().is_file() && entry.path().extension().map_or(false, |ext| ext == "rs")
{
if entry.file_type().is_file() && entry.path().extension().is_some_and(|ext| ext == "rs") {
rs_files.push(entry.into_path());
}
}
Expand Down

0 comments on commit 4348234

Please sign in to comment.