Closed as not planned
Description
Code
I tried this code: [playground] [godbolt]
pub struct Dir<'a>(&'a [File<'a>]);
impl<'a> Dir<'a> {
pub const fn new(x: &'a [File<'a>]) -> Self {
Self(x)
}
}
pub struct File<'a>(&'a str);
impl<'a> File<'a> {
pub const fn new(x: &'a str) -> Self {
Self(x)
}
}
pub static OK: Dir<'static> = Dir::new(&[File::new("")]);
pub static ERR: Dir<'static> = if true {
Dir::new(&[File::new("")]) //~ ERROR: temporary value dropped while borrowed
} else {
unreachable!()
};
I expected to see this happen: code compiles: temporary is promoted to &'static
due to the const
evaluation context.
Instead, this happened: code errors: temporary value dropped while borrowed.
Version it worked on
It most recently worked on: 1.78
Version with regression
rustc --version --verbose
:
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-pc-windows-msvc
release: 1.79.0
LLVM version: 18.1.7
Meta
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
Bisects to #121557
Initially reported on urlo: https://users.rust-lang.org/t/code-compiles-in-1-78-0-but-not-in-1-79-0/113038?u=cad97