Skip to content

Commit

Permalink
Also pluralize disallowed_method(s) lint
Browse files Browse the repository at this point in the history
To stay consistent with the sister lint disallowed_type, also rename the
disallowed_method lint to disallowed_methods.
  • Loading branch information
flip1995 committed Nov 18, 2021
1 parent a0d81d1 commit 9b38fb7
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 54 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Current beta, release 2021-12-02
[#7560](https://github.com/rust-lang/rust-clippy/pull/7560)
* [`unnecessary_unwrap`]: Now also checks for `expect`s
[#7584](https://github.com/rust-lang/rust-clippy/pull/7584)
* [`disallowed_method`]: Allow adding a reason that will be displayed with the
* [`disallowed_methods`]: Allow adding a reason that will be displayed with the
lint message
[#7621](https://github.com/rust-lang/rust-clippy/pull/7621)
* [`approx_constant`]: Now checks the MSRV for `LOG10_2` and `LOG2_10`
Expand Down Expand Up @@ -294,7 +294,7 @@ Released 2021-09-09
[#7379](https://github.com/rust-lang/rust-clippy/pull/7379)
* [`redundant_closure`]: Suggests `&mut` for `FnMut`
[#7437](https://github.com/rust-lang/rust-clippy/pull/7437)
* [`disallowed_method`], [`disallowed_types`]: The configuration values `disallowed-method` and `disallowed-type`
* [`disallowed_methods`], [`disallowed_types`]: The configuration values `disallowed-method` and `disallowed-type`
no longer require fully qualified paths
[#7345](https://github.com/rust-lang/rust-clippy/pull/7345)
* [`zst_offset`]: Fixed lint invocation after it was accidentally suppressed
Expand Down Expand Up @@ -703,7 +703,7 @@ Released 2021-05-06

### Enhancements

* [`disallowed_method`]: Now supports functions in addition to methods
* [`disallowed_methods`]: Now supports functions in addition to methods
[#6674](https://github.com/rust-lang/rust-clippy/pull/6674)
* [`upper_case_acronyms`]: Added a new configuration `upper-case-acronyms-aggressive` to
trigger the lint if there is more than one uppercase character next to each other
Expand Down Expand Up @@ -1044,7 +1044,7 @@ Released 2020-12-31

* [`field_reassign_with_default`] [#5911](https://github.com/rust-lang/rust-clippy/pull/5911)
* [`await_holding_refcell_ref`] [#6029](https://github.com/rust-lang/rust-clippy/pull/6029)
* [`disallowed_method`] [#6081](https://github.com/rust-lang/rust-clippy/pull/6081)
* [`disallowed_methods`] [#6081](https://github.com/rust-lang/rust-clippy/pull/6081)
* [`inline_asm_x86_att_syntax`] [#6092](https://github.com/rust-lang/rust-clippy/pull/6092)
* [`inline_asm_x86_intel_syntax`] [#6092](https://github.com/rust-lang/rust-clippy/pull/6092)
* [`from_iter_instead_of_collect`] [#6101](https://github.com/rust-lang/rust-clippy/pull/6101)
Expand Down Expand Up @@ -2821,7 +2821,7 @@ Released 2018-09-13
[`derivable_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
[`disallowed_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
[`disallowed_script_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ declare_clippy_lint! {
/// xs.push(123); // Vec::push is _not_ disallowed in the config.
/// ```
#[clippy::version = "1.49.0"]
pub DISALLOWED_METHOD,
pub DISALLOWED_METHODS,
nursery,
"use of a disallowed method call"
}

#[derive(Clone, Debug)]
pub struct DisallowedMethod {
pub struct DisallowedMethods {
conf_disallowed: Vec<conf::DisallowedMethod>,
disallowed: DefIdMap<Option<String>>,
}

impl DisallowedMethod {
impl DisallowedMethods {
pub fn new(conf_disallowed: Vec<conf::DisallowedMethod>) -> Self {
Self {
conf_disallowed,
Expand All @@ -68,9 +68,9 @@ impl DisallowedMethod {
}
}

impl_lint_pass!(DisallowedMethod => [DISALLOWED_METHOD]);
impl_lint_pass!(DisallowedMethods => [DISALLOWED_METHODS]);

impl<'tcx> LateLintPass<'tcx> for DisallowedMethod {
impl<'tcx> LateLintPass<'tcx> for DisallowedMethods {
fn check_crate(&mut self, cx: &LateContext<'_>) {
for conf in &self.conf_disallowed {
let (path, reason) = match conf {
Expand Down Expand Up @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethod {
};
let func_path = cx.tcx.def_path_str(def_id);
let msg = format!("use of a disallowed method `{}`", func_path);
span_lint_and_then(cx, DISALLOWED_METHOD, expr.span, &msg, |diag| {
span_lint_and_then(cx, DISALLOWED_METHODS, expr.span, &msg, |diag| {
if let Some(reason) = reason {
diag.note(reason);
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ store.register_lints(&[
derive::DERIVE_ORD_XOR_PARTIAL_ORD,
derive::EXPL_IMPL_CLONE_ON_COPY,
derive::UNSAFE_DERIVE_DESERIALIZE,
disallowed_method::DISALLOWED_METHOD,
disallowed_methods::DISALLOWED_METHODS,
disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS,
disallowed_types::DISALLOWED_TYPES,
doc::DOC_MARKDOWN,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
LintId::of(attrs::EMPTY_LINE_AFTER_OUTER_ATTR),
LintId::of(cognitive_complexity::COGNITIVE_COMPLEXITY),
LintId::of(copies::BRANCHES_SHARING_CODE),
LintId::of(disallowed_method::DISALLOWED_METHOD),
LintId::of(disallowed_methods::DISALLOWED_METHODS),
LintId::of(disallowed_types::DISALLOWED_TYPES),
LintId::of(equatable_if_let::EQUATABLE_IF_LET),
LintId::of(fallible_impl_from::FALLIBLE_IMPL_FROM),
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod default_numeric_fallback;
mod dereference;
mod derivable_impls;
mod derive;
mod disallowed_method;
mod disallowed_methods;
mod disallowed_script_idents;
mod disallowed_types;
mod doc;
Expand Down Expand Up @@ -808,7 +808,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| Box::new(semicolon_if_nothing_returned::SemicolonIfNothingReturned));
store.register_late_pass(|| Box::new(async_yields_async::AsyncYieldsAsync));
let disallowed_methods = conf.disallowed_methods.clone();
store.register_late_pass(move || Box::new(disallowed_method::DisallowedMethod::new(disallowed_methods.clone())));
store.register_late_pass(move || Box::new(disallowed_methods::DisallowedMethods::new(disallowed_methods.clone())));
store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86AttSyntax));
store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86IntelSyntax));
store.register_late_pass(|| Box::new(undropped_manually_drops::UndroppedManuallyDrops));
Expand Down Expand Up @@ -925,6 +925,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
ls.register_renamed("clippy::single_char_push_str", "clippy::single_char_add_str");
ls.register_renamed("clippy::if_let_some_result", "clippy::match_result_ok");
ls.register_renamed("clippy::disallowed_type", "clippy::disallowed_types");
ls.register_renamed("clippy::disallowed_method", "clippy::disallowed_methods");

// uplifted lints
ls.register_renamed("clippy::invalid_ref", "invalid_value");
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Rename {
pub rename: String,
}

/// A single disallowed method, used by the `DISALLOWED_METHOD` lint.
/// A single disallowed method, used by the `DISALLOWED_METHODS` lint.
#[derive(Clone, Debug, Deserialize)]
#[serde(untagged)]
pub enum DisallowedMethod {
Expand Down Expand Up @@ -256,7 +256,7 @@ define_Conf! {
///
/// Whether to allow certain wildcard imports (prelude, super in tests).
(warn_on_all_wildcard_imports: bool = false),
/// Lint: DISALLOWED_METHOD.
/// Lint: DISALLOWED_METHODS.
///
/// The list of disallowed methods, written as fully qualified paths.
(disallowed_methods: Vec<crate::utils::conf::DisallowedMethod> = Vec::new()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![warn(clippy::disallowed_method)]
#![warn(clippy::disallowed_methods)]

extern crate regex;
use regex::Regex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
error: use of a disallowed method `regex::Regex::new`
--> $DIR/conf_disallowed_method.rs:7:14
--> $DIR/conf_disallowed_methods.rs:7:14
|
LL | let re = Regex::new(r"ab.*c").unwrap();
| ^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::disallowed-method` implied by `-D warnings`
= note: `-D clippy::disallowed-methods` implied by `-D warnings`

error: use of a disallowed method `regex::Regex::is_match`
--> $DIR/conf_disallowed_method.rs:8:5
--> $DIR/conf_disallowed_methods.rs:8:5
|
LL | re.is_match("abc");
| ^^^^^^^^^^^^^^^^^^
|
= note: no matching allowed (from clippy.toml)

error: use of a disallowed method `std::iter::Iterator::sum`
--> $DIR/conf_disallowed_method.rs:11:5
--> $DIR/conf_disallowed_methods.rs:11:5
|
LL | a.iter().sum::<i32>();
| ^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/rename.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::new_without_default)]
#![allow(clippy::redundant_static_lifetimes)]
#![allow(clippy::cognitive_complexity)]
#![allow(clippy::bind_instead_of_map)]
#![allow(clippy::box_collection)]
#![allow(clippy::blocks_in_if_conditions)]
Expand All @@ -18,6 +19,7 @@
#![allow(clippy::single_char_add_str)]
#![allow(clippy::match_result_ok)]
#![allow(clippy::disallowed_types)]
#![allow(clippy::disallowed_methods)]
// uplifted lints
#![allow(invalid_value)]
#![allow(array_into_iter)]
Expand Down Expand Up @@ -51,6 +53,7 @@
#![warn(clippy::single_char_add_str)]
#![warn(clippy::match_result_ok)]
#![warn(clippy::disallowed_types)]
#![warn(clippy::disallowed_methods)]
// uplifted lints
#![warn(invalid_value)]
#![warn(array_into_iter)]
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::new_without_default)]
#![allow(clippy::redundant_static_lifetimes)]
#![allow(clippy::cognitive_complexity)]
#![allow(clippy::bind_instead_of_map)]
#![allow(clippy::box_collection)]
#![allow(clippy::blocks_in_if_conditions)]
Expand All @@ -18,6 +19,7 @@
#![allow(clippy::single_char_add_str)]
#![allow(clippy::match_result_ok)]
#![allow(clippy::disallowed_types)]
#![allow(clippy::disallowed_methods)]
// uplifted lints
#![allow(invalid_value)]
#![allow(array_into_iter)]
Expand Down Expand Up @@ -51,6 +53,7 @@
#![warn(clippy::single_char_push_str)]
#![warn(clippy::if_let_some_result)]
#![warn(clippy::disallowed_type)]
#![warn(clippy::disallowed_method)]
// uplifted lints
#![warn(clippy::invalid_ref)]
#![warn(clippy::into_iter_on_array)]
Expand Down
Loading

0 comments on commit 9b38fb7

Please sign in to comment.