@@ -682,25 +682,31 @@ pub enum BorrowKind {
682
682
/// implicit closure bindings. It is needed when the closure
683
683
/// is borrowing or mutating a mutable referent, e.g.:
684
684
///
685
- /// let x: &mut isize = ...;
686
- /// let y = || *x += 5;
685
+ /// ```
686
+ /// let x: &mut isize = ...;
687
+ /// let y = || *x += 5;
688
+ /// ```
687
689
///
688
690
/// If we were to try to translate this closure into a more explicit
689
691
/// form, we'd encounter an error with the code as written:
690
692
///
691
- /// struct Env { x: & &mut isize }
692
- /// let x: &mut isize = ...;
693
- /// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn
694
- /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
693
+ /// ```
694
+ /// struct Env { x: & &mut isize }
695
+ /// let x: &mut isize = ...;
696
+ /// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn
697
+ /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
698
+ /// ```
695
699
///
696
700
/// This is then illegal because you cannot mutate a `&mut` found
697
701
/// in an aliasable location. To solve, you'd have to translate with
698
702
/// an `&mut` borrow:
699
703
///
700
- /// struct Env { x: & &mut isize }
701
- /// let x: &mut isize = ...;
702
- /// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x
703
- /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
704
+ /// ```
705
+ /// struct Env { x: & &mut isize }
706
+ /// let x: &mut isize = ...;
707
+ /// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x
708
+ /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
709
+ /// ```
704
710
///
705
711
/// Now the assignment to `**env.x` is legal, but creating a
706
712
/// mutable pointer to `x` is not because `x` is not mutable. We
0 commit comments