Skip to content

Commit

Permalink
Change lint type to 'complexity'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystucki committed Aug 18, 2019
1 parent 5df84f2 commit 9c39c02
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
methods::OPTION_MAP_UNWRAP_OR,
methods::OPTION_MAP_UNWRAP_OR_ELSE,
methods::RESULT_MAP_UNWRAP_OR_ELSE,
methods::SUSPICIOUS_MAP,
misc::USED_UNDERSCORE_BINDING,
misc_early::UNSEPARATED_LITERAL_SUFFIX,
mut_mut::MUT_MUT,
Expand Down Expand Up @@ -801,6 +800,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
methods::SHOULD_IMPLEMENT_TRAIT,
methods::SINGLE_CHAR_PATTERN,
methods::STRING_EXTEND_CHARS,
methods::SUSPICIOUS_MAP,
methods::TEMPORARY_CSTRING_AS_PTR,
methods::UNNECESSARY_FILTER_MAP,
methods::UNNECESSARY_FOLD,
Expand Down Expand Up @@ -1034,6 +1034,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
methods::FILTER_NEXT,
methods::FLAT_MAP_IDENTITY,
methods::SEARCH_IS_SOME,
methods::SUSPICIOUS_MAP,
methods::UNNECESSARY_FILTER_MAP,
methods::USELESS_ASREF,
misc::SHORT_CIRCUIT_STATEMENT,
Expand Down
10 changes: 6 additions & 4 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use syntax::ast;
use syntax::source_map::Span;
use syntax::symbol::LocalInternedString;

use crate::utils::paths;
use crate::utils::sugg;
use crate::utils::usage::mutated_variables;
use crate::utils::{
Expand All @@ -28,6 +27,7 @@ use crate::utils::{
snippet, snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_sugg,
span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq,
};
use crate::utils::{paths, span_help_and_lint};

declare_clippy_lint! {
/// **What it does:** Checks for `.unwrap()` calls on `Option`s.
Expand Down Expand Up @@ -893,6 +893,7 @@ declare_clippy_lint! {
/// **What it does:** Checks for calls to `map` followed by a `count`.
///
/// **Why is this bad?** It looks suspicious. Maybe `map` was confused with `filter`.
/// If the `map` call is intentional, this should be rewritten.
///
/// **Known problems:** None
///
Expand All @@ -902,7 +903,7 @@ declare_clippy_lint! {
/// let _ = (0..3).map(|x| x + 2).count();
/// ```
pub SUSPICIOUS_MAP,
pedantic,
complexity,
"suspicious usage of map"
}

Expand Down Expand Up @@ -2539,11 +2540,12 @@ fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: Ty<'_
}

fn lint_suspicious_map(cx: &LateContext<'_, '_>, expr: &hir::Expr) {
span_lint(
span_help_and_lint(
cx,
SUSPICIOUS_MAP,
expr.span,
"Make sure you did not confuse `map` with `filter`.",
"this call to `map()` won't have an effect on the call to `count()`",
"make sure you did not confuse `map` with `filter`",
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ pub const ALL_LINTS: [Lint; 310] = [
},
Lint {
name: "suspicious_map",
group: "pedantic",
group: "complexity",
desc: "suspicious usage of map",
deprecation: None,
module: "methods",
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/suspicious_map.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
error: Make sure you did not confuse `map` with `filter`.
error: this call to `map()` won't have an effect on the call to `count()`
--> $DIR/suspicious_map.rs:4:13
|
LL | let _ = (0..3).map(|x| x + 2).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::suspicious-map` implied by `-D warnings`
= help: make sure you did not confuse `map` with `filter`

error: aborting due to previous error

0 comments on commit 9c39c02

Please sign in to comment.