`super let` with `&mut [T; 0]` in `const` has inconsistent borrow-checking behavior
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
It is possible to create a &mut reference pointing to specifically an empty array in const. See #140126.
In the following code, the constants TUPLE, REBORROW, and INFER are slight variations of the constant FAILS.
#![feature(super_let)]
type Ref = &'static mut [i32; 0];
const fn make() -> Ref {
&mut []
}
const FAILS: [Ref; 2] = {
super let x: Ref = make();
[x, x]
};
const TUPLE: (Ref, Ref) = {
super let x: Ref = make();
(x, x)
};
const REBORROW: [Ref; 2] = {
super let x: Ref = make();
[x, &mut *x]
};
const INFER: [Ref; 2] = {
// Don't annotate as 'static
super let x: &mut [i32; 0] = make();
[x, x]
};
I expected all four constants to either all compile or all produce an error. Instead, the FAILS constant produces an error, but the other three compile fine.
error[E0505]: cannot move out of `x` because it is borrowed
--> src/lib.rs:11:9
|
10 | super let x: Ref = make();
| - binding `x` declared here
11 | [x, x]
| ----^-
| || |
| || move out of `x` occurs here
| |borrow of `*x` occurs here
| using this value as a constant requires that `*x` is borrowed for `'static`
For more information about this error, try `rustc --explain E0505`.
error: could not compile `playground` (lib) due to 1 previous error
Maybe related to #142607.
Meta
Reproducible on the playground with version 1.89.0-nightly (2025-06-11 e703dff8fe220b78195c)
@rustbot labels +F-super_let +A-const-eval +A-borrow-checker
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in src/lib.rs and run it on the reported nightly version, focusing on the FAILS, TUPLE, REBORROW, and INFER constants. Compare the borrow-checking behavior of these four forms and verify that the resulting behavior is consistent with the issue's expectation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100