Skip to content

Commit 97a2207

Browse files
committed
sugg on ty
1 parent 457e880 commit 97a2207

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

clippy_lints/src/mut_mut.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use clippy_utils::diagnostics::{span_lint, span_lint_hir_and_then};
1+
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
22
use clippy_utils::higher;
3+
use clippy_utils::source::snippet_with_applicability;
34
use clippy_utils::sugg::Sugg;
45
use rustc_errors::Applicability;
56
use rustc_hir::{self as hir, AmbigArg, intravisit};
@@ -37,15 +38,20 @@ impl<'tcx> LateLintPass<'tcx> for MutMut {
3738
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'_, AmbigArg>) {
3839
if let hir::TyKind::Ref(_, mty) = ty.kind
3940
&& mty.mutbl == hir::Mutability::Mut
40-
&& let hir::TyKind::Ref(_, mty) = mty.ty.kind
41-
&& mty.mutbl == hir::Mutability::Mut
41+
&& let hir::TyKind::Ref(_, mty2) = mty.ty.kind
42+
&& mty2.mutbl == hir::Mutability::Mut
4243
&& !ty.span.in_external_macro(cx.sess().source_map())
4344
{
44-
span_lint(
45+
let mut applicability = Applicability::MaybeIncorrect;
46+
let sugg = snippet_with_applicability(cx.sess(), mty.ty.span, "..", &mut applicability);
47+
span_lint_and_sugg(
4548
cx,
4649
MUT_MUT,
4750
ty.span,
48-
"generally you want to avoid `&mut &mut _` if possible",
51+
"a type of form `&mut &mut _`",
52+
"remove the extra `&mut`",
53+
sugg.to_string(),
54+
applicability,
4955
);
5056
}
5157
}

tests/ui/mut_mut.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: generally you want to avoid `&mut &mut _` if possible
1+
error: a type of form `&mut &mut _`
22
--> tests/ui/mut_mut.rs:15:11
33
|
44
LL | fn fun(x: &mut &mut u32) {
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut u32`
66
|
77
= note: `-D clippy::mut-mut` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::mut_mut)]`
@@ -25,29 +25,29 @@ error: an expression of form `&mut &mut _`
2525
LL | let y: &mut &mut u32 = &mut &mut 2;
2626
| ^^^^^^^^^^^ help: remove the extra `&mut`: `&mut 2`
2727

28-
error: generally you want to avoid `&mut &mut _` if possible
28+
error: a type of form `&mut &mut _`
2929
--> tests/ui/mut_mut.rs:40:16
3030
|
3131
LL | let y: &mut &mut u32 = &mut &mut 2;
32-
| ^^^^^^^^^^^^^
32+
| ^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut u32`
3333

3434
error: an expression of form `&mut &mut _`
3535
--> tests/ui/mut_mut.rs:46:37
3636
|
3737
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
3838
| ^^^^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut &mut 2`
3939

40-
error: generally you want to avoid `&mut &mut _` if possible
40+
error: a type of form `&mut &mut _`
4141
--> tests/ui/mut_mut.rs:46:16
4242
|
4343
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
44-
| ^^^^^^^^^^^^^^^^^^
44+
| ^^^^^^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut &mut u32`
4545

46-
error: generally you want to avoid `&mut &mut _` if possible
46+
error: a type of form `&mut &mut _`
4747
--> tests/ui/mut_mut.rs:46:21
4848
|
4949
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
50-
| ^^^^^^^^^^^^^
50+
| ^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut u32`
5151

5252
error: aborting due to 8 previous errors
5353

tests/ui/mut_mut_unfixable.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: generally you want to avoid `&mut &mut _` if possible
1+
error: a type of form `&mut &mut _`
22
--> tests/ui/mut_mut_unfixable.rs:9:11
33
|
44
LL | fn fun(x: &mut &mut u32) -> bool {
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut u32`
66
|
77
= note: `-D clippy::mut-mut` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::mut_mut)]`

0 commit comments

Comments
 (0)