Cleanup format arguments (#2650)

Inlined format args make code more readable, and code more compact.

I ran this clippy command to fix most cases, and then cleaned up a few trailing commas and uncaught edge cases.

```
cargo clippy --bins --examples  --benches --tests --lib --workspace --fix -- -A clippy::all -W clippy::uninlined_format_args
```
This commit is contained in:
Yuri Astrakhan
2023-07-31 22:27:04 +02:00
committed by GitHub
parent 9463b7592f
commit a824e8468c
80 changed files with 270 additions and 307 deletions

View File

@@ -139,6 +139,6 @@ pub(crate) fn from_url(url: &Url) -> crate::Result<&'static AnyDriver> {
.iter()
.find(|driver| driver.url_schemes.contains(&url.scheme()))
.ok_or_else(|| {
Error::Configuration(format!("no driver found for URL scheme {:?}", scheme).into())
Error::Configuration(format!("no driver found for URL scheme {scheme:?}").into())
})
}

View File

@@ -61,7 +61,7 @@ impl FromStr for AnyKind {
Err(Error::Configuration("database URL has the scheme of a MSSQL database but the `mssql` feature is not enabled".into()))
}
_ => Err(Error::Configuration(format!("unrecognized database url: {:?}", url).into()))
_ => Err(Error::Configuration(format!("unrecognized database url: {url:?}").into()))
}
}
}

View File

@@ -60,7 +60,7 @@ impl Row for AnyRow {
T::decode(value)
}
.map_err(|source| Error::ColumnDecode {
index: format!("{:?}", index),
index: format!("{index:?}"),
source,
})
}

View File

@@ -80,8 +80,7 @@ impl<DB: Database> Describe<DB> {
AnyTypeInfo::try_from(type_info).map_err(|_| {
crate::Error::AnyDriverError(
format!(
"Any driver does not support type {} of parameter {}",
type_info, i
"Any driver does not support type {type_info} of parameter {i}"
)
.into(),
)

View File

@@ -253,10 +253,7 @@ impl dyn DatabaseError {
/// specific error type. In other cases, use `try_downcast_ref`.
pub fn downcast_ref<E: DatabaseError>(&self) -> &E {
self.try_downcast_ref().unwrap_or_else(|| {
panic!(
"downcast to wrong DatabaseError type; original error: {}",
self
)
panic!("downcast to wrong DatabaseError type; original error: {self}")
})
}
@@ -268,12 +265,8 @@ impl dyn DatabaseError {
/// `Error::downcast` which returns `Option<E>`. In normal usage, you should know the
/// specific error type. In other cases, use `try_downcast`.
pub fn downcast<E: DatabaseError>(self: Box<Self>) -> Box<E> {
self.try_downcast().unwrap_or_else(|e| {
panic!(
"downcast to wrong DatabaseError type; original error: {}",
e
)
})
self.try_downcast()
.unwrap_or_else(|e| panic!("downcast to wrong DatabaseError type; original error: {e}"))
}
/// Downcast a reference to this generic database error to a specific

View File

@@ -202,7 +202,7 @@ pub trait Execute<'q, DB: Database>: Send + Sized {
}
// NOTE: `Execute` is explicitly not implemented for String and &String to make it slightly more
// involved to write `conn.execute(format!("SELECT {}", val))`
// involved to write `conn.execute(format!("SELECT {val}"))`
impl<'q, DB: Database> Execute<'q, DB> for &'q str {
#[inline]
fn sql(&self) -> &'q str {

View File

@@ -116,7 +116,7 @@ where
pub fn push(&mut self, sql: impl Display) -> &mut Self {
self.sanity_check();
write!(self.query, "{}", sql).expect("error formatting `sql`");
write!(self.query, "{sql}").expect("error formatting `sql`");
self
}
@@ -258,9 +258,9 @@ where
/// // This would normally produce values forever!
/// let users = (0..).map(|i| User {
/// id: i,
/// username: format!("test_user_{}", i),
/// email: format!("test-user-{}@example.com", i),
/// password: format!("Test!User@Password#{}", i),
/// username: format!("test_user_{i}"),
/// email: format!("test-user-{i}@example.com"),
/// password: format!("Test!User@Password#{i}"),
/// });
///
/// let mut query_builder: QueryBuilder<MySql> = QueryBuilder::new(
@@ -365,9 +365,9 @@ where
/// // This would normally produce values forever!
/// let users = (0..).map(|i| User {
/// id: i,
/// username: format!("test_user_{}", i),
/// email: format!("test-user-{}@example.com", i),
/// password: format!("Test!User@Password#{}", i),
/// username: format!("test_user_{i}"),
/// email: format!("test-user-{i}@example.com"),
/// password: format!("Test!User@Password#{i}"),
/// });
///
/// let mut query_builder: QueryBuilder<MySql> = QueryBuilder::new(

View File

@@ -121,14 +121,14 @@ pub trait Row: Unpin + Send + Sync + 'static {
if !ty.is_null() && !T::compatible(&ty) {
return Err(Error::ColumnDecode {
index: format!("{:?}", index),
index: format!("{index:?}"),
source: mismatched_types::<Self::Database, T>(&ty),
});
}
}
T::decode(value).map_err(|source| Error::ColumnDecode {
index: format!("{:?}", index),
index: format!("{index:?}"),
source,
})
}
@@ -158,7 +158,7 @@ pub trait Row: Unpin + Send + Sync + 'static {
let value = self.try_get_raw(&index)?;
T::decode(value).map_err(|source| Error::ColumnDecode {
index: format!("{:?}", index),
index: format!("{index:?}"),
source,
})
}

View File

@@ -128,7 +128,7 @@ where
continue;
}
query.push(format_args!("INSERT INTO {} (", table));
query.push(format_args!("INSERT INTO {table} ("));
let mut separated = query.separated(", ");

View File

@@ -191,7 +191,7 @@ where
.is_err();
if close_timed_out {
eprintln!("test {} held onto Pool after exiting", test_path);
eprintln!("test {test_path} held onto Pool after exiting");
}
res

View File

@@ -244,7 +244,7 @@ pub fn begin_ansi_transaction_sql(depth: usize) -> Cow<'static, str> {
if depth == 0 {
Cow::Borrowed("BEGIN")
} else {
Cow::Owned(format!("SAVEPOINT _sqlx_savepoint_{}", depth))
Cow::Owned(format!("SAVEPOINT _sqlx_savepoint_{depth}"))
}
}