diesel-rs/diesel

losing type information when adding WHERE (filter) clause to query

is-it-ayush opened this issue ยท 2 comments

Setup

Versions

  • Rust: 1.72.1
  • Diesel: 2.1.0
  • Database: 16.1
  • Operating System Linux 6.1.0-16-amd64

Feature Flags

  • diesel: postgres

Problem Description

Anytime I use a .filter(some_field.<operator>(some_value)) (ex. .filter(username.eq("ayush"))). I loose type information on the returning result. The program still compiles unaffected but the types vanish. Here is an example,

  • with .filter
    image
  • without .filter
    image

You'll notice that without filter it's being parsed as Vec<User> while with filter it's being parsed as ! (diverging). I was following the "getting started" guide so I'm not sure what causes this.

What are you trying to accomplish?

The type information to be parsed correctly.

What is the expected output?

The correct type for results i.e. Vec<User>.

What is the actual output?

It's !. For some reason, rust thinks it's diverging.

Are you seeing any additional errors?

Nope! The program compiles perfectly fine.

Steps to reproduce

Unfortunately I don't yet know why this occurs but here is the link to the above code.

Checklist

  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate

Duplicate of #3876 and rust-lang/rust-analyzer#14607

The code itself is fine as it is accepted by rustc. It's just an IDE issue. There is nothing we can do in diesel to fix this issue. It needs to be fixed in rust-analyzer.

I am glad I am not alone, this drives me crazy.