Skip to content

Instantly share code, notes, and snippets.

@inanna-malick
Last active March 30, 2020 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inanna-malick/12a070623da2d5d508ab940f0923ef92 to your computer and use it in GitHub Desktop.
Save inanna-malick/12a070623da2d5d508ab940f0923ef92 to your computer and use it in GitHub Desktop.
rust phf bug minimal example
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
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