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
This commit is contained in:
parent
d9b940e2c3
commit
9e1c7febe2
@ -1,5 +1,5 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::{has_repr_attr, is_bool};
|
||||
use clippy_utils::{get_parent_as_impl, has_repr_attr, is_bool};
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{Body, FnDecl, HirId, Item, ItemKind, Ty};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
@ -159,11 +159,16 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
|
||||
fn_decl: &'tcx FnDecl<'tcx>,
|
||||
_: &'tcx Body<'tcx>,
|
||||
span: Span,
|
||||
_: HirId,
|
||||
hir_id: HirId,
|
||||
) {
|
||||
if let Some(fn_header) = fn_kind.header()
|
||||
&& fn_header.abi == Abi::Rust
|
||||
&& !span.from_expansion() {
|
||||
&& !span.from_expansion()
|
||||
&& get_parent_as_impl(cx.tcx, hir_id)
|
||||
.map_or(true,
|
||||
|impl_item| impl_item.of_trait.is_none()
|
||||
)
|
||||
{
|
||||
self.check_fn_sig(cx, fn_decl, span);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ impl S {
|
||||
}
|
||||
|
||||
impl Trait for S {
|
||||
// Should not lint because the trait might not be changeable by the user
|
||||
// We only lint in the trait definition
|
||||
fn f(_: bool, _: bool, _: bool, _: bool) {}
|
||||
fn g(_: bool, _: bool, _: bool, _: Vec<u32>) {}
|
||||
}
|
||||
|
@ -24,15 +24,7 @@ LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {}
|
||||
= help: consider refactoring bools into two-variant enums
|
||||
|
||||
error: more than 3 bools in function parameters
|
||||
--> $DIR/fn_params_excessive_bools.rs:38:5
|
||||
|
|
||||
LL | fn f(_: bool, _: bool, _: bool, _: bool) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider refactoring bools into two-variant enums
|
||||
|
||||
error: more than 3 bools in function parameters
|
||||
--> $DIR/fn_params_excessive_bools.rs:43:5
|
||||
--> $DIR/fn_params_excessive_bools.rs:45:5
|
||||
|
|
||||
LL | / fn n(_: bool, _: u32, _: bool, _: Box<u32>, _: bool, _: bool) {
|
||||
LL | | fn nn(_: bool, _: bool, _: bool, _: bool) {}
|
||||
@ -42,12 +34,12 @@ LL | | }
|
||||
= help: consider refactoring bools into two-variant enums
|
||||
|
||||
error: more than 3 bools in function parameters
|
||||
--> $DIR/fn_params_excessive_bools.rs:44:9
|
||||
--> $DIR/fn_params_excessive_bools.rs:46:9
|
||||
|
|
||||
LL | fn nn(_: bool, _: bool, _: bool, _: bool) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider refactoring bools into two-variant enums
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user