Skip to content

FP expected [i32; 0], found [i32; 4] wrong array size infer #23148

Description

@matthiaskrgr

The following code

enum Foo {
    Bar = 4,
}
const I2: usize = Foo::Bar as usize;

fn main () {
    let x: [i32; I2] = [1, 2, 3, 4];
    println!("{:?}", x);
}

comiled with rustc (cargo check):

    Checking _snippet_429 v0.1.0 (/tmp/icemaker_global_tempdir.VC0sDFwRFQgw/rustc_testrunner_tmpdir.GlxEwQv4bx6u/_snippet_429)
warning: enum `Foo` is never used
 --> src/lib.rs:1:6
  |
1 | enum Foo {
  |      ^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: constant `I2` is never used
 --> src/lib.rs:4:7
  |
4 | const I2: usize = Foo::Bar as usize;
  |       ^^

warning: function `main` is never used
 --> src/lib.rs:6:4
  |
6 | fn main () {
  |    ^^^^

warning: `_snippet_429` (lib) generated 3 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.23s

but errors were issued by rust-analyzer diagnostics

at crate _snippet_429, file /tmp/icemaker_global_tempdir.VC0sDFwRFQgw/rustc_testrunner_tmpdir.GlxEwQv4bx6u/_snippet_429/src/lib.rs: Error RustcHardError("E0308") from LineCol { line: 6, col: 23 } to LineCol { line: 6, col: 35 }: expected [i32; 0], found [i32; 4]

diagnostic scan complete


Error: diagnostic error detected

Stack backtrace:
   0: <anyhow::Error>::msg::<&str>
             at /home/matthias/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.102/src/backtrace.rs:10:14
   1: anyhow::__private::format_err
             at /home/matthias/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.102/src/lib.rs:687:13
   2: <rust_analyzer::cli::flags::Diagnostics>::run_
             at /home/matthias/vcs/github/rust-analyzer/crates/rust-analyzer/src/cli/diagnostics.rs:123:13
   3: <rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}
             at /home/matthias/vcs/github/rust-analyzer/crates/rust-analyzer/src/cli/diagnostics.rs:20:29
   4: <stdx::thread::Builder>::spawn::<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}
             at /home/matthias/vcs/github/rust-analyzer/crates/stdx/src/thread.rs:74:13
   5: std::sys::backtrace::__rust_begin_short_backtrace::<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:166:18
   6: std::thread::lifecycle::spawn_unchecked::<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/lifecycle.rs:70:13
   7: <core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:275:9
   8: std::panicking::catch_unwind::do_call::<core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}>, core::result::Result<(), anyhow::Error>>
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:576:43
   9: std::panicking::catch_unwind::<core::result::Result<(), anyhow::Error>, core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}>>
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:544:19
  10: std::panic::catch_unwind::<core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}>, core::result::Result<(), anyhow::Error>>
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:359:14
  11: std::thread::lifecycle::spawn_unchecked::<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/lifecycle.rs:68:26
  12: <std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
  13: <alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output = ()> + core::marker::Send> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/d453bdd8f092d099bc336f0bda4163f809ad18e0/library/alloc/src/boxed.rs:2320:9
  14: <std::sys::thread::unix::Thread>::new::thread_start
             at /rustc/d453bdd8f092d099bc336f0bda4163f809ad18e0/library/std/src/sys/thread/unix.rs:123:17
  15: <unknown>
  16: <unknown>

version information

rust-analyzer 0.0.0 (2d6e364110 2026-08-15)

Activity

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions