Skip to content

Commit 7b9355e

Browse files
committed
Don't require any imports for #[derive(AsChangeset)]
I had accidentally relied on `use diesel::prelude::*` occurring, as I've pretty much never had a place that didn't do that. Still, I make every effort to fully qualify as much as humanly possible in these macros, so we shouldn't rely on it being in scope. This shouldn't cause issues even if the trait is already imported (our integration tests would fail if it were a problem). Fixes diesel-rs#536.
1 parent 47ccc5f commit 7b9355e

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/
1111
* Added missing impls for loading `chrono::NaiveDateTime` from a column of type
1212
`Timestamptz`
1313

14+
* `#[derive(AsChangeset)]` no longer assumes that `use diesel::prelude::*` has
15+
been done.
16+
1417
## [0.9.0] - 2016-12-08
1518

1619
### Added

diesel/src/macros/as_changeset.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ macro_rules! impl_AsChangeset {
228228

229229
#[allow(non_shorthand_field_patterns)]
230230
fn as_changeset(self) -> Self::Changeset {
231+
use $crate::prelude::ExpressionMethods;
231232
let $self_to_columns = *self;
232233
($(
233234
AsChangeset_column_expr!(
@@ -305,3 +306,25 @@ macro_rules! AsChangeset_column_expr {
305306
$column.eq($field_access)
306307
};
307308
}
309+
310+
#[cfg(test)]
311+
mod using_as_changeset_with_any_imports {
312+
table!(users {
313+
id -> Integer,
314+
name -> VarChar,
315+
});
316+
317+
#[allow(missing_debug_implementations)]
318+
struct Changes {
319+
id: i32,
320+
name: String,
321+
}
322+
323+
impl_AsChangeset! {
324+
(users)
325+
struct Changes {
326+
id: i32,
327+
name: String,
328+
}
329+
}
330+
}

0 commit comments

Comments
 (0)