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

GAT ICE: missing generic associated type in trait path #81712

Closed
juntyr opened this issue Feb 3, 2021 · 2 comments · Fixed by #82752
Closed

GAT ICE: missing generic associated type in trait path #81712

juntyr opened this issue Feb 3, 2021 · 2 comments · Fixed by #82752
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@juntyr
Copy link
Contributor

juntyr commented Feb 3, 2021

This ICE is related to #44265:

Code

#![feature(generic_associated_types)]

// The cyclic dependency between trait A and B compiles as expected
trait A {
    type BType: B<AType = Self>;
}

trait B {
    type AType: A<BType = Self>;
}

// rustc crashes on the generic cyclic dependency between traits C and D
trait C {
    type DType<T>: D<T, CType = Self>;
}
trait D<T> {
    type CType: C<DType = Self>;
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:528:17: type parameter `T/#1` (T/1) out of range when substituting, substs=[<Self as D<T>>::CType]

thread 'rustc' panicked at 'Box<Any>', /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/compiler/rustc_errors/src/lib.rs:891:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.
Backtrace

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:528:17: type parameter `T/#1` (T/1) out of range when substituting, substs=[<Self as D<T>>::CType]

thread 'rustc' panicked at 'Box<Any>', /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/compiler/rustc_errors/src/lib.rs:891:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::span_bug
   2: rustc_errors::Handler::span_bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::span_bug_fmt
   8: <rustc_middle::ty::subst::SubstFolder as rustc_middle::ty::fold::TypeFolder>::fold_ty
   9: rustc_middle::ty::fold::TypeFoldable::fold_with
  10: rustc_middle::ty::fold::TypeFoldable::fold_with
  11: rustc_middle::ty::subst::Subst::subst
  12: rustc_middle::ty::GenericPredicates::instantiate_into
  13: rustc_middle::ty::GenericPredicates::instantiate
  14: rustc_trait_selection::traits::wf::WfPredicates::nominal_obligations
  15: rustc_trait_selection::traits::wf::WfPredicates::compute_projection
  16: rustc_trait_selection::traits::wf::predicate_obligations
  17: rustc_typeck::check::wfcheck::check_associated_type_bounds
  18: rustc_infer::infer::InferCtxtBuilder::enter
  19: rustc_typeck::check::wfcheck::check_associated_item
  20: rustc_typeck::check::wfcheck::check_trait_item
  21: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_trait_item_well_formed>::compute
  22: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  24: rustc_data_structures::stack::ensure_sufficient_stack
  25: rustc_query_system::query::plumbing::get_query_impl
  26: rustc_query_system::query::plumbing::ensure_query_impl
  27: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  28: rustc_hir::hir::Crate::par_visit_all_item_likes
  29: rustc_session::session::Session::track_errors
  30: rustc_typeck::check_crate
  31: rustc_interface::passes::analysis
  32: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  33: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  34: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  35: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  36: rustc_query_system::query::plumbing::get_query_impl
  37: rustc_interface::passes::QueryContext::enter
  38: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  39: rustc_span::with_source_map
  40: rustc_interface::interface::create_compiler_and_run
  41: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [check_trait_item_well_formed] checking that `D::CType` is well-formed
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 1 warning emitted

Ideally, C<DType<T> = Self> would compile, but generic associated types in trait paths are currently not implemented. Maybe rustc could give a nice error message when the <T> is missing.

@juntyr juntyr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 3, 2021
@jonas-schievink jonas-schievink added the F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs label Feb 3, 2021
@jackh726
Copy link
Member

jackh726 commented Feb 3, 2021

Duplicate to #79768 and related heavily to others. But this has a nice minimal repro, so worth leaving open. Probably fixed by #79554.

@Alexendoo Alexendoo added the requires-nightly This issue requires a nightly compiler in some way. label Feb 4, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 5, 2021
@cynecx
Copy link
Contributor

cynecx commented Feb 5, 2021

Probably fixed by #79554.

I've tested this locally and I can confirm that #79554 fixes this (with this change: C<DType<T> = Self>).

@jackh726 jackh726 added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 5, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Mar 5, 2021
Add a regression test for issue-81712

Fixes rust-lang#81712, also fixes rust-lang#79768 as duplicate.
r? ``@jackh726``
m-ou-se added a commit to m-ou-se/rust that referenced this issue Mar 5, 2021
Add a regression test for issue-81712

Fixes rust-lang#81712, also fixes rust-lang#79768 as duplicate.
r? ```@jackh726```
@bors bors closed this as completed in e89276b Mar 5, 2021
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 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) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants