inanna@inanna-x1-carbon:~/dev/phf_bug_demonstrator$ rustup default 1.40.0
info: using existing install for '1.40.0-x86_64-unknown-linux-gnu'
info: default toolchain set to '1.40.0-x86_64-unknown-linux-gnu'
1.40.0-x86_64-unknown-linux-gnu unchanged - rustc 1.40.0 (73528e339 2019-12-16)
inanna@inanna-x1-carbon:~/dev/phf_bug_demonstrator$ cargo build
Compiling phf_bug_demonstrator v0.1.0 (/home/inanna/dev/phf_bug_demonstrator)
Finished dev [unoptimized + debuginfo] target(s) in 0.14s
inanna@inanna-x1-carbon:~/dev/phf_bug_demonstrator$ rustup default stable
info: using existing install for 'stable-x86_64-unknown-linux-gnu'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'
stable-x86_64-unknown-linux-gnu unchanged - rustc 1.42.0 (b8cedc004 2020-03-09)
inanna@inanna-x1-carbon:~/dev/phf_bug_demonstrator$ cargo build
Compiling phf_bug_demonstrator v0.1.0 (/home/inanna/dev/phf_bug_demonstrator)
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
error: aborting due to previous error
Last active
March 30, 2020 18:37
-
-
Save inanna-malick/12a070623da2d5d508ab940f0923ef92 to your computer and use it in GitHub Desktop.
rust phf bug minimal example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | |
]), | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment