Repository: rust
Issue: Associated type projection fails within Diesel Insertable constraint
Labels: A-associated-items,T-compiler,C-bug,E-needs-mcve

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:

```rust
use diesel::{
    insertable::CanInsertInSingleQuery, mysql::Mysql, prelude::*, query_builder::QueryFragment,
};

diesel::table! {
  posts (id) {
      id -> Integer,
      title -> Varchar,
      body -> Text,
      published -> Bool,
  }
}

#[derive(Queryable)]
pub struct Post {
    pub id: i32,
    pub title: String,
    pub body: String,
    pub published: bool,
}

trait Create {
    type Table: Table;

    fn create_assoc_type<V, Conn: Connection<Backend = Mysql>>(
        &self,
        values: V,
        conn: &Conn,
    ) -> QueryResult<()>
    where
        V: Insertable<Self::Table>,
        V::Values: QueryFragment<Mysql> + CanInsertInSingleQuery<Mysql>;
}

pub struct PostRepository {}

impl Create for PostRepository {
    type Table = posts::table;

    // impl the function with an associated type
    fn create_assoc_type<V, Conn: Connection<Backend = Mysql>>(
        &self,
        values: V,
        conn: &Conn,
    ) -> QueryResult<()>
    where
        V: Insertable<Self::Table>,
        V::Values: QueryFragment<Mysql> + CanInsertInSingleQuery<Mysql>,
    {
        values.insert_into(posts::table).execute(conn)?;
        Ok(())
    }
}

impl PostRepository {
    // impl the function without an associated type
    fn create_fixed_type<V, Conn: Connection<Backend = Mysql>>(
        &self,
        values: V,
        conn: &Conn,
    ) -> QueryResult<()>
    where
        V: Insertable<posts::table>,
        V::Values: QueryFragment<Mysql> + CanInsertInSingleQuery<Mysql>,
    {
        values.insert_into(posts::table).execute(conn)?;

        Ok(())
    }
}
```
The above file is running on Diesel's master branch from its Mysql 'getting_started_step_1' (model.rs) example as a minimum reproduction; I couldn't find a way to make a smaller reproduction without Diesel sorry.

I expected to see this happen: 
There are two versions of largely the same function:
- `create_assoc_type` from the trait `Create` which uses an associated type in a constraint `V: Insertable<Self::Table>`, with `type Table = posts::table`.
- `create_fixed_type` implemented directly on the struct, using the same value directly in the constraint instead of through an associated type `V: Insertable<posts::table>`

Given `Self::Table` refers to the exact same type used in `create_fixed_type` I would expect these to behave largely identically.

Instead, this happened:
`create_fixed_type` compiles okay, but `create_assoc_type` does not compile with the below error. If I remove the constraint `V::Values: QueryFragment<Mysql> + CanInsertInSingleQuery<Mysql>` from `create_assoc_type` the error goes away, but to call `.execute()` those constraints are required.

I originally reported in on Diesel's Gitter, but was [referred to reporting the bug](https://gitter.im/diesel-rs/diesel?at=60990357d261cc4d74bb46f3) upstream here.

```
error[E0277]: the trait bound `V: diesel::Insertable<models::posts::table>` is not satisfied
  --> examples/mysql/getting_started_step_1/src/models.rs:41:5
   |
41 | /     fn create_assoc_type<V, Conn: Connection<Backend = Mysql>>(
42 | |         &self,
43 | |         values: V,
44 | |         conn: &Conn,
...  |
47 | |         V: Insertable<Self::Table>,
48 | |         V::Values: QueryFragment<Mysql> + CanInsertInSingleQuery<Mysql>,
   | |________________________________________________________________________^ the trait `diesel::Insertable<models::posts::table>` is not implemented for `V`
   |
help: consider further restricting this bound
   |
47 |         V: Insertable<Self::Table> + diesel::Insertable<models::posts::table>,
   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->
Replicated this on 1.51 and nightly.
`rustc +nightly --version --verbose`:
```
rustc 1.54.0-nightly (676ee1472 2021-05-06)
binary: rustc
commit-hash: 676ee14729462585b969bbc52f32c307403f4126
commit-date: 2021-05-06
host: x86_64-apple-darwin
release: 1.54.0-nightly
LLVM version: 12.0.0
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
RUST_BACKTRACE=1 cargo +nightly check
    Checking diesel_demo_step_1_mysql v0.1.0 (/Users/.../Downloads/diesel-master/examples/mysql/getting_started_step_1)
error[E0277]: the trait bound `V: diesel::Insertable<models::posts::table>` is not satisfied
  --> examples/mysql/getting_started_step_1/src/models.rs:41:5
   |
41 | /     fn create_assoc_type<V, Conn: Connection<Backend = Mysql>>(
42 | |         &self,
43 | |         values: V,
44 | |         conn: &Conn,
...  |
47 | |         V: Insertable<Self::Table>,
48 | |         V::Values: QueryFragment<Mysql> + CanInsertInSingleQuery<Mysql>,
   | |________________________________________________________________________^ the trait `diesel::Insertable<models::posts::table>` is not implemented for `V`
   |
help: consider further restricting this bound
   |
47 |         V: Insertable<Self::Table> + diesel::Insertable<models::posts::table>,
   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `V: diesel::Insertable<models::posts::table>` is not satisfied
  --> examples/mysql/getting_started_step_1/src/models.rs:41:8
   |
41 |     fn create_assoc_type<V, Conn: Connection<Backend = Mysql>>(
   |        ^^^^^^^^^^^^^^^^^ the trait `diesel::Insertable<models::posts::table>` is not implemented for `V`
   |
help: consider further restricting this bound
   |
47 |         V: Insertable<Self::Table> + diesel::Insertable<models::posts::table>,
   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
error: could not compile `diesel_demo_step_1_mysql`

To learn more, run the command again with --verbose.
```

</p>
</details>