Skip to content

Commit

Permalink
update error message, refactor disallowed_method
Browse files Browse the repository at this point in the history
  • Loading branch information
ilknarf committed Sep 25, 2020
1 parent 3886edb commit f9da294
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
17 changes: 8 additions & 9 deletions clippy_lints/src/disallowed_method.rs
Expand Up @@ -27,7 +27,7 @@ declare_clippy_lint! {
/// ```
pub DISALLOWED_METHOD,
nursery,
"used disallowed method call"
"use of a disallowed method call"
}

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

let method_call = cx.get_def_path(def_id);
if self.disallowed.contains(&method_call) {
let method = method_call
.iter()
.map(|s| s.to_ident_string())
.collect::<Vec<_>>()
.join("::");

span_lint(
cx,
DISALLOWED_METHOD,
expr.span,
&format!(
"Use of a disallowed method `{}`",
method_call
.iter()
.map(|s| s.to_ident_string())
.collect::<Vec<_>>()
.join("::"),
),
&format!("use of a disallowed method `{}`", method),
);
}
}
Expand Down
@@ -1,12 +1,12 @@
error: Use of a disallowed method `regex::re_unicode::Regex::is_match`
error: use of a disallowed method `regex::re_unicode::Regex::is_match`
--> $DIR/conf_disallowed_method.rs:10:5
|
LL | re.is_match("abc");
| ^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::disallowed-method` implied by `-D warnings`

error: Use of a disallowed method `core::iter::traits::iterator::Iterator::sum`
error: use of a disallowed method `core::iter::traits::iterator::Iterator::sum`
--> $DIR/conf_disallowed_method.rs:12:5
|
LL | a.iter().sum::<i32>();
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/disallowed_method.stderr
@@ -1,18 +1,18 @@
error: Use of a disallowed method `disallowed_method::Baz::bad_method`
error: use of a disallowed method `disallowed_method::Baz::bad_method`
--> $DIR/disallowed_method.rs:48:5
|
LL | b.bad_method();
| ^^^^^^^^^^^^^^
|
= note: `-D clippy::disallowed-method` implied by `-D warnings`

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

error: Use of a disallowed method `disallowed_method::Foo::bad_method`
error: use of a disallowed method `disallowed_method::Foo::bad_method`
--> $DIR/disallowed_method.rs:50:5
|
LL | f.bad_method();
Expand Down

0 comments on commit f9da294

Please sign in to comment.