Merge pull request #1267 from gwenn/clippy

[breaking change] Update edition from 2018 to 2021
This commit is contained in:
gwenn 2023-06-17 07:44:02 +02:00 committed by GitHub
commit dd05c992c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 45 additions and 71 deletions

View File

@ -3,7 +3,7 @@ name = "rusqlite"
# Note: Update version in README.md when you change this.
version = "0.29.0"
authors = ["The rusqlite developers"]
edition = "2018"
edition = "2021"
description = "Ergonomic wrapper for SQLite"
repository = "https://github.com/rusqlite/rusqlite"
documentation = "https://docs.rs/rusqlite/"

View File

@ -274,7 +274,6 @@ impl Blob<'_> {
#[inline]
#[must_use]
pub fn len(&self) -> usize {
use std::convert::TryInto;
self.size().try_into().unwrap()
}

View File

@ -203,7 +203,7 @@ mod test {
assert_eq!(ty, Type::Integer);
}
e => {
panic!("Unexpected error type: {:?}", e);
panic!("Unexpected error type: {e:?}");
}
}
match row.get::<_, String>("y").unwrap_err() {
@ -213,7 +213,7 @@ mod test {
assert_eq!(ty, Type::Null);
}
e => {
panic!("Unexpected error type: {:?}", e);
panic!("Unexpected error type: {e:?}");
}
}
Ok(())

View File

@ -252,11 +252,7 @@ impl fmt::Display for Error {
),
Error::FromSqlConversionFailure(i, ref t, ref err) => {
if i != UNKNOWN_COLUMN {
write!(
f,
"Conversion error from type {} at index: {}, {}",
t, i, err
)
write!(f, "Conversion error from type {t} at index: {i}, {err}")
} else {
err.fmt(f)
}
@ -278,15 +274,12 @@ impl fmt::Display for Error {
Error::QueryReturnedNoRows => write!(f, "Query returned no rows"),
Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {i}"),
Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {name}"),
Error::InvalidColumnType(i, ref name, ref t) => write!(
f,
"Invalid column type {} at index: {}, name: {}",
t, i, name
),
Error::InvalidColumnType(i, ref name, ref t) => {
write!(f, "Invalid column type {t} at index: {i}, name: {name}")
}
Error::InvalidParameterCount(i1, n1) => write!(
f,
"Wrong number of parameters passed to query. Got {}, needed {}",
i1, n1
"Wrong number of parameters passed to query. Got {i1}, needed {n1}"
),
Error::StatementChangedRows(i) => write!(f, "Query changed {i} rows"),

View File

@ -656,7 +656,7 @@ unsafe fn free_boxed_hook<F>(p: *mut c_void) {
unsafe fn expect_utf8<'a>(p_str: *const c_char, description: &'static str) -> &'a str {
expect_optional_utf8(p_str, description)
.unwrap_or_else(|| panic!("received empty {}", description))
.unwrap_or_else(|| panic!("received empty {description}"))
}
unsafe fn expect_optional_utf8<'a>(
@ -667,7 +667,7 @@ unsafe fn expect_optional_utf8<'a>(
return None;
}
std::str::from_utf8(std::ffi::CStr::from_ptr(p_str).to_bytes())
.unwrap_or_else(|_| panic!("received non-utf8 string as {}", description))
.unwrap_or_else(|_| panic!("received non-utf8 string as {description}"))
.into()
}

View File

@ -1307,9 +1307,7 @@ mod test {
assert_eq!(ffi::SQLITE_CANTOPEN, e.extended_code);
assert!(
msg.contains(filename),
"error message '{}' does not contain '{}'",
msg,
filename
"error message '{msg}' does not contain '{filename}'"
);
} else {
panic!("SqliteFailure expected");
@ -1437,8 +1435,7 @@ mod test {
assert_eq!(
err,
Error::ExecuteReturnedResults,
"Unexpected error: {}",
err
"Unexpected error: {err}"
);
}
@ -1454,7 +1451,7 @@ mod test {
.unwrap_err();
match err {
Error::MultipleStatement => (),
_ => panic!("Unexpected error: {}", err),
_ => panic!("Unexpected error: {err}"),
}
}
@ -1565,7 +1562,7 @@ mod test {
let result: Result<i64> = db.one_column("SELECT x FROM foo WHERE x > 5");
match result.unwrap_err() {
Error::QueryReturnedNoRows => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
let bad_query_result = db.query_row("NOT A PROPER QUERY; test123", [], |_| Ok(()));
@ -1617,7 +1614,7 @@ mod test {
// > MEMORY or OFF and can not be changed to a different value. An
// > attempt to change the journal_mode of an in-memory database to
// > any setting other than MEMORY or OFF is ignored.
assert!(mode == "memory" || mode == "off", "Got mode {:?}", mode);
assert!(mode == "memory" || mode == "off", "Got mode {mode:?}");
}
Ok(())
@ -1704,7 +1701,7 @@ mod test {
assert_eq!(err.code, ErrorCode::ConstraintViolation);
check_extended_code(err.extended_code);
}
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
Ok(())
}
@ -1896,7 +1893,7 @@ mod test {
match bad_type.unwrap_err() {
Error::InvalidColumnType(..) => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
let bad_idx: Result<Vec<String>> =
@ -1904,7 +1901,7 @@ mod test {
match bad_idx.unwrap_err() {
Error::InvalidColumnIndex(_) => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
Ok(())
}
@ -1949,7 +1946,7 @@ mod test {
match bad_type.unwrap_err() {
CustomError::Sqlite(Error::InvalidColumnType(..)) => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
let bad_idx: CustomResult<Vec<String>> = query
@ -1958,7 +1955,7 @@ mod test {
match bad_idx.unwrap_err() {
CustomError::Sqlite(Error::InvalidColumnIndex(_)) => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
let non_sqlite_err: CustomResult<Vec<String>> = query
@ -1967,7 +1964,7 @@ mod test {
match non_sqlite_err.unwrap_err() {
CustomError::SomeError => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
Ok(())
}
@ -2004,7 +2001,7 @@ mod test {
match bad_type.unwrap_err() {
CustomError::Sqlite(Error::InvalidColumnType(..)) => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
let bad_idx: CustomResult<String> =
@ -2012,7 +2009,7 @@ mod test {
match bad_idx.unwrap_err() {
CustomError::Sqlite(Error::InvalidColumnIndex(_)) => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
let non_sqlite_err: CustomResult<String> =
@ -2020,7 +2017,7 @@ mod test {
match non_sqlite_err.unwrap_err() {
CustomError::SomeError => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
Ok(())
}

View File

@ -405,18 +405,17 @@ mod test {
db.pragma_update_and_check(None, "journal_mode", "OFF", |row| row.get(0))?;
assert!(
journal_mode == "off" || journal_mode == "memory",
"mode: {:?}",
journal_mode,
"mode: {journal_mode:?}"
);
// Sanity checks to ensure the move to a generic `ToSql` wasn't breaking
let mode =
db.pragma_update_and_check(None, "journal_mode", "OFF", |row| row.get::<_, String>(0))?;
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
assert!(mode == "off" || mode == "memory", "mode: {mode:?}");
let param: &dyn crate::ToSql = &"OFF";
let mode =
db.pragma_update_and_check(None, "journal_mode", param, |row| row.get::<_, String>(0))?;
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
assert!(mode == "off" || mode == "memory", "mode: {mode:?}");
Ok(())
}

View File

@ -1081,12 +1081,12 @@ mod test {
assert_eq!(stmt.insert([2i32])?, 2);
match stmt.insert([1i32]).unwrap_err() {
Error::StatementChangedRows(0) => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
let mut multi = db.prepare("INSERT INTO foo (x) SELECT 3 UNION ALL SELECT 4")?;
match multi.insert([]).unwrap_err() {
Error::StatementChangedRows(2) => (),
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
Ok(())
}
@ -1349,7 +1349,7 @@ mod test {
assert_eq!(error.code, ErrorCode::Unknown);
assert_eq!(offset, 7);
}
err => panic!("Unexpected error {}", err),
err => panic!("Unexpected error {err}"),
}
Ok(())
}

View File

@ -558,7 +558,7 @@ mod test {
assert_eq!(e.code, crate::ErrorCode::Unknown);
assert!(m.contains("transaction"));
} else {
panic!("Unexpected error type: {:?}", e);
panic!("Unexpected error type: {e:?}");
}
}

View File

@ -59,8 +59,7 @@ impl fmt::Display for FromSqlError {
} => {
write!(
f,
"Cannot read {} byte value out of {} byte blob",
expected_size, blob_size
"Cannot read {expected_size} byte value out of {blob_size} byte blob"
)
}
FromSqlError::Other(ref err) => err.fmt(f),
@ -273,7 +272,7 @@ mod test {
.unwrap_err();
match err {
Error::IntegralValueOutOfRange(_, value) => assert_eq!(*n, value),
_ => panic!("unexpected error: {}", err),
_ => panic!("unexpected error: {err}"),
}
}
for n in in_range {

View File

@ -353,7 +353,7 @@ mod test {
assert_eq!(Value::Integer(1), row.get::<_, Value>(2)?);
match row.get::<_, Value>(3)? {
Value::Real(val) => assert!((1.5 - val).abs() < f64::EPSILON),
x => panic!("Invalid Value {:?}", x),
x => panic!("Invalid Value {x:?}"),
}
assert_eq!(Value::Null, row.get::<_, Value>(4)?);
Ok(())

View File

@ -74,7 +74,7 @@ mod test {
);
}
e => {
panic!("Expected conversion failure, got {}", e);
panic!("Expected conversion failure, got {e}");
}
}
Ok(())

View File

@ -106,7 +106,6 @@ impl SqliteMallocString {
/// This means it's safe to use in extern "C" functions even outside of
/// `catch_unwind`.
pub(crate) fn from_str(s: &str) -> Self {
use std::convert::TryFrom;
let s = if s.as_bytes().contains(&0) {
std::borrow::Cow::Owned(make_nonnull(s))
} else {

View File

@ -113,10 +113,7 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
match param {
"filename" => {
if !Path::new(value).exists() {
return Err(Error::ModuleError(format!(
"file '{}' does not exist",
value
)));
return Err(Error::ModuleError(format!("file '{value}' does not exist")));
}
vtab.filename = value.to_owned();
}
@ -137,8 +134,7 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
n_col = Some(n);
} else {
return Err(Error::ModuleError(format!(
"unrecognized argument to 'columns': {}",
value
"unrecognized argument to 'columns': {value}"
)));
}
}
@ -147,8 +143,7 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
vtab.has_headers = b;
} else {
return Err(Error::ModuleError(format!(
"unrecognized argument to 'header': {}",
value
"unrecognized argument to 'header': {value}"
)));
}
}
@ -157,8 +152,7 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
vtab.delimiter = b;
} else {
return Err(Error::ModuleError(format!(
"unrecognized argument to 'delimiter': {}",
value
"unrecognized argument to 'delimiter': {value}"
)));
}
}
@ -171,15 +165,13 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
}
} else {
return Err(Error::ModuleError(format!(
"unrecognized argument to 'quote': {}",
value
"unrecognized argument to 'quote': {value}"
)));
}
}
_ => {
return Err(Error::ModuleError(format!(
"unrecognized parameter '{}'",
param
"unrecognized parameter '{param}'"
)));
}
}
@ -326,8 +318,7 @@ unsafe impl VTabCursor for CsvTabCursor<'_> {
fn column(&self, ctx: &mut Context, col: c_int) -> Result<()> {
if col < 0 || col as usize >= self.cols.len() {
return Err(Error::ModuleError(format!(
"column index out of bounds: {}",
col
"column index out of bounds: {col}"
)));
}
if self.cols.is_empty() {

View File

@ -56,8 +56,7 @@ impl VTabLog {
"schema" => {
if schema.is_some() {
return Err(Error::ModuleError(format!(
"more than one '{}' parameter",
param
"more than one '{param}' parameter"
)));
}
schema = Some(value.to_owned())
@ -65,8 +64,7 @@ impl VTabLog {
"rows" => {
if n_row.is_some() {
return Err(Error::ModuleError(format!(
"more than one '{}' parameter",
param
"more than one '{param}' parameter"
)));
}
if let Ok(n) = i64::from_str(value) {
@ -75,8 +73,7 @@ impl VTabLog {
}
_ => {
return Err(Error::ModuleError(format!(
"unrecognized parameter '{}'",
param
"unrecognized parameter '{param}'"
)));
}
}