Closed
Description
Given this code:
pub struct Struct {}
pub trait Trait<'a> {
type Assoc;
fn method() -> Self::Assoc;
}
impl<'a> Trait<'a> for Struct {
type Assoc = ();
fn method() -> Self::Assoc {}
}
pub fn function<F, T>(f: F)
where
F: for<'a> FnOnce(<T as Trait<'a>>::Assoc),
T: for<'b> Trait<'b>,
{
f(T::method());
}
fn main() {
function::<_, Struct>(|_| {});
}
Trying to build results in an internal compiler error:
Compiling playground v0.0.1 (file:///playground)
error: internal compiler error: librustc/traits/trans/mod.rs:68: Encountered error `OutputTypeParameterMismatch(Binder(<[closure@src/main.rs:24:27: 24:33] as std::ops::FnOnce<(<Struct as Trait<'_>>::Assoc,)>>), Binder(<[closure@src/main.rs:24:27: 24:33] as std::ops::FnOnce<((),)>>), Sorts(ExpectedFound { expected: (), found: <Struct as Trait<'_>>::Assoc }))` selecting `Binder(<[closure@src/main.rs:24:27: 24:33] as std::ops::FnOnce<((),)>>)` during trans
thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:543:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to previous error
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: rustc 1.26.0 (a77568041 2018-05-07) running on x86_64-unknown-linux-gnu
note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
Note that cargo check
finishes without errors; it's only when building that the ICE occurs.
Meta
On my machine, rustc --version --verbose
:
rustc 1.26.0 (a77568041 2018-05-07)
binary: rustc
commit-hash: a7756804103447ea4e68a71ccf071e7ad8f7a03e
commit-date: 2018-05-07
host: x86_64-unknown-linux-gnu
release: 1.26.0
LLVM version: 6.0
On the playground, the ICE occurs on stable, beta, and nightly channels in both debug and release mode.
Backtrace generated by running RUST_BACKTRACE=1 cargo build
on my machine:
error: internal compiler error: librustc/traits/trans/mod.rs:68: Encountered error `OutputTypeParameterMismatch(Binder(<[closure@src/main.rs:24:27: 24:33] as std::ops::FnOnce<(<Struct as Trait<'_>>::Assoc,)>>), Binder(<[closure@src/main.rs:24:27: 24:33] as std::ops::FnOnce<((),)>>), Sorts(ExpectedFound { expected: (), found: <Struct as Trait<'_>>::Assoc }))` selecting `Binder(<[closure@src/main.rs:24:27: 24:33] as std::ops::FnOnce<((),)>>)` during trans
thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:543:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::print
at libstd/sys_common/backtrace.rs:71
at libstd/sys_common/backtrace.rs:59
2: std::panicking::default_hook::{{closure}}
at libstd/panicking.rs:207
3: std::panicking::default_hook
at libstd/panicking.rs:223
4: core::ops::function::Fn::call
5: std::panicking::rust_panic_with_hook
at libstd/panicking.rs:403
6: std::panicking::begin_panic
7: rustc_errors::Handler::bug
8: rustc::session::opt_span_bug_fmt::{{closure}}
9: rustc::ty::context::tls::with_opt::{{closure}}
10: <std::thread::local::LocalKey<T>>::try_with
11: <std::thread::local::LocalKey<T>>::with
12: rustc::ty::context::tls::with
13: rustc::ty::context::tls::with_opt
14: rustc::session::opt_span_bug_fmt
15: rustc::session::bug_fmt
16: <std::thread::local::LocalKey<T>>::with
17: rustc::ty::context::GlobalCtxt::enter_local
18: rustc::traits::trans::trans_fulfill_obligation
19: rustc::dep_graph::graph::DepGraph::with_task_impl
20: rustc_errors::Handler::track_diagnostics
21: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
22: rustc::ty::maps::<impl rustc::ty::maps::queries::trans_fulfill_obligation<'tcx>>::force
23: rustc::ty::maps::<impl rustc::ty::maps::queries::trans_fulfill_obligation<'tcx>>::try_get
24: rustc::ty::maps::TyCtxtAt::trans_fulfill_obligation
25: rustc::ty::instance::Instance::resolve
26: <rustc_mir::monomorphize::collector::MirNeighborCollector<'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_terminator_kind
27: rustc_mir::monomorphize::collector::collect_items_rec
28: rustc_mir::monomorphize::collector::collect_items_rec
29: rustc_mir::monomorphize::collector::collect_crate_mono_items
30: rustc::util::common::time
31: rustc_trans::base::collect_and_partition_translation_items
32: rustc::dep_graph::graph::DepGraph::with_task_impl
33: rustc_errors::Handler::track_diagnostics
34: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
35: rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::force
36: rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::try_get
37: rustc::ty::maps::TyCtxtAt::collect_and_partition_translation_items
38: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::collect_and_partition_translation_items
39: rustc_trans::base::trans_crate
40: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
41: rustc::util::common::time
42: rustc_driver::driver::phase_4_translate_to_llvm
43: rustc_driver::driver::compile_input::{{closure}}
44: <std::thread::local::LocalKey<T>>::with
45: <std::thread::local::LocalKey<T>>::with
46: rustc::ty::context::TyCtxt::create_and_enter
47: rustc_driver::driver::compile_input
48: rustc_driver::run_compiler_impl
49: syntax::with_globals
error: aborting due to previous error