@@ -210,9 +210,9 @@ purposes of this section, assume that the `entry` API for maps does
210
210
not exist):
211
211
212
212
``` rust
213
- fn get_default <'r ,K : Hash + Eq ,V : Default >(map : & 'r mut HashMap <K ,V >,
214
- key : K )
215
- -> & 'r mut V {
213
+ fn get_default <'r ,K : Hash + Eq + Copy ,V : Default >(map : & 'r mut HashMap <K ,V >,
214
+ key : K )
215
+ -> & 'r mut V {
216
216
match map . get_mut (& key ) { // -------------+ 'r
217
217
Some (value ) => value , // |
218
218
None => { // |
@@ -258,9 +258,9 @@ If we attempt the same workaround for this case that we tried
258
258
in the previous example, we will find that it does not work:
259
259
260
260
``` rust
261
- fn get_default1 <'r ,K : Hash + Eq ,V : Default >(map : & 'r mut HashMap <K ,V >,
262
- key : K )
263
- -> & 'r mut V {
261
+ fn get_default1 <'r ,K : Hash + Eq + Copy ,V : Default >(map : & 'r mut HashMap <K ,V >,
262
+ key : K )
263
+ -> & 'r mut V {
264
264
match map . get_mut (& key ) { // -------------+ 'r
265
265
Some (value ) => return value , // |
266
266
None => { } // |
@@ -281,9 +281,9 @@ the fact that the borrow checker uses the precise control-flow of the
281
281
function to determine which borrows are in scope.
282
282
283
283
``` rust
284
- fn get_default2 <'r ,K : Hash + Eq ,V : Default >(map : & 'r mut HashMap <K ,V >,
285
- key : K )
286
- -> & 'r mut V {
284
+ fn get_default2 <'r ,K : Hash + Eq + Copy ,V : Default >(map : & 'r mut HashMap <K ,V >,
285
+ key : K )
286
+ -> & 'r mut V {
287
287
if map . contains (& key ) {
288
288
// ^~~~~~~~~~~~~~~~~~ 'n
289
289
return match map . get_mut (& key ) { // + 'r
0 commit comments