Skip to content

ICE on let mut [N] when N is a generic parameter #82610

Closed
@jamesmunns

Description

@jamesmunns

Code

struct Pixel;

fn demo<const N: usize>() {
    let mut [Pixel; N] = todo!();
}

Meta

This ICE is present on the current stable (1.50), beta (1.51), and nightly (rust version 1.52.0-nightly (9c09c1f7c 2021-02-26))

Error output

james@archx1c6g ➜  poc git:(main) ✗ cargo check
    Checking poc v0.1.0 (/tmp/poc)
error: expected one of `,`, `@`, `]`, or `|`, found `;`
 --> src/lib.rs:4:19
  |
4 |     let mut [Pixel; N] = todo!();
  |                   ^
  |                   |
  |                   expected one of `,`, `@`, `]`, or `|`
  |                   help: missing `,`

error: `mut` must be attached to each individual binding
 --> src/lib.rs:4:9
  |
4 |     let mut [Pixel; N] = todo!();
  |         ^^^^^^^^^^^^^^ help: add `mut` to each binding: `[mut Pixel, mut N]`
  |
  = note: `mut` may be followed by `variable` and `variable @ pattern`

error[E0530]: let bindings cannot shadow unit structs
 --> src/lib.rs:4:14
  |
1 | struct Pixel;
  | ------------- the unit struct `Pixel` is defined here
...
4 |     let mut [Pixel; N] = todo!();
  |              ^^^^^ cannot be named the same as a unit struct

thread 'rustc' panicked at 'compiler/rustc_resolve/src/late.rs:1764:18: unexpected resolution for an identifier in pattern: Def(ConstParam, DefId(0:6))', /rustc/9c09c1f7cfcf9de0522bcd1cfda32b552195c464/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

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.52.0-nightly (9c09c1f7c 2021-02-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0530`.
error: could not compile `poc`
Backtrace

thread 'rustc' panicked at 'compiler/rustc_resolve/src/late.rs:1764:18: unexpected resolution for an identifier in pattern: Def(ConstParam, DefId(0:6))', /rustc/9c09c1f7cfcf9de0522bcd1cfda32b552195c464/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_middle::ty::context::tls::with_opt
   3: rustc_middle::util::bug::opt_span_bug_fmt
   4: rustc_middle::util::bug::span_bug_fmt
   5: rustc_resolve::late::LateResolutionVisitor::try_resolve_as_non_binding
   6: rustc_ast::ast::Pat::walk
   7: rustc_ast::ast::Pat::walk
   8: rustc_resolve::late::LateResolutionVisitor::resolve_pattern_top
   9: rustc_ast::visit::walk_stmt
  10: <rustc_resolve::late::LateResolutionVisitor as rustc_ast::visit::Visitor>::visit_block
  11: <rustc_resolve::late::LateResolutionVisitor as rustc_ast::visit::Visitor>::visit_fn
  12: rustc_ast::visit::walk_item
  13: rustc_resolve::late::LateResolutionVisitor::resolve_item
  14: rustc_resolve::late::<impl rustc_resolve::Resolver>::late_resolve_crate
  15: rustc_session::utils::<impl rustc_session::session::Session>::time
  16: rustc_resolve::Resolver::resolve_crate
  17: rustc_interface::passes::configure_and_expand_inner
  18: rustc_interface::passes::configure_and_expand::{{closure}}
  19: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
  20: rustc_interface::queries::Queries::expansion
  21: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  22: rustc_span::with_source_map
  23: rustc_interface::interface::create_compiler_and_run
  24: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

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.52.0-nightly (9c09c1f7c 2021-02-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0530`.
error: could not compile `poc`

To learn more, run the command again with --verbose.

I don't expect this code to compile (I was mid- writing something else and hit this ICE on a cargo watch invocation), but also wouldn't expect it to ICE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/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