Skip to content

Commit bfe610c

Browse files
committed
ignore mutable self reference parameters
1 parent e03f73e commit bfe610c

4 files changed

+9
-11
lines changed

clippy_lints/src/needless_arbitrary_self_type.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ impl EarlyLintPass for NeedlessArbitrarySelfType {
104104
}
105105
},
106106
TyKind::Rptr(lifetime, mut_ty) => {
107-
if let TyKind::Path(None, path) = &mut_ty.ty.kind {
108-
check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Ref(*lifetime), mut_ty.mutbl)
107+
if_chain! {
108+
if let TyKind::Path(None, path) = &mut_ty.ty.kind;
109+
if let PatKind::Ident(BindingMode::ByValue(Mutability::Not), _, _) = p.pat.kind;
110+
then {
111+
check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Ref(*lifetime), mut_ty.mutbl)
112+
}
109113
}
110114
},
111115
_ => {},

tests/ui/needless_arbitrary_self_type.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl ValType {
5757
unimplemented!();
5858
}
5959

60-
pub fn mut_ref_mut_bad(&mut self) {
60+
pub fn mut_ref_mut_good(mut self: &mut Self) {
6161
unimplemented!();
6262
}
6363

tests/ui/needless_arbitrary_self_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl ValType {
5757
unimplemented!();
5858
}
5959

60-
pub fn mut_ref_mut_bad(mut self: &mut Self) {
60+
pub fn mut_ref_mut_good(mut self: &mut Self) {
6161
unimplemented!();
6262
}
6363

tests/ui/needless_arbitrary_self_type.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,5 @@ error: the type of the `self` parameter does not need to be arbitrary
3636
LL | pub fn mut_ref_bad_with_lifetime<'a>(self: &'a mut Self) {
3737
| ^^^^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'a mut self`
3838

39-
error: the type of the `self` parameter does not need to be arbitrary
40-
--> $DIR/needless_arbitrary_self_type.rs:60:28
41-
|
42-
LL | pub fn mut_ref_mut_bad(mut self: &mut Self) {
43-
| ^^^^^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&mut self`
44-
45-
error: aborting due to 7 previous errors
39+
error: aborting due to 6 previous errors
4640

0 commit comments

Comments
 (0)