Skip to content

fix: Clippy lints #1329

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 7 commits into from
Jul 1, 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
2 changes: 2 additions & 0 deletions relay-common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::str::FromStr;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::macros::impl_str_serde;

/// The type of an event.
///
/// The event type determines how Sentry handles the event and has an impact on processing, rate
Expand Down
2 changes: 1 addition & 1 deletion relay-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
html_favicon_url = "https://raw.githubusercontent.com/getsentry/relay/master/artwork/relay-icon.png"
)]

#[macro_use]
mod macros;

mod cell;
Expand All @@ -19,6 +18,7 @@ mod utils;
pub use crate::cell::*;
pub use crate::constants::*;
pub use crate::glob::*;
pub use crate::macros::*;
pub use crate::project::*;
pub use crate::retry::*;
pub use crate::time::*;
Expand Down
10 changes: 10 additions & 0 deletions relay-common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ macro_rules! impl_str_ser {
};
}

pub use impl_str_ser;

/// Helper macro to implement string based deserialization.
///
/// If a type implements `FromStr` then this automatically
Expand Down Expand Up @@ -58,6 +60,8 @@ macro_rules! impl_str_de {
};
}

pub use impl_str_de;

/// Helper macro to implement string based serialization and deserialization.
///
/// If a type implements `FromStr` and `Display` then this automatically
Expand All @@ -71,6 +75,8 @@ macro_rules! impl_str_serde {
};
}

pub use impl_str_serde;

/// Same as `try` but to be used in functions that return `Box<Future>` instead of `Result`.
///
/// Useful when calling synchronous (but cheap enough) functions in async code.
Expand All @@ -84,6 +90,8 @@ macro_rules! tryf {
};
}

pub use tryf;

/// A cloning alternative to a `move` closure.
///
/// When one needs to use a closure with move semantics one often needs to clone and move some of
Expand Down Expand Up @@ -127,3 +135,5 @@ macro_rules! clone {
move |$($p),+| $body
}};
}

pub use clone;
2 changes: 2 additions & 0 deletions relay-common/src/project.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::fmt;
use std::str::FromStr;

use crate::macros::impl_str_serde;

#[doc(inline)]
pub use sentry_types::{ParseProjectIdError, ProjectId};

Expand Down
2 changes: 2 additions & 0 deletions relay-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::str;
use lazy_static::lazy_static;
use regex::Regex;

use crate::macros::impl_str_serde;

lazy_static! {
static ref GLOB_RE: Regex = Regex::new(r#"\?|\*\*|\*"#).unwrap();
}
Expand Down
2 changes: 0 additions & 2 deletions relay-general/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
#[macro_use]
extern crate relay_general_derive;

#[macro_use]
mod macros;

#[cfg(test)]
#[macro_use]
mod testutils;

pub mod pii;
Expand Down
6 changes: 5 additions & 1 deletion relay-general/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ macro_rules! derive_string_meta_structure {
};
}

pub(crate) use derive_string_meta_structure;

/// Implements FromStr and Display on a flat/C-like enum such that strings roundtrip correctly and
/// all variants can be FromStr'd.
///
///
/// Usage:
///
/// ```rust
/// ```ignore
/// // derive fail for this or whatever you need. The type must be ZST though.
/// struct ValueTypeError;
///
Expand Down Expand Up @@ -99,3 +101,5 @@ macro_rules! derive_fromstr_and_display {
}
}
}

pub(crate) use derive_fromstr_and_display;
1 change: 1 addition & 0 deletions relay-general/src/pii/attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ mod tests {
use itertools::Itertools;

use crate::pii::PiiConfig;
use crate::testutils::assert_eq_bytes_str;

use super::*;

Expand Down
1 change: 1 addition & 0 deletions relay-general/src/pii/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ mod tests {
use crate::pii::processor::PiiProcessor;
use crate::pii::{Redaction, ReplaceRedaction};
use crate::processor::{process_value, ProcessingState, ValueType};
use crate::testutils::{assert_eq_dbg, assert_eq_str};
use crate::types::{Annotated, Remark, RemarkType};

use super::{BUILTIN_RULES, BUILTIN_RULES_MAP};
Expand Down
1 change: 1 addition & 0 deletions relay-general/src/pii/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ mod tests {
use crate::pii::{DataScrubbingConfig, PiiConfig, PiiProcessor};
use crate::processor::{process_value, ProcessingState};
use crate::protocol::Event;
use crate::testutils::{assert_annotated_snapshot, assert_eq_dbg};
use crate::types::FromValue;

use super::to_pii_config as to_pii_config_impl;
Expand Down
1 change: 1 addition & 0 deletions relay-general/src/pii/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ use {
Addr, DebugImage, DebugMeta, Event, ExtraValue, Headers, LogEntry, NativeDebugImage,
Request,
},
crate::testutils::assert_annotated_snapshot,
crate::types::{Annotated, Object, Value},
};

Expand Down
1 change: 1 addition & 0 deletions relay-general/src/processor/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use enumset::{EnumSet, EnumSetType};
use failure::Fail;
use smallvec::SmallVec;

use crate::macros::derive_fromstr_and_display;
use crate::processor::{ProcessValue, SelectorPathItem, SelectorSpec};
use crate::types::Annotated;

Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/processor/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ where
}
}

#[cfg(test)]
use crate::testutils::assert_eq_dbg;

#[test]
fn test_chunk_split() {
let remarks = vec![Remark::with_range(
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/breadcrumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ pub struct Breadcrumb {
pub other: Object<Value>,
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_breadcrumb_roundtrip() {
use crate::types::Map;
Expand Down
2 changes: 2 additions & 0 deletions relay-general/src/protocol/client_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ impl ClientReport {
mod tests {
use super::*;

use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_client_report_roundtrip() {
let json = r#"{
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/clientsdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ pub struct ClientSdkInfo {
pub other: Object<Value>,
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_client_sdk_roundtrip() {
use crate::types::Map;
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,9 @@ impl FromValue for Contexts {
}
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_device_context_roundtrip() {
let json = r#"{
Expand Down
5 changes: 4 additions & 1 deletion relay-general/src/protocol/debugmeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,10 @@ pub struct DebugMeta {
}

#[cfg(test)]
use crate::types::Map;
use {
crate::testutils::{assert_eq_dbg, assert_eq_str},
crate::types::Map,
};

#[test]
fn test_debug_image_proguard_roundtrip() {
Expand Down
4 changes: 4 additions & 0 deletions relay-general/src/protocol/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use schemars::schema::Schema;

use serde::{Serialize, Serializer};

use crate::macros::derive_string_meta_structure;
use crate::processor::ProcessValue;
use crate::protocol::{
Breadcrumb, Breakdowns, ClientSdkInfo, Contexts, Csp, DebugMeta, Exception, ExpectCt,
Expand Down Expand Up @@ -532,6 +533,9 @@ pub struct Event {
pub other: Object<Value>,
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_event_roundtrip() {
use chrono::{TimeZone, Utc};
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ pub struct Exception {
pub other: Object<Value>,
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_exception_roundtrip() {
use crate::types::Map;
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ impl IntoValue for Fingerprint {
// Fingerprints must not be trimmed.
impl ProcessValue for Fingerprint {}

#[cfg(test)]
use crate::testutils::assert_eq_dbg;

#[test]
fn test_fingerprint_string() {
assert_eq_dbg!(
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/logentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ impl FromValue for LogEntry {
}
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_logentry_roundtrip() {
let json = r#"{
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/measurements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ fn is_valid_measurement_name(name: &str) -> bool {
.all(|c| matches!(c, 'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' | '.'))
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_measurements_serialization() {
use crate::protocol::Event;
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/mechanism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ impl FromValue for Mechanism {
}
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_mechanism_roundtrip() {
use crate::types::Map;
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ pub struct Request {
pub other: Object<Value>,
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_header_normalization() {
let json = r#"{
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/security_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use serde::de::{Error, IgnoredAny};
use serde::{Deserialize, Serialize};
use url::Url;

use crate::macros::derive_fromstr_and_display;
use crate::protocol::{
Event, HeaderName, HeaderValue, Headers, LogEntry, PairList, Request, TagEntry, Tags,
};
Expand Down Expand Up @@ -1083,6 +1084,8 @@ impl SecurityReportType {
mod tests {
use super::*;

use crate::testutils::assert_annotated_snapshot;

#[test]
fn test_unsplit_uri() {
assert_eq!(unsplit_uri("", ""), "");
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use failure::Fail;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::macros::derive_fromstr_and_display;
use crate::protocol::IpAddr;

/// The type of session event we're dealing with.
Expand Down Expand Up @@ -295,6 +296,8 @@ impl SessionAggregates {
mod tests {
use super::*;

use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_session_default_values() {
let json = r#"{
Expand Down
1 change: 1 addition & 0 deletions relay-general/src/protocol/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct Span {
#[cfg(test)]
mod tests {
use super::*;
use crate::testutils::{assert_eq_dbg, assert_eq_str};
use chrono::{TimeZone, Utc};

#[test]
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/stacktrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ impl From<Stacktrace> for RawStacktrace {
}
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_frame_roundtrip() {
let json = r#"{
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ impl std::ops::DerefMut for Tags {
}
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_tags_from_object() {
let json = r#"{
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/templateinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub struct TemplateInfo {
pub other: Object<Value>,
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_template_roundtrip() {
use crate::types::Map;
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ pub struct Thread {
pub other: Object<Value>,
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_thread_id() {
assert_eq_dbg!(
Expand Down
3 changes: 3 additions & 0 deletions relay-general/src/protocol/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,9 @@ impl schemars::JsonSchema for Timestamp {
}
}

#[cfg(test)]
use crate::testutils::{assert_eq_dbg, assert_eq_str};

#[test]
fn test_values_serialization() {
let value = Annotated::new(Values {
Expand Down
Loading