Closed
Description
The below code compiles in 1.40.0 but not in 1.42.0 (stable). (minimized example from rust-phf)
pub enum Slice<T: 'static> {
Static(&'static [T]),
}
pub struct Map<K: 'static, V: 'static> {
pub entries: Slice<(K, V)>,
}
static CONTENT : & 'static [ u8 ] = b"a";
pub static CONTENT_MAP: Map<&'static str, &'static [u8]> = {
Map {
entries: Slice::Static(&[
("content", CONTENT),
]),
}
};
When built in 1.42.0, it produces the following error:
error[E0716]: temporary value dropped while borrowed
--> src/lib.rs:13:33
|
13 | entries: Slice::Static(&[
| ________________________________-^
| |________________________________|
| ||
14 | || ("content", CONTENT),
15 | || ]),
| || ^
| ||_________|
| |__________creates a temporary which is freed while still in use
| cast requires that borrow lasts for `'static`
16 | }
17 | };
| - temporary value is freed at the end of this statement
The same error occurs using nightly.
There's an issue from January mentioning this build error on the rust-phf repo (seems to occur in 1.41.0+), but no followup discussion/work that I could find. rust-phf/rust-phf#187