Fix regression with <Cow<'_, _> as ToSql> (#681)

This commit is contained in:
Thom Chiovoloni 2020-04-06 17:00:15 -07:00 committed by GitHub
parent 169b3c51fd
commit 76336369ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,7 +90,7 @@ pub trait ToSql {
fn to_sql(&self) -> Result<ToSqlOutput<'_>>; fn to_sql(&self) -> Result<ToSqlOutput<'_>>;
} }
impl<T: ToSql + Clone + ?Sized> ToSql for Cow<'_, T> { impl<T: ToSql + ToOwned + ?Sized> ToSql for Cow<'_, T> {
fn to_sql(&self) -> Result<ToSqlOutput<'_>> { fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
self.as_ref().to_sql() self.as_ref().to_sql()
} }
@ -223,17 +223,20 @@ mod test {
fn test_cow_str() { fn test_cow_str() {
use std::borrow::Cow; use std::borrow::Cow;
let s = "str"; let s = "str";
let cow = Cow::Borrowed(s); let cow: Cow<str> = Cow::Borrowed(s);
let r = cow.to_sql(); let r = cow.to_sql();
assert!(r.is_ok()); assert!(r.is_ok());
let cow = Cow::Owned::<str>(String::from(s)); let cow: Cow<str> = Cow::Owned::<str>(String::from(s));
let r = cow.to_sql(); let r = cow.to_sql();
assert!(r.is_ok()); assert!(r.is_ok());
// Ensure this compiles.
let _p: &[&dyn ToSql] = crate::params![cow];
} }
#[test] #[test]
fn test_box_dyn() { fn test_box_dyn() {
let s: Box<dyn ToSql> = Box::new("Hello world!"); let s: Box<dyn ToSql> = Box::new("Hello world!");
let _s: &[&dyn ToSql] = crate::params![s];
let r = ToSql::to_sql(&s); let r = ToSql::to_sql(&s);
assert!(r.is_ok()); assert!(r.is_ok());
@ -242,6 +245,7 @@ mod test {
#[test] #[test]
fn test_box_deref() { fn test_box_deref() {
let s: Box<str> = "Hello world!".into(); let s: Box<str> = "Hello world!".into();
let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql(); let r = s.to_sql();
assert!(r.is_ok()); assert!(r.is_ok());
@ -250,6 +254,7 @@ mod test {
#[test] #[test]
fn test_box_direct() { fn test_box_direct() {
let s: Box<str> = "Hello world!".into(); let s: Box<str> = "Hello world!".into();
let _s: &[&dyn ToSql] = crate::params![s];
let r = ToSql::to_sql(&s); let r = ToSql::to_sql(&s);
assert!(r.is_ok()); assert!(r.is_ok());
@ -261,11 +266,33 @@ mod test {
let source_str: Box<str> = "Hello world!".into(); let source_str: Box<str> = "Hello world!".into();
let s: Rc<_> = Rc::new(source_str.clone()); let s: Rc<Box<str>> = Rc::new(source_str.clone());
let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql(); let r = s.to_sql();
assert!(r.is_ok()); assert!(r.is_ok());
let s: Arc<_> = Arc::new(source_str); let s: Arc<Box<str>> = Arc::new(source_str.clone());
let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql();
assert!(r.is_ok());
let s: Arc<str> = Arc::from(&*source_str);
let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql();
assert!(r.is_ok());
let s: Arc<dyn ToSql> = Arc::new(source_str.clone());
let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql();
assert!(r.is_ok());
let s: Rc<str> = Rc::from(&*source_str);
let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql();
assert!(r.is_ok());
let s: Rc<dyn ToSql> = Rc::new(source_str);
let _s: &[&dyn ToSql] = crate::params![s];
let r = s.to_sql(); let r = s.to_sql();
assert!(r.is_ok()); assert!(r.is_ok());
} }