@@ -965,49 +965,58 @@ mod move_keyword {}
965
965
966
966
#[ doc( keyword = "mut" ) ]
967
967
//
968
- /// A mutable binding , reference, or pointer.
968
+ /// A mutable variable , reference, or pointer.
969
969
///
970
- /// `mut` can be used in several situations. The first is mutable bindings ,
970
+ /// `mut` can be used in several situations. The first is mutable variables ,
971
971
/// which can be used anywhere you can bind a value to a variable name. Some
972
972
/// examples:
973
973
///
974
- /// ```
975
- /// // A mutable binding in the parameter list of a function.
974
+ /// ```rust
975
+ /// // A mutable variable in the parameter list of a function.
976
976
/// fn foo(mut x: u8, y: u8) -> u8 {
977
977
/// x += y;
978
978
/// x
979
979
/// }
980
980
///
981
- /// // A mutable binding for a variable.
981
+ /// // Modifying a mutable variable.
982
+ /// # #[allow(unused_assignments)]
982
983
/// let mut a = 5;
983
984
/// a = 6;
984
985
///
985
986
/// assert_eq!(foo(3, 4), 7);
986
987
/// assert_eq!(a, 6);
987
988
/// ```
988
989
///
989
- /// The second is references. They can be created from `mut` bindings and must
990
- /// be unique: no other binding can have a mutable reference, nor a simple
991
- /// reference.
990
+ /// The second is mutable references. They can be created from `mut` variables
991
+ /// and must be unique: no other variables can have a mutable reference, nor a
992
+ /// shared reference.
992
993
///
993
- /// ```
994
+ /// ```rust
994
995
/// // Taking a mutable reference.
995
996
/// fn push_two(v: &mut Vec<u8>) {
996
997
/// v.push(2);
997
998
/// }
998
999
///
999
- /// // You cannot take a mutable reference to a non-mutable variable.
1000
+ /// // A mutable reference cannot be taken to a non-mutable variable.
1000
1001
/// let mut v = vec![0, 1];
1001
1002
/// // Passing a mutable reference.
1002
1003
/// push_two(&mut v);
1003
1004
///
1004
1005
/// assert_eq!(v, vec![0, 1, 2]);
1005
1006
/// ```
1006
1007
///
1007
- /// Mutable pointers work much like mutable references, with the added
1008
- /// possibility of being nul. The syntax is `*mut Type`.
1008
+ /// ```rust,compile_fail,E0502
1009
+ /// let mut v = vec![0, 1];
1010
+ /// let mut_ref_v = &mut v;
1011
+ /// ##[allow(unused)]
1012
+ /// let ref_v = &v;
1013
+ /// mut_ref_v.push(2);
1014
+ /// ```
1015
+ ///
1016
+ /// Mutable raw pointers work much like mutable references, with the added
1017
+ /// possibility of not pointing to a valid object. The syntax is `*mut Type`.
1009
1018
///
1010
- /// You can find more information on mutable references and pointers in the
1019
+ /// More information on mutable references and pointers can be found in```
1011
1020
/// [Reference].
1012
1021
///
1013
1022
/// [Reference]: ../reference/types/pointer.html#mutable-references-mut
0 commit comments