Open
Description
Code
I tried writing some macro code that in some cases generates code similar to:
pub trait A {
type X;
}
pub trait B: A<X = Self::Y> {
type Y: C;
}
impl<L> A for L {
type X = L;
}
pub trait C {}
impl C for () {}
impl<T> B for T
where
T: A,
T::X: C,
{
type Y = T::X;
}
fn demo() where for<'a> (): B {}
I expected to see this happen: The code should compile without error.
Instead, this happened: The following compile error happens.
error[E0284]: type annotations needed
--> <source>:25:1
|
25 | fn demo() where for<'a> (): B {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
|
= note: cannot satisfy `<() as B>::Y == _`
error[E0284]: type annotations needed
--> <source>:25:29
|
25 | fn demo() where for<'a> (): B {}
| ^ cannot infer type
|
= note: cannot satisfy `<() as B>::Y == _`
Discussing with @compiler-errors some it would appear #122791 is the cause of the change. The above code does compile if it isn't a trivial bound. For example when you do this instead:
fn demo<T>() where T: B {}
fn other() {
demo::<()>();
}
For more context on 1.78.0 and before if you remove the for<'a>
you get the following.
error[E0271]: type mismatch resolving `<() as A>::X == <() as B>::Y`
--> <source>:25:17
|
25 | fn demo() where (): B {}
| ^^^^^ type mismatch resolving `<() as A>::X == <() as B>::Y`
|
note: expected this to be `()`
--> <source>:10:14
|
10 | type X = L;
| ^
= note: expected unit type `()`
found associated type `<() as B>::Y`
= help: consider constraining the associated type `<() as B>::Y` to `()`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
= help: see issue #48214
Version it worked on
It most recently worked on: 1.78.0
Version with regression
All versions including 1.79.0 and after. Specifically starting with nightly-2024-04-04 (found with a bisection).
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged