Skip to content

Commit 9e1c7fe

Browse files
committed
excessive_bools, do not lint in trait impls
Should not lint because the trait might not be changeable by the user We only lint in the trait definition
1 parent d9b940e commit 9e1c7fe

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

clippy_lints/src/excessive_bools.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::{has_repr_attr, is_bool};
2+
use clippy_utils::{get_parent_as_impl, has_repr_attr, is_bool};
33
use rustc_hir::intravisit::FnKind;
44
use rustc_hir::{Body, FnDecl, HirId, Item, ItemKind, Ty};
55
use rustc_lint::{LateContext, LateLintPass};
@@ -159,11 +159,16 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
159159
fn_decl: &'tcx FnDecl<'tcx>,
160160
_: &'tcx Body<'tcx>,
161161
span: Span,
162-
_: HirId,
162+
hir_id: HirId,
163163
) {
164164
if let Some(fn_header) = fn_kind.header()
165165
&& fn_header.abi == Abi::Rust
166-
&& !span.from_expansion() {
166+
&& !span.from_expansion()
167+
&& get_parent_as_impl(cx.tcx, hir_id)
168+
.map_or(true,
169+
|impl_item| impl_item.of_trait.is_none()
170+
)
171+
{
167172
self.check_fn_sig(cx, fn_decl, span);
168173
}
169174
}

tests/ui/fn_params_excessive_bools.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ impl S {
3535
}
3636

3737
impl Trait for S {
38+
// Should not lint because the trait might not be changeable by the user
39+
// We only lint in the trait definition
3840
fn f(_: bool, _: bool, _: bool, _: bool) {}
3941
fn g(_: bool, _: bool, _: bool, _: Vec<u32>) {}
4042
}

tests/ui/fn_params_excessive_bools.stderr

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@ LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {}
2424
= help: consider refactoring bools into two-variant enums
2525

2626
error: more than 3 bools in function parameters
27-
--> $DIR/fn_params_excessive_bools.rs:38:5
28-
|
29-
LL | fn f(_: bool, _: bool, _: bool, _: bool) {}
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31-
|
32-
= help: consider refactoring bools into two-variant enums
33-
34-
error: more than 3 bools in function parameters
35-
--> $DIR/fn_params_excessive_bools.rs:43:5
27+
--> $DIR/fn_params_excessive_bools.rs:45:5
3628
|
3729
LL | / fn n(_: bool, _: u32, _: bool, _: Box<u32>, _: bool, _: bool) {
3830
LL | | fn nn(_: bool, _: bool, _: bool, _: bool) {}
@@ -42,12 +34,12 @@ LL | | }
4234
= help: consider refactoring bools into two-variant enums
4335

4436
error: more than 3 bools in function parameters
45-
--> $DIR/fn_params_excessive_bools.rs:44:9
37+
--> $DIR/fn_params_excessive_bools.rs:46:9
4638
|
4739
LL | fn nn(_: bool, _: bool, _: bool, _: bool) {}
4840
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4941
|
5042
= help: consider refactoring bools into two-variant enums
5143

52-
error: aborting due to 6 previous errors
44+
error: aborting due to 5 previous errors
5345

0 commit comments

Comments
 (0)