Skip to content

Commit

Permalink
Rename logic_bug to overly_complex_bool_expr
Browse files Browse the repository at this point in the history
Closes #1916
  • Loading branch information
guerinoni committed Aug 8, 2022
1 parent 4912c0e commit f6cab94
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 73 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3818,6 +3818,7 @@ Released 2018-09-13
[`or_then_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#or_then_unwrap
[`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing
[`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional
[`overly_complex_bool_expr`]: https://rust-lang.github.io/rust-clippy/master/index.html#overly_complex_bool_expr
[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic
[`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result_fn
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ declare_clippy_lint! {
/// if a {}
/// ```
#[clippy::version = "pre 1.29.0"]
pub LOGIC_BUG,
pub OVERLY_COMPLEX_BOOL_EXPR,
correctness,
"boolean expressions that contain terminals which can be eliminated"
}

// For each pairs, both orders are considered.
const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")];

declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, LOGIC_BUG]);
declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, OVERLY_COMPLEX_BOOL_EXPR]);

impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
fn check_fn(
Expand Down Expand Up @@ -396,7 +396,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
if stats.terminals[i] != 0 && simplified_stats.terminals[i] == 0 {
span_lint_hir_and_then(
self.cx,
LOGIC_BUG,
OVERLY_COMPLEX_BOOL_EXPR,
e.hir_id,
e.span,
"this boolean expression contains a logic bug",
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(await_holding_invalid::AWAIT_HOLDING_REFCELL_REF),
LintId::of(blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS),
LintId::of(bool_assert_comparison::BOOL_ASSERT_COMPARISON),
LintId::of(booleans::LOGIC_BUG),
LintId::of(booleans::NONMINIMAL_BOOL),
LintId::of(booleans::OVERLY_COMPLEX_BOOL_EXPR),
LintId::of(borrow_deref_ref::BORROW_DEREF_REF),
LintId::of(bytes_count_to_len::BYTES_COUNT_TO_LEN),
LintId::of(casts::CAST_ABS_TO_UNSIGNED),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ store.register_group(true, "clippy::correctness", Some("clippy_correctness"), ve
LintId::of(attrs::DEPRECATED_SEMVER),
LintId::of(attrs::MISMATCHED_TARGET_OS),
LintId::of(attrs::USELESS_ATTRIBUTE),
LintId::of(booleans::LOGIC_BUG),
LintId::of(booleans::OVERLY_COMPLEX_BOOL_EXPR),
LintId::of(casts::CAST_REF_TO_MUT),
LintId::of(casts::CAST_SLICE_DIFFERENT_SIZES),
LintId::of(copies::IFS_SAME_COND),
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 @@ -57,8 +57,8 @@ store.register_lints(&[
await_holding_invalid::AWAIT_HOLDING_REFCELL_REF,
blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS,
bool_assert_comparison::BOOL_ASSERT_COMPARISON,
booleans::LOGIC_BUG,
booleans::NONMINIMAL_BOOL,
booleans::OVERLY_COMPLEX_BOOL_EXPR,
borrow_as_ptr::BORROW_AS_PTR,
borrow_deref_ref::BORROW_DEREF_REF,
bytecount::NAIVE_BYTECOUNT,
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/renamed_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#[rustfmt::skip]
pub static RENAMED_LINTS: &[(&str, &str)] = &[
("clippy::blacklisted_name", "clippy::disallowed_names"),
("clippy::block_in_if_condition_expr", "clippy::blocks_in_if_conditions"),
("clippy::block_in_if_condition_stmt", "clippy::blocks_in_if_conditions"),
("clippy::box_vec", "clippy::box_collection"),
("clippy::blacklisted_name", "clippy::disallowed_names"),
("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes"),
("clippy::cyclomatic_complexity", "clippy::cognitive_complexity"),
("clippy::disallowed_method", "clippy::disallowed_methods"),
Expand All @@ -15,6 +15,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
("clippy::for_loop_over_result", "clippy::for_loops_over_fallibles"),
("clippy::identity_conversion", "clippy::useless_conversion"),
("clippy::if_let_some_result", "clippy::match_result_ok"),
("clippy::logic_bug", "clippy::overly_complex_bool_expr"),
("clippy::new_without_default_derive", "clippy::new_without_default"),
("clippy::option_and_then_some", "clippy::bind_instead_of_map"),
("clippy::option_expect_used", "clippy::expect_used"),
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/diverging_sub_expression.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![warn(clippy::diverging_sub_expression)]
#![allow(clippy::match_same_arms, clippy::logic_bug)]
#![allow(clippy::match_same_arms, clippy::overly_complex_bool_expr)]
#[allow(clippy::empty_loop)]
fn diverge() -> ! {
loop {}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/expect_tool_lint_rfc_2383.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ mod clippy_ok {
let _ = if true { 42 } else { 42 };
}

#[expect(clippy::logic_bug)]
#[expect(clippy::overly_complex_bool_expr)]
fn burger() {
let a = false;
let b = true;
Expand Down Expand Up @@ -127,7 +127,7 @@ mod clippy_warn {
let _ = if true { 33 } else { 42 };
}

#[expect(clippy::logic_bug)]
#[expect(clippy::overly_complex_bool_expr)]
fn burger() {
let a = false;
let b = true;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/expect_tool_lint_rfc_2383.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ LL | #[expect(clippy::if_same_then_else)]
error: this lint expectation is unfulfilled
--> $DIR/expect_tool_lint_rfc_2383.rs:130:14
|
LL | #[expect(clippy::logic_bug)]
| ^^^^^^^^^^^^^^^^^
LL | #[expect(clippy::overly_complex_bool_expr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 6 previous errors

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(lint_reasons)]
#![allow(unused, clippy::diverging_sub_expression)]
#![warn(clippy::logic_bug)]
#![warn(clippy::overly_complex_bool_expr)]

fn main() {
let a: bool = unimplemented!();
Expand Down Expand Up @@ -29,6 +29,6 @@ fn equality_stuff() {
fn check_expect() {
let a: i32 = unimplemented!();
let b: i32 = unimplemented!();
#[expect(clippy::logic_bug)]
#[expect(clippy::overly_complex_bool_expr)]
let _ = a < b && a >= b;
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
error: this boolean expression contains a logic bug
--> $DIR/logic_bug.rs:11:13
--> $DIR/overly_complex_bool_expr.rs:11:13
|
LL | let _ = a && b || a;
| ^^^^^^^^^^^ help: it would look like the following: `a`
|
= note: `-D clippy::logic-bug` implied by `-D warnings`
= note: `-D clippy::overly-complex-bool-expr` implied by `-D warnings`
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/logic_bug.rs:11:18
--> $DIR/overly_complex_bool_expr.rs:11:18
|
LL | let _ = a && b || a;
| ^

error: this boolean expression contains a logic bug
--> $DIR/logic_bug.rs:13:13
--> $DIR/overly_complex_bool_expr.rs:13:13
|
LL | let _ = false && a;
| ^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/logic_bug.rs:13:22
--> $DIR/overly_complex_bool_expr.rs:13:22
|
LL | let _ = false && a;
| ^

error: this boolean expression contains a logic bug
--> $DIR/logic_bug.rs:23:13
--> $DIR/overly_complex_bool_expr.rs:23:13
|
LL | let _ = a == b && a != b;
| ^^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/logic_bug.rs:23:13
--> $DIR/overly_complex_bool_expr.rs:23:13
|
LL | let _ = a == b && a != b;
| ^^^^^^

error: this boolean expression contains a logic bug
--> $DIR/logic_bug.rs:24:13
--> $DIR/overly_complex_bool_expr.rs:24:13
|
LL | let _ = a < b && a >= b;
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/logic_bug.rs:24:13
--> $DIR/overly_complex_bool_expr.rs:24:13
|
LL | let _ = a < b && a >= b;
| ^^^^^

error: this boolean expression contains a logic bug
--> $DIR/logic_bug.rs:25:13
--> $DIR/overly_complex_bool_expr.rs:25:13
|
LL | let _ = a > b && a <= b;
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/logic_bug.rs:25:13
--> $DIR/overly_complex_bool_expr.rs:25:13
|
LL | let _ = a > b && a <= b;
| ^^^^^
Expand Down
6 changes: 4 additions & 2 deletions tests/ui/rename.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

// run-rustfix

#![allow(clippy::disallowed_names)]
#![allow(clippy::blocks_in_if_conditions)]
#![allow(clippy::box_collection)]
#![allow(clippy::disallowed_names)]
#![allow(clippy::redundant_static_lifetimes)]
#![allow(clippy::cognitive_complexity)]
#![allow(clippy::disallowed_methods)]
Expand All @@ -15,6 +15,7 @@
#![allow(clippy::for_loops_over_fallibles)]
#![allow(clippy::useless_conversion)]
#![allow(clippy::match_result_ok)]
#![allow(clippy::overly_complex_bool_expr)]
#![allow(clippy::new_without_default)]
#![allow(clippy::bind_instead_of_map)]
#![allow(clippy::expect_used)]
Expand All @@ -34,10 +35,10 @@
#![allow(temporary_cstring_as_ptr)]
#![allow(unknown_lints)]
#![allow(unused_labels)]
#![warn(clippy::disallowed_names)]
#![warn(clippy::blocks_in_if_conditions)]
#![warn(clippy::blocks_in_if_conditions)]
#![warn(clippy::box_collection)]
#![warn(clippy::disallowed_names)]
#![warn(clippy::redundant_static_lifetimes)]
#![warn(clippy::cognitive_complexity)]
#![warn(clippy::disallowed_methods)]
Expand All @@ -47,6 +48,7 @@
#![warn(clippy::for_loops_over_fallibles)]
#![warn(clippy::useless_conversion)]
#![warn(clippy::match_result_ok)]
#![warn(clippy::overly_complex_bool_expr)]
#![warn(clippy::new_without_default)]
#![warn(clippy::bind_instead_of_map)]
#![warn(clippy::expect_used)]
Expand Down
6 changes: 4 additions & 2 deletions tests/ui/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

// run-rustfix

#![allow(clippy::disallowed_names)]
#![allow(clippy::blocks_in_if_conditions)]
#![allow(clippy::box_collection)]
#![allow(clippy::disallowed_names)]
#![allow(clippy::redundant_static_lifetimes)]
#![allow(clippy::cognitive_complexity)]
#![allow(clippy::disallowed_methods)]
Expand All @@ -15,6 +15,7 @@
#![allow(clippy::for_loops_over_fallibles)]
#![allow(clippy::useless_conversion)]
#![allow(clippy::match_result_ok)]
#![allow(clippy::overly_complex_bool_expr)]
#![allow(clippy::new_without_default)]
#![allow(clippy::bind_instead_of_map)]
#![allow(clippy::expect_used)]
Expand All @@ -34,10 +35,10 @@
#![allow(temporary_cstring_as_ptr)]
#![allow(unknown_lints)]
#![allow(unused_labels)]
#![warn(clippy::blacklisted_name)]
#![warn(clippy::block_in_if_condition_expr)]
#![warn(clippy::block_in_if_condition_stmt)]
#![warn(clippy::box_vec)]
#![warn(clippy::blacklisted_name)]
#![warn(clippy::const_static_lifetime)]
#![warn(clippy::cyclomatic_complexity)]
#![warn(clippy::disallowed_method)]
Expand All @@ -47,6 +48,7 @@
#![warn(clippy::for_loop_over_result)]
#![warn(clippy::identity_conversion)]
#![warn(clippy::if_let_some_result)]
#![warn(clippy::logic_bug)]
#![warn(clippy::new_without_default_derive)]
#![warn(clippy::option_and_then_some)]
#![warn(clippy::option_expect_used)]
Expand Down
Loading

0 comments on commit f6cab94

Please sign in to comment.