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 crash #98702

Closed
497e0bdf29873 opened this issue Jun 30, 2022 · 6 comments · Fixed by #99730
Closed

GAT crash #98702

497e0bdf29873 opened this issue Jun 30, 2022 · 6 comments · Fixed by #99730
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. 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

@497e0bdf29873
Copy link

The compiler crashes with an internal error on the following MWE of a GAT workaround attempt to current const generics limitations, i.e., not being able to just do {N*N} (or rather pow(2, N) in my real code). There is no crash if T is fixed to some type, i.e, GATs are not needed, however, the idea would be to limit “trait bound bloat” by only having to repeat NodeLookup : NodeT<N> throughout the code without T and its trait bounds, etc..

Code

#![feature(generic_associated_types)]

struct Node<T, const N : usize, const P : usize> {
    data : [[T; N]; P]
}

trait NodeT<const N : usize> {
    type Node<T>;
}

struct NodeLookup;

macro_rules! impl_lookup {
    ($($n:literal)*) => { $(
        impl NodeT<$n> for NodeLookup {
            type Node<T> = Node<T, $n, {$n*$n}>;
        }
    )* }
}

impl_lookup!(1 2 3 4);

fn main() {
}

Meta

rustc --version --verbose:

rustc 1.64.0-nightly (ddcbba036 2022-06-29)
binary: rustc
commit-hash: ddcbba036aee08f0709f98a92a342a278eae5c05
commit-date: 2022-06-29
host: aarch64-apple-darwin
release: 1.64.0-nightly
LLVM version: 14.0.6

Error output

error: internal compiler error: /rustc/ddcbba036aee08f0709f98a92a342a278eae5c05/compiler/rustc_middle/src/ty/fold.rs:756:29: unexpected bound ty in binder: BoundTy { var: 0, kind: Param("T") }

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/ddcbba036aee08f0709f98a92a342a278eae5c05/compiler/rustc_errors/src/lib.rs:1391:9
stack backtrace:
   0:        0x10111ff18 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h094534642b0a9537
   1:        0x10116cab4 - core::fmt::write::he79b8cc7db6af844
   2:        0x101112f7c - std::io::Write::write_fmt::h9824dce6dc163d2c
   3:        0x101122b5c - std::panicking::default_hook::{{closure}}::h3cd2810b91c69805
   4:        0x1011228c4 - std::panicking::default_hook::hddba5976d502416b
   5:        0x1085cb5f4 - rustc_driver[f51bca0c71cdd034]::DEFAULT_HOOK::{closure#0}::{closure#0}
   6:        0x10112312c - std::panicking::rust_panic_with_hook::h94731f9d6cc315f3
   7:        0x10c0aa758 - std[ec5bd7e3f33f3027]::panicking::begin_panic::<rustc_errors[77f389aec993a0ef]::ExplicitBug>::{closure#0}
   8:        0x10c0a86cc - std[ec5bd7e3f33f3027]::sys_common::backtrace::__rust_end_short_backtrace::<std[ec5bd7e3f33f3027]::panicking::begin_panic<rustc_errors[77f389aec993a0ef]::ExplicitBug>::{closure#0}, !>
   9:        0x10c509f04 - std[ec5bd7e3f33f3027]::panicking::begin_panic::<rustc_errors[77f389aec993a0ef]::ExplicitBug>
  10:        0x10c00bc50 - std[ec5bd7e3f33f3027]::panic::panic_any::<rustc_errors[77f389aec993a0ef]::ExplicitBug>
  11:        0x10c0064d4 - <rustc_errors[77f389aec993a0ef]::HandlerInner>::bug::<&alloc[cde6e00f4e7b7126]::string::String>
  12:        0x10c0060a0 - <rustc_errors[77f389aec993a0ef]::Handler>::bug::<&alloc[cde6e00f4e7b7126]::string::String>
  13:        0x10c0be8b0 - rustc_middle[9331575e900b72f8]::ty::context::tls::with_opt::<rustc_middle[9331575e900b72f8]::util::bug::opt_span_bug_fmt<rustc_span[b8e5c2445f520dcd]::span_encoding::Span>::{closure#0}, ()>
  14:        0x10c0c0408 - rustc_middle[9331575e900b72f8]::util::bug::opt_span_bug_fmt::<rustc_span[b8e5c2445f520dcd]::span_encoding::Span>
  15:        0x10c50c650 - rustc_middle[9331575e900b72f8]::util::bug::bug_fmt
  16:        0x10be5ce1c - <rustc_middle[9331575e900b72f8]::ty::context::TyCtxt>::replace_late_bound_regions_uncached::<rustc_middle[9331575e900b72f8]::ty::PredicateKind, <rustc_middle[9331575e900b72f8]::ty::context::TyCtxt>::replace_late_bound_regions<rustc_middle[9331575e900b72f8]::ty::PredicateKind, <rustc_middle[9331575e900b72f8]::ty::context::TyCtxt>::anonymize_late_bound_regions<rustc_middle[9331575e900b72f8]::ty::PredicateKind>::{closure#0}>::{closure#0}>::{closure#0}
  17:        0x10c08da1c - <rustc_middle[9331575e900b72f8]::ty::fold::BoundVarReplacer as rustc_middle[9331575e900b72f8]::ty::fold::TypeFolder>::fold_ty
  18:        0x10be40f88 - <&rustc_middle[9331575e900b72f8]::ty::list::List<rustc_middle[9331575e900b72f8]::ty::subst::GenericArg> as rustc_middle[9331575e900b72f8]::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle[9331575e900b72f8]::ty::fold::BoundVarReplacer>
  19:        0x10be7082c - <rustc_middle[9331575e900b72f8]::ty::PredicateKind as rustc_middle[9331575e900b72f8]::ty::fold::TypeFoldable>::fold_with::<rustc_middle[9331575e900b72f8]::ty::fold::BoundVarReplacer>
  20:        0x10be582cc - <rustc_middle[9331575e900b72f8]::ty::context::TyCtxt>::anonymize_late_bound_regions::<rustc_middle[9331575e900b72f8]::ty::PredicateKind>
  21:        0x10bdfe5f0 - <rustc_middle[9331575e900b72f8]::ty::erase_regions::RegionEraserVisitor as rustc_middle[9331575e900b72f8]::ty::fold::FallibleTypeFolder>::try_fold_binder::<rustc_middle[9331575e900b72f8]::ty::PredicateKind>
  22:        0x10be3effc - <&rustc_middle[9331575e900b72f8]::ty::list::List<rustc_middle[9331575e900b72f8]::ty::Predicate> as rustc_middle[9331575e900b72f8]::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle[9331575e900b72f8]::ty::erase_regions::RegionEraserVisitor>
  23:        0x10bdbf7f4 - <rustc_trait_selection[b4f82a16548071ea]::traits::project::AssocTypeNormalizer as rustc_middle[9331575e900b72f8]::ty::fold::TypeFolder>::fold_const
  24:        0x10be44734 - <&rustc_middle[9331575e900b72f8]::ty::list::List<rustc_middle[9331575e900b72f8]::ty::subst::GenericArg> as rustc_middle[9331575e900b72f8]::ty::fold::TypeFoldable>::try_fold_with::<rustc_trait_selection[b4f82a16548071ea]::traits::project::AssocTypeNormalizer>
  25:        0x10be71208 - <rustc_middle[9331575e900b72f8]::ty::Ty as rustc_middle[9331575e900b72f8]::ty::fold::TypeSuperFoldable>::super_fold_with::<rustc_trait_selection[b4f82a16548071ea]::traits::project::AssocTypeNormalizer>
  26:        0x10bdbb148 - <rustc_trait_selection[b4f82a16548071ea]::traits::project::AssocTypeNormalizer as rustc_middle[9331575e900b72f8]::ty::fold::TypeFolder>::fold_ty
  27:        0x10bdc04dc - rustc_trait_selection[b4f82a16548071ea]::traits::project::opt_normalize_projection_type
  28:        0x10bdbbd54 - rustc_trait_selection[b4f82a16548071ea]::traits::project::normalize_projection_type
  29:        0x10bdbaf18 - <rustc_trait_selection[b4f82a16548071ea]::traits::project::AssocTypeNormalizer as rustc_middle[9331575e900b72f8]::ty::fold::TypeFolder>::fold_ty
  30:        0x10ab6613c - <&rustc_middle[9331575e900b72f8]::ty::list::List<rustc_middle[9331575e900b72f8]::ty::subst::GenericArg> as rustc_middle[9331575e900b72f8]::ty::fold::TypeFoldable>::try_fold_with::<rustc_trait_selection[b4f82a16548071ea]::traits::project::AssocTypeNormalizer>
  31:        0x10abe2fe8 - <rustc_middle[9331575e900b72f8]::ty::PredicateKind as rustc_middle[9331575e900b72f8]::ty::fold::TypeFoldable>::try_fold_with::<rustc_trait_selection[b4f82a16548071ea]::traits::project::AssocTypeNormalizer>
  32:        0x10abf0724 - <rustc_middle[9331575e900b72f8]::ty::Predicate as rustc_middle[9331575e900b72f8]::ty::fold::TypeSuperFoldable>::super_fold_with::<rustc_trait_selection[b4f82a16548071ea]::traits::project::AssocTypeNormalizer>
  33:        0x10ac5a1f4 - <rustc_trait_selection[b4f82a16548071ea]::traits::project::AssocTypeNormalizer>::fold::<rustc_middle[9331575e900b72f8]::ty::Predicate>
  34:        0x10ac5e55c - rustc_trait_selection[b4f82a16548071ea]::traits::project::normalize::<rustc_middle[9331575e900b72f8]::ty::Predicate>
  35:        0x10abb0a68 - <rustc_infer[45d40a8feb40e3fa]::infer::InferCtxtBuilder>::enter::<core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>, rustc_typeck[67235f765db4edde]::check::compare_method::check_type_bounds::{closure#2}>
  36:        0x10ac2b1f4 - rustc_typeck[67235f765db4edde]::check::compare_method::check_type_bounds
  37:        0x10ac20290 - rustc_typeck[67235f765db4edde]::check::compare_method::compare_ty_impl
  38:        0x10aac793c - rustc_typeck[67235f765db4edde]::check::check::check_item_type
  39:        0x10aacaca0 - rustc_typeck[67235f765db4edde]::check::check::check_mod_item_types
  40:        0x10b386704 - rustc_query_system[e247dafbc3a4ff98]::query::plumbing::try_execute_query::<rustc_query_impl[90b84e005b379a12]::plumbing::QueryCtxt, rustc_query_system[e247dafbc3a4ff98]::query::caches::DefaultCache<rustc_span[b8e5c2445f520dcd]::def_id::LocalDefId, ()>>
  41:        0x10b42c6a0 - rustc_query_system[e247dafbc3a4ff98]::query::plumbing::get_query::<rustc_query_impl[90b84e005b379a12]::queries::check_mod_item_types, rustc_query_impl[90b84e005b379a12]::plumbing::QueryCtxt>
  42:        0x10abdb8c8 - <rustc_session[24b5e5485ce21942]::session::Session>::time::<(), rustc_typeck[67235f765db4edde]::check_crate::{closure#6}>
  43:        0x10ab8dfc4 - rustc_typeck[67235f765db4edde]::check_crate
  44:        0x108656888 - rustc_interface[5cb818030c646550]::passes::analysis
  45:        0x10b3b96f8 - rustc_query_system[e247dafbc3a4ff98]::query::plumbing::try_execute_query::<rustc_query_impl[90b84e005b379a12]::plumbing::QueryCtxt, rustc_query_system[e247dafbc3a4ff98]::query::caches::DefaultCache<(), core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>>>
  46:        0x10b457934 - rustc_query_system[e247dafbc3a4ff98]::query::plumbing::get_query::<rustc_query_impl[90b84e005b379a12]::queries::analysis, rustc_query_impl[90b84e005b379a12]::plumbing::QueryCtxt>
  47:        0x10858d7e8 - <rustc_interface[5cb818030c646550]::passes::QueryContext>::enter::<rustc_driver[f51bca0c71cdd034]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>>
  48:        0x1085717a4 - <rustc_interface[5cb818030c646550]::interface::Compiler>::enter::<rustc_driver[f51bca0c71cdd034]::run_compiler::{closure#1}::{closure#2}, core[c82fdd3b01836480]::result::Result<core[c82fdd3b01836480]::option::Option<rustc_interface[5cb818030c646550]::queries::Linker>, rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>>
  49:        0x1085bd41c - rustc_span[b8e5c2445f520dcd]::with_source_map::<core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>, rustc_interface[5cb818030c646550]::interface::create_compiler_and_run<core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>, rustc_driver[f51bca0c71cdd034]::run_compiler::{closure#1}>::{closure#1}>
  50:        0x108571f9c - <scoped_tls[c0f860eaab270d6e]::ScopedKey<rustc_span[b8e5c2445f520dcd]::SessionGlobals>>::set::<rustc_interface[5cb818030c646550]::interface::run_compiler<core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>, rustc_driver[f51bca0c71cdd034]::run_compiler::{closure#1}>::{closure#0}, core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>>
  51:        0x10858fdd8 - std[ec5bd7e3f33f3027]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[5cb818030c646550]::util::run_in_thread_pool_with_globals<rustc_interface[5cb818030c646550]::interface::run_compiler<core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>, rustc_driver[f51bca0c71cdd034]::run_compiler::{closure#1}>::{closure#0}, core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>>::{closure#0}, core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>>
  52:        0x1085904a4 - <<std[ec5bd7e3f33f3027]::thread::Builder>::spawn_unchecked_<rustc_interface[5cb818030c646550]::util::run_in_thread_pool_with_globals<rustc_interface[5cb818030c646550]::interface::run_compiler<core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>, rustc_driver[f51bca0c71cdd034]::run_compiler::{closure#1}>::{closure#0}, core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>>::{closure#0}, core[c82fdd3b01836480]::result::Result<(), rustc_errors[77f389aec993a0ef]::ErrorGuaranteed>>::{closure#1} as core[c82fdd3b01836480]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  53:        0x10112b58c - std::sys::unix::thread::Thread::new::thread_start::h46c89a4ac1d16d95
  54:        0x1a242226c - __pthread_deallocate

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.64.0-nightly (ddcbba036 2022-06-29) running on aarch64-apple-darwin

query stack during panic:
#0 [check_mod_item_types] checking item types in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error
Backtrace

$ RUST_BACKTRACE=1 rustc crash.rs 
error: internal compiler error: /rustc/ddcbba036aee08f0709f98a92a342a278eae5c05/compiler/rustc_middle/src/ty/fold.rs:756:29: unexpected bound ty in binder: BoundTy { var: 0, kind: Param("T") }

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/ddcbba036aee08f0709f98a92a342a278eae5c05/compiler/rustc_errors/src/lib.rs:1391:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug::<&alloc::string::String>
   3: <rustc_errors::Handler>::bug::<&alloc::string::String>
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_middle::ty::context::TyCtxt>::replace_late_bound_regions_uncached::<rustc_middle::ty::PredicateKind, <rustc_middle::ty::context::TyCtxt>::replace_late_bound_regions<rustc_middle::ty::PredicateKind, <rustc_middle::ty::context::TyCtxt>::anonymize_late_bound_regions<rustc_middle::ty::PredicateKind>::{closure#0}>::{closure#0}>::{closure#0}
   8: <rustc_middle::ty::fold::BoundVarReplacer as rustc_middle::ty::fold::TypeFolder>::fold_ty
   9: <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_middle::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle::ty::fold::BoundVarReplacer>
  10: <rustc_middle::ty::PredicateKind as rustc_middle::ty::fold::TypeFoldable>::fold_with::<rustc_middle::ty::fold::BoundVarReplacer>
  11: <rustc_middle::ty::context::TyCtxt>::anonymize_late_bound_regions::<rustc_middle::ty::PredicateKind>
  12: <rustc_middle::ty::erase_regions::RegionEraserVisitor as rustc_middle::ty::fold::FallibleTypeFolder>::try_fold_binder::<rustc_middle::ty::PredicateKind>
  13: <&rustc_middle::ty::list::List<rustc_middle::ty::Predicate> as rustc_middle::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle::ty::erase_regions::RegionEraserVisitor>
  14: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_const
  15: <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_middle::ty::fold::TypeFoldable>::try_fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
  16: <rustc_middle::ty::Ty as rustc_middle::ty::fold::TypeSuperFoldable>::super_fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
  17: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  18: rustc_trait_selection::traits::project::opt_normalize_projection_type
  19: rustc_trait_selection::traits::project::normalize_projection_type
  20: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  21: <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_middle::ty::fold::TypeFoldable>::try_fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
  22: <rustc_middle::ty::PredicateKind as rustc_middle::ty::fold::TypeFoldable>::try_fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
  23: <rustc_middle::ty::Predicate as rustc_middle::ty::fold::TypeSuperFoldable>::super_fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
  24: <rustc_trait_selection::traits::project::AssocTypeNormalizer>::fold::<rustc_middle::ty::Predicate>
  25: rustc_trait_selection::traits::project::normalize::<rustc_middle::ty::Predicate>
  26: <rustc_infer::infer::InferCtxtBuilder>::enter::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_typeck::check::compare_method::check_type_bounds::{closure#2}>
  27: rustc_typeck::check::compare_method::check_type_bounds
  28: rustc_typeck::check::compare_method::compare_ty_impl
  29: rustc_typeck::check::check::check_item_type
  30: rustc_typeck::check::check::check_mod_item_types
  31: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  32: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::check_mod_item_types, rustc_query_impl::plumbing::QueryCtxt>
  33: <rustc_session::session::Session>::time::<(), rustc_typeck::check_crate::{closure#6}>
  34: rustc_typeck::check_crate
  35: rustc_interface::passes::analysis
  36: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorGuaranteed>>>
  37: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  38: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  39: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  40: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  41: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
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.64.0-nightly (ddcbba036 2022-06-29) running on aarch64-apple-darwin

query stack during panic:
#0 [check_mod_item_types] checking item types in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

@497e0bdf29873 497e0bdf29873 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 Jun 30, 2022
@Rageking8
Copy link
Contributor

@rustbot label +requires-nightly

@rustbot rustbot added the requires-nightly This issue requires a nightly compiler in some way. label Jun 30, 2022
matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Jun 30, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 30, 2022
@voidc
Copy link
Contributor

voidc commented Jul 1, 2022

Minimized:

#![feature(generic_associated_types)]

trait Foo {
    type Assoc<T>;
}

impl Foo for () {
    type Assoc<T> = [T; 2*2];
}

Playground

@BoxyUwU BoxyUwU added the F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs label Jul 1, 2022
@jackh726
Copy link
Member

jackh726 commented Jul 2, 2022

@lcnr ^

@jackh726
Copy link
Member

jackh726 commented Jul 2, 2022

The problem is we end up with for<T> <() as Foo>::Assoc<T> = [T; 2*2] in the param_env.

When folding consts, we eval them (here:

constant.eval(self.selcx.tcx(), self.param_env)
)

try_eval_inner calls erase_regions here:

.erase_regions(param_env)

Part of erasing regions is anonymizing late-bound regions (here:

let u = self.tcx.anonymize_late_bound_regions(t);
)

In anonymize_late_bound_regions (

pub fn anonymize_late_bound_regions<T>(self, sig: Binder<'tcx, T>) -> Binder<'tcx, T>
), we delegate to replace_late_bound_regions, which returns T instead of Binder<T>, which "makes sense" if we assume that there are no bound tys or consts.

It's a bit of a tug of war game between wanting to catch unexpected bound tys/consts, and "delegating" bound variable binding higher up. Probably the right thing to do for now would be to revert the bound variable handling to just not panic if we encounter bound tys or consts.

@lcnr
Copy link
Contributor

lcnr commented Jul 4, 2022

Part of erasing regions is anonymizing late-bound regions here

I guess alternatively, just anonymize all bound variables at this point? don't think regions should be special, going to try that

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. 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.

9 participants