Skip to content

Commit 63de1ec

Browse files
Apply suggestions from code review
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
1 parent 08fa70e commit 63de1ec

File tree

1 file changed

+9
-10
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+9
-10
lines changed

compiler/rustc_error_codes/src/error_codes/E0311.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
E0311 occurs when there is insufficient information for the rust compiler to
1+
This error occurs when there is insufficient information for the rust compiler to
22
prove that some time has a long enough lifetime.
33

44
Erroneous code example:
55

6-
```compile_fail, E0311
6+
```compile_fail,E0311
77
use std::borrow::BorrowMut;
88
99
trait NestedBorrowMut<U, V> {
@@ -13,20 +13,19 @@ trait NestedBorrowMut<U, V> {
1313
impl<T, U, V> NestedBorrowMut<U, V> for T
1414
where
1515
T: BorrowMut<U>,
16-
U: BorrowMut<V>, // missing lifetime specifier here --> compile fail
16+
U: BorrowMut<V>, // error: missing lifetime specifier
1717
{
1818
fn nested_borrow_mut(&mut self) -> &mut V {
1919
self.borrow_mut().borrow_mut()
2020
}
2121
}
2222
```
2323

24-
In this example we have a trait that borrows some inner data element of type V
25-
from an outer type T, through an intermediate type U. The compiler is unable to
26-
prove that the livetime of U is long enough to support the reference, so it
27-
throws E0311. To fix the issue we can explicitly add lifetime specifiers to the
28-
trait, which link the lifetimes of the various data types and allow the code
29-
to compile.
24+
In this example we have a trait that borrows some inner data element of type `V`
25+
from an outer type `T`, through an intermediate type `U`. The compiler is unable to
26+
prove that the livetime of `U` is long enough to support the reference. To fix the
27+
issue we can explicitly add lifetime specifiers to the `NestedBorrowMut` trait, which
28+
link the lifetimes of the various data types and allow the code to compile.
3029

3130
Working implementation of the `NestedBorrowMut` trait:
3231

@@ -40,7 +39,7 @@ trait NestedBorrowMut<'a, U, V> {
4039
impl<'a, T, U, V> NestedBorrowMut<'a, U, V> for T
4140
where
4241
T: BorrowMut<U>,
43-
U: BorrowMut<V> + 'a,
42+
U: BorrowMut<V> + 'a, // Adding lifetime specifier
4443
{
4544
fn nested_borrow_mut(&'a mut self) -> &'a mut V {
4645
self.borrow_mut().borrow_mut()

0 commit comments

Comments
 (0)