style(core): apply future-incompatible suggestions

This commit is contained in:
Ryan Leckey
2020-05-30 18:04:23 -07:00
parent 72c1f52caf
commit 9b299d9f09
15 changed files with 29 additions and 25 deletions

View File

@@ -19,7 +19,7 @@ pub trait Connection: Send {
fn close(self) -> BoxFuture<'static, Result<(), Error>>;
/// Checks if a connection to the database is still valid.
fn ping(&mut self) -> BoxFuture<Result<(), Error>>;
fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>>;
/// Begin a new transaction or establish a savepoint within the active transaction.
///
@@ -66,7 +66,7 @@ pub trait Connection: Send {
/// Flush any pending commands to the database.
#[doc(hidden)]
fn flush(&mut self) -> BoxFuture<Result<(), Error>>;
fn flush(&mut self) -> BoxFuture<'_, Result<(), Error>>;
#[doc(hidden)]
fn get_ref(&self) -> &<Self::Database as Database>::Connection;

View File

@@ -135,7 +135,7 @@ pub trait DatabaseError: 'static + Send + Sync + StdError {
fn message(&self) -> &str;
/// The (SQLSTATE) code for the error.
fn code(&self) -> Option<Cow<str>> {
fn code(&self) -> Option<Cow<'_, str>> {
None
}

View File

@@ -8,12 +8,12 @@ use std::task::{Context, Poll};
// Atomic operation that writes the full buffer to the stream, flushes the stream, and then
// clears the buffer (even if either of the two previous operations failed).
pub struct WriteAndFlush<'a, S: 'a> {
pub struct WriteAndFlush<'a, S> {
pub(super) stream: &'a mut S,
pub(super) buf: Cursor<&'a mut Vec<u8>>,
}
impl<'a, S: AsyncWrite + Unpin> Future for WriteAndFlush<'a, S> {
impl<S: AsyncWrite + Unpin> Future for WriteAndFlush<'_, S> {
type Output = Result<(), Error>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {

View File

@@ -1,6 +1,7 @@
//! Core of SQLx, the rust SQL toolkit.
//! Not intended to be used directly.
#![recursion_limit = "512"]
#![warn(future_incompatible, rust_2018_idioms)]
//
// Allows an API be documented as only available in some specific platforms.
// <https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html>

View File

@@ -58,7 +58,7 @@ impl DatabaseError for MySqlDatabaseError {
}
#[inline]
fn code(&self) -> Option<Cow<str>> {
fn code(&self) -> Option<Cow<'_, str>> {
self.code().map(Cow::Borrowed)
}

View File

@@ -33,7 +33,7 @@ impl Row for MySqlRow {
self.row.len()
}
fn try_get_raw<I>(&self, index: I) -> Result<MySqlValueRef, Error>
fn try_get_raw<I>(&self, index: I) -> Result<MySqlValueRef<'_>, Error>
where
I: ColumnIndex<Self>,
{

View File

@@ -69,12 +69,12 @@ impl<DB: Database> Connection for PoolConnection<DB> {
}
#[inline]
fn ping(&mut self) -> BoxFuture<Result<(), Error>> {
fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>> {
Box::pin(self.deref_mut().ping())
}
#[doc(hidden)]
fn flush(&mut self) -> BoxFuture<Result<(), Error>> {
fn flush(&mut self) -> BoxFuture<'_, Result<(), Error>> {
self.get_mut().flush()
}
@@ -112,7 +112,7 @@ impl<DB: Database> Drop for PoolConnection<DB> {
}
impl<DB: Database> Live<DB> {
pub fn float(self, pool: &SharedPool<DB>) -> Floating<Self> {
pub fn float(self, pool: &SharedPool<DB>) -> Floating<'_, Self> {
Floating {
inner: self,
guard: DecrementSizeGuard::new(pool),

View File

@@ -58,11 +58,11 @@ impl<DB: Database> SharedPool<DB> {
}
#[inline]
pub(super) fn try_acquire(&self) -> Option<Floating<Live<DB>>> {
pub(super) fn try_acquire(&self) -> Option<Floating<'_, Live<DB>>> {
Some(self.pop_idle()?.into_live())
}
fn pop_idle(&self) -> Option<Floating<Idle<DB>>> {
fn pop_idle(&self) -> Option<Floating<'_, Idle<DB>>> {
if self.is_closed.load(Ordering::Acquire) {
return None;
}
@@ -70,7 +70,7 @@ impl<DB: Database> SharedPool<DB> {
Some(Floating::from_idle(self.idle_conns.pop().ok()?, self))
}
pub(super) fn release(&self, floating: Floating<Live<DB>>) {
pub(super) fn release(&self, floating: Floating<'_, Live<DB>>) {
self.idle_conns
.push(floating.into_idle().into_leakable())
.expect("BUG: connection queue overflow in release()");
@@ -83,7 +83,7 @@ impl<DB: Database> SharedPool<DB> {
/// Try to atomically increment the pool size for a new connection.
///
/// Returns `None` if we are at max_size.
fn try_increment_size(&self) -> Option<DecrementSizeGuard> {
fn try_increment_size(&self) -> Option<DecrementSizeGuard<'_>> {
let mut size = self.size();
while size < self.options.max_size {

View File

@@ -125,7 +125,7 @@ impl Connection for PgConnection {
}
#[doc(hidden)]
fn flush(&mut self) -> BoxFuture<Result<(), Error>> {
fn flush(&mut self) -> BoxFuture<'_, Result<(), Error>> {
self.wait_until_ready().boxed()
}

View File

@@ -166,7 +166,7 @@ impl DatabaseError for PgDatabaseError {
self.message()
}
fn code(&self) -> Option<Cow<str>> {
fn code(&self) -> Option<Cow<'_, str>> {
Some(Cow::Borrowed(self.code()))
}

View File

@@ -37,7 +37,7 @@ impl Row for PgRow {
self.data.len()
}
fn try_get_raw<I>(&self, index: I) -> Result<PgValueRef, Error>
fn try_get_raw<I>(&self, index: I) -> Result<PgValueRef<'_>, Error>
where
I: ColumnIndex<Self>,
{

View File

@@ -302,7 +302,7 @@ where
/// Make a SQL query.
#[inline]
pub fn query<'q, DB>(sql: &'q str) -> Query<DB, <DB as HasArguments<'q>>::Arguments>
pub fn query<'q, DB>(sql: &'q str) -> Query<'q, DB, <DB as HasArguments<'q>>::Arguments>
where
DB: Database,
{

View File

@@ -133,7 +133,7 @@ where
#[inline]
pub fn query_scalar<'q, DB, O>(
sql: &'q str,
) -> QueryScalar<DB, O, <DB as HasArguments<'q>>::Arguments>
) -> QueryScalar<'q, DB, O, <DB as HasArguments<'q>>::Arguments>
where
DB: Database,
(O,): for<'r> FromRow<'r, DB::Row>,
@@ -146,7 +146,7 @@ where
/// Make a SQL query, with the given arguments, that is mapped to a single concrete type
/// using [`FromRow`](crate::row::FromRow).
#[inline]
pub fn query_scalar_with<'q, DB, O, A>(sql: &'q str, arguments: A) -> QueryScalar<DB, O, A>
pub fn query_scalar_with<'q, DB, O, A>(sql: &'q str, arguments: A) -> QueryScalar<'q, DB, O, A>
where
DB: Database,
A: IntoArguments<'q, DB>,

View File

@@ -195,7 +195,10 @@ pub trait Row: private_row::Sealed + Unpin + Send + Sync + 'static {
/// [`ColumnNotFound`]: crate::Error::ColumnNotFound
/// [`ColumnIndexOutOfBounds`]: crate::Error::ColumnIndexOutOfBounds
///
fn try_get_raw<I>(&self, index: I) -> Result<<Self::Database as HasValueRef>::ValueRef, Error>
fn try_get_raw<I>(
&self,
index: I,
) -> Result<<Self::Database as HasValueRef<'_>>::ValueRef, Error>
where
I: ColumnIndex<Self>;
}

View File

@@ -21,19 +21,19 @@ pub trait TransactionManager {
fn begin(
conn: &mut <Self::Database as Database>::Connection,
depth: usize,
) -> BoxFuture<Result<(), Error>>;
) -> BoxFuture<'_, Result<(), Error>>;
/// Commit the active transaction or release the most recent savepoint.
fn commit(
conn: &mut <Self::Database as Database>::Connection,
depth: usize,
) -> BoxFuture<Result<(), Error>>;
) -> BoxFuture<'_, Result<(), Error>>;
/// Abort the active transaction or restore from the most recent savepoint.
fn rollback(
conn: &mut <Self::Database as Database>::Connection,
depth: usize,
) -> BoxFuture<Result<(), Error>>;
) -> BoxFuture<'_, Result<(), Error>>;
/// Starts to abort the active transaction or restore from the most recent snapshot.
fn start_rollback(conn: &mut <Self::Database as Database>::Connection, depth: usize);
@@ -116,7 +116,7 @@ where
}
#[doc(hidden)]
fn flush(&mut self) -> BoxFuture<Result<(), Error>> {
fn flush(&mut self) -> BoxFuture<'_, Result<(), Error>> {
self.get_mut().flush()
}