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: const generic with default const expr specified before type generic causes compiler to crash #123954

Closed
w-utter opened this issue Apr 15, 2024 · 1 comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@w-utter
Copy link
Contributor

w-utter commented Apr 15, 2024

The order of terms does not seem to be checked before trying to make a well-formedness check on a struct if a const expr is present in the constants default value.

I tried this code:

#![feature(generic_const_exprs)]

struct A<const N: usize = {2 + 1}, B = u8> {
    _i: [B; N]
}

And this code (which gave the right error message in rust-analyzer):

#![feature(generic_const_exprs)]

struct A<const N: usize = {2 + 1}, B> {
    _i: [B; N]
}

and both cause ICE's during compilation.

If the order of the parameters are switched, or the const expr for N is removed, then the compiler does not crash and either the expected error is reported, or successfully compiles.

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (0d8b3346a 2024-04-14)
binary: rustc
commit-hash: 0d8b3346a3992ab11ea35ff0fb95a6864b91f797
commit-date: 2024-04-14
host: aarch64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.3
Backtrace

thread 'rustc' panicked at compiler/rustc_middle/src/ty/generic_args.rs:917:9:
Box<dyn Any>
stack backtrace:
   0:        0x103152cc0 - std::backtrace::Backtrace::create::hdc1994fcb4e8c481
   1:        0x10c850c08 - <alloc[b0dc11c95d7216a5]::boxed::Box<rustc_driver_impl[3cc9bf65ca00f6ee]::install_ice_hook::{closure#0}> as core[153a4a09f3d31382]::ops::function::Fn<(&dyn for<'a, 'b> core[153a4a09f3d31382]::ops::function::Fn<(&'a core[153a4a09f3d31382]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[153a4a09f3d31382]::marker::Sync + core[153a4a09f3d31382]::marker::Send, &core[153a4a09f3d31382]::panic::panic_info::PanicInfo)>>::call
   2:        0x10316bc74 - std::panicking::rust_panic_with_hook::h83d90448f6646b96
   3:        0x10c91590c - std[b70c874603df6a6]::panicking::begin_panic::<rustc_errors[8afa06678af9db0e]::ExplicitBug>::{closure#0}
   4:        0x10c915608 - std[b70c874603df6a6]::sys_common::backtrace::__rust_end_short_backtrace::<std[b70c874603df6a6]::panicking::begin_panic<rustc_errors[8afa06678af9db0e]::ExplicitBug>::{closure#0}, !>
   5:        0x1109db768 - std[b70c874603df6a6]::panicking::begin_panic::<rustc_errors[8afa06678af9db0e]::ExplicitBug>
   6:        0x10c8fb68c - <rustc_errors[8afa06678af9db0e]::diagnostic::BugAbort as rustc_errors[8afa06678af9db0e]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   7:        0x10d2e78c8 - rustc_middle[41002bb16f18dd76]::util::bug::opt_span_bug_fmt::<rustc_span[5f336a5c6a7d3b2b]::span_encoding::Span>::{closure#0}
   8:        0x10d2e6f38 - rustc_middle[41002bb16f18dd76]::ty::context::tls::with_opt::<rustc_middle[41002bb16f18dd76]::util::bug::opt_span_bug_fmt<rustc_span[5f336a5c6a7d3b2b]::span_encoding::Span>::{closure#0}, !>::{closure#0}
   9:        0x10d2e6f04 - rustc_middle[41002bb16f18dd76]::ty::context::tls::with_context_opt::<rustc_middle[41002bb16f18dd76]::ty::context::tls::with_opt<rustc_middle[41002bb16f18dd76]::util::bug::opt_span_bug_fmt<rustc_span[5f336a5c6a7d3b2b]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  10:        0x110a5ac9c - rustc_middle[41002bb16f18dd76]::util::bug::bug_fmt
  11:        0x110a5bbe8 - <rustc_middle[41002bb16f18dd76]::ty::generic_args::ArgFolder>::type_param_out_of_range
  12:        0x10d3237b4 - <rustc_middle[41002bb16f18dd76]::ty::generic_args::ArgFolder as rustc_type_ir[38402fc3e0792e7a]::fold::TypeFolder<rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt>>::fold_ty
  13:        0x10d2f5dcc - <&rustc_middle[41002bb16f18dd76]::ty::list::RawList<(), rustc_middle[41002bb16f18dd76]::ty::generic_args::GenericArg> as rustc_type_ir[38402fc3e0792e7a]::fold::TypeFoldable<rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[41002bb16f18dd76]::ty::generic_args::ArgFolder>
  14:        0x10d2eb6f4 - <rustc_type_ir[38402fc3e0792e7a]::predicate_kind::ClauseKind<rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt> as rustc_type_ir[38402fc3e0792e7a]::fold::TypeFoldable<rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[41002bb16f18dd76]::ty::generic_args::ArgFolder>
  15:        0x10d2fc044 - <rustc_middle[41002bb16f18dd76]::ty::sty::Binder<rustc_type_ir[38402fc3e0792e7a]::predicate_kind::PredicateKind<rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt>>>::try_map_bound::<<rustc_middle[41002bb16f18dd76]::ty::sty::Binder<rustc_type_ir[38402fc3e0792e7a]::predicate_kind::PredicateKind<rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt>> as rustc_type_ir[38402fc3e0792e7a]::fold::TypeSuperFoldable<rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt>>::try_super_fold_with<rustc_middle[41002bb16f18dd76]::ty::generic_args::ArgFolder>::{closure#0}, rustc_type_ir[38402fc3e0792e7a]::predicate_kind::PredicateKind<rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt>, !>
  16:        0x10d327eac - <rustc_middle[41002bb16f18dd76]::ty::predicate::Clause as rustc_type_ir[38402fc3e0792e7a]::fold::TypeFoldable<rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[41002bb16f18dd76]::ty::generic_args::ArgFolder>
  17:        0x10d3c0224 - <rustc_middle[41002bb16f18dd76]::ty::generics::GenericPredicates>::instantiate_into
  18:        0x10e0ff520 - <rustc_trait_selection[903f6ad29f897722]::traits::wf::WfPredicates>::nominal_obligations
  19:        0x10e0fc594 - <rustc_trait_selection[903f6ad29f897722]::traits::wf::WfPredicates as rustc_type_ir[38402fc3e0792e7a]::visit::TypeVisitor<rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt>>::visit_const
  20:        0x10e0fa2b4 - rustc_trait_selection[903f6ad29f897722]::traits::wf::obligations
  21:        0x10e0d6c10 - <rustc_trait_selection[903f6ad29f897722]::traits::fulfill::FulfillProcessor as rustc_data_structures[b85285f53c509edc]::obligation_forest::ObligationProcessor>::process_obligation
  22:        0x10e0bfd08 - <rustc_data_structures[b85285f53c509edc]::obligation_forest::ObligationForest<rustc_trait_selection[903f6ad29f897722]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[903f6ad29f897722]::traits::fulfill::FulfillProcessor>
  23:        0x10e0d1c7c - <rustc_trait_selection[903f6ad29f897722]::traits::fulfill::FulfillmentContext as rustc_infer[7476a3dc73ea6c0d]::traits::engine::TraitEngine>::select_where_possible
  24:        0x10cbbcc14 - rustc_hir_analysis[2c387bcc114465b6]::check::wfcheck::check_type_defn
  25:        0x10cbb9c4c - rustc_hir_analysis[2c387bcc114465b6]::check::wfcheck::check_well_formed
  26:        0x10db6f0d4 - rustc_query_impl[816618de84ba844]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[816618de84ba844]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[41002bb16f18dd76]::query::erase::Erased<[u8; 1usize]>>
  27:        0x10dbff0b8 - <rustc_query_impl[816618de84ba844]::query_impl::check_well_formed::dynamic_query::{closure#2} as core[153a4a09f3d31382]::ops::function::FnOnce<(rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt, rustc_hir[895c406cf2976696]::hir_id::OwnerId)>>::call_once
  28:        0x10db22064 - rustc_query_system[4617ca2eed8c4435]::query::plumbing::try_execute_query::<rustc_query_impl[816618de84ba844]::DynamicConfig<rustc_query_system[4617ca2eed8c4435]::query::caches::VecCache<rustc_hir[895c406cf2976696]::hir_id::OwnerId, rustc_middle[41002bb16f18dd76]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[816618de84ba844]::plumbing::QueryCtxt, true>
  29:        0x10dc02c9c - rustc_query_impl[816618de84ba844]::query_impl::check_well_formed::get_query_incr::__rust_end_short_backtrace
  30:        0x10cbe0068 - rustc_middle[41002bb16f18dd76]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[4617ca2eed8c4435]::query::caches::VecCache<rustc_hir[895c406cf2976696]::hir_id::OwnerId, rustc_middle[41002bb16f18dd76]::query::erase::Erased<[u8; 1usize]>>, ()>
  31:        0x10cbdce94 - <rustc_data_structures[b85285f53c509edc]::sync::parallel::ParallelGuard>::run::<core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>, rustc_data_structures[b85285f53c509edc]::sync::parallel::enabled::try_par_for_each_in<&[rustc_hir[895c406cf2976696]::hir::ImplItemId], rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed, <rustc_middle[41002bb16f18dd76]::hir::ModuleItems>::par_impl_items<rustc_hir_analysis[2c387bcc114465b6]::check::wfcheck::check_mod_type_wf::{closure#1}>::{closure#0}>::{closure#0}::{closure#2}::{closure#0}>
  32:        0x10cb96440 - <rustc_middle[41002bb16f18dd76]::hir::ModuleItems>::par_items::<rustc_hir_analysis[2c387bcc114465b6]::check::wfcheck::check_mod_type_wf::{closure#0}>
  33:        0x10cbc0458 - rustc_hir_analysis[2c387bcc114465b6]::check::wfcheck::check_mod_type_wf
  34:        0x10db6f0b0 - rustc_query_impl[816618de84ba844]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[816618de84ba844]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[41002bb16f18dd76]::query::erase::Erased<[u8; 1usize]>>
  35:        0x10dc693c0 - <rustc_query_impl[816618de84ba844]::query_impl::check_mod_type_wf::dynamic_query::{closure#2} as core[153a4a09f3d31382]::ops::function::FnOnce<(rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt, rustc_span[5f336a5c6a7d3b2b]::def_id::LocalModDefId)>>::call_once
  36:        0x10dacaf80 - rustc_query_system[4617ca2eed8c4435]::query::plumbing::try_execute_query::<rustc_query_impl[816618de84ba844]::DynamicConfig<rustc_query_system[4617ca2eed8c4435]::query::caches::DefaultCache<rustc_span[5f336a5c6a7d3b2b]::def_id::LocalModDefId, rustc_middle[41002bb16f18dd76]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[816618de84ba844]::plumbing::QueryCtxt, true>
  37:        0x10dd4ced4 - rustc_query_impl[816618de84ba844]::query_impl::check_mod_type_wf::get_query_incr::__rust_end_short_backtrace
  38:        0x10cbdd420 - <rustc_data_structures[b85285f53c509edc]::sync::parallel::ParallelGuard>::run::<(), rustc_data_structures[b85285f53c509edc]::sync::parallel::enabled::par_for_each_in<&rustc_hir[895c406cf2976696]::hir_id::OwnerId, &[rustc_hir[895c406cf2976696]::hir_id::OwnerId], <rustc_middle[41002bb16f18dd76]::hir::map::Map>::par_for_each_module<rustc_hir_analysis[2c387bcc114465b6]::check_crate::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}::{closure#0}>
  39:        0x10cba5a80 - rustc_hir_analysis[2c387bcc114465b6]::check_crate
  40:        0x10cfca310 - rustc_interface[7886f7beac8da793]::passes::analysis
  41:        0x10db72968 - rustc_query_impl[816618de84ba844]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[816618de84ba844]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[41002bb16f18dd76]::query::erase::Erased<[u8; 1usize]>>
  42:        0x10dd2c7f8 - <rustc_query_impl[816618de84ba844]::query_impl::analysis::dynamic_query::{closure#2} as core[153a4a09f3d31382]::ops::function::FnOnce<(rustc_middle[41002bb16f18dd76]::ty::context::TyCtxt, ())>>::call_once
  43:        0x10da89c10 - rustc_query_system[4617ca2eed8c4435]::query::plumbing::try_execute_query::<rustc_query_impl[816618de84ba844]::DynamicConfig<rustc_query_system[4617ca2eed8c4435]::query::caches::SingleCache<rustc_middle[41002bb16f18dd76]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[816618de84ba844]::plumbing::QueryCtxt, true>
  44:        0x10dc6c644 - rustc_query_impl[816618de84ba844]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  45:        0x10c88c194 - <rustc_interface[7886f7beac8da793]::queries::QueryResult<&rustc_middle[41002bb16f18dd76]::ty::context::GlobalCtxt>>::enter::<core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>, rustc_driver_impl[3cc9bf65ca00f6ee]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  46:        0x10c874c50 - <rustc_interface[7886f7beac8da793]::interface::Compiler>::enter::<rustc_driver_impl[3cc9bf65ca00f6ee]::run_compiler::{closure#0}::{closure#1}, core[153a4a09f3d31382]::result::Result<core[153a4a09f3d31382]::option::Option<rustc_interface[7886f7beac8da793]::queries::Linker>, rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>>
  47:        0x10c853628 - rustc_span[5f336a5c6a7d3b2b]::set_source_map::<core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>, rustc_interface[7886f7beac8da793]::interface::run_compiler<core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>, rustc_driver_impl[3cc9bf65ca00f6ee]::run_compiler::{closure#0}>::{closure#0}::{closure#0}>
  48:        0x10c88fbac - <scoped_tls[e07671f0187c90a4]::ScopedKey<rustc_span[5f336a5c6a7d3b2b]::SessionGlobals>>::set::<rustc_interface[7886f7beac8da793]::util::run_in_thread_with_globals<rustc_interface[7886f7beac8da793]::util::run_in_thread_pool_with_globals<rustc_interface[7886f7beac8da793]::interface::run_compiler<core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>, rustc_driver_impl[3cc9bf65ca00f6ee]::run_compiler::{closure#0}>::{closure#0}, core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>>::{closure#0}, core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>>
  49:        0x10c85bf14 - std[b70c874603df6a6]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[7886f7beac8da793]::util::run_in_thread_with_globals<rustc_interface[7886f7beac8da793]::util::run_in_thread_pool_with_globals<rustc_interface[7886f7beac8da793]::interface::run_compiler<core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>, rustc_driver_impl[3cc9bf65ca00f6ee]::run_compiler::{closure#0}>::{closure#0}, core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>>::{closure#0}, core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>>
  50:        0x10c8977b8 - <<std[b70c874603df6a6]::thread::Builder>::spawn_unchecked_<rustc_interface[7886f7beac8da793]::util::run_in_thread_with_globals<rustc_interface[7886f7beac8da793]::util::run_in_thread_pool_with_globals<rustc_interface[7886f7beac8da793]::interface::run_compiler<core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>, rustc_driver_impl[3cc9bf65ca00f6ee]::run_compiler::{closure#0}>::{closure#0}, core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>>::{closure#0}, core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[153a4a09f3d31382]::result::Result<(), rustc_span[5f336a5c6a7d3b2b]::ErrorGuaranteed>>::{closure#2} as core[153a4a09f3d31382]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:        0x1031746fc - std::sys::pal::unix::thread::Thread::new::thread_start::h56bc2156fc274a0f
  52:        0x188e02034 - __pthread_joiner_wake


rustc version: 1.79.0-nightly (0d8b3346a 2024-04-14)
platform: aarch64-apple-darwin

query stack during panic:
#0 [check_well_formed] checking that `A` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack

@w-utter w-utter added the C-bug Category: This is a bug. label Apr 15, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 15, 2024
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue requires-incomplete-features I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 15, 2024
@compiler-errors
Copy link
Member

I'm pretty sure this is a duplicate of #106994

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants