Skip to content

Commit f9da294

Browse files
author
Frank
committed
update error message, refactor disallowed_method
1 parent 3886edb commit f9da294

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

clippy_lints/src/disallowed_method.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ declare_clippy_lint! {
2727
/// ```
2828
pub DISALLOWED_METHOD,
2929
nursery,
30-
"used disallowed method call"
30+
"use of a disallowed method call"
3131
}
3232

3333
#[derive(Clone, Debug)]
@@ -55,18 +55,17 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethod {
5555

5656
let method_call = cx.get_def_path(def_id);
5757
if self.disallowed.contains(&method_call) {
58+
let method = method_call
59+
.iter()
60+
.map(|s| s.to_ident_string())
61+
.collect::<Vec<_>>()
62+
.join("::");
63+
5864
span_lint(
5965
cx,
6066
DISALLOWED_METHOD,
6167
expr.span,
62-
&format!(
63-
"Use of a disallowed method `{}`",
64-
method_call
65-
.iter()
66-
.map(|s| s.to_ident_string())
67-
.collect::<Vec<_>>()
68-
.join("::"),
69-
),
68+
&format!("use of a disallowed method `{}`", method),
7069
);
7170
}
7271
}

tests/ui-toml/toml_disallowed_method/conf_disallowed_method.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error: Use of a disallowed method `regex::re_unicode::Regex::is_match`
1+
error: use of a disallowed method `regex::re_unicode::Regex::is_match`
22
--> $DIR/conf_disallowed_method.rs:10:5
33
|
44
LL | re.is_match("abc");
55
| ^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::disallowed-method` implied by `-D warnings`
88

9-
error: Use of a disallowed method `core::iter::traits::iterator::Iterator::sum`
9+
error: use of a disallowed method `core::iter::traits::iterator::Iterator::sum`
1010
--> $DIR/conf_disallowed_method.rs:12:5
1111
|
1212
LL | a.iter().sum::<i32>();

tests/ui/disallowed_method.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
error: Use of a disallowed method `disallowed_method::Baz::bad_method`
1+
error: use of a disallowed method `disallowed_method::Baz::bad_method`
22
--> $DIR/disallowed_method.rs:48:5
33
|
44
LL | b.bad_method();
55
| ^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::disallowed-method` implied by `-D warnings`
88

9-
error: Use of a disallowed method `disallowed_method::Baz::bad_method`
9+
error: use of a disallowed method `disallowed_method::Baz::bad_method`
1010
--> $DIR/disallowed_method.rs:49:5
1111
|
1212
LL | c.bad_method();
1313
| ^^^^^^^^^^^^^^
1414

15-
error: Use of a disallowed method `disallowed_method::Foo::bad_method`
15+
error: use of a disallowed method `disallowed_method::Foo::bad_method`
1616
--> $DIR/disallowed_method.rs:50:5
1717
|
1818
LL | f.bad_method();

0 commit comments

Comments
 (0)