Skip to content

Commit 4f194a7

Browse files
Fix rust-doc error
There was a partial rust code block in the readme that was invalid because of a missing line. I inlined the code snippet into the text to fix the error. This also improves readability a bit.
1 parent fc02eee commit 4f194a7

File tree

1 file changed

+11
-16
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+11
-16
lines changed

compiler/rustc_error_codes/src/error_codes/E0311.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,30 @@ where
2525

2626
Why doesn't this code compile? It helps to look at the lifetime bounds that
2727
the compiler is automatically adding ("Lifetime Ellision", Chapter 10.3 in the
28-
Rust book) to the `nested_borrow_mut` and `borrow_mut` functions. In both cases
29-
the input is a reference to `self`, so the compiler attempts to assign the
28+
Rust book) to the `nested_borrow_mut()` and `borrow_mut()` functions. In both
29+
cases the input is a reference to `self`, so the compiler attempts to assign
3030
the same lifetime to the input and output.
3131

32-
Looking specifically at `nested_borrow_mut`, we see that there are three object
33-
references to keep track of, along with their associated lifetimes:
32+
Looking specifically at `nested_borrow_mut()`, we see that there are three
33+
object references to keep track of, along with their associated lifetimes:
3434
- `self` (which is a `&mut T`)
3535
- `u_ref` (which is a `&mut U`)
3636
- `v_ref` (which is a `&mut V`)
3737

3838
The `borrow_mut()` method implicitly requires that that the input and output
39-
have the same lifetime bounds. Thus the lines:
40-
41-
```rust
42-
let u_ref = self.borrow_mut();
43-
let v_ref = u_ref.borrow_mut();
44-
```
45-
46-
imply that `u_ref` and `self` must share a lifetime bound, and also that
47-
`v_ref` and `u_ref` share a lifetime bound. The problem is that the function
48-
signature for `nested_borrow_mut` only gives the compiler information about the
49-
lifetimes of `self` and `v_ref` -- nothing about `u_ref`.
39+
have the same lifetime bounds. Thus the lines: `let u_ref = self.borrow_mut();`
40+
and `let v_ref = u_ref.borrow_mut();` in `nested_borrow_mut()` above imply that
41+
`u_ref` and `self` must share a lifetime bound, and also that `v_ref` and
42+
`u_ref` share a lifetime bound. The problem is that the function signature for
43+
`nested_borrow_mut()` only gives the compiler information about the lifetimes
44+
of `self` and `v_ref` -- nothing about `u_ref`.
5045

5146
The way to fix this error is then to explicitly tell the compiler that the
5247
lifetime of `u_ref` is the same as `self` and `v_ref`, which then allows it
5348
to satisfy the two lifetime bound requirements described above.
5449

5550
Here is the working version of the code:
56-
```rust
51+
```
5752
use std::borrow::BorrowMut;
5853
5954
trait NestedBorrowMut<'a, U, V> {

0 commit comments

Comments
 (0)