Repository: rust
Issue: Warning init error on array const generic
Labels: A-diagnostics,T-compiler

### Code

```Rust
fn main() {
    // This produces a warn about undefined behavior (bad init). OK!
    let _: [Vec<i32>; 42] = unsafe { std::mem::zeroed() };

    foo::<42>();
}

fn foo<const N: usize> () {
    // This does *not* produce a warn about undefined behavior. Nice to have!
    let _: [Vec<i32>; N] = unsafe { std::mem::zeroed() };
}
```


### Current output

```Shell
warning: the type `[Vec<i32>; 42]` does not permit zero-initialization
 --> test.rs:3:38
  |
3 |     let _: [Vec<i32>; 42] = unsafe { std::mem::zeroed() };
  |                                      ^^^^^^^^^^^^^^^^^^
  |                                      |
  |                                      this code causes undefined behavior when executed
  |                                      help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
  |
  = note: `std::ptr::Unique<i32>` must be non-null
  = note: because `std::ptr::NonNull<i32>` must be non-null
  = note: `#[warn(invalid_value)]` on by default
```


### Desired output

```Shell
warning: the type `[Vec<i32>; 42]` does not permit zero-initialization
 --> src/main.rs:3:38
  |
3 |     let _: [Vec<i32>; 42] = unsafe { std::mem::zeroed() };
  |                                      ^^^^^^^^^^^^^^^^^^
  |                                      |
  |                                      this code causes undefined behavior when executed
  |                                      help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
  |
  = note: `std::ptr::Unique<i32>` must be non-null
  = note: because `std::ptr::NonNull<i32>` must be non-null
  = note: `#[warn(invalid_value)]` on by default

warning: the type `[Vec<i32>; N = 42]` does not permit zero-initialization
  --> src/main.rs:10:38
   |
10 |     let _: [Vec<i32>; N] = unsafe { std::mem::zeroed() };
   |                                     ^^^^^^^^^^^^^^^^^^
   |                                     |
   |                                     this code causes undefined behavior when executed
   |                                     help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
   |
   = note: `std::ptr::Unique<i32>` must be non-null
   = note: because `std::ptr::NonNull<i32>` must be non-null
```


### Rationale and extra context

Rustc lint module conservatly checks for undefined behavior initialization.

It correctly prints a warning when one tries to initialize a zeroed array of `Vec` (because `Vec` contains `NonNull`).

However, when using const-generic to declare the array the warning is not produced (with the current nightly 1.70; see code example).

By quickly inspecting the compiler code, it seems the lint cannot evaluate the length of the array ([code here from current main](https://github.com/rust-lang/rust/blob/dd7df04e168324fc002ab4985b6c7513f08ccf49/compiler/rustc_lint/src/builtin.rs#L2611-L2618)).

I am not sure if generic evaluation can happen before lint checks and resolve the array length (and, thus, printing the same error when `N > 0`). However, in theory, the array length is known at compile time and, if possible, it would be nice to have the lint when const-generic array.

### Other cases

_No response_

### Anything else?

_No response_