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 (Internal Compiler Error) triggered in code with const generics and enum initialization #116554

Closed
iamanonymouscs opened this issue Oct 9, 2023 · 0 comments
Labels
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.

Comments

@iamanonymouscs
Copy link

I got this code by our own fuzzing tool.
This ICE looks like #114317 ,and it also caused by generic_const_exprs😂

Code

#![feature(generic_const_exprs)]

const fn t<const N: usize>() -> u8 {

    N as u8

}

#[repr(u8)]

enum T<const N: u8 = { T::<0>::A as u8 + T::<0>::B as u8 }>

where

    [(); N as usize]:,

    T: ?Sized,

{

    A,

}

fn main() {
    A = t::<N>() as u8,

    B,

}

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

It can also be reproduced by nightly(2023-10-8)

Error output

error: expected one of `!`, `(`, `.`, `::`, `;`, `<`, `?`, or `}`, found `,`
  --> interesting/code.rs:26:23
   |
26 |     A = t::<N>() as u8,
   |                       ^ expected one of 8 possible tokens

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> interesting/code.rs:1:1
  |
1 | #![feature(generic_const_exprs)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> interesting/code.rs:1:12
  |
1 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

error: `?Trait` bounds are only permitted at the point where a type parameter is declared
  --> interesting/code.rs:17:8
   |
17 |     T: ?Sized,
   |        ^^^^^^

error: internal compiler error: compiler/rustc_middle/src/ty/generic_args.rs:942:9: const parameter `N/#0` (Const { ty: u8, kind: N/#0 }/0) out of range when substituting args=[]

thread 'rustc' panicked at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/compiler/rustc_errors/src/lib.rs:1635:9:
Box<dyn Any>
Backtrace

stack backtrace:
   0:     0x7fa258a4849c - std::backtrace_rs::backtrace::libunwind::trace::he43a6a3949163f8c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fa258a4849c - std::backtrace_rs::backtrace::trace_unsynchronized::h50db52ca99f692e7
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fa258a4849c - std::sys_common::backtrace::_print_fmt::hd37d595f2ceb2d3c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fa258a4849c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h678bbcf9da6d7d75
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fa258aae3fc - core::fmt::rt::Argument::fmt::h3a159adc080a6fc9
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/rt.rs:138:9
   5:     0x7fa258aae3fc - core::fmt::write::hb8eaf5a8e45a738e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/mod.rs:1094:21
   6:     0x7fa258a3b12e - std::io::Write::write_fmt::h9663fe36b2ee08f9
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/io/mod.rs:1714:15
   7:     0x7fa258a48284 - std::sys_common::backtrace::_print::hcd4834796ee88ad2
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fa258a48284 - std::sys_common::backtrace::print::h1360e9450e4f922a
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fa258a4b193 - std::panicking::default_hook::{{closure}}::h2609fa95cd5ab1f4
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:270:22
  10:     0x7fa258a4aeac - std::panicking::default_hook::h6d75f5747cab6e8d
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:290:9
  11:     0x7fa25bc15a3e - <alloc[98253621d83cbf53]::boxed::Box<rustc_driver_impl[566d207f92c3d9d2]::install_ice_hook::{closure#0}> as core[d28c4e8d9c4eebaa]::ops::function::Fn<(&dyn for<'a, 'b> core[d28c4e8d9c4eebaa]::ops::function::Fn<(&'a core[d28c4e8d9c4eebaa]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[d28c4e8d9c4eebaa]::marker::Sync + core[d28c4e8d9c4eebaa]::marker::Send, &core[d28c4e8d9c4eebaa]::panic::panic_info::PanicInfo)>>::call
  12:     0x7fa258a4b9be - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h05249de742e1768e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2021:9
  13:     0x7fa258a4b9be - std::panicking::rust_panic_with_hook::h57e78470c47c84de
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:711:13
  14:     0x7fa25c166521 - std[3759e478f3a6c4f2]::panicking::begin_panic::<rustc_errors[f3962fbeb8edb247]::ExplicitBug>::{closure#0}
  15:     0x7fa25c162206 - std[3759e478f3a6c4f2]::sys_common::backtrace::__rust_end_short_backtrace::<std[3759e478f3a6c4f2]::panicking::begin_panic<rustc_errors[f3962fbeb8edb247]::ExplicitBug>::{closure#0}, !>
  16:     0x7fa25c12c6c6 - std[3759e478f3a6c4f2]::panicking::begin_panic::<rustc_errors[f3962fbeb8edb247]::ExplicitBug>
  17:     0x7fa25c139134 - <rustc_errors[f3962fbeb8edb247]::HandlerInner>::bug::<alloc[98253621d83cbf53]::string::String>
  18:     0x7fa25c138fc6 - <rustc_errors[f3962fbeb8edb247]::Handler>::bug::<alloc[98253621d83cbf53]::string::String>
  19:     0x7fa25c1e05ac - rustc_middle[5935fdd60c99b3fe]::util::bug::opt_span_bug_fmt::<rustc_span[4c9f011e8b033119]::span_encoding::Span>::{closure#0}
  20:     0x7fa25c1dec5a - rustc_middle[5935fdd60c99b3fe]::ty::context::tls::with_opt::<rustc_middle[5935fdd60c99b3fe]::util::bug::opt_span_bug_fmt<rustc_span[4c9f011e8b033119]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7fa25c1dec28 - rustc_middle[5935fdd60c99b3fe]::ty::context::tls::with_context_opt::<rustc_middle[5935fdd60c99b3fe]::ty::context::tls::with_opt<rustc_middle[5935fdd60c99b3fe]::util::bug::opt_span_bug_fmt<rustc_span[4c9f011e8b033119]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7fa25a4e21b0 - rustc_middle[5935fdd60c99b3fe]::util::bug::bug_fmt
  23:     0x7fa25c15d620 - <rustc_middle[5935fdd60c99b3fe]::ty::generic_args::ArgFolder>::const_param_out_of_range
  24:     0x7fa25a7519ad - <rustc_middle[5935fdd60c99b3fe]::ty::generic_args::ArgFolder as rustc_type_ir[230b024fbe18c114]::fold::FallibleTypeFolder<rustc_middle[5935fdd60c99b3fe]::ty::context::TyCtxt>>::try_fold_const
  25:     0x7fa259d19971 - <&rustc_middle[5935fdd60c99b3fe]::ty::list::List<rustc_middle[5935fdd60c99b3fe]::ty::generic_args::GenericArg> as rustc_type_ir[230b024fbe18c114]::fold::TypeFoldable<rustc_middle[5935fdd60c99b3fe]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[5935fdd60c99b3fe]::ty::generic_args::ArgFolder>
  26:     0x7fa259d079f5 - <rustc_middle[5935fdd60c99b3fe]::ty::consts::Const as rustc_type_ir[230b024fbe18c114]::fold::TypeSuperFoldable<rustc_middle[5935fdd60c99b3fe]::ty::context::TyCtxt>>::try_super_fold_with::<rustc_middle[5935fdd60c99b3fe]::ty::generic_args::ArgFolder>
  27:     0x7fa259d06e66 - <rustc_middle[5935fdd60c99b3fe]::ty::generic_args::GenericArg as rustc_type_ir[230b024fbe18c114]::fold::TypeFoldable<rustc_middle[5935fdd60c99b3fe]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[5935fdd60c99b3fe]::ty::generic_args::ArgFolder>
  28:     0x7fa25a4ff7d0 - <rustc_middle[5935fdd60c99b3fe]::ty::generics::GenericPredicates>::instantiate_into
  29:     0x7fa259fb67e0 - <rustc_trait_selection[48b7f7e13fbddf35]::traits::wf::WfPredicates>::nominal_obligations
  30:     0x7fa259f98415 - <rustc_trait_selection[48b7f7e13fbddf35]::traits::wf::WfPredicates>::compute
  31:     0x7fa259f877a2 - <rustc_trait_selection[48b7f7e13fbddf35]::traits::fulfill::FulfillProcessor as rustc_data_structures[29929b1a5d4d6700]::obligation_forest::ObligationProcessor>::process_obligation
  32:     0x7fa259f83074 - <rustc_data_structures[29929b1a5d4d6700]::obligation_forest::ObligationForest<rustc_trait_selection[48b7f7e13fbddf35]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[48b7f7e13fbddf35]::traits::fulfill::FulfillProcessor>
  33:     0x7fa25a5da251 - <rustc_trait_selection[48b7f7e13fbddf35]::traits::engine::ObligationCtxt>::select_all_or_error
  34:     0x7fa25a526729 - rustc_hir_analysis[9bbb5014796bfef7]::check::wfcheck::check_type_defn
  35:     0x7fa25a50429e - rustc_hir_analysis[9bbb5014796bfef7]::check::wfcheck::check_well_formed
  36:     0x7fa259cea44c - rustc_query_impl[778daaabc67f3fff]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[778daaabc67f3fff]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5935fdd60c99b3fe]::query::erase::Erased<[u8; 0usize]>>
  37:     0x7fa25a5ed077 - rustc_query_system[e0e328d29a6e1c80]::query::plumbing::try_execute_query::<rustc_query_impl[778daaabc67f3fff]::DynamicConfig<rustc_query_system[e0e328d29a6e1c80]::query::caches::VecCache<rustc_hir[eee75afb991cf387]::hir_id::OwnerId, rustc_middle[5935fdd60c99b3fe]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[778daaabc67f3fff]::plumbing::QueryCtxt, false>
  38:     0x7fa25a5ecd84 - rustc_query_impl[778daaabc67f3fff]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7fa25adbcc00 - rustc_data_structures[29929b1a5d4d6700]::sync::par_for_each_in::<&[rustc_hir[eee75afb991cf387]::hir::ImplItemId], <rustc_middle[5935fdd60c99b3fe]::hir::ModuleItems>::par_impl_items<rustc_hir_analysis[9bbb5014796bfef7]::check::wfcheck::check_mod_type_wf::{closure#1}>::{closure#0}>
  40:     0x7fa25adbca7f - rustc_hir_analysis[9bbb5014796bfef7]::check::wfcheck::check_mod_type_wf
  41:     0x7fa25a94ba3c - rustc_query_impl[778daaabc67f3fff]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[778daaabc67f3fff]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5935fdd60c99b3fe]::query::erase::Erased<[u8; 0usize]>>
  42:     0x7fa25a94ba1e - <rustc_query_impl[778daaabc67f3fff]::query_impl::check_mod_type_wf::dynamic_query::{closure#2} as core[d28c4e8d9c4eebaa]::ops::function::FnOnce<(rustc_middle[5935fdd60c99b3fe]::ty::context::TyCtxt, rustc_span[4c9f011e8b033119]::def_id::LocalModDefId)>>::call_once
  43:     0x7fa25aba35e3 - rustc_query_system[e0e328d29a6e1c80]::query::plumbing::try_execute_query::<rustc_query_impl[778daaabc67f3fff]::DynamicConfig<rustc_query_system[e0e328d29a6e1c80]::query::caches::DefaultCache<rustc_span[4c9f011e8b033119]::def_id::LocalModDefId, rustc_middle[5935fdd60c99b3fe]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[778daaabc67f3fff]::plumbing::QueryCtxt, false>
  44:     0x7fa25b589234 - rustc_query_impl[778daaabc67f3fff]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7fa25addd8b3 - rustc_data_structures[29929b1a5d4d6700]::sync::par_for_each_in::<&[rustc_hir[eee75afb991cf387]::hir_id::OwnerId], <rustc_middle[5935fdd60c99b3fe]::hir::map::Map>::par_for_each_module<rustc_hir_analysis[9bbb5014796bfef7]::check_crate::{closure#5}::{closure#0}::{closure#0}>::{closure#0}>
  46:     0x7fa25addcc6e - rustc_hir_analysis[9bbb5014796bfef7]::check_crate
  47:     0x7fa25add349a - rustc_interface[5bdd18de9f5858d8]::passes::analysis
  48:     0x7fa25b11b70a - rustc_query_impl[778daaabc67f3fff]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[778daaabc67f3fff]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5935fdd60c99b3fe]::query::erase::Erased<[u8; 1usize]>>
  49:     0x7fa25b11b6f9 - <rustc_query_impl[778daaabc67f3fff]::query_impl::analysis::dynamic_query::{closure#2} as core[d28c4e8d9c4eebaa]::ops::function::FnOnce<(rustc_middle[5935fdd60c99b3fe]::ty::context::TyCtxt, ())>>::call_once
  50:     0x7fa25b2bdbe8 - rustc_query_system[e0e328d29a6e1c80]::query::plumbing::try_execute_query::<rustc_query_impl[778daaabc67f3fff]::DynamicConfig<rustc_query_system[e0e328d29a6e1c80]::query::caches::SingleCache<rustc_middle[5935fdd60c99b3fe]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[778daaabc67f3fff]::plumbing::QueryCtxt, false>
  51:     0x7fa25b2bd969 - rustc_query_impl[778daaabc67f3fff]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  52:     0x7fa25aec7973 - <rustc_interface[5bdd18de9f5858d8]::queries::QueryResult<&rustc_middle[5935fdd60c99b3fe]::ty::context::GlobalCtxt>>::enter::<core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>, rustc_driver_impl[566d207f92c3d9d2]::run_compiler::{closure#1}::{closure#2}::{closure#6}>
  53:     0x7fa25aec694a - <rustc_interface[5bdd18de9f5858d8]::interface::Compiler>::enter::<rustc_driver_impl[566d207f92c3d9d2]::run_compiler::{closure#1}::{closure#2}, core[d28c4e8d9c4eebaa]::result::Result<core[d28c4e8d9c4eebaa]::option::Option<rustc_interface[5bdd18de9f5858d8]::queries::Linker>, rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>
  54:     0x7fa25aec3c68 - std[3759e478f3a6c4f2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[5bdd18de9f5858d8]::util::run_in_thread_pool_with_globals<rustc_interface[5bdd18de9f5858d8]::interface::run_compiler<core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>, rustc_driver_impl[566d207f92c3d9d2]::run_compiler::{closure#1}>::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>
  55:     0x7fa25aec33ee - <<std[3759e478f3a6c4f2]::thread::Builder>::spawn_unchecked_<rustc_interface[5bdd18de9f5858d8]::util::run_in_thread_pool_with_globals<rustc_interface[5bdd18de9f5858d8]::interface::run_compiler<core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>, rustc_driver_impl[566d207f92c3d9d2]::run_compiler::{closure#1}>::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>::{closure#1} as core[d28c4e8d9c4eebaa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  56:     0x7fa258a56295 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::haadd4e5af2ab0d62
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  57:     0x7fa258a56295 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he4ba1fb09c16d807
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  58:     0x7fa258a56295 - std::sys::unix::thread::Thread::new::thread_start::he524ecf4b47bee95
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys/unix/thread.rs:108:17
  59:     0x7fa25891a609 - start_thread
  60:     0x7fa25883d133 - clone
  61:                0x0 - <unknown>

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.73.0 (cc66ad468 2023-10-03) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `T` 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
error: aborting due to 4 previous errors; 1 warning emitted

@iamanonymouscs iamanonymouscs 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 Oct 9, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 9, 2023
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

No branches or pull requests

3 participants