Skip to content

Commit

Permalink
style: simplify statements for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
hamirmahal committed Nov 19, 2024
1 parent 827cd14 commit db0b421
Show file tree
Hide file tree
Showing 51 changed files with 194 additions and 232 deletions.
4 changes: 2 additions & 2 deletions examples/examples/custom-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn main() {
.with(ErrorSubscriber::default())
.init();
match do_something("hello world") {
Ok(result) => println!("did something successfully: {}", result),
Err(e) => eprintln!("error: {}", e),
Ok(result) => println!("did something successfully: {result}"),
Err(e) => eprintln!("error: {e}"),
};
}
2 changes: 1 addition & 1 deletion examples/examples/fmt-custom-field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() {
// Format fields using the provided closure.
let format = format::debug_fn(|writer, field, value| {
// We'll format the field name and value separated with a colon.
write!(writer, "{}: {:?}", field, value)
write!(writer, "{field}: {value:?}")
})
// Separate each field with a comma.
// This method is provided by an extension trait in the
Expand Down
8 changes: 4 additions & 4 deletions examples/examples/instrumented-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn main() {
.init();

match do_something("hello world") {
Ok(result) => println!("did something successfully: {}", result),
Ok(result) => println!("did something successfully: {result}"),
Err(e) => {
eprintln!("printing error chain naively");
print_naive_spantraces(&e);
Expand All @@ -72,9 +72,9 @@ fn print_extracted_spantraces(error: &(dyn Error + 'static)) {

while let Some(err) = error {
if let Some(spantrace) = err.span_trace() {
eprintln!("Span Backtrace:\n{}", spantrace);
eprintln!("Span Backtrace:\n{spantrace}");
} else {
eprintln!("Error {}: {}", ind, err);
eprintln!("Error {ind}: {err}");
}

error = err.source();
Expand All @@ -88,7 +88,7 @@ fn print_naive_spantraces(error: &(dyn Error + 'static)) {
let mut error = Some(error);
let mut ind = 0;
while let Some(err) = error {
eprintln!("Error {}: {}", ind, err);
eprintln!("Error {ind}: {err}");
error = err.source();
ind += 1;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/examples/map-traced-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ fn print_extracted_spantraces(error: &(dyn Error + 'static)) {

while let Some(err) = error {
if let Some(spantrace) = err.span_trace() {
eprintln!("Span Backtrace:\n{}", spantrace);
eprintln!("Span Backtrace:\n{spantrace}");
} else {
eprintln!("Error {}: {}", ind, err);
eprintln!("Error {ind}: {err}");
}

error = err.source();
Expand Down
14 changes: 7 additions & 7 deletions examples/examples/serde-yak-shave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Collect for JsonCollector {
"enabled": {
"metadata": metadata.as_serde(),
}});
println!("{}", json);
println!("{json}");
true
}

Expand All @@ -38,7 +38,7 @@ impl Collect for JsonCollector {
"attributes": attrs.as_serde(),
"id": id.as_serde(),
}});
println!("{}", json);
println!("{json}");
id
}

Expand All @@ -48,7 +48,7 @@ impl Collect for JsonCollector {
"span": span.as_serde(),
"values": values.as_serde(),
}});
println!("{}", json);
println!("{json}");
}

fn record_follows_from(&self, span: &Id, follows: &Id) {
Expand All @@ -57,28 +57,28 @@ impl Collect for JsonCollector {
"span": span.as_serde(),
"follows": follows.as_serde(),
}});
println!("{}", json);
println!("{json}");
}

fn event(&self, event: &Event<'_>) {
let json = json!({
"event": event.as_serde(),
});
println!("{}", json);
println!("{json}");
}

fn enter(&self, span: &Id) {
let json = json!({
"enter": span.as_serde(),
});
println!("{}", json);
println!("{json}");
}

fn exit(&self, span: &Id) {
let json = json!({
"exit": span.as_serde(),
});
println!("{}", json);
println!("{json}");
}

fn current_span(&self) -> Current {
Expand Down
4 changes: 2 additions & 2 deletions examples/examples/sloggish/sloggish_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Span {

impl Visit for Span {
fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) {
self.kvs.push((field.name(), format!("{:?}", value)))
self.kvs.push((field.name(), format!("{value:?}")))
}
}

Expand All @@ -123,7 +123,7 @@ impl<'a> Visit for Event<'a> {
&mut self.stderr,
"{}",
// Have to alloc here due to `nu_ansi_term`'s API...
Style::new().bold().paint(format!("{:?}", value))
Style::new().bold().paint(format!("{value:?}"))
)
.unwrap();
} else {
Expand Down
12 changes: 6 additions & 6 deletions examples/examples/tower-load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ impl Service<Request<Body>> for AdminSvc {
impl AdminSvc {
fn set_from(&self, bytes: Bytes) -> Result<(), String> {
use std::str;
let body = str::from_utf8(bytes.as_ref()).map_err(|e| format!("{}", e))?;
let body = str::from_utf8(bytes.as_ref()).map_err(|e| format!("{e}"))?;
trace!(request.body = ?body);
let new_filter = body
.parse::<tracing_subscriber::filter::EnvFilter>()
.map_err(|e| format!("{}", e))?;
self.handle.reload(new_filter).map_err(|e| format!("{}", e))
.map_err(|e| format!("{e}"))?;
self.handle.reload(new_filter).map_err(|e| format!("{e}"))
}
}

Expand All @@ -280,7 +280,7 @@ impl fmt::Display for HandleError {
match self {
HandleError::BadPath => f.pad("path must be a single ASCII character"),
HandleError::NoContentLength => f.pad("request must have Content-Length header"),
HandleError::BadRequest(ref e) => write!(f, "bad request: {}", e),
HandleError::BadRequest(ref e) => write!(f, "bad request: {e}"),
HandleError::Unknown => f.pad("unknown internal error"),
}
}
Expand All @@ -302,7 +302,7 @@ fn gen_uri(authority: &str) -> (usize, String) {
let idx = rng.gen_range(0, ALPHABET.len() + 1);
let len = rng.gen_range(0, 26);
let letter = ALPHABET.get(idx..=idx).unwrap_or("");
(len, format!("http://{}/{}", authority, letter))
(len, format!("http://{authority}/{letter}"))
}

#[tracing::instrument(target = "gen", "load_gen")]
Expand All @@ -316,7 +316,7 @@ async fn load_gen(addr: SocketAddr) -> Result<(), Err> {

loop {
interval.tick().await;
let authority = format!("{}", addr);
let authority = format!("{addr}");
let mut svc = svc.clone().ready_oneshot().await?;

let f = async move {
Expand Down
2 changes: 1 addition & 1 deletion tracing-attributes/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl InstrumentArgs {
/// the only way to do this on stable Rust right now.
pub(crate) fn warnings(&self) -> impl ToTokens {
let warnings = self.parse_warnings.iter().map(|err| {
let msg = format!("found unrecognized input, {}", err);
let msg = format!("found unrecognized input, {err}");
let msg = LitStr::new(&msg, err.span());
// TODO(eliza): This is a bit of a hack, but it's just about the
// only way to emit warnings from a proc macro on stable Rust.
Expand Down
8 changes: 4 additions & 4 deletions tracing-core/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,13 +887,13 @@ impl fmt::Debug for Dispatch {
#[cfg(feature = "alloc")]
Kind::Global(collector) => f
.debug_tuple("Dispatch::Global")
.field(&format_args!("{:p}", collector))
.field(&format_args!("{collector:p}"))
.finish(),

#[cfg(feature = "alloc")]
Kind::Scoped(collector) => f
.debug_tuple("Dispatch::Scoped")
.field(&format_args!("{:p}", collector))
.field(&format_args!("{collector:p}"))
.finish(),

#[cfg(not(feature = "alloc"))]
Expand Down Expand Up @@ -955,13 +955,13 @@ impl fmt::Debug for WeakDispatch {
#[cfg(feature = "alloc")]
Kind::Global(collector) => f
.debug_tuple("WeakDispatch::Global")
.field(&format_args!("{:p}", collector))
.field(&format_args!("{collector:p}"))
.finish(),

#[cfg(feature = "alloc")]
Kind::Scoped(collector) => f
.debug_tuple("WeakDispatch::Scoped")
.field(&format_args!("{:p}", collector))
.field(&format_args!("{collector:p}"))
.finish(),

#[cfg(not(feature = "alloc"))]
Expand Down
12 changes: 6 additions & 6 deletions tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<'a, 'b> Visit for fmt::DebugStruct<'a, 'b> {

impl<'a, 'b> Visit for fmt::DebugMap<'a, 'b> {
fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) {
self.entry(&format_args!("{}", field), value);
self.entry(&format_args!("{field}"), value);
}
}

Expand Down Expand Up @@ -602,7 +602,7 @@ impl fmt::Debug for dyn Value {

let mut res = Ok(());
self.record(&FIELD, &mut |_: &Field, val: &dyn fmt::Debug| {
res = write!(f, "{:?}", val);
res = write!(f, "{val:?}");
});
res
}
Expand Down Expand Up @@ -1154,7 +1154,7 @@ mod test {
let mut result = String::new();
valueset.record(&mut |_: &Field, value: &dyn fmt::Debug| {
use core::fmt::Write;
write!(&mut result, "{:?}", value).unwrap();
write!(&mut result, "{value:?}").unwrap();
});
assert_eq!(result, String::from("123"));
}
Expand All @@ -1174,9 +1174,9 @@ mod test {
let mut result = String::new();
valueset.record(&mut |_: &Field, value: &dyn fmt::Debug| {
use core::fmt::Write;
write!(&mut result, "{:?}", value).unwrap();
write!(&mut result, "{value:?}").unwrap();
});
assert_eq!(result, format!("{}", err));
assert_eq!(result, format!("{err}"));
}

#[test]
Expand All @@ -1193,7 +1193,7 @@ mod test {
let mut result = String::new();
valueset.record(&mut |_: &Field, value: &dyn fmt::Debug| {
use core::fmt::Write;
write!(&mut result, "{:?}", value).unwrap();
write!(&mut result, "{value:?}").unwrap();
});
assert_eq!(result, format!("{}", r#"[61 62 63]" "[c0 ff ee]"#));
}
Expand Down
6 changes: 3 additions & 3 deletions tracing-core/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ impl<'a> fmt::Debug for Metadata<'a> {

match (self.file(), self.line()) {
(Some(file), Some(line)) => {
meta.field("location", &format_args!("{}:{}", file, line));
meta.field("location", &format_args!("{file}:{line}"));
}
(Some(file), None) => {
meta.field("file", &format_args!("{}", file));
meta.field("file", &format_args!("{file}"));
}

// Note: a line num with no file is a kind of weird case that _probably_ never occurs...
Expand Down Expand Up @@ -1110,7 +1110,7 @@ mod tests {
// We're not going to do anything with it that might be unsound.
mem::transmute::<LevelFilter, usize>(filter)
};
assert_eq!(expected, repr, "repr changed for {:?}", filter)
assert_eq!(expected, repr, "repr changed for {filter:?}")
}
}
}
2 changes: 1 addition & 1 deletion tracing-error/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl fmt::Debug for SpanTrace {
.file()
.and_then(|file| self.metadata.line().map(|line| (file, line)))
{
write!(f, ", file: {:?}, line: {:?}", file, line)?;
write!(f, ", file: {file:?}, line: {line:?}")?;
}

write!(f, " }}")?;
Expand Down
2 changes: 1 addition & 1 deletion tracing-flame/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Error {
eprintln!("Error:");

while let Some(error) = current_error {
eprintln!(" {}: {}", ind, error);
eprintln!(" {ind}: {error}");
ind += 1;
current_error = error.source();
}
Expand Down
10 changes: 5 additions & 5 deletions tracing-flame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ where
write!(&mut stack, " {}", samples.as_nanos())
.expect("expected: write to String never fails");

let _ = writeln!(*self.out.lock().unwrap(), "{}", stack);
let _ = writeln!(*self.out.lock().unwrap(), "{stack}");
}

fn on_exit(&self, id: &span::Id, ctx: Context<'_, C>) {
Expand Down Expand Up @@ -459,7 +459,7 @@ where
"expected: write to String never fails"
);

let _ = writeln!(*expect!(self.out.lock()), "{}", stack);
let _ = writeln!(*expect!(self.out.lock()), "{stack}");
}
}

Expand Down Expand Up @@ -487,19 +487,19 @@ where
{
if config.module_path {
if let Some(module_path) = span.metadata().module_path() {
write!(dest, "{}::", module_path)?;
write!(dest, "{module_path}::")?;
}
}

write!(dest, "{}", span.name())?;

if config.file_and_line {
if let Some(file) = span.metadata().file() {
write!(dest, ":{}", file)?;
write!(dest, ":{file}")?;
}

if let Some(line) = span.metadata().line() {
write!(dest, ":{}", line)?;
write!(dest, ":{line}")?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tracing-flame/tests/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn capture_supported() {
flame_guard.flush().unwrap();

let traces = std::fs::read_to_string(&path).unwrap();
println!("{}", traces);
println!("{traces}");
assert_eq!(5, traces.lines().count());

tmp_dir.close().expect("failed to delete tempdir");
Expand Down
Loading

0 comments on commit db0b421

Please sign in to comment.