mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-04-14 16:30:16 +00:00
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:
@@ -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())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ impl Row for AnyRow {
|
||||
T::decode(value)
|
||||
}
|
||||
.map_err(|source| Error::ColumnDecode {
|
||||
index: format!("{:?}", index),
|
||||
index: format!("{index:?}"),
|
||||
source,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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(", ");
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user