Make IntoIterator lifetime bounds of &BTreeMap match with &HashMap #75203
Make IntoIterator lifetime bounds of &BTreeMap match with &HashMap #75203bors merged 2 commits intorust-lang:masterfrom
IntoIterator lifetime bounds of &BTreeMap match with &HashMap #75203Conversation
|
I don't quite understand the reason why |
|
Yeah, |
|
What I am suggesting is that this may be an issue with the compiler and we might want to fix that instead. |
|
Well, yes, we can investigate more if we think this is a bug, but I don't think so really. I'm looking all the use cases of |
|
@bors r+ |
|
📌 Commit cedf96c has been approved by |
This is certainly a bug. If you look at the minimal example in the original issue: fn foo<'a, K, V, I: 'a + IntoIterator<Item = (&'a K, &'a V)>>(i: I) {}
fn bar() {
let map = HashMap::<u32, u32>::new();
foo(&map);
let map = BTreeMap::<u32, u32>::new();
foo(&map);
}This code is rejected in Rust 2015 for both HashMap and BTreeMap, suggesting that |
…arth Rollup of 4 pull requests Successful merges: - rust-lang#74774 (adds [*mut|*const] ptr::set_ptr_value) - rust-lang#75079 (Disallow linking to items with a mismatched disambiguator) - rust-lang#75203 (Make `IntoIterator` lifetime bounds of `&BTreeMap` match with `&HashMap` ) - rust-lang#75227 (Fix ICE when using asm! on an unsupported architecture) Failed merges: r? @ghost
Hm, this minimal example also fails for |
This is a pretty small change on the lifetime bounds of
IntoIteratorimplementations of both&BTreeMapand&mut BTreeMap. This is loosening the lifetime bounds, so more code should be accepted with this PR. This is lifetime bounds will still be implicit since we havetype Item = (&'a K, &'a V);in the implementation. This change will make the HashMap and BTreeMap share the same signature, so we can share the same function/trait with both HashMap and BTreeMap in the code.Fixes #74034.
r? @dtolnay hey, I was touching this file on my previous PR and wanted to fix this on the way. Would you mind taking a look at this, or redirecting it if you are busy?