Skip to content

Commit

Permalink
wrong_self_conversion: Emit lint msg with help msg
Browse files Browse the repository at this point in the history
  • Loading branch information
mgacek8 committed Mar 11, 2021
1 parent 1e1f408 commit e077208
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 29 deletions.
6 changes: 4 additions & 2 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1954,19 +1954,21 @@ fn lint_wrong_self_convention<'tcx>(
}
};

span_lint(
span_lint_and_help(
cx,
lint,
first_arg_span,
&format!(
"{} usually take {}; consider choosing a less ambiguous name",
"{} usually take {}",
suggestion,
&self_kinds
.iter()
.map(|k| k.description())
.collect::<Vec<_>>()
.join(" or ")
),
None,
"consider choosing a less ambiguous name",
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/def_id_nocore.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name
error: methods called `as_*` usually take self by reference or self by mutable reference
--> $DIR/def_id_nocore.rs:26:19
|
LL | pub fn as_ref(self) -> &'static str {
| ^^^^
|
= note: `-D clippy::wrong-self-convention` implied by `-D warnings`
= help: consider choosing a less ambiguous name

error: aborting due to previous error

103 changes: 77 additions & 26 deletions tests/ui/wrong_self_convention.stderr
Original file line number Diff line number Diff line change
@@ -1,160 +1,211 @@
error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
error: methods called `from_*` usually take no self
--> $DIR/wrong_self_convention.rs:18:17
|
LL | fn from_i32(self) {}
| ^^^^
|
= note: `-D clippy::wrong-self-convention` implied by `-D warnings`
= help: consider choosing a less ambiguous name

error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
error: methods called `from_*` usually take no self
--> $DIR/wrong_self_convention.rs:24:21
|
LL | pub fn from_i64(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name
error: methods called `as_*` usually take self by reference or self by mutable reference
--> $DIR/wrong_self_convention.rs:36:15
|
LL | fn as_i32(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
error: methods called `into_*` usually take self by value
--> $DIR/wrong_self_convention.rs:38:17
|
LL | fn into_i32(&self) {}
| ^^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name
error: methods called `is_*` usually take self by reference or no self
--> $DIR/wrong_self_convention.rs:40:15
|
LL | fn is_i32(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
error: methods called `to_*` usually take self by reference
--> $DIR/wrong_self_convention.rs:42:15
|
LL | fn to_i32(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
error: methods called `from_*` usually take no self
--> $DIR/wrong_self_convention.rs:44:17
|
LL | fn from_i32(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name
error: methods called `as_*` usually take self by reference or self by mutable reference
--> $DIR/wrong_self_convention.rs:46:19
|
LL | pub fn as_i64(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
error: methods called `into_*` usually take self by value
--> $DIR/wrong_self_convention.rs:47:21
|
LL | pub fn into_i64(&self) {}
| ^^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name
error: methods called `is_*` usually take self by reference or no self
--> $DIR/wrong_self_convention.rs:48:19
|
LL | pub fn is_i64(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
error: methods called `to_*` usually take self by reference
--> $DIR/wrong_self_convention.rs:49:19
|
LL | pub fn to_i64(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
error: methods called `from_*` usually take no self
--> $DIR/wrong_self_convention.rs:50:21
|
LL | pub fn from_i64(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name
error: methods called `as_*` usually take self by reference or self by mutable reference
--> $DIR/wrong_self_convention.rs:95:19
|
LL | fn as_i32(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
error: methods called `into_*` usually take self by value
--> $DIR/wrong_self_convention.rs:98:25
|
LL | fn into_i32_ref(&self) {}
| ^^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name
error: methods called `is_*` usually take self by reference or no self
--> $DIR/wrong_self_convention.rs:100:19
|
LL | fn is_i32(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
error: methods called `to_*` usually take self by reference
--> $DIR/wrong_self_convention.rs:102:19
|
LL | fn to_i32(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
error: methods called `from_*` usually take no self
--> $DIR/wrong_self_convention.rs:104:21
|
LL | fn from_i32(self) {}
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name
error: methods called `as_*` usually take self by reference or self by mutable reference
--> $DIR/wrong_self_convention.rs:119:19
|
LL | fn as_i32(self);
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
error: methods called `into_*` usually take self by value
--> $DIR/wrong_self_convention.rs:122:25
|
LL | fn into_i32_ref(&self);
| ^^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name
error: methods called `is_*` usually take self by reference or no self
--> $DIR/wrong_self_convention.rs:124:19
|
LL | fn is_i32(self);
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
error: methods called `to_*` usually take self by reference
--> $DIR/wrong_self_convention.rs:126:19
|
LL | fn to_i32(self);
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
error: methods called `from_*` usually take no self
--> $DIR/wrong_self_convention.rs:128:21
|
LL | fn from_i32(self);
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
error: methods called `into_*` usually take self by value
--> $DIR/wrong_self_convention.rs:146:25
|
LL | fn into_i32_ref(&self);
| ^^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
error: methods called `from_*` usually take no self
--> $DIR/wrong_self_convention.rs:152:21
|
LL | fn from_i32(self);
| ^^^^
|
= help: consider choosing a less ambiguous name

error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
error: methods called `to_*` usually take self by reference
--> $DIR/wrong_self_convention.rs:175:24
|
LL | pub fn to_many(&mut self) -> Option<&mut [T]> {
| ^^^^^^^^^
|
= help: consider choosing a less ambiguous name

error: methods called like this: (`to_*` and `*_mut`) usually take self by mutable reference; consider choosing a less ambiguous name
error: methods called like this: (`to_*` and `*_mut`) usually take self by mutable reference
--> $DIR/wrong_self_convention.rs:183:28
|
LL | pub fn to_many_mut(&self) -> Option<&[T]> {
| ^^^^^
|
= help: consider choosing a less ambiguous name

error: aborting due to 26 previous errors

0 comments on commit e077208

Please sign in to comment.