@@ -275,40 +275,31 @@ mod linear {
275
275
}
276
276
}
277
277
278
- /*
279
- FIXME(#3148)--region inference fails to capture needed deps
280
-
281
- fn find_ref(&self, k: &K) -> option<&self/V> {
282
- match self.bucket_for_key(self.buckets, k) {
283
- FoundEntry(idx) => {
284
- match check self.buckets[idx] {
285
- some(ref bkt) => some(&bkt.value)
286
- }
287
- }
288
- TableFull | FoundHole(_) => {
289
- none
290
- }
291
- }
292
- }
293
- */
294
-
295
- fn with_find_ref < T > ( & self , k : & K , blk : fn ( Option < & V > ) -> T ) -> T {
278
+ fn find_ref ( & self , k : & K ) -> Option < & self /V > {
296
279
match self . bucket_for_key ( self . buckets , k) {
297
280
FoundEntry ( idx) => {
298
281
match self . buckets [ idx] {
299
- Some ( bkt) => blk ( Some ( & bkt. value ) ) ,
300
- None => fail ~"LinearMap :: find: internal logic error"
282
+ Some ( ref bkt) => {
283
+ let ptr = unsafe {
284
+ // FIXME(#3148)--region inference
285
+ // fails to capture needed deps.
286
+ // Here, the bucket value is known to
287
+ // live as long as self, because self
288
+ // is immutable. But the region
289
+ // inference stupidly infers a
290
+ // lifetime for `ref bkt` that is
291
+ // shorter than it needs to be.
292
+ unsafe :: copy_lifetime ( self , & bkt. value )
293
+ } ;
294
+ Some ( ptr)
295
+ }
296
+ None => {
297
+ fail ~"LinearMap :: find: internal logic error"
298
+ }
301
299
}
302
300
}
303
- TableFull | FoundHole ( _) => blk ( None ) ,
304
- }
305
- }
306
-
307
- fn with_get_ref < T > ( & self , k : & K , blk : fn ( v : & V ) -> T ) -> T {
308
- do self . with_find_ref ( k) |v| {
309
- match v {
310
- Some ( v) => blk ( v) ,
311
- None => fail fmt ! ( "No entry found for key: %?" , k) ,
301
+ TableFull | FoundHole ( _) => {
302
+ None
312
303
}
313
304
}
314
305
}
@@ -451,10 +442,13 @@ mod test {
451
442
}
452
443
453
444
#[ test]
454
- fn with_find_ref ( ) {
445
+ fn find_ref ( ) {
455
446
let mut m = ~LinearMap ( ) ;
456
- m . with_find_ref ( & 1 , |v| assert v . is_none ( ) ) ;
447
+ assert m . find_ref ( & 1 ) . is_none ( ) ;
457
448
m. insert ( 1 , 2 ) ;
458
- m. with_find_ref ( & 1 , |v| assert * v. get ( ) == 2 ) ;
449
+ match m. find_ref ( & 1 ) {
450
+ None => fail,
451
+ Some ( v) => assert * v == 2
452
+ }
459
453
}
460
454
}
0 commit comments