From e4c84fb37090f2b13617b23cd5542b3e57de7868 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Tue, 28 Nov 2023 15:55:24 -0500 Subject: [PATCH] Update some more format strings --- compatibility-tests/futures/src/lib.rs | 18 +++++++++--------- compatibility-tests/futures/src/location.rs | 2 +- src/futures/try_future.rs | 2 +- src/futures/try_stream.rs | 2 +- src/guide/comparison/failure.md | 4 ++-- src/lib.rs | 21 ++++++++++----------- tests/backtrace.rs | 2 +- tests/basic.rs | 4 ++-- tests/doc_comment.rs | 2 +- tests/error_chain.rs | 2 +- tests/generics.rs | 4 ++-- tests/generics_with_default.rs | 2 +- tests/location.rs | 4 ++-- tests/multiple_attributes.rs | 2 +- tests/opaque.rs | 2 +- tests/options.rs | 4 ++-- tests/report.rs | 4 ++-- tests/single_use_lifetimes_lint.rs | 4 ++-- tests/stringly_typed.rs | 8 ++++---- tests/structs/from_option.rs | 2 +- tests/structs/generics.rs | 4 ++-- tests/structs/with_source.rs | 2 +- tests/structs/without_source.rs | 2 +- 23 files changed, 51 insertions(+), 52 deletions(-) diff --git a/compatibility-tests/futures/src/lib.rs b/compatibility-tests/futures/src/lib.rs index 2eb89e0b..931a8389 100644 --- a/compatibility-tests/futures/src/lib.rs +++ b/compatibility-tests/futures/src/lib.rs @@ -37,7 +37,7 @@ enum Error { name: String, }, - #[snafu(whatever, display("{}", message))] + #[snafu(whatever, display("{message}"))] UnableToLoadOtherStock { message: String, @@ -66,9 +66,9 @@ async fn load_stock_data_sequential() -> Result { let symbol = "other_2"; let other_2 = api::fetch_page(symbol) .await - .with_whatever_context(|_| format!("Unable to get stock prices for: {}", symbol))?; + .with_whatever_context(|_| format!("Unable to get stock prices for: {symbol}"))?; - Ok(format!("{}+{}+{}+{}", apple, google, other_1, other_2)) + Ok(format!("{apple}+{google}+{other_1}+{other_2}")) } // Can be used as a `Future` combinator @@ -80,12 +80,12 @@ async fn load_stock_data_concurrent() -> Result { let other_1 = api::fetch_page("other_1").whatever_context::<_, Error>("Oh no!"); let symbol = "other_2"; let other_2 = api::fetch_page(symbol) - .with_whatever_context(|_| format!("Unable to get stock prices for: {}", symbol)); + .with_whatever_context(|_| format!("Unable to get stock prices for: {symbol}")); let (apple, google, other_1, other_2) = future::try_join4(apple, google, other_1, other_2).await?; - Ok(format!("{}+{}+{}+{}", apple, google, other_1, other_2)) + Ok(format!("{apple}+{google}+{other_1}+{other_2}")) } // Return values of the combinators implement `Future` @@ -106,10 +106,10 @@ async fn load_stock_data_sequential_again() -> Result { let symbol = "other_2"; let other_2 = api::fetch_page(symbol) - .with_whatever_context(|_| format!("Unable to get stock prices for: {}", symbol)) + .with_whatever_context(|_| format!("Unable to get stock prices for: {symbol}")) .await?; - Ok(format!("{}+{}+{}+{}", apple, google, other_1, other_2)) + Ok(format!("{apple}+{google}+{other_1}+{other_2}")) } // Can be used as a `Stream` combinator @@ -121,7 +121,7 @@ async fn load_stock_data_series() -> Result { let other_1 = api::keep_fetching_page("other_1").whatever_context("Oh no!"); let symbol = "other_2"; let other_2 = api::keep_fetching_page(symbol) - .with_whatever_context(|_| format!("Unable to get stock prices for: {}", symbol)); + .with_whatever_context(|_| format!("Unable to get stock prices for: {symbol}")); let together = apple.zip(google).zip(other_1).zip(other_2); @@ -132,7 +132,7 @@ async fn load_stock_data_series() -> Result { .take(10) .try_fold(String::new(), |mut acc, (a, g, o1, o2)| { use std::fmt::Write; - writeln!(&mut acc, "{}+{}+{}+{}", a, g, o1, o2).expect("Could not format"); + writeln!(&mut acc, "{a}+{g}+{o1}+{o2}").expect("Could not format"); future::ready(Ok(acc)) }) .await diff --git a/compatibility-tests/futures/src/location.rs b/compatibility-tests/futures/src/location.rs index 87d16c6d..1b97bb5c 100644 --- a/compatibility-tests/futures/src/location.rs +++ b/compatibility-tests/futures/src/location.rs @@ -21,7 +21,7 @@ struct ManuallyWrappedError { } #[derive(Debug, Snafu)] -#[snafu(display("{}", message))] +#[snafu(display("{message}"))] #[snafu(whatever)] pub struct MyWhatever { #[snafu(source(from(Box, Some)))] diff --git a/src/futures/try_future.rs b/src/futures/try_future.rs index f7c373df..6c64f50d 100644 --- a/src/futures/try_future.rs +++ b/src/futures/try_future.rs @@ -138,7 +138,7 @@ pub trait TryFutureExt: TryFuture + Sized { /// /// fn example(arg: &'static str) -> impl TryFuture { /// api_function(arg) - /// .with_whatever_context(move |_| format!("The API failed for argument {}", arg)) + /// .with_whatever_context(move |_| format!("The API failed for argument {arg}")) /// } /// /// # type ApiError = Box; diff --git a/src/futures/try_stream.rs b/src/futures/try_stream.rs index 0aada739..012accf9 100644 --- a/src/futures/try_stream.rs +++ b/src/futures/try_stream.rs @@ -141,7 +141,7 @@ pub trait TryStreamExt: TryStream + Sized { /// /// fn example(symbol: &'static str) -> impl TryStream { /// stock_prices(symbol) - /// .with_whatever_context(move |_| format!("Couldn't get stock prices for {}", symbol)) + /// .with_whatever_context(move |_| format!("Couldn't get stock prices for {symbol}")) /// } /// /// # type ApiError = Box; diff --git a/src/guide/comparison/failure.md b/src/guide/comparison/failure.md index 3ef9ec7d..f909bea7 100644 --- a/src/guide/comparison/failure.md +++ b/src/guide/comparison/failure.md @@ -16,10 +16,10 @@ use std::ops::Range; fn check_range(x: usize, range: Range) -> Result { if x < range.start { - whatever!("{} is below {}", x, range.start); + whatever!("{x} is below {}", range.start); } if x >= range.end { - whatever!("{} is above {}", x, range.end); + whatever!("{x} is above {}", range.end); } Ok(x) } diff --git a/src/lib.rs b/src/lib.rs index bdd19598..6f282702 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ //! //! fn is_valid_id(id: u16) -> Result<(), Whatever> { //! if id < 10 { -//! whatever!("ID may not be less than 10, but it was {}", id); +//! whatever!("ID may not be less than 10, but it was {id}"); //! } //! Ok(()) //! } @@ -55,7 +55,7 @@ //! //! fn read_config_file(path: &str) -> Result { //! std::fs::read_to_string(path) -//! .with_whatever_context(|_| format!("Could not read file {}", path)) +//! .with_whatever_context(|_| format!("Could not read file {path}")) //! } //! ``` //! @@ -67,10 +67,10 @@ //! //! # fn returns_an_error() -> Result<(), Whatever> { Ok(()) } //! if let Err(e) = returns_an_error() { -//! eprintln!("An error occurred: {}", e); +//! eprintln!("An error occurred: {e}"); //! if let Some(bt) = ErrorCompat::backtrace(&e) { //! # #[cfg(not(feature = "backtraces-impl-backtrace-crate"))] -//! eprintln!("{}", bt); +//! eprintln!("{bt}"); //! } //! } //! ``` @@ -516,8 +516,7 @@ macro_rules! whatever { /// # fn moon_is_rising() -> bool { false } /// ensure_whatever!( /// moon_is_rising(), -/// "We are recalibrating the dynamos for account {}, sorry", -/// account_id, +/// "We are recalibrating the dynamos for account {account_id}, sorry", /// ); /// /// Ok(100) @@ -658,7 +657,7 @@ pub trait ResultExt: Sized { /// fn example() -> Result<(), Whatever> { /// let filename = "/this/does/not/exist"; /// std::fs::read_to_string(filename) - /// .with_whatever_context(|_| format!("couldn't open the file {}", filename))?; + /// .with_whatever_context(|_| format!("couldn't open the file {filename}"))?; /// Ok(()) /// } /// @@ -912,7 +911,7 @@ pub trait OptionExt: Sized { /// /// fn example(user_id: i32) -> Result<(), Error> { /// let name = username(user_id).context(UserLookupSnafu { user_id })?; - /// println!("Username was {}", name); + /// println!("Username was {name}"); /// Ok(()) /// } /// @@ -951,7 +950,7 @@ pub trait OptionExt: Sized { /// user_id, /// previous_ids: Vec::new(), /// })?; - /// println!("Username was {}", name); + /// println!("Username was {name}"); /// Ok(()) /// } /// @@ -1012,7 +1011,7 @@ pub trait OptionExt: Sized { /// /// fn example(env_var_name: &str) -> Result<(), Whatever> { /// std::env::var_os(env_var_name).with_whatever_context(|| { - /// format!("couldn't get the environment variable {}", env_var_name) + /// format!("couldn't get the environment variable {env_var_name}") /// })?; /// Ok(()) /// } @@ -1566,7 +1565,7 @@ macro_rules! location { /// if a > b { /// Ok(a - b) /// } else { -/// whatever!("Can't subtract {} - {}", a, b) +/// whatever!("Can't subtract {a} - {b}") /// } /// } /// diff --git a/tests/backtrace.rs b/tests/backtrace.rs index 445fdebc..f830b4f6 100644 --- a/tests/backtrace.rs +++ b/tests/backtrace.rs @@ -4,7 +4,7 @@ type AnotherError = Box; #[derive(Debug, Snafu)] enum Error { - #[snafu(display("Invalid user {}:\n{}", user_id, backtrace))] + #[snafu(display("Invalid user {user_id}:\n{backtrace}"))] InvalidUser { user_id: i32, backtrace: Backtrace }, WithSource { source: AnotherError, diff --git a/tests/basic.rs b/tests/basic.rs index b3e97f86..9970823b 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -11,9 +11,9 @@ enum Error { filename: PathBuf, source: io::Error, }, - #[snafu(display("Could not open config file at {}", source))] + #[snafu(display("Could not open config file at {source}"))] SaveConfig { source: io::Error }, - #[snafu(display("User ID {} is invalid", user_id))] + #[snafu(display("User ID {user_id} is invalid"))] InvalidUser { user_id: i32 }, #[snafu(display("No user available"))] MissingUser, diff --git a/tests/doc_comment.rs b/tests/doc_comment.rs index f42d9f66..022a197d 100644 --- a/tests/doc_comment.rs +++ b/tests/doc_comment.rs @@ -9,7 +9,7 @@ enum Error { MissingUser, /// This is just a doc comment. - #[snafu(display("This is {}", stronger))] + #[snafu(display("This is {stronger}"))] Stronger { stronger: &'static str }, #[doc(hidden)] diff --git a/tests/error_chain.rs b/tests/error_chain.rs index c4e15af7..d50c102c 100644 --- a/tests/error_chain.rs +++ b/tests/error_chain.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; #[derive(Debug, Clone, Snafu, PartialEq)] enum LeafError { - #[snafu(display("User ID {} is invalid", user_id))] + #[snafu(display("User ID {user_id} is invalid"))] InvalidUser { user_id: i32 }, #[snafu(display("no user available"))] MissingUser, diff --git a/tests/generics.rs b/tests/generics.rs index 546dd878..d1adf454 100644 --- a/tests/generics.rs +++ b/tests/generics.rs @@ -60,7 +60,7 @@ mod bounds { #[derive(Debug, Snafu)] enum Error { - #[snafu(display("Boom: {}", value))] + #[snafu(display("Boom: {value}"))] Boom { value: T }, } @@ -86,7 +86,7 @@ mod bounds { where T: Display, { - #[snafu(display("Boom: {}", value))] + #[snafu(display("Boom: {value}"))] Boom { value: T }, } diff --git a/tests/generics_with_default.rs b/tests/generics_with_default.rs index f0e145e4..67f10ee4 100644 --- a/tests/generics_with_default.rs +++ b/tests/generics_with_default.rs @@ -14,7 +14,7 @@ mod default_with_lifetime { T: Display, S: std::error::Error + AsErrorSource, { - #[snafu(display("Boom: {}", value))] + #[snafu(display("Boom: {value}"))] Boom { value: T, name: &'a str, diff --git a/tests/location.rs b/tests/location.rs index 78665e32..72c77bae 100644 --- a/tests/location.rs +++ b/tests/location.rs @@ -5,7 +5,7 @@ mod basics { #[derive(Debug, Snafu)] enum Error { - #[snafu(display("Created at {}", location))] + #[snafu(display("Created at {location}"))] Usage { #[snafu(implicit)] location: Location, @@ -54,7 +54,7 @@ mod track_caller { } #[derive(Debug, Snafu)] - #[snafu(display("{}", message))] + #[snafu(display("{message}"))] #[snafu(whatever)] pub struct MyWhatever { #[snafu(source(from(Box, Some)))] diff --git a/tests/multiple_attributes.rs b/tests/multiple_attributes.rs index 49a260b2..ff8f5953 100644 --- a/tests/multiple_attributes.rs +++ b/tests/multiple_attributes.rs @@ -35,5 +35,5 @@ fn example() -> Result { #[test] fn has_display() { let err = example().context(error::AlphaSnafu).unwrap_err(); - assert_eq!(format!("{}", err), "Moo"); + assert_eq!(err.to_string(), "Moo"); } diff --git a/tests/opaque.rs b/tests/opaque.rs index a1e97bbd..f0f1ad82 100644 --- a/tests/opaque.rs +++ b/tests/opaque.rs @@ -20,7 +20,7 @@ mod inner { #[derive(Debug, Snafu)] enum InnerError { - #[snafu(display("The value {} is too big", count))] + #[snafu(display("The value {count} is too big"))] TooBig { count: i32 }, } diff --git a/tests/options.rs b/tests/options.rs index 1ac2459d..222eb4c4 100644 --- a/tests/options.rs +++ b/tests/options.rs @@ -3,9 +3,9 @@ use std::collections::HashMap; #[derive(Debug, Snafu)] enum Error { - #[snafu(display("The left-hand argument {} was missing", "id"))] + #[snafu(display("The left-hand argument {id} was missing"))] LeftHandMissing { id: i32, backtrace: Backtrace }, - #[snafu(display("The right-hand argument {} was missing", "id"))] + #[snafu(display("The right-hand argument {id} was missing"))] RightHandMissing { id: i32, backtrace: Backtrace }, } diff --git a/tests/report.rs b/tests/report.rs index 15bf02ab..f079c0e6 100644 --- a/tests/report.rs +++ b/tests/report.rs @@ -135,8 +135,8 @@ fn debug_and_display_are_the_same() { let e = OuterSnafu.into_error(InnerError); let r = Report::from_error(e); - let display = format!("{}", r); - let debug = format!("{:?}", r); + let display = format!("{r}",); + let debug = format!("{r:?}"); assert_eq!(display, debug); } diff --git a/tests/single_use_lifetimes_lint.rs b/tests/single_use_lifetimes_lint.rs index 318510bd..fa07dfe6 100644 --- a/tests/single_use_lifetimes_lint.rs +++ b/tests/single_use_lifetimes_lint.rs @@ -4,9 +4,9 @@ use snafu::prelude::*; #[derive(Debug, Snafu)] pub enum Enum<'id> { - #[snafu(display("`{}` is foo, yo", to))] + #[snafu(display("`{to}` is foo, yo"))] Foo { to: &'id u32 }, - #[snafu(display("bar `{}` frobnicated `{}`", from, to))] + #[snafu(display("bar `{from}` frobnicated `{to}`"))] Bar { from: &'id String, to: &'id i8 }, } diff --git a/tests/stringly_typed.rs b/tests/stringly_typed.rs index 1e3825aa..7bc63b8f 100644 --- a/tests/stringly_typed.rs +++ b/tests/stringly_typed.rs @@ -6,7 +6,7 @@ mod message_only { #[derive(Debug, Snafu)] enum Error { - #[snafu(whatever, display("{}", message))] + #[snafu(whatever, display("{message}"))] Whatever { message: String }, } @@ -53,7 +53,7 @@ mod message_and_source { #[derive(Debug, Snafu)] enum Error { // THOUGHT: Should display automatically do message? - #[snafu(whatever, display("{}", message))] + #[snafu(whatever, display("{message}"))] Whatever { #[snafu(source(from(Box, Some)))] source: Option>, @@ -210,7 +210,7 @@ mod struck { use snafu::{prelude::*, Backtrace}; #[derive(Debug, Snafu)] - #[snafu(whatever, display("{}", message))] + #[snafu(whatever, display("{message}"))] struct Error { #[snafu(source(from(Box, Some)))] source: Option>, @@ -252,7 +252,7 @@ mod send_and_sync { #[derive(Debug, Snafu)] enum Error { - #[snafu(whatever, display("{}", message))] + #[snafu(whatever, display("{message}"))] Whatever { #[snafu(source(from(Box, Some)))] source: Option>, diff --git a/tests/structs/from_option.rs b/tests/structs/from_option.rs index 64945a2a..199a4063 100644 --- a/tests/structs/from_option.rs +++ b/tests/structs/from_option.rs @@ -1,7 +1,7 @@ use snafu::{prelude::*, Backtrace}; #[derive(Debug, Snafu)] -#[snafu(display("The argument at index {} was missing", idx))] +#[snafu(display("The argument at index {idx} was missing"))] struct Error { idx: usize, backtrace: Backtrace, diff --git a/tests/structs/generics.rs b/tests/structs/generics.rs index 1f423183..614a3aa9 100644 --- a/tests/structs/generics.rs +++ b/tests/structs/generics.rs @@ -60,7 +60,7 @@ mod bounds { use std::fmt::Display; #[derive(Debug, Snafu)] - #[snafu(display("key: {}", key))] + #[snafu(display("key: {key}"))] struct Error { key: T, } @@ -78,7 +78,7 @@ mod bounds { use std::fmt::Display; #[derive(Debug, Snafu)] - #[snafu(display("key: {}", key))] + #[snafu(display("key: {key}"))] struct Error where T: Display, diff --git a/tests/structs/with_source.rs b/tests/structs/with_source.rs index 63384526..b1637dd6 100644 --- a/tests/structs/with_source.rs +++ b/tests/structs/with_source.rs @@ -7,7 +7,7 @@ use std::{ }; #[derive(Debug, Snafu)] -#[snafu(display("filename: {}, source: {}", filename.display(), source))] +#[snafu(display("filename: {}, source: {source}", filename.display()))] struct Error { filename: PathBuf, source: io::Error, diff --git a/tests/structs/without_source.rs b/tests/structs/without_source.rs index 4d78997a..3f7ed7f3 100644 --- a/tests/structs/without_source.rs +++ b/tests/structs/without_source.rs @@ -2,7 +2,7 @@ use snafu::prelude::*; use std::error::Error as StdError; #[derive(Debug, Snafu)] -#[snafu(display("name: [{}]", name))] +#[snafu(display("name: [{name}]"))] struct Error { name: String, }