Skip to content

Commit dc534c4

Browse files
committed
doc: add more examples, and a "Use instead" section, don't be condescending
1 parent 75b6860 commit dc534c4

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

clippy_lints/src/mut_mut.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,30 @@ declare_clippy_lint! {
1414
/// Checks for instances of `mut mut` references.
1515
///
1616
/// ### Why is this bad?
17-
/// Multiple `mut`s don't add anything meaningful to the
18-
/// source. This is either a copy'n'paste error, or it shows a fundamental
19-
/// misunderstanding of references.
17+
/// This is usually just a typo or a misunderstanding of how references work.
2018
///
2119
/// ### Example
2220
/// ```no_run
23-
/// # let mut y = 1;
24-
/// let x = &mut &mut y;
21+
/// let x = &mut &mut 1;
22+
///
23+
/// let mut x = &mut 1;
24+
/// let y = &mut x;
25+
///
26+
/// fn foo(x: &mut &mut u32) {}
27+
/// ```
28+
/// Use instead
29+
/// ```no_run
30+
/// let x = &mut 1;
31+
///
32+
/// let mut x = &mut 1;
33+
/// let y = &mut *x; // reborrow
34+
///
35+
/// fn foo(x: &mut u32) {}
2536
/// ```
2637
#[clippy::version = "pre 1.29.0"]
2738
pub MUT_MUT,
2839
pedantic,
29-
"usage of double-mut refs, e.g., `&mut &mut ...`"
40+
"usage of double mut-refs, e.g., `&mut &mut ...`"
3041
}
3142

3243
impl_lint_pass!(MutMut => [MUT_MUT]);

0 commit comments

Comments
 (0)