New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diesel::migrations::run_migrations has a weird type signature #593

Closed
jethrogb opened this Issue Jan 28, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@jethrogb
Contributor

jethrogb commented Jan 28, 2017

List: IntoIterator<Item=M>, M: Deref<Target=Migration> means that you can't pass in a slice of &Migration. Arrays don't implement IntoIterator. This means you have to allocate a container of references, but that's not possible because references passed in need to be 'static. So, you need to pass in a container of boxes.

@weiznich

This comment has been minimized.

Contributor

weiznich commented Jan 29, 2017

It's working without the need of having a box. Iterator itself implements IntoIterator, therefore it is sufficient to call .iter() on the array.
See the embedded_migration code for an example. (In special line 56)

@jethrogb

This comment has been minimized.

Contributor

jethrogb commented Jan 29, 2017

That only works because the references there are 'static. The Box is necessary for the implicit 'static bound on M. But you're right, I can get rid of the collection like so: [Box::new(my_migration) as Box<Migration>].iter().map(|v|&**v)

sgrif added a commit that referenced this issue Feb 2, 2017

Remove the implicit `'static` bound from `run_migrations`
Rust has the undocumented behavior of implying `+ 'static` any time you
reference a trait object directly. Normally this isn't a problem since
the only time you'd usually do that is as `Box<Trait>`, where you can
just write `Box<Trait + 'a>` instead. We can't do that here, however,
sicne `Deref<Target=Trait + 'a>` is not valid syntax. I'm not sure if
there's a workaround to keep the old code that I'm missing, or if this
is legitimately a problem in the language.

Either way it doesn't matter, we can just implement the trait on box and
ref and everything is fine.

I did not include a changelog entry, as all previous callers of this
function should continue to work, and this is a function that is
documented as "you probably should be using something else"

Fixes #593.

@sgrif sgrif closed this in #606 Feb 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment