Skip to content

[ICE] with const generics in subst.rs #71922

Closed
@leonardo-m

Description

This is wrong code because it lacks the const_generics feature request, and because currently calling a const function in this context isn't allowed:

const fn foo(n: usize) -> usize { n * 2 }
fn bar<const N: usize>() -> [u32; foo(N)] {
    [0; foo(N)]
}
fn main() {}

Gives:

error[E0658]: const generics are unstable
 --> ...\test.rs:2:14
  |
2 | fn bar<const N: usize>() -> [u32; foo(N)] {
  |              ^
  |
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
  = help: add `#![feature(const_generics)]` to the crate attributes to enable

error: internal compiler error: src\librustc_middle\ty\subst.rs:581: const parameter `N/#0` (Const { ty: usize, val: Param(N/#0) }/0) out of range when substituting substs=[]

thread 'rustc' panicked at 'Box<Any>', /rustc/2454a68cfbb63aa7b8e09fe05114d5f98b2f9740\src\libstd\macros.rs:13:23
stack backtrace:
  ...

note: rustc 1.45.0-nightly (2454a68cf 2020-05-04) running on x86_64-pc-windows-gnu

query stack during panic:
#0 [const_eval_raw] const-evaluating `bar::{{constant}}#0`
#1 [const_eval_validated] const-evaluating + checking `bar::{{constant}}#0`
#2 [const_eval_validated] const-evaluating + checking `bar::{{constant}}#0`
#3 [check_item_well_formed] processing `bar`
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-const_generics`#![feature(const_generics)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-const-genericsEnabling feature `const_generics` fixes the issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions