Description
Seems to be caused by #92917 @jackh726
Not a fix, but a mitigation to prevent a backwards-compatible hazard where we normalize using a predicate only because it's the only one available, but shouldn't.
So this regression seems to be intentional, but I want to make sure because even very basic inference fails now, making any use of GATs very fill up with explicit type annotations. It doesn't look so bad in this example, but with complex types it's bad, and I think there's a more complex example the compiler can't even tell what _x
is at all, but I'm still working on that.
Code
#![feature(generic_associated_types)]
pub trait Build {
type Output<O>;
fn build<O>(self, input: O) -> Self::Output<O>;
}
pub struct IdentityBuild;
impl Build for IdentityBuild {
type Output<O> = O;
fn build<O>(self, input: O) -> Self::Output<O> {
input
}
}
fn a() {
let _x: u8 = IdentityBuild.build(10);
// ^type mismatch resolving `<IdentBuild as Build>::Output<i32> == u8`
}
fn b() {
let _x: Vec<u8> = IdentityBuild.build(Vec::new());
// ^type annotations needed: cannot satisfy `<IdentBuild as Build>::Output<Vec<_>> == Vec<u8>`
// cannot satisfy `<IdentBuild as Build>::Output<Vec<_>> == Vec<u8>`
}
// edit: added
fn c() {
let mut f = IdentityBuild.build(|| ());
(f)();
// ^type annotations needed
// type must be known at this pointrustcE0282
// main.rs(17, 9): consider giving `x` a type
}
pub fn main() {
a();
b();
c();
}
I expected to see this happen: compiles without error
Instead, this happened: Type inference fails, Output<O> = O
seems to be ignored or not understood by the compiler.
Version it worked on
It most recently worked on:
- cc38176
- nightly-2022-02-09
Version with regression
- 9a5a961
- nightly-2022-02-10
rustc --version --verbose
:
rustc 1.60.0-nightly (e7aca8959 2022-02-09)
binary: rustc
commit-hash: e7aca895980f25f6d2d3c48e10fd04656764d1e4
commit-date: 2022-02-09
host: x86_64-pc-windows-msvc
release: 1.60.0-nightly
LLVM version: 13.0.0
Backtrace
(no crash)