From e5aec914deb458aecda64f8a30f092bbf9381598 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Thu, 5 May 2022 07:42:35 +0200 Subject: [PATCH 1/2] Rephrase improperly reduced borrows introduction The issue with the current version of this paragraph is that it refers to code that will occur later. It can only be understood once we know what is borrowed and when, which only becomes clear when the error message is shown. With this new phrasing, I hope that the introduction prepares the reader to what they'll find out. Another solution would be to imitate the first example of this page. Introduce the code with just "Given the following code:" and then comment why it failed. --- src/lifetime-mismatch.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lifetime-mismatch.md b/src/lifetime-mismatch.md index 18082a43..68994655 100644 --- a/src/lifetime-mismatch.md +++ b/src/lifetime-mismatch.md @@ -73,9 +73,10 @@ care about, but the lifetime system is too coarse-grained to handle that. ## Improperly reduced borrows -The following code fails to compile, because Rust doesn't understand that the borrow -is no longer needed and conservatively falls back to using a whole scope for it. -This will eventually get fixed. +The following code fails to compile, because Rust sees that a variable, `map`, +is borrowed twice, and can not infer that the first borrow stops to be needed +before the second one occurs. This is caused by Rust conservatively falling back +to using a whole scope for the first borow. This will eventually get fixed. ```rust,compile_fail # use std::collections::HashMap; From 01b1274429f7c0ebc22f84da5b6940a42fc9679f Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 7 May 2022 10:18:47 +0900 Subject: [PATCH 2/2] Update src/lifetime-mismatch.md --- src/lifetime-mismatch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lifetime-mismatch.md b/src/lifetime-mismatch.md index 68994655..0494d492 100644 --- a/src/lifetime-mismatch.md +++ b/src/lifetime-mismatch.md @@ -76,7 +76,7 @@ care about, but the lifetime system is too coarse-grained to handle that. The following code fails to compile, because Rust sees that a variable, `map`, is borrowed twice, and can not infer that the first borrow stops to be needed before the second one occurs. This is caused by Rust conservatively falling back -to using a whole scope for the first borow. This will eventually get fixed. +to using a whole scope for the first borow. This will eventually get fixed. ```rust,compile_fail # use std::collections::HashMap;