Repository: rust
Issue: Invalid suggestion for using a non-constant value in a constant
Labels: A-diagnostics,T-compiler,D-incorrect

### Code

```Rust
fn foo(size: usize) {
    let size = size;
    [0; size];
}
```


### Current output

```Shell
error[E0435]: attempt to use a non-constant value in a constant
 --> src/lib.rs:3:9
  |
2 |     let size = size;
  |     -------- help: consider using `const` instead of `let`: `const size`
3 |     [0; size];
  |         ^^^^ non-constant value

For more information about this error, try `rustc --explain E0435`.
error: could not compile `playground` (lib) due to previous error
```


### Desired output

```Shell
error[E0435]: attempt to use a non-constant value in a constant
 --> src/lib.rs:3:9
  |
3 |     [0; size];
  |         ^^^^ non-constant value

For more information about this error, try `rustc --explain E0435`.
error: could not compile `playground` (lib) due to previous error
```

### Rationale and extra context

The help is completely invalid in this case; attempting to follow the suggestion leads to another error ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1ff1426ce35160d58050295647d08519)):

```
error[[E0391]](https://doc.rust-lang.org/nightly/error_codes/E0391.html): cycle detected when computing type of `foo::size`
 --> src/lib.rs:2:5
  |
2 |     const size = size;
  |     ^^^^^^^^^^
  |
note: ...which requires type-checking `foo::size`...
 --> src/lib.rs:2:5
  |
2 |     const size = size;
  |     ^^^^^^^^^^
  = note: ...which again requires computing type of `foo::size`, completing the cycle
note: cycle used when collecting item types in top-level module
 --> src/lib.rs:1:1
  |
1 | / fn foo(size: usize) {
2 | |     const size = size;
3 | |     [0; size];
4 | | }
  | |_^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

error: missing type for `const` item
 --> src/lib.rs:2:15
  |
2 |     const size = size;
  |               ^ help: provide a type for the item: `: <type>`

For more information about this error, try `rustc --explain E0391`.
error: could not compile `playground` (lib) due to 2 previous errors
```

Giving the hint as needed really doesn't help either ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1ff1426ce35160d58050295647d08519)):
```
error[[E0391]](https://doc.rust-lang.org/nightly/error_codes/E0391.html): cycle detected when const-evaluating + checking `foo::size`
 --> src/lib.rs:2:25
  |
2 |     const size: usize = size;
  |                         ^^^^
  |
  = note: ...which immediately requires const-evaluating + checking `foo::size` again
note: cycle used when const-evaluating + checking `foo::{constant#0}`
 --> src/lib.rs:3:9
  |
3 |     [0; size];
  |         ^^^^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

For more information about this error, try `rustc --explain E0391`.
error: could not compile `playground` (lib) due to previous error
```

### Other cases

It seems like suppressing the help is possible. Using this example ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=6957314402f72dadb0013d3ce4373978)):

```Rust
fn foo(size: usize) {
    [0; size];
}
```

yields a much better message:

```
error[E0435]: attempt to use a non-constant value in a constant
 --> src/lib.rs:2:9
  |
1 | fn foo(size: usize) {
  |        ---- this would need to be a `const`
2 |     [0; size];
  |         ^^^^

For more information about this error, try `rustc --explain E0435`.
error: could not compile `playground` (lib) due to previous error
```


### Anything else?

`rustc` version: `1.74.0-nightly (2023-08-22 c469197b19d53a6c4537)`

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":null}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->