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 on let mut [N] when N is a generic parameter #82610

Closed
jamesmunns opened this issue Feb 27, 2021 · 7 comments
Closed

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

jamesmunns opened this issue Feb 27, 2021 · 7 comments
Labels
A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jamesmunns
Copy link
Member

jamesmunns commented Feb 27, 2021

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.

@jamesmunns jamesmunns 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 27, 2021
@jamesmunns
Copy link
Member Author

jamesmunns commented Feb 27, 2021

Actually, even more simply, this triggers the ICE:

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

The error is the same (modulo the Unit Struct shadowing error)

@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 27, 2021
@apiraino
Copy link
Contributor

I've tried bisecting, here's the results (I'm afraid not really useful):

********************************************************************************
Regression in nightly-2020-03-16
********************************************************************************

converted 2020-03-15 to 7cdbc87a49b0b705a41a004a6d486b0952521ae7
converted 2020-03-16 to 45ebd5808afd3df7ba842797c0fcd4447ddf30fb

found 5 bors merge commits in the specified range
  commit[0] 2020-03-14UTC: Auto merge of #69999 - RalfJung:miri-unwind, r=oli-obk
  commit[1] 2020-03-15UTC: Auto merge of #70016 - Dylan-DPC:rollup-5k7lxs3, r=Dylan-DPC
  commit[2] 2020-03-15UTC: Auto merge of #69961 - RalfJung:miri, r=RalfJung
  commit[3] 2020-03-15UTC: Auto merge of #70024 - Centril:rollup-cppmaxr, r=Centril
  commit[4] 2020-03-15UTC: Auto merge of #68944 - Zoxc:hir-map, r=eddyb

bisect command: cargo bisect-rustc --preserve --end=2020-04-01 --regress ice

@jyn514
Copy link
Member

jyn514 commented Feb 28, 2021

Slightly smaller (this doesn't have anything to do with the diverging expression):

fn f<const N: usize>() {
    let mut [N];
}

@jyn514 jyn514 changed the title ICE when mixing todo!() and Const Generics ICE on let mut [N] = [0] when N is a generic parameter Feb 28, 2021
@jyn514 jyn514 changed the title ICE on let mut [N] = [0] when N is a generic parameter ICE on let mut [N] when N is a generic parameter Feb 28, 2021
@apiraino
Copy link
Contributor

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 28, 2021
@38
Copy link

38 commented Mar 1, 2021

Seems this also repo the bug:

fn f<const N:usize>() {
    mut N
}

@chengniansun
Copy link

chengniansun commented Mar 4, 2021

A duplicate.

impl<const N: usize> ArrayWindowsExample {
    fn next() {
        let mut N;
    }
}

fanninpm added a commit to fanninpm/glacier that referenced this issue Mar 5, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 6, 2021
@Alexendoo
Copy link
Member

Fixed by #85478

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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

9 participants