Generic for diesel fall in infinite recursion

I try to implement helper for unit tests:

    pub fn assert_sql_conversion<'a, T, R>(conn: &PgConnection, t: T, r: &'a R)
    where
        T: Table,
        R: Debug + PartialEq,
        &'a R: Insertable<T>,
        InsertStatement<T, <&'a R as Insertable<T>>::Values>: ExecuteDsl<PgConnection> + LoadQuery<PgConnection, R>,
    {
        let v = diesel::insert_into(t).values(r).get_result(conn).unwrap();
        assert_eq!(r, &v);
    }

Usage:

common::assert_sql_conversion(&conn, test_uri::table, &TestUri { id: Url::new("http://example.com") });

Error:

error[E0275]: overflow evaluating the requirement `&(_, _, _, _, _): diesel::Insertable<_>`
  --> src/types/tests/uri/diesel.rs:35:9
   |
35 |         common::assert_sql_conversion(&conn, test_uri::table, &TestUri { id: u })
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`tickets`)
   = note: required because of the requirements on the impl of `diesel::Insertable<_>` for `(&(_, _, _, _, _), &_, &_, &_, &_)`
   = note: required because of the requirements on the impl of `diesel::Insertable<_>` for `&((_, _, _, _, _), _, _, _, _)`
   = note: required because of the requirements on the impl of `diesel::Insertable<_>` for `(&((_, _, _, _, _), _, _, _, _), &_, &_, &_, &_)`
   = note: required because of the requirements on the impl of `diesel::Insertable<_>` for `&(((_, _, _, _, _), _, _, _, _), _, _, _, _)`

Sorry if I misunderstand some basic stuff, I am pretty new to rust.
I will be glad of any help.

Thanks!

For me this looks like a bug in rustc.
The following code works:

pub fn assert_sql_conversion<'a, T, R>(conn: &PgConnection, t: T, r: R)
    where
        T: Table,
        R: Debug + PartialEq + Clone,
        R: Insertable<T>,
        InsertStatement<T, <R as Insertable<T>>::Values>: ExecuteDsl<PgConnection> + LoadQuery<PgConnection, R>,
    {
        let v = diesel::insert_into(t).values(r.clone()).get_result(conn).unwrap();
        assert_eq!(r, v);
    }

common::assert_sql_conversion(&conn, test_uri::table, TestUri { id: Url::new("http://example.com") });

Now this removes the lifetime from the trait bounds so it is not strictly the same code. That written diesel’s #[derive(Insertable)] generates an impl Insertable<T> for tpe and an impl Insertable<T> for &tpe which behave the same from a type level point of view. I’m not sure why rustc tries to recurse in the second case, but does not for the first one.

EDIT: I’ve created a issue for that in the rustc repo: https://github.com/rust-lang/rust/issues/78982