Skip to content

Commit 9a68da7

Browse files
committed
auto merge of rust-lang#17517 : pczarn/rust/hashmap-lifetimes, r=alexcrichton
Fixes rust-lang#17500
2 parents ef112fe + 0a10b9d commit 9a68da7

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

src/libstd/collections/hashmap/table.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ impl<K, V> RawTable<K, V> {
663663
raw: self.first_bucket_raw(),
664664
hashes_end: unsafe {
665665
self.hashes.offset(self.capacity as int)
666-
}
666+
},
667+
marker: marker::ContravariantLifetime,
667668
}
668669
}
669670

@@ -682,8 +683,14 @@ impl<K, V> RawTable<K, V> {
682683
}
683684

684685
pub fn into_iter(self) -> MoveEntries<K, V> {
686+
let RawBuckets { raw, hashes_end, .. } = self.raw_buckets();
687+
// Replace the marker regardless of lifetime bounds on parameters.
685688
MoveEntries {
686-
iter: self.raw_buckets(),
689+
iter: RawBuckets {
690+
raw: raw,
691+
hashes_end: hashes_end,
692+
marker: marker::ContravariantLifetime,
693+
},
687694
table: self,
688695
}
689696
}
@@ -695,7 +702,8 @@ impl<K, V> RawTable<K, V> {
695702
RevMoveBuckets {
696703
raw: raw_bucket.offset(self.capacity as int),
697704
hashes_end: raw_bucket.hash,
698-
elems_left: self.size
705+
elems_left: self.size,
706+
marker: marker::ContravariantLifetime,
699707
}
700708
}
701709
}
@@ -704,7 +712,8 @@ impl<K, V> RawTable<K, V> {
704712
/// this interface is safe, it's not used outside this module.
705713
struct RawBuckets<'a, K, V> {
706714
raw: RawBucket<K, V>,
707-
hashes_end: *mut u64
715+
hashes_end: *mut u64,
716+
marker: marker::ContravariantLifetime<'a>,
708717
}
709718

710719
impl<'a, K, V> Iterator<RawBucket<K, V>> for RawBuckets<'a, K, V> {
@@ -730,7 +739,8 @@ impl<'a, K, V> Iterator<RawBucket<K, V>> for RawBuckets<'a, K, V> {
730739
struct RevMoveBuckets<'a, K, V> {
731740
raw: RawBucket<K, V>,
732741
hashes_end: *mut u64,
733-
elems_left: uint
742+
elems_left: uint,
743+
marker: marker::ContravariantLifetime<'a>,
734744
}
735745

736746
impl<'a, K, V> Iterator<(K, V)> for RevMoveBuckets<'a, K, V> {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let mut my_stuff = std::collections::HashMap::new();
13+
my_stuff.insert(0i, 42i);
14+
15+
let (_, thing) = my_stuff.iter().next().unwrap();
16+
17+
my_stuff.clear(); //~ ERROR cannot borrow
18+
19+
println!("{}", *thing);
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let mut my_stuff = std::collections::HashMap::new();
13+
my_stuff.insert(0i, 42i);
14+
15+
let mut it = my_stuff.iter();
16+
my_stuff.swap(1, 43); //~ ERROR cannot borrow
17+
}

0 commit comments

Comments
 (0)