Fix warnings related to deprecated Error::description

This commit is contained in:
gwenn 2020-01-26 16:57:58 +01:00
parent d1813caa1d
commit adb904650d
6 changed files with 21 additions and 30 deletions

View File

@ -253,6 +253,7 @@ impl fmt::Display for Error {
} }
impl error::Error for Error { impl error::Error for Error {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
Error::SqliteFailure(ref err, None) => err.description(), Error::SqliteFailure(ref err, None) => err.description(),

View File

@ -61,7 +61,6 @@
//! Ok(()) //! Ok(())
//! } //! }
//! ``` //! ```
use std::error::Error as StdError;
use std::os::raw::{c_int, c_void}; use std::os::raw::{c_int, c_void};
use std::panic::{catch_unwind, RefUnwindSafe, UnwindSafe}; use std::panic::{catch_unwind, RefUnwindSafe, UnwindSafe};
use std::ptr; use std::ptr;
@ -99,7 +98,7 @@ unsafe fn report_error(ctx: *mut sqlite3_context, err: &Error) {
} }
_ => { _ => {
ffi::sqlite3_result_error_code(ctx, constraint_error_code()); ffi::sqlite3_result_error_code(ctx, constraint_error_code());
if let Ok(cstr) = str_to_cstring(err.description()) { if let Ok(cstr) = str_to_cstring(&err.to_string()) {
ffi::sqlite3_result_error(ctx, cstr.as_ptr(), -1); ffi::sqlite3_result_error(ctx, cstr.as_ptr(), -1);
} }
} }

View File

@ -1454,8 +1454,8 @@ mod test {
impl fmt::Display for CustomError { impl fmt::Display for CustomError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> {
match *self { match *self {
CustomError::SomeError => write!(f, "{}", self.description()), CustomError::SomeError => write!(f, "my custom error"),
CustomError::Sqlite(ref se) => write!(f, "{}: {}", self.description(), se), CustomError::Sqlite(ref se) => write!(f, "my custom error: {}", se),
} }
} }
} }
@ -1693,10 +1693,8 @@ mod test {
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?;", ?, ?, ?, ?;",
params![ params![
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1,
], ],
|r| { |r| {
assert_eq!(1, r.get_unwrap::<_, i32>(0)); assert_eq!(1, r.get_unwrap::<_, i32>(0));

View File

@ -60,6 +60,7 @@ impl fmt::Display for FromSqlError {
} }
impl Error for FromSqlError { impl Error for FromSqlError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
FromSqlError::InvalidType => "invalid type", FromSqlError::InvalidType => "invalid type",

View File

@ -338,8 +338,7 @@ impl VTabCursor for CSVTabCursor {
impl From<csv::Error> for Error { impl From<csv::Error> for Error {
fn from(err: csv::Error) -> Error { fn from(err: csv::Error) -> Error {
use std::error::Error as StdError; Error::ModuleError(err.to_string())
Error::ModuleError(String::from(err.description()))
} }
} }

View File

@ -656,7 +656,6 @@ unsafe extern "C" fn rust_create<T>(
where where
T: CreateVTab, T: CreateVTab,
{ {
use std::error::Error as StdError;
use std::ffi::CStr; use std::ffi::CStr;
let mut conn = VTabConnection(db); let mut conn = VTabConnection(db);
@ -676,12 +675,12 @@ where
ffi::SQLITE_OK ffi::SQLITE_OK
} else { } else {
let err = error_from_sqlite_code(rc, None); let err = error_from_sqlite_code(rc, None);
*err_msg = mprintf(err.description()); *err_msg = mprintf(&err.to_string());
rc rc
} }
} }
Err(err) => { Err(err) => {
*err_msg = mprintf(err.description()); *err_msg = mprintf(&err.to_string());
ffi::SQLITE_ERROR ffi::SQLITE_ERROR
} }
}, },
@ -692,7 +691,7 @@ where
err.extended_code err.extended_code
} }
Err(err) => { Err(err) => {
*err_msg = mprintf(err.description()); *err_msg = mprintf(&err.to_string());
ffi::SQLITE_ERROR ffi::SQLITE_ERROR
} }
} }
@ -709,7 +708,6 @@ unsafe extern "C" fn rust_connect<T>(
where where
T: VTab, T: VTab,
{ {
use std::error::Error as StdError;
use std::ffi::CStr; use std::ffi::CStr;
let mut conn = VTabConnection(db); let mut conn = VTabConnection(db);
@ -729,12 +727,12 @@ where
ffi::SQLITE_OK ffi::SQLITE_OK
} else { } else {
let err = error_from_sqlite_code(rc, None); let err = error_from_sqlite_code(rc, None);
*err_msg = mprintf(err.description()); *err_msg = mprintf(&err.to_string());
rc rc
} }
} }
Err(err) => { Err(err) => {
*err_msg = mprintf(err.description()); *err_msg = mprintf(&err.to_string());
ffi::SQLITE_ERROR ffi::SQLITE_ERROR
} }
}, },
@ -745,7 +743,7 @@ where
err.extended_code err.extended_code
} }
Err(err) => { Err(err) => {
*err_msg = mprintf(err.description()); *err_msg = mprintf(&err.to_string());
ffi::SQLITE_ERROR ffi::SQLITE_ERROR
} }
} }
@ -758,7 +756,6 @@ unsafe extern "C" fn rust_best_index<T>(
where where
T: VTab, T: VTab,
{ {
use std::error::Error as StdError;
let vt = vtab as *mut T; let vt = vtab as *mut T;
let mut idx_info = IndexInfo(info); let mut idx_info = IndexInfo(info);
match (*vt).best_index(&mut idx_info) { match (*vt).best_index(&mut idx_info) {
@ -770,7 +767,7 @@ where
err.extended_code err.extended_code
} }
Err(err) => { Err(err) => {
set_err_msg(vtab, err.description()); set_err_msg(vtab, &err.to_string());
ffi::SQLITE_ERROR ffi::SQLITE_ERROR
} }
} }
@ -792,7 +789,6 @@ unsafe extern "C" fn rust_destroy<T>(vtab: *mut ffi::sqlite3_vtab) -> c_int
where where
T: CreateVTab, T: CreateVTab,
{ {
use std::error::Error as StdError;
if vtab.is_null() { if vtab.is_null() {
return ffi::SQLITE_OK; return ffi::SQLITE_OK;
} }
@ -809,7 +805,7 @@ where
err.extended_code err.extended_code
} }
Err(err) => { Err(err) => {
set_err_msg(vtab, err.description()); set_err_msg(vtab, &err.to_string());
ffi::SQLITE_ERROR ffi::SQLITE_ERROR
} }
} }
@ -822,7 +818,6 @@ unsafe extern "C" fn rust_open<T>(
where where
T: VTab, T: VTab,
{ {
use std::error::Error as StdError;
let vt = vtab as *mut T; let vt = vtab as *mut T;
match (*vt).open() { match (*vt).open() {
Ok(cursor) => { Ok(cursor) => {
@ -837,7 +832,7 @@ where
err.extended_code err.extended_code
} }
Err(err) => { Err(err) => {
set_err_msg(vtab, err.description()); set_err_msg(vtab, &err.to_string());
ffi::SQLITE_ERROR ffi::SQLITE_ERROR
} }
} }
@ -925,7 +920,6 @@ where
/// Virtual table cursors can set an error message by assigning a string to /// Virtual table cursors can set an error message by assigning a string to
/// `zErrMsg`. /// `zErrMsg`.
unsafe fn cursor_error<T>(cursor: *mut ffi::sqlite3_vtab_cursor, result: Result<T>) -> c_int { unsafe fn cursor_error<T>(cursor: *mut ffi::sqlite3_vtab_cursor, result: Result<T>) -> c_int {
use std::error::Error as StdError;
match result { match result {
Ok(_) => ffi::SQLITE_OK, Ok(_) => ffi::SQLITE_OK,
Err(Error::SqliteFailure(err, s)) => { Err(Error::SqliteFailure(err, s)) => {
@ -935,7 +929,7 @@ unsafe fn cursor_error<T>(cursor: *mut ffi::sqlite3_vtab_cursor, result: Result<
err.extended_code err.extended_code
} }
Err(err) => { Err(err) => {
set_err_msg((*cursor).pVtab, err.description()); set_err_msg((*cursor).pVtab, &err.to_string());
ffi::SQLITE_ERROR ffi::SQLITE_ERROR
} }
} }
@ -953,7 +947,6 @@ unsafe fn set_err_msg(vtab: *mut ffi::sqlite3_vtab, err_msg: &str) {
/// To raise an error, the `column` method should use this method to set the /// To raise an error, the `column` method should use this method to set the
/// error message and return the error code. /// error message and return the error code.
unsafe fn result_error<T>(ctx: *mut ffi::sqlite3_context, result: Result<T>) -> c_int { unsafe fn result_error<T>(ctx: *mut ffi::sqlite3_context, result: Result<T>) -> c_int {
use std::error::Error as StdError;
match result { match result {
Ok(_) => ffi::SQLITE_OK, Ok(_) => ffi::SQLITE_OK,
Err(Error::SqliteFailure(err, s)) => { Err(Error::SqliteFailure(err, s)) => {
@ -975,7 +968,7 @@ unsafe fn result_error<T>(ctx: *mut ffi::sqlite3_context, result: Result<T>) ->
} }
Err(err) => { Err(err) => {
ffi::sqlite3_result_error_code(ctx, ffi::SQLITE_ERROR); ffi::sqlite3_result_error_code(ctx, ffi::SQLITE_ERROR);
if let Ok(cstr) = str_to_cstring(err.description()) { if let Ok(cstr) = str_to_cstring(&err.to_string()) {
ffi::sqlite3_result_error(ctx, cstr.as_ptr(), -1); ffi::sqlite3_result_error(ctx, cstr.as_ptr(), -1);
} }
ffi::SQLITE_ERROR ffi::SQLITE_ERROR