Bump to the latest nightly

We were affected by breaking changes with how struct fields are
represented. Now that I can get the tests compiling, I noticed that I
implemented the `Option` impl for specialization incorrectly.
This commit is contained in:
Sean Griffin 2016-04-08 15:31:10 -04:00
parent 6a0c594dd1
commit 848d191515
7 changed files with 19 additions and 11 deletions

View File

@ -4,7 +4,7 @@ dist: trusty
rust: rust:
- stable - stable
- beta - beta
- nightly-2016-04-01 - nightly-2016-04-07
- nightly - nightly
addons: addons:
postgresql: '9.4' postgresql: '9.4'

View File

@ -5,6 +5,7 @@ impl<T, ST, DB> FromSqlRow<Nullable<ST>, DB> for Option<T> where
{ {
default fn build_from_row<R: Row<DB>>(row: &mut R) -> Result<Self, Box<Error+Send+Sync>> { default fn build_from_row<R: Row<DB>>(row: &mut R) -> Result<Self, Box<Error+Send+Sync>> {
if row.next_is_null(1) { if row.next_is_null(1) {
row.take();
Ok(None) Ok(None)
} else { } else {
T::build_from_row(row).map(Some) T::build_from_row(row).map(Some)

View File

@ -80,7 +80,9 @@ impl<'a, 'b> BelongsToAssociationBuilder<'a, 'b> {
} }
fn foreign_key_type(&self) -> P<ast::Ty> { fn foreign_key_type(&self) -> P<ast::Ty> {
self.model.attr_named(self.foreign_key_name()) let name = self.foreign_key_name();
self.model.attr_named(name)
.expect(&format!("Couldn't find an attr named {}", name))
.ty.clone() .ty.clone()
} }

View File

@ -14,10 +14,10 @@ pub struct Attr {
impl Attr { impl Attr {
pub fn from_struct_field(cx: &mut ExtCtxt, field: &ast::StructField) -> Option<Self> { pub fn from_struct_field(cx: &mut ExtCtxt, field: &ast::StructField) -> Option<Self> {
let field_name = field.node.ident(); let field_name = field.ident;
let column_name = let column_name =
str_value_of_attr_with_name(cx, &field.node.attrs, "column_name"); str_value_of_attr_with_name(cx, &field.attrs, "column_name");
let ty = field.node.ty.clone(); let ty = field.ty.clone();
match (column_name, field_name) { match (column_name, field_name) {
(Some(column_name), f) => Some(Attr { (Some(column_name), f) => Some(Attr {

View File

@ -47,10 +47,16 @@ impl Model {
}) })
} }
pub fn attr_named(&self, name: ast::Ident) -> &Attr { pub fn attr_named(&self, name: ast::Ident) -> Option<&Attr> {
self.attrs.iter().find(|attr| { self.attrs.iter().find(|attr| {
attr.field_name == Some(name) attr.field_name.map(|f| f.name) == Some(name.name)
}).expect(&format!("Couldn't find an attr named {}", name)) })
}
pub fn attr_for_column(&self, name: ast::Ident) -> Option<&Attr> {
self.attrs.iter().find(|attr| {
attr.column_name.name == name.name
})
} }
} }

View File

@ -91,7 +91,7 @@ fn changeset_impl(
let ref struct_name = model.ty; let ref struct_name = model.ty;
let pk = model.primary_key_name(); let pk = model.primary_key_name();
let table_name = options.table_name; let table_name = options.table_name;
let attrs_for_changeset = model.attrs.iter().filter(|a| a.column_name != pk) let attrs_for_changeset = model.attrs.iter().filter(|a| a.column_name.name != pk.name)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let changeset_ty = cx.ty(span, TyKind::Tup( let changeset_ty = cx.ty(span, TyKind::Tup(
attrs_for_changeset.iter() attrs_for_changeset.iter()
@ -127,7 +127,7 @@ fn save_changes_impl(
let sql_type = cx.path(span, vec![options.table_name, str_to_ident("SqlType")]); let sql_type = cx.path(span, vec![options.table_name, str_to_ident("SqlType")]);
let table = cx.path(span, vec![options.table_name, str_to_ident("table")]); let table = cx.path(span, vec![options.table_name, str_to_ident("table")]);
let mut result = Vec::new(); let mut result = Vec::new();
if let Some(pk) = model.attrs.iter().find(|a| a.column_name == pk) { if let Some(pk) = model.attr_for_column(pk) {
let pk_field = pk.field_name.unwrap(); let pk_field = pk.field_name.unwrap();
if cfg!(feature = "postgres") { if cfg!(feature = "postgres") {
result.push(quote_item!(cx, result.push(quote_item!(cx,

View File

@ -377,7 +377,6 @@ fn third_party_crates_can_add_new_types() {
} }
} }
#[cfg(not(feature = "unstable"))]
impl FromSqlRow<MyInt, Pg> for i32 { impl FromSqlRow<MyInt, Pg> for i32 {
fn build_from_row<R: ::diesel::row::Row<Pg>>(row: &mut R) -> Result<Self, Box<Error+Send+Sync>> { fn build_from_row<R: ::diesel::row::Row<Pg>>(row: &mut R) -> Result<Self, Box<Error+Send+Sync>> {
FromSql::<MyInt, Pg>::from_sql(row.take()) FromSql::<MyInt, Pg>::from_sql(row.take())