Closed frankmcsherry closed 5 years ago
Minified:
trait Mirror { type Image; }
impl<T> Mirror for T { type Image = T; }
fn test<L,T>(l: L) where L: FnOnce(Option<<&T as Mirror>::Image>),
for<'a> &'a T: Mirror
{ l(None); }
fn main() {
test::<_,u8>(|_| {});
}
@nikomatsakis @eddyb : why is fulfill_obligation
taking a PolyTraitRef
rather than a regular TraitRef
?
@arielb1
ok, finally getting to some of my older notifications, sorry. An interesting question. Digging through the codebase, I see that there is only one call -- get_vtable
-- where the generality of taking a polytraitref is used. But it makes sense there, no? An object type can be something like Box<Fn(&i32)>
, after all.
Let me look into your minified example a bit.
I guess we should just erase regions in that case too.
The PolyTraitRef
in fulfill_obligation
seems to be of no good reason.
The root cause of the problem here is that typeck/trans assume that if for<'a> Ψ['a]: Trait
holds then Ψ['s]: Trait
holds after normalizing, and this does not work (maybe that is limited only to closures?)
I've hit this I think. Other issues with visually similar error messages which I assume are related: https://github.com/rust-lang/rust/issues/33364#issuecomment-221601950, #39779.
Reposting #39779 here for future reference:
This seems to cause rustc to crash (link shows a slightly more complicated example than the reduced example below):
trait Fun<'a> { type Output; }
impl<'a> Fun<'a> for () { type Output = &'a str; }
fn with<F, G>(x: <F as Fun<'static>>::Output, g: G)
where F: for<'a> Fun<'a>,
G: for<'a> FnOnce(<F as Fun<'a>>::Output) {
g(x)
}
fn main() {
with::<(), _>("", |_| ());
}
It looks like it forgot to normalize <() as Fun<'a>>::Output
to &'a str
?
error: internal compiler error:
src/librustc_trans/common.rs:473:
Encountered error
OutputTypeParameterMismatch(
Binder(<[closure] as FnOnce(<() as Fun<'a>>::Output))>,
Binder(<[closure] as FnOnce(&str))>,
Sorts(ExpectedFound {
expected: &str,
found: <() as Fun<'_>>::Output
})
)
selecting
Binder(<[closure] as FnOnce(&str)>)
during trans
```
error: internal compiler error: /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/common.rs:473: Encountered error `OutputTypeParameterMismatch(Binder(<[closure@/tmp/bug.rs:12:23: 12:29] as std::ops::FnOnce<(<() as Fun<'a>>::Output,)>>), Binder(<[closure@/tmp/bug.rs:12:23: 12:29] as std::ops::FnOnce<(&str,)>>), Sorts(ExpectedFound { expected: &str, found: <() as Fun<'_>>::Output }))` selecting `Binder(<[closure@/tmp/bug.rs:12:23: 12:29] as std::ops::FnOnce<(&str,)>>)` during trans
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box', /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_errors/lib.rs:376
stack backtrace:
1: 0x7f867e11e52c - std::sys::imp::backtrace::tracing::imp::write::h1d59ca58eb86a1e2
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
2: 0x7f867e12cb1e - std::panicking::default_hook::{{closure}}::hc8550e2dc230bf9b
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:351
3: 0x7f867e12c6c3 - std::panicking::default_hook::he85ae9e5c9867198
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:361
4: 0x7f867e12cfbb - std::panicking::rust_panic_with_hook::h319375f6b98710b0
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:555
5: 0x7f867ca6fa78 - std::panicking::begin_panic::hcffa9fd2a04ec06f
6: 0x7f867ca8d595 - rustc::session::opt_span_bug_fmt::{{closure}}::h614c6fe11c4465e9
7: 0x7f867ca8d3aa - rustc::session::span_bug_fmt::h8b2f72c913194199
8: 0x7f867cb02fa7 - rustc_trans::common::fulfill_obligation::{{closure}}::{{closure}}::h765609b5f897b16b
9: 0x7f867caff22c - rustc_trans::common::fulfill_obligation::h5accac95e8a401b5
10: 0x7f867cafb98b - rustc_trans::collector::do_static_dispatch::hce598ea3ab1ce3a5
11: 0x7f867cafb00d - as rustc::mir::visit::Visitor<'tcx>>::visit_operand::hd92120f4e6379a7e
12: 0x7f867cafb58a - as rustc::mir::visit::Visitor<'tcx>>::visit_terminator_kind::hccb2193f3818a450
13: 0x7f867ca88286 - rustc::mir::visit::Visitor::visit_mir::hfb8959f7b6b5ba95
14: 0x7f867cafd449 - rustc_trans::collector::collect_neighbours::he1db279e25d9c10d
15: 0x7f867caf9522 - rustc_trans::collector::collect_items_rec::hbbb361a730e6b0d3
16: 0x7f867caf9844 - rustc_trans::collector::collect_items_rec::hbbb361a730e6b0d3
17: 0x7f867cae64d8 - rustc_trans::base::collect_and_partition_translation_items::{{closure}}::h742429e3883a12cb
18: 0x7f867cae1bc2 - rustc_trans::base::collect_and_partition_translation_items::hac7e8bb398fe3219
19: 0x7f867cad4e52 - rustc_trans::base::trans_crate::hf153b22edafcd3f0
20: 0x7f867e4e0e80 - rustc_driver::driver::phase_4_translate_to_llvm::h6ba7de0cd156758c
21: 0x7f867e4ad282 - rustc_driver::driver::compile_input::{{closure}}::h40e96e4888acf56e
22: 0x7f867e4df551 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::hfacc2eff9ff79a87
23: 0x7f867e4bd516 - rustc_driver::driver::phase_3_run_analysis_passes::h40916decd3c5ea98
24: 0x7f867e4ab220 - rustc_driver::driver::compile_input::hce31fd38e3368b28
25: 0x7f867e4f5ba4 - rustc_driver::run_compiler::hf9be2d0376d35b2a
26: 0x7f867e401f1b - std::panicking::try::do_call::h996393a0ecaa9347
27: 0x7f867e135dfa - __rust_maybe_catch_panic
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
28: 0x7f867e42a292 - >::call_box::h70b5304598a75c7d
29: 0x7f867e12b974 - std::sys::imp::thread::Thread::new::thread_start::hc16926852e47c008
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/liballoc/boxed.rs:623
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys_common/thread.rs:21
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/thread.rs:84
30: 0x7f8675f14453 - start_thread
31: 0x7f867ddee7de - __GI___clone
32: 0x0 -
```
While working on a StreamingIterator trait, I got a similar ICE about an OutputTypeParameterMismatch.
pub trait StreamingIterator<'a> {
type Item: 'a;
fn next(&'a mut self) -> Option<Self::Item>;
}
pub trait StreamingIteratorExt: for<'a> StreamingIterator<'a> {
fn for_each<F>(mut self, mut func: F) where
Self: Sized,
F: for<'a> FnMut(<Self as StreamingIterator<'a>>::Item)
{
while let Some(item) = self.next() {
func(item)
}
}
}
impl<I> StreamingIteratorExt for I where
I: for<'a>StreamingIterator<'a>
{}
impl<'a, I: Iterator + 'a> StreamingIterator<'a> for I {
type Item = I::Item;
fn next(&'a mut self) -> Option<Self::Item> {
self.next()
}
}
#[test]
fn test_basic_stuff() {
let it = vec![1i32,2,3].into_iter();
StreamingIteratorExt::for_each(it, |x| println!("{}", x));
}
And here's the error on Rust 1.21.0 stable
error: internal compiler error: src/librustc/traits/trans/mod.rs:75: Encountered error
`OutputTypeParameterMismatch(
Binder(<[closure@src/lib.rs:34:40: 34:61]
as std::ops::FnMut<(
<std::vec::IntoIter<i32> as StreamingIterator<'_>>::Item,
)>>),
Binder(<[closure@src/lib.rs:34:40: 34:61]
as std::ops::FnMut<(i32,)>>),
Sorts(ExpectedFound {
expected: i32,
found: <std::vec::IntoIter<i32> as StreamingIterator<'_>>::Item
})
)`
selecting `Binder(<[closure@src/lib.rs:34:40: 34:61] as std::ops::FnMut<(i32,)>>)` during trans
Note that <std::vec::IntoIter<i32> as StreamingIterator<'_>>::Item
= i32
Another minimal example (#53420):
trait Lt<'a> {
type T;
}
impl<'a> Lt<'a> for () {
type T = ();
}
fn main() {
let _:fn(<() as Lt<'_>>::T) = |()| {};
}
Is #33364 a duplicate of this?
closing as duplicate of #62529, which is where I will try to track future instances of this field of ICE.
The error is very long, and the example is not reduced (I tried, but the simple reduction worked ok, so no dice there). To reproduce, one can pull
https://github.com/frankmcsherry/differential-dataflow/commit/2fa719e78b6634159ed79bb5e0453e1230c5fae2
and then
cargo build --example cc
. I'm onThe same project ICEs on stable as well, but for a different reason (issue #29991; EDIT: Sorry, not actually this issue; rather, a different ICE that seems fixed in nightly).
I think the salient points are in the complaint
where it seems to be unhappy that it found a weird associated type rather than a
DifferenceIterator<u32>
. Of course, the associated type is thatDifferenceIterator<u32>
, which Rust knew at one point but seems to have lost track of, maybe? There is admittedly a bunch of horribleness going on with associated types, specifically faking out HKT for lifetimes through associated types of traits containing a lifetime implemented for references with that lifetime to the type in question. I can explain what it is doing if that helps, but given that it just ICEs differently in each release mode, maybe it's just time to delete it and try another way.Full backtrace: