Skip to content

Commit

Permalink
fix: Lint (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim authored Feb 3, 2023
1 parent 616587b commit 3e7eec2
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion sentry-actix/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() -> io::Result<()> {
runtime.block_on(async move {
let addr = "127.0.0.1:3001";

println!("Starting server on http://{}", addr);
println!("Starting server on http://{addr}");

HttpServer::new(|| {
App::new()
Expand Down
2 changes: 1 addition & 1 deletion sentry-anyhow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn event_from_error(err: &anyhow::Error) -> Event<'static> {
// exception records are sorted in reverse
if let Some(exc) = event.exception.iter_mut().last() {
let backtrace = err.backtrace();
exc.stacktrace = sentry_backtrace::parse_stacktrace(&format!("{:#}", backtrace));
exc.stacktrace = sentry_backtrace::parse_stacktrace(&format!("{backtrace:#}"));
}
}

Expand Down
9 changes: 4 additions & 5 deletions sentry-contexts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
f,
"pub const RUSTC_VERSION: Option<&'static str> = {};",
if let Ok(version) = version() {
format!("Some(\"{}\")", version)
format!("Some(\"{version}\")")
} else {
"None".into()
}
Expand All @@ -45,7 +45,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Channel::Beta => "beta",
Channel::Stable => "stable",
};
format!("Some(\"{}\")", chan)
format!("Some(\"{chan}\")")
} else {
"None".into()
}
Expand All @@ -54,11 +54,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
writeln!(f, "/// The platform identifier.")?;
writeln!(
f,
"#[allow(unused)] pub const PLATFORM: &str = \"{}\";",
platform
"#[allow(unused)] pub const PLATFORM: &str = \"{platform}\";"
)?;
writeln!(f, "/// The CPU architecture identifier.")?;
writeln!(f, "pub const ARCH: &str = \"{}\";", arch)?;
writeln!(f, "pub const ARCH: &str = \"{arch}\";")?;

println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=Cargo.toml");
Expand Down
6 changes: 3 additions & 3 deletions sentry-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn event_from_error<E: Error + ?Sized>(err: &E) -> Event<'static> {
}

fn exception_from_error<E: Error + ?Sized>(err: &E) -> Exception {
let dbg = format!("{:?}", err);
let dbg = format!("{err:?}");
let value = err.to_string();

// A generic `anyhow::msg` will just `Debug::fmt` the `String` that you feed
Expand All @@ -106,7 +106,7 @@ fn exception_from_error<E: Error + ?Sized>(err: &E) -> Exception {
// To work around this, we check if the `Debug::fmt` of the complete error
// matches its `Display::fmt`, in which case there is no type to parse and
// we will just be using `Error`.
let ty = if dbg == format!("{:?}", value) {
let ty = if dbg == format!("{value:?}") {
String::from("Error")
} else {
parse_type_from_debug(&dbg).to_owned()
Expand Down Expand Up @@ -140,7 +140,7 @@ fn test_parse_type_from_debug() {
use parse_type_from_debug as parse;
#[derive(Debug)]
struct MyStruct;
let err = format!("{:?}", MyStruct);
let err = format!("{MyStruct:?}");
assert_eq!(parse(&err), "MyStruct");

let err = format!("{:?}", "NaN".parse::<usize>().unwrap_err());
Expand Down
2 changes: 1 addition & 1 deletion sentry-core/src/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ mod tests {
);

let trace = SentryTrace(Default::default(), Default::default(), None);
let parsed = parse_sentry_trace(&format!("{}", trace));
let parsed = parse_sentry_trace(&trace.to_string());
assert_eq!(parsed, Some(trace));
}

Expand Down
4 changes: 2 additions & 2 deletions sentry-core/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn debug_images() -> Vec<DebugImage> {
.unwrap_or_else(|_| "<main>".to_string());
}

let code_id = shlib.id().map(|id| CodeId::new(format!("{}", id)));
let code_id = shlib.id().map(|id| CodeId::new(id.to_string()));
let debug_name = shlib.debug_name().map(|n| n.to_string_lossy().to_string());

// For windows, the `virtual_memory_bias` actually returns the real
Expand Down Expand Up @@ -271,7 +271,7 @@ fn get_profile_from_report(
.into_iter()
.map(|address| -> RustFrame {
RustFrame {
instruction_addr: format!("{:p}", address),
instruction_addr: format!("{address:p}"),
}
})
.collect(),
Expand Down
2 changes: 1 addition & 1 deletion sentry-debug-images/src/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn debug_images() -> Vec<DebugImage> {
.unwrap_or_else(|_| "<main>".to_string());
}

let code_id = shlib.id().map(|id| CodeId::new(format!("{}", id)));
let code_id = shlib.id().map(|id| CodeId::new(id.to_string()));
let debug_name = shlib.debug_name().map(|n| n.to_string_lossy().to_string());

// For windows, the `virtual_memory_bias` actually returns the real
Expand Down
2 changes: 1 addition & 1 deletion sentry-slog/src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ macro_rules! impl_into {
}
impl<'a> Serializer for MapSerializer<'a> {
fn emit_arguments(&mut self, key: Key, val: &fmt::Arguments) -> slog::Result {
self.0.insert(key.into(), format!("{}", val).into());
self.0.insert(key.into(), val.to_string().into());
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion sentry-tracing/src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Visit for FieldVisitor {
}

fn record_debug(&mut self, field: &Field, value: &dyn std::fmt::Debug) {
self.record(field, format!("{:?}", value));
self.record(field, format!("{value:?}"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion sentry-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ where
if target.is_empty() {
op.to_string()
} else {
format!("{}::{}", target, op)
format!("{target}::{op}")
}
});

Expand Down
4 changes: 2 additions & 2 deletions sentry-types/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ impl fmt::Display for Auth {
write!(f, ", sentry_timestamp={}", datetime_to_timestamp(&ts))?;
}
if let Some(ref client) = self.client {
write!(f, ", sentry_client={}", client)?;
write!(f, ", sentry_client={client}")?;
}
if let Some(ref secret) = self.secret {
write!(f, ", sentry_secret={}", secret)?;
write!(f, ", sentry_secret={secret}")?;
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions sentry-types/src/dsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ impl fmt::Display for Dsn {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}://{}:", self.scheme, self.public_key)?;
if let Some(ref secret_key) = self.secret_key {
write!(f, "{}", secret_key)?;
write!(f, "{secret_key}")?;
}
write!(f, "@{}", self.host)?;
if let Some(ref port) = self.port {
write!(f, ":{}", port)?;
write!(f, ":{port}")?;
}
write!(f, "{}{}", self.path, self.project_id)?;
Ok(())
Expand All @@ -179,7 +179,7 @@ impl FromStr for Dsn {
.map_err(ParseDsnError::InvalidProjectId)?;
let path = match path_segments.next().unwrap_or("") {
"" | "/" => "/".into(),
other => format!("/{}/", other),
other => format!("/{other}/"),
};

let public_key = match url.username() {
Expand Down
2 changes: 1 addition & 1 deletion sentry-types/src/protocol/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl Envelope {
// write the headers:
let event_id = self.uuid();
match event_id {
Some(uuid) => writeln!(writer, r#"{{"event_id":"{}"}}"#, uuid)?,
Some(uuid) => writeln!(writer, r#"{{"event_id":"{uuid}"}}"#)?,
_ => writeln!(writer, "{{}}")?,
}

Expand Down
10 changes: 5 additions & 5 deletions sentry-types/src/protocol/v7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ impl From<u16> for ThreadId {
impl fmt::Display for ThreadId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ThreadId::Int(i) => write!(f, "{}", i),
ThreadId::String(ref s) => write!(f, "{}", s),
ThreadId::Int(i) => write!(f, "{i}"),
ThreadId::String(ref s) => write!(f, "{s}"),
}
}
}
Expand Down Expand Up @@ -821,7 +821,7 @@ impl fmt::Display for IpAddress {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
IpAddress::Auto => write!(f, "{{{{auto}}}}"),
IpAddress::Exact(ref addr) => write!(f, "{}", addr),
IpAddress::Exact(ref addr) => write!(f, "{addr}"),
}
}
}
Expand Down Expand Up @@ -1362,7 +1362,7 @@ impl Default for SpanId {
let mut buf = [0; 8];

getrandom::getrandom(&mut buf)
.unwrap_or_else(|err| panic!("could not retrieve random bytes for SpanId: {}", err));
.unwrap_or_else(|err| panic!("could not retrieve random bytes for SpanId: {err}"));

Self(buf)
}
Expand Down Expand Up @@ -1408,7 +1408,7 @@ impl Default for TraceId {
let mut buf = [0; 16];

getrandom::getrandom(&mut buf)
.unwrap_or_else(|err| panic!("could not retrieve random bytes for TraceId: {}", err));
.unwrap_or_else(|err| panic!("could not retrieve random bytes for TraceId: {err}"));

Self(buf)
}
Expand Down
19 changes: 8 additions & 11 deletions sentry-types/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ pub mod ts_seconds_float {
}
}
Err(_) => Err(ser::Error::custom(format!(
"invalid `SystemTime` instance: {:?}",
st
"invalid `SystemTime` instance: {st:?}"
))),
}
}
Expand All @@ -74,19 +73,19 @@ pub mod ts_seconds_float {
{
match timestamp_to_datetime(value) {
Some(st) => Ok(st),
None => Err(E::custom(format!("invalid timestamp: {}", value))),
None => Err(E::custom(format!("invalid timestamp: {value}"))),
}
}

fn visit_i64<E>(self, value: i64) -> Result<SystemTime, E>
where
E: de::Error,
{
let value = value.try_into().map_err(|e| E::custom(format!("{}", e)))?;
let value = value.try_into().map_err(|e| E::custom(format!("{e}")))?;
let duration = Duration::from_secs(value);
match SystemTime::UNIX_EPOCH.checked_add(duration) {
Some(st) => Ok(st),
None => Err(E::custom(format!("invalid timestamp: {}", value))),
None => Err(E::custom(format!("invalid timestamp: {value}"))),
}
}

Expand All @@ -97,7 +96,7 @@ pub mod ts_seconds_float {
let duration = Duration::from_secs(value);
match SystemTime::UNIX_EPOCH.checked_add(duration) {
Some(st) => Ok(st),
None => Err(E::custom(format!("invalid timestamp: {}", value))),
None => Err(E::custom(format!("invalid timestamp: {value}"))),
}
}

Expand Down Expand Up @@ -138,8 +137,7 @@ pub mod ts_rfc3339 {
{
Some(formatted) => serializer.serialize_str(&formatted),
None => Err(ser::Error::custom(format!(
"invalid `SystemTime` instance: {:?}",
st
"invalid `SystemTime` instance: {st:?}"
))),
}
}
Expand All @@ -157,9 +155,8 @@ pub mod ts_rfc3339 {
where
E: de::Error,
{
let dt = OffsetDateTime::parse(v, &Rfc3339).map_err(|e| E::custom(format!("{}", e)))?;
let secs =
u64::try_from(dt.unix_timestamp()).map_err(|e| E::custom(format!("{}", e)))?;
let dt = OffsetDateTime::parse(v, &Rfc3339).map_err(|e| E::custom(format!("{e}")))?;
let secs = u64::try_from(dt.unix_timestamp()).map_err(|e| E::custom(format!("{e}")))?;
let nanos = dt.nanosecond();
let duration = Duration::new(secs, nanos);
SystemTime::UNIX_EPOCH
Expand Down
2 changes: 1 addition & 1 deletion sentry/examples/anyhow-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() {
});

if let Err(err) = execute() {
println!("error: {}", err);
println!("error: {err}");
sentry_anyhow::capture_anyhow(&err);
}
}
2 changes: 1 addition & 1 deletion sentry/examples/before-send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ fn main() {
});

let id = sentry::capture_message("An HTTP request failed.", sentry::Level::Error);
println!("sent event {}", id);
println!("sent event {id}");
}
2 changes: 1 addition & 1 deletion sentry/examples/event-processors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ fn main() {
});

let id = sentry::capture_message("An HTTP request failed.", sentry::Level::Error);
println!("sent event {}", id);
println!("sent event {id}");
}
2 changes: 1 addition & 1 deletion sentry/src/transports/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl CurlHttpTransport {
let mut retry_after = None;
let mut sentry_header = None;
let mut headers = curl::easy::List::new();
headers.append(&format!("X-Sentry-Auth: {}", auth)).unwrap();
headers.append(&format!("X-Sentry-Auth: {auth}")).unwrap();
headers.append("Expect:").unwrap();
handle.http_headers(headers).unwrap();
handle.upload(true).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions sentry/tests/test_tower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ fn test_tower_hub() {
.service_fn(|req: String| async move {
// This breadcrumb should not be seen in any other hub
sentry::add_breadcrumb(Breadcrumb {
message: Some(format!("Got request with arg: {}", req)),
message: Some(format!("Got request with arg: {req}")),
level: Level::Info,
..Default::default()
});
sentry::capture_message("Request failed", Level::Error);
Err::<(), _>(format!("Can't greet {}, sorry.", req))
Err::<(), _>(format!("Can't greet {req}, sorry."))
});

let rt = tokio::runtime::Builder::new_current_thread()
Expand Down

0 comments on commit 3e7eec2

Please sign in to comment.