contain-rs / linked-hash-map

A HashMap wrapper that holds key-value pairs in insertion order
https://contain-rs.github.io/linked-hash-map/linked_hash_map/
Apache License 2.0
169 stars 60 forks source link

Lifetime issue with linked_hash_map iter_mut where there is none with hash_map iter_mut #81

Closed mattmacy closed 5 years ago

mattmacy commented 7 years ago

The following code works without issue: https://is.gd/BIFxdX

However, when I comment out the hash_map usage and uncomment the linked_hash_map code - which is verbatim the same AFAICT- it can't resolve the lifetime of iter_mut

dtolnay commented 7 years ago

Reduced:

#[cfg(not(feature = "linked-hash-map"))]
use std::collections::hash_map::{HashMap as Map, IterMut};

#[cfg(feature = "linked-hash-map")]
extern crate linked_hash_map;
#[cfg(feature = "linked-hash-map")]
use linked_hash_map::{LinkedHashMap as Map, IterMut};

fn f<'a, 'r>(m: &'r mut Map<&'a (), ()>) -> IterMut<'r, &'r (), ()> {
    m.iter_mut()
}

fn main() {}
dtolnay commented 7 years ago

Looks like a linked-hash-map bug. Relevant code from libstd that makes this work:

mattmacy commented 5 years ago

¯_(ツ)_/¯