Skip to content

Commit

Permalink
Update some more format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Nov 28, 2023
1 parent a567925 commit e4c84fb
Show file tree
Hide file tree
Showing 23 changed files with 51 additions and 52 deletions.
18 changes: 9 additions & 9 deletions compatibility-tests/futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum Error {
name: String,
},

#[snafu(whatever, display("{}", message))]
#[snafu(whatever, display("{message}"))]
UnableToLoadOtherStock {
message: String,

Expand Down Expand Up @@ -66,9 +66,9 @@ async fn load_stock_data_sequential() -> Result<String, Error> {
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
Expand All @@ -80,12 +80,12 @@ async fn load_stock_data_concurrent() -> Result<String, Error> {
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`
Expand All @@ -106,10 +106,10 @@ async fn load_stock_data_sequential_again() -> Result<String, Error> {

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
Expand All @@ -121,7 +121,7 @@ async fn load_stock_data_series() -> Result<String, Error> {
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);

Expand All @@ -132,7 +132,7 @@ async fn load_stock_data_series() -> Result<String, Error> {
.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
Expand Down
2 changes: 1 addition & 1 deletion compatibility-tests/futures/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct ManuallyWrappedError {
}

#[derive(Debug, Snafu)]
#[snafu(display("{}", message))]
#[snafu(display("{message}"))]
#[snafu(whatever)]
pub struct MyWhatever {
#[snafu(source(from(Box<dyn std::error::Error>, Some)))]
Expand Down
2 changes: 1 addition & 1 deletion src/futures/try_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub trait TryFutureExt: TryFuture + Sized {
///
/// fn example(arg: &'static str) -> impl TryFuture<Ok = i32, Error = Whatever> {
/// 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<dyn std::error::Error>;
Expand Down
2 changes: 1 addition & 1 deletion src/futures/try_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub trait TryStreamExt: TryStream + Sized {
///
/// fn example(symbol: &'static str) -> impl TryStream<Ok = i32, Error = Whatever> {
/// 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<dyn std::error::Error>;
Expand Down
4 changes: 2 additions & 2 deletions src/guide/comparison/failure.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use std::ops::Range;

fn check_range(x: usize, range: Range<usize>) -> Result<usize, Whatever> {
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)
}
Expand Down
21 changes: 10 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
//! }
Expand All @@ -55,7 +55,7 @@
//!
//! fn read_config_file(path: &str) -> Result<String, Whatever> {
//! std::fs::read_to_string(path)
//! .with_whatever_context(|_| format!("Could not read file {}", path))
//! .with_whatever_context(|_| format!("Could not read file {path}"))
//! }
//! ```
//!
Expand All @@ -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}");
//! }
//! }
//! ```
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -658,7 +657,7 @@ pub trait ResultExt<T, E>: 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(())
/// }
///
Expand Down Expand Up @@ -912,7 +911,7 @@ pub trait OptionExt<T>: 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(())
/// }
///
Expand Down Expand Up @@ -951,7 +950,7 @@ pub trait OptionExt<T>: Sized {
/// user_id,
/// previous_ids: Vec::new(),
/// })?;
/// println!("Username was {}", name);
/// println!("Username was {name}");
/// Ok(())
/// }
///
Expand Down Expand Up @@ -1012,7 +1011,7 @@ pub trait OptionExt<T>: 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(())
/// }
Expand Down Expand Up @@ -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}")
/// }
/// }
///
Expand Down
2 changes: 1 addition & 1 deletion tests/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type AnotherError = Box<dyn std::error::Error>;

#[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,
Expand Down
4 changes: 2 additions & 2 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/doc_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion tests/error_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod bounds {

#[derive(Debug, Snafu)]
enum Error<T: Display> {
#[snafu(display("Boom: {}", value))]
#[snafu(display("Boom: {value}"))]
Boom { value: T },
}

Expand All @@ -86,7 +86,7 @@ mod bounds {
where
T: Display,
{
#[snafu(display("Boom: {}", value))]
#[snafu(display("Boom: {value}"))]
Boom { value: T },
}

Expand Down
2 changes: 1 addition & 1 deletion tests/generics_with_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<dyn std::error::Error>, Some)))]
Expand Down
2 changes: 1 addition & 1 deletion tests/multiple_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ fn example() -> Result<u8, InnerError> {
#[test]
fn has_display() {
let err = example().context(error::AlphaSnafu).unwrap_err();
assert_eq!(format!("{}", err), "Moo");
assert_eq!(err.to_string(), "Moo");
}
2 changes: 1 addition & 1 deletion tests/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}

Expand Down
4 changes: 2 additions & 2 deletions tests/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}

Expand Down
4 changes: 2 additions & 2 deletions tests/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/single_use_lifetimes_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}

Expand Down
8 changes: 4 additions & 4 deletions tests/stringly_typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod message_only {

#[derive(Debug, Snafu)]
enum Error {
#[snafu(whatever, display("{}", message))]
#[snafu(whatever, display("{message}"))]
Whatever { message: String },
}

Expand Down Expand Up @@ -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<dyn std::error::Error>, Some)))]
source: Option<Box<dyn std::error::Error>>,
Expand Down Expand Up @@ -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<dyn std::error::Error>, Some)))]
source: Option<Box<dyn std::error::Error>>,
Expand Down Expand Up @@ -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<dyn std::error::Error + Send + Sync>, Some)))]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
Expand Down
2 changes: 1 addition & 1 deletion tests/structs/from_option.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/structs/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod bounds {
use std::fmt::Display;

#[derive(Debug, Snafu)]
#[snafu(display("key: {}", key))]
#[snafu(display("key: {key}"))]
struct Error<T: Display> {
key: T,
}
Expand All @@ -78,7 +78,7 @@ mod bounds {
use std::fmt::Display;

#[derive(Debug, Snafu)]
#[snafu(display("key: {}", key))]
#[snafu(display("key: {key}"))]
struct Error<T>
where
T: Display,
Expand Down
2 changes: 1 addition & 1 deletion tests/structs/with_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit e4c84fb

Please sign in to comment.