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

Internal Compiler Error with generic const parameters #136416

Open
setupminimal opened this issue Feb 2, 2025 · 1 comment
Open

Internal Compiler Error with generic const parameters #136416

setupminimal opened this issue Feb 2, 2025 · 1 comment
Labels
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@setupminimal
Copy link

setupminimal commented Feb 2, 2025

rustc-ice-2025-02-02T02_19_03-370381.txt

Code

#![feature(generic_const_exprs)]
struct State<const S : usize = {}> where[(); S] :;

I think this should be a parser error? I reduced it from a much more complicated test case that I think was hitting an actual logic bug, but this is the smallest program that triggers a failure in the same way.

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (8239a37f9 2025-02-01)
binary: rustc
commit-hash: 8239a37f9c0951a037cfc51763ea52a20e71e6bd
commit-date: 2025-02-01
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Error output

query stack during panic:
#0 [check_well_formed] checking that `State` 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
Backtrace

thread 'rustc' panicked at /rustc/8239a37f9c0951a037cfc51763ea52a20e71e6bd/compiler/rustc_type_ir/src/binder.rs:776:9:
const parameter `S/#0` (S/#0/0) out of range when instantiating args=[]
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt>>::const_param_out_of_range
   3: <rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt> as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
   4: <rustc_middle::ty::generics::GenericPredicates>::instantiate_into
   5: <rustc_trait_selection::traits::wf::WfPredicates>::nominal_obligations
   6: <rustc_trait_selection::traits::wf::WfPredicates as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_const
   7: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
   8: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
   9: <rustc_trait_selection::traits::fulfill::FulfillmentContext<rustc_trait_selection::traits::FulfillmentError> as rustc_infer::traits::engine::TraitEngine<rustc_trait_selection::traits::FulfillmentError>>::select_all_or_error
  10: rustc_hir_analysis::check::wfcheck::check_type_defn
  11: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
  12: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
  13: rustc_hir_analysis::check_crate
  14: rustc_interface::passes::run_required_analyses
  15: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  16: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  17: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}

@setupminimal setupminimal 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 2, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 2, 2025
@fmease fmease added the F-generic_const_exprs `#![feature(generic_const_exprs)]` label Feb 2, 2025
@theemathas
Copy link
Contributor

Another variant of the issue:

#![feature(generic_const_exprs)]
struct Foo;
struct State<const S: usize = Foo> where [(); S]:;

In the original code, the {} is being parsed as a block that produces the value (). The code should parse but produce a type error.

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 2, 2025
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. F-generic_const_exprs `#![feature(generic_const_exprs)]` 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

5 participants