Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions text/2094-nll.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ purposes of this section, assume that the `entry` API for maps does
not exist):

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

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

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

```rust
fn get_default3<'r,K,V:Default>(map: &'r mut HashMap<K,V>,
key: K)
-> &'r mut V {
fn get_default3<'r,K:Hash+Eq,V:Default>(map: &'r mut HashMap<K,V>,
key: K)
-> &'r mut V {
map.entry(key)
.or_insert_with(|| V::default())
}
Expand Down Expand Up @@ -352,7 +352,7 @@ fn to_refs<T>(mut list: &mut List<T>) -> Vec<&mut T> {
loop {
result.push(&mut list.value);
if let Some(n) = list.next.as_mut() {
list = &mut n;
list = n;
} else {
return result;
}
Expand Down Expand Up @@ -400,7 +400,7 @@ fn to_refs<T>(mut list: &mut List<T>) -> Vec<&mut T> {
let list1 = list;
result.push(&mut list1.value);
if let Some(n) = list1.next.as_mut() {
list = &mut n;
list = n;
} else {
return result;
}
Expand Down