Skip to content

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

Closed

Description

@leonardo-m

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

  1. added
    C-bugCategory: This is a bug.
    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.
    on May 5, 2020
  2. added
    A-const-genericsArea: const generics (parameters and arguments)
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on May 5, 2020
  3. lcnr commented on May 5, 2020

    @lcnr
    Contributor

    blocked on lazy normalization #67890.

    Probably a duplicate of #69913

  4. added 2 commits that reference this issue on May 18, 2020
    9f59db5
    c6030c9
  5. lcnr commented on Jun 30, 2020

    @lcnr
    Contributor

    This issue still isn't fixed 🤔 It seems like I made a mistake in #71973

  6. reopened this on Jun 30, 2020
  7. added a commit that references this issue on Jul 1, 2020
  8. added 4 commits that reference this issue on Jul 1, 2020
  9. added a commit that references this issue on Oct 5, 2020
  10. JohnTitor commented on Dec 30, 2020

    @JohnTitor
    Member

    Triage: This is no longer ICE (even with const_generics) on the latest nightly: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f0afc6e029354b7b4e933cb00c9b0cba

  11. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Dec 30, 2020
  12. lcnr commented on Dec 30, 2020

    @lcnr
    Contributor

    we already have a bunch of similar tests, closing without adding an additional one

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

Metadata

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