Open
Description
This code works:
trait Boring {}
trait Usage
where
Self::Thing: Boring,
{
type Thing;
}
fn value_example<T: Usage>(t: T::Thing) {
use_the_trait(t);
}
fn use_the_trait<T: Boring>(_: T) {}
fn main() {}
While this code fails:
trait Boring {}
trait Usage
where
for<'a> &'a Self::Thing: Boring,
{
type Thing;
}
fn ref_example<T: Usage>(t: T::Thing) {
use_the_trait(&t);
}
fn use_the_trait<T: Boring>(_: T) {}
fn main() {}
error[E0277]: the trait bound `for<'a> &'a <T as Usage>::Thing: Boring` is not satisfied
--> src/main.rs:10:1
|
10 | / fn ref_example<T: Usage>(t: T::Thing) {
11 | | use_the_trait(&t);
12 | | }
| |_^ the trait `for<'a> Boring` is not implemented for `&'a <T as Usage>::Thing`
|
note: required by `Usage`
--> src/main.rs:3:1
|
3 | / trait Usage
4 | | where
5 | | for<'a> &'a Self::Thing: Boring,
6 | | {
7 | | type Thing;
8 | | }
| |_^
This is probably related to #20671, but seems slightly different from the examples posited there. Specifically, the "standard" case (the first example) does work.
Also highly relevant: #44656 and #32722.
Tested with Rust 1.25.0 and 1.27.0-nightly (2018-04-29 79252ff)