Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE when using constraint on Generic Associated Type #52068

Closed
Nashenas88 opened this issue Jul 5, 2018 · 1 comment
Closed

ICE when using constraint on Generic Associated Type #52068

Nashenas88 opened this issue Jul 5, 2018 · 1 comment
Labels
A-GATs Area: Generic associated types (GATs) A-trait-system Area: Trait system F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Nashenas88
Copy link
Contributor

Nashenas88 commented Jul 5, 2018

The following code

#![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 😦 .

@estebank estebank added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-NLL Area: Non-lexical lifetimes (NLL) labels Jul 5, 2018
@matthewjasper matthewjasper added A-trait-system Area: Trait system and removed A-NLL Area: Non-lexical lifetimes (NLL) labels Jul 5, 2018
@kennytm
Copy link
Member

kennytm commented Jul 5, 2018

GATs is still not implemented yet, so this ICE is kinda expected.

Closing as duplicate of #49362.

@kennytm kennytm closed this as completed Jul 5, 2018
@Centril Centril added the F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs label Aug 5, 2019
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
@fmease fmease added A-trait-system Area: Trait system and removed A-trait-system Area: Trait system labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) A-trait-system Area: Trait system F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

6 participants