-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)A-trait-systemArea: Trait systemArea: Trait systemF-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATs`#![feature(generic_associated_types)]` a.k.a. GATsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Description
#![feature(generic_associated_types)]
trait Fut {
fn do_the_thing() -> usize;
}
trait WantsToReturnFuture<F> where F: Fut {
fn returns_future() -> F;
}
trait HasAssociatedTypes {
type Generic<F: Fut>: WantsToReturnFuture<F>;
fn get_generic() -> Self::Generic;
}
fn main() {
println!("Hello, world!");
}
causes this ICE:
$ RUST_BACKTRACE=1 cargo check
Checking bug_case v0.1.0 (file:///Users/pfaria/bug_case)
error: internal compiler error: librustc/ty/subst.rs:479: Type parameter `F/#1` (F/1) out of range when substituting (root type=Some(F)) substs=[Self]
thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:499:9
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
1: std::sys_common::backtrace::print
2: std::panicking::default_hook::{{closure}}
3: std::panicking::default_hook
4: rustc::util::common::panic_hook
5: std::panicking::rust_panic_with_hook
6: std::panicking::begin_panic
7: rustc_errors::Handler::span_bug
8: rustc::session::opt_span_bug_fmt::{{closure}}
9: rustc::ty::context::tls::with_opt::{{closure}}
10: rustc::ty::context::tls::with_context_opt
11: rustc::ty::context::tls::with_opt
12: rustc::session::opt_span_bug_fmt
13: rustc::session::span_bug_fmt
14: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
15: rustc::ty::fold::TypeFoldable::fold_with
16: rustc::ty::Predicate::subst_supertrait
17: <core::iter::Map<I, F> as core::iter::iterator::Iterator>::try_fold
18: rustc::traits::object_safety::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::predicates_reference_self
19: rustc::traits::object_safety::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::object_safety_violations_for_trait
20: <core::iter::FlatMap<I, U, F> as core::iter::iterator::Iterator>::next
21: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
22: rustc::traits::object_safety::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::object_safety_violations
23: rustc::traits::object_safety::is_object_safe_provider
24: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::is_object_safe<'tcx>>::compute
25: rustc::ty::context::tls::with_context
26: rustc::dep_graph::graph::DepGraph::with_task_impl
27: rustc::ty::context::tls::with_related_context
28: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
30: rustc::traits::select::SelectionContext::assemble_candidates
31: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
32: rustc::ty::context::tls::with_context
33: rustc::dep_graph::graph::DepGraph::with_anon_task
34: rustc::traits::select::SelectionContext::candidate_from_obligation
35: rustc::traits::select::SelectionContext::select
36: rustc::infer::InferCtxt::commit_if_ok
37: rustc::traits::project::opt_normalize_projection_type
38: rustc::traits::project::normalize_projection_type
39: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
40: rustc::ty::fold::TypeFoldable::fold_with
41: rustc::ty::fold::TypeFoldable::fold_with
42: rustc::ty::fold::TypeFoldable::fold_with
43: rustc::traits::project::normalize
44: rustc::traits::fully_normalize
45: rustc::ty::context::tls::with_context::{{closure}}
46: rustc::ty::context::tls::with_related_context
47: rustc::ty::context::GlobalCtxt::enter_local
48: rustc::traits::normalize_param_env_or_error
49: rustc::ty::param_env
50: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::param_env<'tcx>>::compute
51: rustc::ty::context::tls::with_context
52: rustc::dep_graph::graph::DepGraph::with_task_impl
53: rustc::ty::context::tls::with_related_context
54: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
55: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
56: rustc_typeck::check::wfcheck::for_id
57: rustc_typeck::check::wfcheck::check_item_well_formed
58: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::check_item_well_formed<'tcx>>::compute
59: rustc::ty::context::tls::with_context
60: rustc::dep_graph::graph::DepGraph::with_task_impl
61: rustc::ty::context::tls::with_related_context
62: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
63: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
64: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
65: rustc::hir::Crate::visit_all_item_likes
66: rustc::session::Session::track_errors
67: rustc::util::common::time
68: rustc_typeck::check_crate
69: rustc::ty::context::tls::enter_context
70: <std::thread::local::LocalKey<T>>::with
71: rustc::ty::context::TyCtxt::create_and_enter
72: rustc_driver::driver::compile_input
73: rustc_driver::run_compiler_with_pool
74: <scoped_tls::ScopedKey<T>>::set
75: syntax::with_globals
76: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
77: __rust_maybe_catch_panic
78: rustc_driver::run
79: rustc_driver::main
80: std::rt::lang_start::{{closure}}
81: std::panicking::try::do_call
82: __rust_maybe_catch_panic
83: std::rt::lang_start_internal
84: main
query stack during panic:
#0 [is_object_safe] determine object safety of trait `HasAssociatedTypes`
#1 [param_env] processing `HasAssociatedTypes`
#2 [check_item_well_formed] processing `HasAssociatedTypes`
end of query stack
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.28.0-nightly (e3bf634e0 2018-06-28) running on x86_64-apple-darwin
note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `bug_case`.
To learn more, run the command again with --verbose.
Version info:
$ rustc --version --verbose
rustc 1.28.0-nightly (e3bf634e0 2018-06-28)
binary: rustc
commit-hash: e3bf634e060bc2f8665878288bcea02008ca346e
commit-date: 2018-06-28
host: x86_64-apple-darwin
release: 1.28.0-nightly
LLVM version: 6.0
As a workaround I can instead implement this as:
trait Fut {
fn do_the_thing() -> usize;
}
trait WantsToReturnFuture<F> where F: Fut {
fn returns_future() -> F;
}
trait HasAssociatedTypes<F: Fut> {
type Generic: WantsToReturnFuture<F>;
fn get_generic() -> Self::Generic;
}
fn main() {
println!("Hello, world!");
}
with the downside being I need to require users of the trait to work with PhantomData
😦 .
Metadata
Metadata
Assignees
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)A-trait-systemArea: Trait systemArea: Trait systemF-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATs`#![feature(generic_associated_types)]` a.k.a. GATsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️