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