diff options
| author | Matthew Kelly <matthew.kelly2@gmail.com> | 2022-08-19 09:34:20 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-19 09:34:20 -0400 |
| commit | 63de1ec0706ddbb8e4d3aacba71ad47308d8dfa9 (patch) | |
| tree | 0a95174768005dfac7934c20ac1f0bd97e59ff50 /compiler/rustc_error_codes/src | |
| parent | 08fa70e5c5beb8d84c528d8effb481c4f830b28d (diff) | |
| download | rust-63de1ec0706ddbb8e4d3aacba71ad47308d8dfa9.tar.gz rust-63de1ec0706ddbb8e4d3aacba71ad47308d8dfa9.zip | |
Apply suggestions from code review
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0311.md | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0311.md b/compiler/rustc_error_codes/src/error_codes/E0311.md index 8b5daaaa178..a5975c4f472 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0311.md +++ b/compiler/rustc_error_codes/src/error_codes/E0311.md @@ -1,9 +1,9 @@ -E0311 occurs when there is insufficient information for the rust compiler to +This error occurs when there is insufficient information for the rust compiler to prove that some time has a long enough lifetime. Erroneous code example: -```compile_fail, E0311 +```compile_fail,E0311 use std::borrow::BorrowMut; trait NestedBorrowMut<U, V> { @@ -13,7 +13,7 @@ trait NestedBorrowMut<U, V> { impl<T, U, V> NestedBorrowMut<U, V> for T where T: BorrowMut<U>, - U: BorrowMut<V>, // missing lifetime specifier here --> compile fail + U: BorrowMut<V>, // error: missing lifetime specifier { fn nested_borrow_mut(&mut self) -> &mut V { self.borrow_mut().borrow_mut() @@ -21,12 +21,11 @@ where } ``` -In this example we have a trait that borrows some inner data element of type V -from an outer type T, through an intermediate type U. The compiler is unable to -prove that the livetime of U is long enough to support the reference, so it -throws E0311. To fix the issue we can explicitly add lifetime specifiers to the -trait, which link the lifetimes of the various data types and allow the code -to compile. +In this example we have a trait that borrows some inner data element of type `V` +from an outer type `T`, through an intermediate type `U`. The compiler is unable to +prove that the livetime of `U` is long enough to support the reference. To fix the +issue we can explicitly add lifetime specifiers to the `NestedBorrowMut` trait, which +link the lifetimes of the various data types and allow the code to compile. Working implementation of the `NestedBorrowMut` trait: @@ -40,7 +39,7 @@ trait NestedBorrowMut<'a, U, V> { impl<'a, T, U, V> NestedBorrowMut<'a, U, V> for T where T: BorrowMut<U>, - U: BorrowMut<V> + 'a, + U: BorrowMut<V> + 'a, // Adding lifetime specifier { fn nested_borrow_mut(&'a mut self) -> &'a mut V { self.borrow_mut().borrow_mut() |
