temporary value dropped while borrowed
Open
Nobody has claimed this yet.
A-const-eval
A-constant-promotion
C-bug
regression-from-stable-to-stable
T-compiler
WG-const-eval
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
I tried this code:
pub const fn concat(_x: &[u8], _y: &[u8]) -> [u8; 1024] {
[0u8; 1024]
}
const _: &[u8] = &concat(
if b"".len() > 0 {
&concat(b"", b"")
} else {
b""
},
b""
);
I expected to see this happen: compiles
Instead, this happened: fails to compile with the following error:
error[E0716]: temporary value dropped while borrowed
--> <source>:7:10
|
5 | const _: &[u8] = &concat(
| ------ borrow later used by call
6 | if b"".len() > 0 {
7 | &concat(b"", b"")
| ^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
8 | } else {
| - temporary value is freed at the end of this statement
|
= note: consider using a `let` binding to create a longer lived value
Version it worked on
It most recently worked on: 1.78.0
Version with regression
rustc --version --verbose:
rustc 1.79.0 (129f3b996 2024-06-10)
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
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 by reproducing the provided const-evaluation example with rustc 1.79.0, then compare its behavior with 1.78.0 using the same snippet. Done means identifying the regression and restoring the expected successful compilation, with coverage for this case where appropriate.
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
- Mostly clear
- Newbie friendliness
- 35/100