diff options
| author | bors <bors@rust-lang.org> | 2021-08-07 13:05:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-07 13:05:53 +0000 |
| commit | 6cb30ad58128426307a7e476a2f81ef1e9673d3c (patch) | |
| tree | 6bd85ff2206ddcb0e1799662b8e63f1a86f6768b /clippy_lints | |
| parent | a0e71e5d637329e3904a659e9a876ccc8844e68a (diff) | |
| parent | 4743ec19489702b0c09adf684f7d9d8a9bcfdb10 (diff) | |
| download | rust-6cb30ad58128426307a7e476a2f81ef1e9673d3c.tar.gz rust-6cb30ad58128426307a7e476a2f81ef1e9673d3c.zip | |
Auto merge of #7534 - LeSeulArtichaut:7517-closure-too-many-lines, r=flip1995
Don't emit `too_many_lines` for closures changelog: don't emit the [`too_many_lines`] lint inside closures to avoir duplicated diagnostics. Fixes #7517.
Diffstat (limited to 'clippy_lints')
| -rw-r--r-- | clippy_lints/src/functions/mod.rs | 2 | ||||
| -rw-r--r-- | clippy_lints/src/functions/too_many_lines.rs | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/clippy_lints/src/functions/mod.rs b/clippy_lints/src/functions/mod.rs index ce23c0ce4a0..04fc5887e8e 100644 --- a/clippy_lints/src/functions/mod.rs +++ b/clippy_lints/src/functions/mod.rs @@ -251,7 +251,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { hir_id: hir::HirId, ) { too_many_arguments::check_fn(cx, kind, decl, span, hir_id, self.too_many_arguments_threshold); - too_many_lines::check_fn(cx, span, body, self.too_many_lines_threshold); + too_many_lines::check_fn(cx, kind, span, body, self.too_many_lines_threshold); not_unsafe_ptr_arg_deref::check_fn(cx, kind, decl, body, hir_id); } diff --git a/clippy_lints/src/functions/too_many_lines.rs b/clippy_lints/src/functions/too_many_lines.rs index a666fee1a4a..008ef661b55 100644 --- a/clippy_lints/src/functions/too_many_lines.rs +++ b/clippy_lints/src/functions/too_many_lines.rs @@ -1,4 +1,5 @@ use rustc_hir as hir; +use rustc_hir::intravisit::FnKind; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_span::Span; @@ -8,8 +9,16 @@ use clippy_utils::source::snippet_opt; use super::TOO_MANY_LINES; -pub(super) fn check_fn(cx: &LateContext<'_>, span: Span, body: &'tcx hir::Body<'_>, too_many_lines_threshold: u64) { - if in_external_macro(cx.sess(), span) { +pub(super) fn check_fn( + cx: &LateContext<'_>, + kind: FnKind<'tcx>, + span: Span, + body: &'tcx hir::Body<'_>, + too_many_lines_threshold: u64, +) { + // Closures must be contained in a parent body, which will be checked for `too_many_lines`. + // Don't check closures for `too_many_lines` to avoid duplicated lints. + if matches!(kind, FnKind::Closure) || in_external_macro(cx.sess(), span) { return; } |
