2022-07-14 19:12:01 -05:00
|
|
|
// run-rustfix
|
2015-01-07 20:53:58 -06:00
|
|
|
|
2022-07-14 19:12:01 -05:00
|
|
|
use std::collections::HashMap;
|
2012-08-17 19:30:29 -05:00
|
|
|
|
|
|
|
fn main() {
|
2015-02-15 02:52:21 -06:00
|
|
|
let tmp: Box<_>;
|
2015-01-08 05:02:42 -06:00
|
|
|
let mut buggy_map: HashMap<usize, &usize> = HashMap::new();
|
2019-04-22 02:40:08 -05:00
|
|
|
buggy_map.insert(42, &*Box::new(1)); //~ ERROR temporary value dropped while borrowed
|
2013-01-22 19:20:08 -06:00
|
|
|
|
2012-08-17 19:30:29 -05:00
|
|
|
// but it is ok if we use a temporary
|
2021-08-24 19:39:40 -05:00
|
|
|
tmp = Box::new(2);
|
2013-01-22 19:20:08 -06:00
|
|
|
buggy_map.insert(43, &*tmp);
|
2012-08-17 19:30:29 -05:00
|
|
|
}
|