-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
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)
jesskfullwood, bhgomes, kmaork, Gnurou, mbrobbel and 1 more
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.