-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make IntoIterator
lifetime bounds of &BTreeMap
match with &HashMap
#75203
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@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
IntoIterator
implementations of both&BTreeMap
and&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?