Skip to content

Commit cfd720d

Browse files
committed
Auto merge of rust-lang#5563 - ThibsG:MergeLints, r=flip1995
Merge some lints together This PR merges following lints: - `block_in_if_condition_expr` and `block_in_if_condition_stmt` → `blocks_in_if_conditions` - `option_map_unwrap_or`, `option_map_unwrap_or_else` and `result_map_unwrap_or_else` → `map_unwrap` - `option_unwrap_used` and `result_unwrap_used` → `unwrap_used` - `option_expect_used` and `result_expect_used` → `expect_used` - `wrong_pub_self_convention` into `wrong_self_convention` - `for_loop_over_option` and `for_loop_over_result` → `for_loops_over_fallibles` Lints that have already been merged since the issue was created: - [x] `new_without_default` and `new_without_default_derive` → `new_without_default` Need more discussion: - `string_add` and `string_add_assign`: do we agree to merge them or not? Is there something more to do? → **not merge finally** - `identity_op` and `modulo_one` → `useless_arithmetic`: seems outdated, since `modulo_arithmetic` has been created. fixes rust-lang#1078 changelog: Merging some lints together: - `block_in_if_condition_expr` and `block_in_if_condition_stmt` → `blocks_in_if_conditions` - `option_map_unwrap_or`, `option_map_unwrap_or_else` and `result_map_unwrap_or_else` → `map_unwrap_or` - `option_unwrap_used` and `result_unwrap_used` → `unwrap_used` - `option_expect_used` and `result_expect_used` → `expect_used` - `for_loop_over_option` and `for_loop_over_result` → `for_loops_over_fallibles`
2 parents 0c94273 + ab87f87 commit cfd720d

22 files changed

+277
-438
lines changed

CHANGELOG.md

+14-20
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Released 2020-03-12
198198

199199
### Suggestion Improvements
200200

201-
* [`option_map_unwrap_or`] [#4634](https://github.com/rust-lang/rust-clippy/pull/4634)
201+
* `option_map_unwrap_or` [#4634](https://github.com/rust-lang/rust-clippy/pull/4634)
202202
* [`wildcard_enum_match_arm`] [#4934](https://github.com/rust-lang/rust-clippy/pull/4934)
203203
* [`cognitive_complexity`] [#4935](https://github.com/rust-lang/rust-clippy/pull/4935)
204204
* [`decimal_literal_representation`] [#4956](https://github.com/rust-lang/rust-clippy/pull/4956)
@@ -282,8 +282,8 @@ Released 2019-12-19
282282
* [`panic`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657)
283283
* [`unreachable`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657)
284284
* [`todo`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657)
285-
* [`option_expect_used`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657)
286-
* [`result_expect_used`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657)
285+
* `option_expect_used` [#4657](https://github.com/rust-lang/rust-clippy/pull/4657)
286+
* `result_expect_used` [#4657](https://github.com/rust-lang/rust-clippy/pull/4657)
287287
* Move `redundant_clone` to perf group [#4509](https://github.com/rust-lang/rust-clippy/pull/4509)
288288
* Move `manual_mul_add` to nursery group [#4736](https://github.com/rust-lang/rust-clippy/pull/4736)
289289
* Expand `unit_cmp` to also work with `assert_eq!`, `debug_assert_eq!`, `assert_ne!` and `debug_assert_ne!` [#4613](https://github.com/rust-lang/rust-clippy/pull/4613)
@@ -395,7 +395,7 @@ Released 2019-08-15
395395
* Fix false positive in [`useless_attribute`] [#4107](https://github.com/rust-lang/rust-clippy/pull/4107)
396396
* Fix incorrect suggestion for [`float_cmp`] [#4214](https://github.com/rust-lang/rust-clippy/pull/4214)
397397
* Add suggestions for [`print_with_newline`] and [`write_with_newline`] [#4136](https://github.com/rust-lang/rust-clippy/pull/4136)
398-
* Improve suggestions for [`option_map_unwrap_or_else`] and [`result_map_unwrap_or_else`] [#4164](https://github.com/rust-lang/rust-clippy/pull/4164)
398+
* Improve suggestions for `option_map_unwrap_or_else` and `result_map_unwrap_or_else` [#4164](https://github.com/rust-lang/rust-clippy/pull/4164)
399399
* Improve suggestions for [`non_ascii_literal`] [#4119](https://github.com/rust-lang/rust-clippy/pull/4119)
400400
* Improve diagnostics for [`let_and_return`] [#4137](https://github.com/rust-lang/rust-clippy/pull/4137)
401401
* Improve diagnostics for [`trivially_copy_pass_by_ref`] [#4071](https://github.com/rust-lang/rust-clippy/pull/4071)
@@ -448,7 +448,7 @@ Released 2019-05-20
448448
* Fix false positive in [`needless_range_loop`] pertaining to structs without a `.iter()`
449449
* Fix false positive in [`bool_comparison`] pertaining to non-bool types
450450
* Fix false positive in [`redundant_closure`] pertaining to differences in borrows
451-
* Fix false positive in [`option_map_unwrap_or`] on non-copy types
451+
* Fix false positive in `option_map_unwrap_or` on non-copy types
452452
* Fix false positives in [`missing_const_for_fn`] pertaining to macros and trait method impls
453453
* Fix false positive in [`needless_pass_by_value`] pertaining to procedural macros
454454
* Fix false positive in [`needless_continue`] pertaining to loop labels
@@ -794,7 +794,7 @@ Released 2018-09-13
794794

795795
## 0.0.169
796796
* Rustup to *rustc 1.23.0-nightly (3b82e4c74 2017-11-05)*
797-
* New lints: [`just_underscores_and_digits`], [`result_map_unwrap_or_else`], [`transmute_bytes_to_str`]
797+
* New lints: [`just_underscores_and_digits`], `result_map_unwrap_or_else`, [`transmute_bytes_to_str`]
798798

799799
## 0.0.168
800800
* Rustup to *rustc 1.23.0-nightly (f0fe716db 2017-10-30)*
@@ -1068,7 +1068,7 @@ Released 2018-09-13
10681068

10691069
## 0.0.93 — 2016-10-03
10701070
* Rustup to *rustc 1.14.0-nightly (144af3e97 2016-10-02)*
1071-
* [`option_map_unwrap_or`] and [`option_map_unwrap_or_else`] are now
1071+
* `option_map_unwrap_or` and `option_map_unwrap_or_else` are now
10721072
allowed by default.
10731073
* New lint: [`explicit_into_iter_loop`]
10741074

@@ -1087,8 +1087,8 @@ Released 2018-09-13
10871087
## 0.0.88 — 2016-09-04
10881088
* Rustup to *rustc 1.13.0-nightly (70598e04f 2016-09-03)*
10891089
* The following lints are not new but were only usable through the `clippy`
1090-
lint groups: [`filter_next`], [`for_loop_over_option`],
1091-
[`for_loop_over_result`] and [`match_overlapping_arm`]. You should now be
1090+
lint groups: [`filter_next`], `for_loop_over_option`,
1091+
`for_loop_over_result` and [`match_overlapping_arm`]. You should now be
10921092
able to `#[allow/deny]` them individually and they are available directly
10931093
through `cargo clippy`.
10941094

@@ -1274,8 +1274,7 @@ Released 2018-09-13
12741274
[`await_holding_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_lock
12751275
[`bad_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
12761276
[`blacklisted_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name
1277-
[`block_in_if_condition_expr`]: https://rust-lang.github.io/rust-clippy/master/index.html#block_in_if_condition_expr
1278-
[`block_in_if_condition_stmt`]: https://rust-lang.github.io/rust-clippy/master/index.html#block_in_if_condition_stmt
1277+
[`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
12791278
[`bool_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
12801279
[`borrow_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const
12811280
[`borrowed_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box
@@ -1338,6 +1337,7 @@ Released 2018-09-13
13381337
[`excessive_precision`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision
13391338
[`exit`]: https://rust-lang.github.io/rust-clippy/master/index.html#exit
13401339
[`expect_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call
1340+
[`expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_used
13411341
[`expl_impl_clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#expl_impl_clone_on_copy
13421342
[`explicit_counter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_counter_loop
13431343
[`explicit_deref_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_deref_methods
@@ -1361,8 +1361,7 @@ Released 2018-09-13
13611361
[`fn_to_numeric_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast
13621362
[`fn_to_numeric_cast_with_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast_with_truncation
13631363
[`for_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_kv_map
1364-
[`for_loop_over_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loop_over_option
1365-
[`for_loop_over_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loop_over_result
1364+
[`for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles
13661365
[`forget_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_copy
13671366
[`forget_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_ref
13681367
[`future_not_send`]: https://rust-lang.github.io/rust-clippy/master/index.html#future_not_send
@@ -1431,6 +1430,7 @@ Released 2018-09-13
14311430
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
14321431
[`map_entry`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
14331432
[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
1433+
[`map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or
14341434
[`match_as_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_as_ref
14351435
[`match_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_bool
14361436
[`match_on_vec_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_on_vec_items
@@ -1497,13 +1497,9 @@ Released 2018-09-13
14971497
[`option_and_then_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_and_then_some
14981498
[`option_as_ref_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
14991499
[`option_env_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_env_unwrap
1500-
[`option_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_expect_used
15011500
[`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none
15021501
[`option_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn
1503-
[`option_map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or
1504-
[`option_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or_else
15051502
[`option_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_option
1506-
[`option_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_unwrap_used
15071503
[`or_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call
15081504
[`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing
15091505
[`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional
@@ -1540,11 +1536,8 @@ Released 2018-09-13
15401536
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
15411537
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
15421538
[`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs
1543-
[`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used
15441539
[`result_map_or_into_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_or_into_option
15451540
[`result_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unit_fn
1546-
[`result_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else
1547-
[`result_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unwrap_used
15481541
[`reversed_empty_ranges`]: https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges
15491542
[`same_functions_in_if_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_functions_in_if_condition
15501543
[`search_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some
@@ -1625,6 +1618,7 @@ Released 2018-09-13
16251618
[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label
16261619
[`unused_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_self
16271620
[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
1621+
[`unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
16281622
[`use_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_debug
16291623
[`use_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_self
16301624
[`used_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding

clippy_lints/src/block_in_if_condition.rs renamed to clippy_lints/src/blocks_in_if_conditions.rs

+25-28
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,40 @@ use rustc_middle::lint::in_external_macro;
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99

1010
declare_clippy_lint! {
11-
/// **What it does:** Checks for `if` conditions that use blocks to contain an
12-
/// expression.
11+
/// **What it does:** Checks for `if` conditions that use blocks containing an
12+
/// expression, statements or conditions that use closures with blocks.
1313
///
14-
/// **Why is this bad?** It isn't really Rust style, same as using parentheses
15-
/// to contain expressions.
14+
/// **Why is this bad?** Style, using blocks in the condition makes it hard to read.
1615
///
1716
/// **Known problems:** None.
1817
///
19-
/// **Example:**
18+
/// **Examples:**
2019
/// ```rust
20+
/// // Bad
2121
/// if { true } { /* ... */ }
22+
///
23+
/// // Good
24+
/// if true { /* ... */ }
2225
/// ```
23-
pub BLOCK_IN_IF_CONDITION_EXPR,
24-
style,
25-
"braces that can be eliminated in conditions, e.g., `if { true } ...`"
26-
}
27-
28-
declare_clippy_lint! {
29-
/// **What it does:** Checks for `if` conditions that use blocks containing
30-
/// statements, or conditions that use closures with blocks.
3126
///
32-
/// **Why is this bad?** Using blocks in the condition makes it hard to read.
27+
/// // or
3328
///
34-
/// **Known problems:** None.
29+
/// ```rust
30+
/// # fn somefunc() -> bool { true };
3531
///
36-
/// **Example:**
37-
/// ```rust,ignore
38-
/// if { let x = somefunc(); x } {}
39-
/// // or
40-
/// if somefunc(|x| { x == 47 }) {}
32+
/// // Bad
33+
/// if { let x = somefunc(); x } { /* ... */ }
34+
///
35+
/// // Good
36+
/// let res = { let x = somefunc(); x };
37+
/// if res { /* ... */ }
4138
/// ```
42-
pub BLOCK_IN_IF_CONDITION_STMT,
39+
pub BLOCKS_IN_IF_CONDITIONS,
4340
style,
44-
"complex blocks in conditions, e.g., `if { let x = true; x } ...`"
41+
"useless or complex blocks that can be eliminated in conditions"
4542
}
4643

47-
declare_lint_pass!(BlockInIfCondition => [BLOCK_IN_IF_CONDITION_EXPR, BLOCK_IN_IF_CONDITION_STMT]);
44+
declare_lint_pass!(BlocksInIfConditions => [BLOCKS_IN_IF_CONDITIONS]);
4845

4946
struct ExVisitor<'a, 'tcx> {
5047
found_block: Option<&'tcx Expr<'tcx>>,
@@ -72,9 +69,9 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
7269

7370
const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression condition";
7471
const COMPLEX_BLOCK_MESSAGE: &str = "in an `if` condition, avoid complex blocks or closures with blocks; \
75-
instead, move the block or closure higher and bind it with a `let`";
72+
instead, move the block or closure higher and bind it with a `let`";
7673

77-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
74+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlocksInIfConditions {
7875
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
7976
if in_external_macro(cx.sess(), expr.span) {
8077
return;
@@ -92,7 +89,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
9289
let mut applicability = Applicability::MachineApplicable;
9390
span_lint_and_sugg(
9491
cx,
95-
BLOCK_IN_IF_CONDITION_EXPR,
92+
BLOCKS_IN_IF_CONDITIONS,
9693
cond.span,
9794
BRACED_EXPR_MESSAGE,
9895
"try",
@@ -118,7 +115,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
118115
let mut applicability = Applicability::MachineApplicable;
119116
span_lint_and_sugg(
120117
cx,
121-
BLOCK_IN_IF_CONDITION_STMT,
118+
BLOCKS_IN_IF_CONDITIONS,
122119
expr.span.with_hi(cond.span.hi()),
123120
COMPLEX_BLOCK_MESSAGE,
124121
"try",
@@ -140,7 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
140137
let mut visitor = ExVisitor { found_block: None, cx };
141138
walk_expr(&mut visitor, cond);
142139
if let Some(block) = visitor.found_block {
143-
span_lint(cx, BLOCK_IN_IF_CONDITION_STMT, block.span, COMPLEX_BLOCK_MESSAGE);
140+
span_lint(cx, BLOCKS_IN_IF_CONDITIONS, block.span, COMPLEX_BLOCK_MESSAGE);
144141
}
145142
}
146143
}

0 commit comments

Comments
 (0)