Verified Solution[rust-lang/rust] [ICE]: assertion failed `Inherent == Projection`
Sponsored Content
### ROOT CAUSE
The ICE occurs due to an internal assertion failure in the Rust compiler's type system when using the `-Znext-solver=globally` flag. The issue arises from how the compiler handles inherent associated types and closures with generic lifetimes during type inference. Specifically, the closure's return type `S<'a>::P` is being mismatched during type checking, leading to an assertion failure.
### CODE FIX
The problem can be avoided by simplifying the closure definition to avoid the explicit generic lifetime and associated type. Here's the fix:
```rust
struct S<'a>(&'a ());
impl S<'_> {
type P = ();
}
fn ret_ref_local<'e>() -> &'e i32 {
let f = |x| _ = x;
f(&1)
}
```
This change removes the explicit `for<'a>` lifetime and return type annotation for the closure, which can cause the ICE under the next-solver flag. The closure now uses implicit type inference, which avoids the problematic type checking scenario.
Deploy on DigitalOcean ($200 Credit)
Related Fixes
[StackOverflow/rust] Why is Option with if let Some seemingly interfering with interior mutability?
[StackOverflow/python] Developer python environments including DLLs
[golang/go] build: build failure on go1.26-linux-arm64_c4as16-perf_vs_release