Closed
Description
I tried this code:
#![feature(generic_associated_types)]
use std::marker::PhantomData;
trait Family: Sized {
type Item<'a>;
fn apply_all<F>(&self, f: F)
where
F: FamilyItemFn<Self> { }
}
struct Array<T>(PhantomData<T>);
impl<T: 'static> Family for Array<T> {
type Item<'a> = &'a T;
}
trait FamilyItemFn<T: Family> {
fn apply(&self, item: T::Item<'_>);
}
impl<T, F> FamilyItemFn<T> for F
where
T: Family,
for<'a> F: Fn(T::Item<'a>)
{
fn apply(&self, item: T::Item<'_>) {
(*self)(item);
}
}
fn process<T: 'static>(array: Array<T>) {
// Works
array.apply_all(|x: &T| { });
// ICE: NoSolution
array.apply_all(|x: <Array<T> as Family>::Item<'_>| { });
}
This should compile and work, but instead it ICEs.
It doesn't ICE if I remove the generic parameter from Array
or use array.apply_all(|x: &T| { });
Meta
rustc --version --verbose
:
rustc 1.58.0-nightly (1f12ac872 2021-10-17)
binary: rustc
commit-hash: 1f12ac87296ac61ec002e0243e7ad5a50364da35
commit-date: 2021-10-17
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0
Backtrace
error: internal compiler error: broken MIR in DefId(0:30 ~ test[68ae]::process::{closure#1}) (bb0[0]): equate_normalized_input_or_output: `&[[email protected]:46:21: 46:60]==&[[email protected]:46:21: 46:60]` failed with `NoSolution`
--> test.rs:46:60
|
46 | array.apply_all(|x: <Array<T> as Family>::Item<'_>| { });
| ^
|
= note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:330:27
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1165:13
stack backtrace:
0: rust_begin_unwind
at /rustc/1f12ac87296ac61ec002e0243e7ad5a50364da35/library/std/src/panicking.rs:517:5
1: core::panicking::panic_fmt
at /rustc/1f12ac87296ac61ec002e0243e7ad5a50364da35/library/core/src/panicking.rs:100:14
2: core::panicking::panic_display
3: rustc_errors::HandlerInner::flush_delayed
4: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
5: core::ptr::drop_in_place<rustc_session::parse::ParseSess>
6: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
7: core::ptr::drop_in_place<rustc_interface::interface::Compiler>
8: rustc_span::with_source_map
9: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: internal compiler error: unexpected panic