Open
Description
Adding an bound on an associated type (where T::BarOutput: TraitFoo
) causes the compiler to erroneously complain about the original bound:
the trait bound ``T: TraitBar<u64>`` is not satisfied
The compiler is able to expand the associated type BazOutput
enough to generate that error, but not enough to realize it would satisfy that bound.
pub trait TraitFoo {}
pub trait TraitBar<T> {
type BarOutput;
}
pub trait TraitBaz {
type BazOutput;
}
pub trait TraitFum<T> {}
pub struct StructZot;
impl TraitBaz for StructZot {
type BazOutput = u64;
}
macro_rules! test {
(1) => {
impl<T: TraitBar<<Self as TraitBaz>::BazOutput>> TraitFum<T> for StructZot {}
};
(2) => {
impl<T: TraitBar<<StructZot as TraitBaz>::BazOutput>> TraitFum<T> for StructZot {}
};
(3) => {
impl<T: TraitBar<u64>> TraitFum<T> for StructZot {}
};
(4) => {
impl<T: TraitBar<<Self as TraitBaz>::BazOutput>> TraitFum<T> for StructZot where
T::BarOutput: TraitFoo
{
}
};
(5) => {
impl<T: TraitBar<<StructZot as TraitBaz>::BazOutput>> TraitFum<T> for StructZot where
T::BarOutput: TraitFoo
{
}
};
(6) => {
impl<T: TraitBar<u64>> TraitFum<T> for StructZot where T::BarOutput: TraitFoo {}
};
}
//test!{1} // Works
//test!{2} // Works
//test!{3} // Works
//test!{4} // Fails
test!{5} // Fails
//test!{6} // Works
I expected to see all 6 versions compile cleanly.
Instead, this happened:
error[E0277]: the trait bound `T: TraitBar<u64>` is not satisfied
--> src/lib.rs:35:9
|
35 | / impl<T: TraitBar<<StructZot as TraitBaz>::BazOutput>> TraitFum<T> for StructZot where
36 | | T::BarOutput: TraitFoo
37 | | {
38 | | }
| |_________^ the trait `TraitBar<u64>` is not implemented for `T`
...
49 | test!{5} // Fails
| -------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `T`
|
36 | T::BarOutput: TraitFoo, T: TraitBar<u64>
| ^^^^^^^^^^^^^^^^^^
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: Lazy normalization (tracking issue: #60471)Area: Trait systemCategory: This is a bug.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.Fixed by the next-generation trait solver, `-Znext-solver`.