Skip to content

Commit b38be11

Browse files
authored
Merge pull request #2257 from xfix/patch-2
Fix code errors in RFC 2094
2 parents 0bd84de + 99ec468 commit b38be11

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

text/2094-nll.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ purposes of this section, assume that the `entry` API for maps does
210210
not exist):
211211

212212
```rust
213-
fn get_default<'r,K,V:Default>(map: &'r mut HashMap<K,V>,
214-
key: K)
215-
-> &'r mut V {
213+
fn get_default<'r,K:Hash+Eq,V:Default>(map: &'r mut HashMap<K,V>,
214+
key: K)
215+
-> &'r mut V {
216216
match map.get_mut(&key) { // -------------+ 'r
217217
Some(value) => value, // |
218218
None => { // |
@@ -258,9 +258,9 @@ If we attempt the same workaround for this case that we tried
258258
in the previous example, we will find that it does not work:
259259

260260
```rust
261-
fn get_default1<'r,K,V:Default>(map: &'r mut HashMap<K,V>,
262-
key: K)
263-
-> &'r mut V {
261+
fn get_default1<'r,K:Hash+Eq,V:Default>(map: &'r mut HashMap<K,V>,
262+
key: K)
263+
-> &'r mut V {
264264
match map.get_mut(&key) { // -------------+ 'r
265265
Some(value) => return value, // |
266266
None => { } // |
@@ -281,9 +281,9 @@ the fact that the borrow checker uses the precise control-flow of the
281281
function to determine which borrows are in scope.
282282

283283
```rust
284-
fn get_default2<'r,K,V:Default>(map: &'r mut HashMap<K,V>,
285-
key: K)
286-
-> &'r mut V {
284+
fn get_default2<'r,K:Hash+Eq,V:Default>(map: &'r mut HashMap<K,V>,
285+
key: K)
286+
-> &'r mut V {
287287
if map.contains(&key) {
288288
// ^~~~~~~~~~~~~~~~~~ 'n
289289
return match map.get_mut(&key) { // + 'r
@@ -318,9 +318,9 @@ both nicer to read and more efficient even than the original version,
318318
since it avoids extra lookups on the "not present" path as well:
319319

320320
```rust
321-
fn get_default3<'r,K,V:Default>(map: &'r mut HashMap<K,V>,
322-
key: K)
323-
-> &'r mut V {
321+
fn get_default3<'r,K:Hash+Eq,V:Default>(map: &'r mut HashMap<K,V>,
322+
key: K)
323+
-> &'r mut V {
324324
map.entry(key)
325325
.or_insert_with(|| V::default())
326326
}
@@ -352,7 +352,7 @@ fn to_refs<T>(mut list: &mut List<T>) -> Vec<&mut T> {
352352
loop {
353353
result.push(&mut list.value);
354354
if let Some(n) = list.next.as_mut() {
355-
list = &mut n;
355+
list = n;
356356
} else {
357357
return result;
358358
}
@@ -400,7 +400,7 @@ fn to_refs<T>(mut list: &mut List<T>) -> Vec<&mut T> {
400400
let list1 = list;
401401
result.push(&mut list1.value);
402402
if let Some(n) = list1.next.as_mut() {
403-
list = &mut n;
403+
list = n;
404404
} else {
405405
return result;
406406
}

0 commit comments

Comments
 (0)