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

Error message is unclear when compiling #323

Closed
am0d opened this Issue May 11, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@am0d

am0d commented May 11, 2016

I had a schema in Postgres, with a column of type DATE.
I created a struct to match this in Rust, and tried to map that DATE column to a chrono::NaiveDateTime type, like this:

#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Queryable)]
#[insertable_into(periods)]
#[changeset_for(periods)]
pub struct Period {
    pub id: i32,
    pub name: String,
    pub start_date: NaiveDateTime,
    pub end_date: NaiveDateTime,
}

However, this failed to compile (only when the insertable_into or changeset_for attributes were there), but the error message was very unhelpful, and didn't point to the root cause at all:

error: the trait bound `chrono::NaiveDateTime: diesel::Expression` is not satisfied

(and the error span was pointing at the #[insertable_into(...)] attribute.

@sgrif

This comment has been minimized.

Member

sgrif commented May 11, 2016

Unsure how much control we have here, but I'd like the error message to either be:

`NaiveDateTime: AsExpression<types::Date>` is not satisfied

or

`NaiveDateTime: ToSql<types::Date, Pg>` is not satisfied

Those are only marginally more clear, but at least they mention the fact that the column is of type date. Ideally we could give an even better message, explicitly calling out the mistake, but I don't believe we have the ability to do that at the moment.

@sgrif

This comment has been minimized.

Member

sgrif commented May 11, 2016

This is another instance of rust-lang/rust#28894 biting us. It's picking up on the impl<T: Expression> AsExpression<T::SqlType> for T blanket impl, and complaining about Expression missing even though the underlying problem is the missing AsExpression impl. I'm trying to see if there's a way for me to move this around to circumvent the problem, but this might just need to be fixed upstream.

@arielb1

This comment has been minimized.

arielb1 commented May 11, 2016

This should be better in rustc 1.10.

@sgrif sgrif closed this May 11, 2016

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