rust-analyzer: Problem differentiating between built-in PartialEq trait and Diesel ExpressionMethods trait

extern crate diesel;

use diesel::prelude::*;
use crate::{database, schema::recurring_log::dsl::*};
use database::models::*;
pub fn get_post() {

    let connection = database::connect_to_db();

    let results = recurring_log.filter(finished.eq(true))
    .limit(5)
    .load::<RecurringLog>(&connection)
    .expect("Error loading posts");
}

rust-analyzer says that eq() is not found but rustc does not show the same error.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (21 by maintainers)

Most upvoted comments

Can reproduce at 92a6dcc36 and 0ac4a8f35497718a5d17f74e0dd3ef36227222cc.

I spotted a couple of problems:

  • there are some local imports, but they don’t seem to matter
  • we don’t expand table! correctly
  • we don’t understand associated type projections
  • “expand glob import” doesn’t import traits?
  • even after fixing the above, we still don’t resolve eq
Somewhat minimized test case
use diesel::prelude::ExpressionMethods;
use diesel::query_builder::nodes::Identifier;
use diesel::query_builder::{AsQuery, QueryId, SelectStatement};
use diesel::query_source::{AppearsInFromClause, Never, Once};
use diesel::sql_types::Integer;
use diesel::{QuerySource, Table};

/// The actual table struct
///
/// This is the type which provides the base methods of the query
/// builder, such as `.select` and `.filter`.
pub struct table;

impl QueryId for table {
    type QueryId = table;
    const HAS_STATIC_QUERY_ID: bool = true;
}
/// The SQL type of all of the columns on this table
pub type SqlType = (Integer,);
impl QuerySource for table {
    type FromClause = Identifier<'static>;
    type DefaultSelection = (id,);
    fn from_clause(&self) -> Identifier<'static> {
        Identifier("recurring_log")
    }
    fn default_selection(&self) -> (id,) {
        Self::all_columns()
    }
}
impl AsQuery for table {
    type SqlType = SqlType;
    type Query = SelectStatement<Self>;
    fn as_query(self) -> SelectStatement<Self> {
        SelectStatement::simple(self)
    }
}
impl Table for table {
    type PrimaryKey = id;
    type AllColumns = (id,);
    fn primary_key(&self) -> id {
        id
    }
    fn all_columns() -> (id,) {
        (id,)
    }
}
impl AppearsInFromClause<table> for table {
    type Count = Once;
}
impl AppearsInFromClause<table> for () {
    type Count = Never;
}
/// Contains all of the columns of this table
pub mod columns {
    use super::table;
    use diesel::expression::{Expression, NonAggregate};
    use diesel::query_builder::QueryId;
    use diesel::query_source::Column;
    use diesel::sql_types::Integer;
    use diesel::{AppearsOnTable, SelectableExpression};

    pub struct id;

    impl QueryId for id {
        type QueryId = id;
        const HAS_STATIC_QUERY_ID: bool = true;
    }

    impl Expression for id {
        type SqlType = Integer;
    }

    impl SelectableExpression<table> for id {}
    impl<QS> AppearsOnTable<QS> for id {}
    impl NonAggregate for id {}
    impl Column for id {
        type Table = table;
        const NAME: &'static str = "id";
    }
}

use self::columns::id;

pub fn main() {
    id.eq(42);
}

@edwin0cheng I’ve haven’t tried to reproduce that by my self yet, we only got that report in our gitter channel, so I’ve forwarded it to the in my opinion right place to report it.

That’s a great idea. In fact using extern crate self as diesel; works and removes the issue. I’ve filled https://github.com/diesel-rs/diesel/pull/3564 in diesel to resolve that. Thanks for the pointer 🙏

Note that this has nothing to do with PartialEq, it happens with all/most of diesel’s ExpressionMethods.

The minimized example can’t find the Eq type at all. That’s probably because it’s defined inside a macro.