Skip to content

Commit 6ae0643

Browse files
committed
Auto merge of #5529 - alex-700:improve-option-and-then-some-lint, r=phansch
Improve `option_and_then_some` lint fixed #5492 changelog: Improve and generalize `option_and_then_some` and rename it to `bind_instead_of_map`.
2 parents 440a46d + 07f1edf commit 6ae0643

20 files changed

+523
-125
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ Released 2019-11-07
315315
* [`missing_safety_doc`] [#4535](https://github.com/rust-lang/rust-clippy/pull/4535)
316316
* [`mem_replace_with_uninit`] [#4511](https://github.com/rust-lang/rust-clippy/pull/4511)
317317
* [`suspicious_map`] [#4394](https://github.com/rust-lang/rust-clippy/pull/4394)
318-
* [`option_and_then_some`] [#4386](https://github.com/rust-lang/rust-clippy/pull/4386)
318+
* `option_and_then_some` [#4386](https://github.com/rust-lang/rust-clippy/pull/4386)
319319
* [`manual_saturating_arithmetic`] [#4498](https://github.com/rust-lang/rust-clippy/pull/4498)
320320
* Deprecate `unused_collect` lint. This is fully covered by rustc's `#[must_use]` on `collect` [#4348](https://github.com/rust-lang/rust-clippy/pull/4348)
321321
* Move `type_repetition_in_bounds` to pedantic group [#4403](https://github.com/rust-lang/rust-clippy/pull/4403)
@@ -1273,6 +1273,7 @@ Released 2018-09-13
12731273
[`assign_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_ops
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
1276+
[`bind_instead_of_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map
12761277
[`blacklisted_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name
12771278
[`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
12781279
[`bool_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
@@ -1494,7 +1495,6 @@ Released 2018-09-13
14941495
[`not_unsafe_ptr_arg_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
14951496
[`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect
14961497
[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
1497-
[`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
15001500
[`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none

clippy_lints/src/eq_op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
115115
let rsnip = snippet(cx, r.span, "...").to_string();
116116
multispan_sugg(
117117
diag,
118-
"use the values directly".to_string(),
118+
"use the values directly",
119119
vec![(left.span, lsnip), (right.span, rsnip)],
120120
);
121121
},

clippy_lints/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
650650
&mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
651651
&mem_replace::MEM_REPLACE_WITH_DEFAULT,
652652
&mem_replace::MEM_REPLACE_WITH_UNINIT,
653+
&methods::BIND_INSTEAD_OF_MAP,
653654
&methods::CHARS_LAST_CMP,
654655
&methods::CHARS_NEXT_CMP,
655656
&methods::CLONE_DOUBLE_REF,
@@ -676,7 +677,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
676677
&methods::MAP_UNWRAP_OR,
677678
&methods::NEW_RET_NO_SELF,
678679
&methods::OK_EXPECT,
679-
&methods::OPTION_AND_THEN_SOME,
680680
&methods::OPTION_AS_REF_DEREF,
681681
&methods::OPTION_MAP_OR_NONE,
682682
&methods::OR_FUN_CALL,
@@ -1291,6 +1291,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12911291
LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE),
12921292
LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT),
12931293
LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT),
1294+
LintId::of(&methods::BIND_INSTEAD_OF_MAP),
12941295
LintId::of(&methods::CHARS_LAST_CMP),
12951296
LintId::of(&methods::CHARS_NEXT_CMP),
12961297
LintId::of(&methods::CLONE_DOUBLE_REF),
@@ -1307,7 +1308,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13071308
LintId::of(&methods::MANUAL_SATURATING_ARITHMETIC),
13081309
LintId::of(&methods::NEW_RET_NO_SELF),
13091310
LintId::of(&methods::OK_EXPECT),
1310-
LintId::of(&methods::OPTION_AND_THEN_SOME),
13111311
LintId::of(&methods::OPTION_AS_REF_DEREF),
13121312
LintId::of(&methods::OPTION_MAP_OR_NONE),
13131313
LintId::of(&methods::OR_FUN_CALL),
@@ -1559,10 +1559,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15591559
LintId::of(&matches::MATCH_AS_REF),
15601560
LintId::of(&matches::MATCH_SINGLE_BINDING),
15611561
LintId::of(&matches::WILDCARD_IN_OR_PATTERNS),
1562+
LintId::of(&methods::BIND_INSTEAD_OF_MAP),
15621563
LintId::of(&methods::CLONE_ON_COPY),
15631564
LintId::of(&methods::FILTER_NEXT),
15641565
LintId::of(&methods::FLAT_MAP_IDENTITY),
1565-
LintId::of(&methods::OPTION_AND_THEN_SOME),
15661566
LintId::of(&methods::OPTION_AS_REF_DEREF),
15671567
LintId::of(&methods::SEARCH_IS_SOME),
15681568
LintId::of(&methods::SKIP_WHILE_NEXT),
@@ -1784,6 +1784,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
17841784
ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
17851785
ls.register_renamed("clippy::cyclomatic_complexity", "clippy::cognitive_complexity");
17861786
ls.register_renamed("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes");
1787+
ls.register_renamed("clippy::option_and_then_some", "clippy::bind_instead_of_map");
17871788
ls.register_renamed("clippy::block_in_if_condition_expr", "clippy::blocks_in_if_conditions");
17881789
ls.register_renamed("clippy::block_in_if_condition_stmt", "clippy::blocks_in_if_conditions");
17891790
ls.register_renamed("clippy::option_map_unwrap_or", "clippy::map_unwrap_or");

clippy_lints/src/loops.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ fn check_for_loop_range<'a, 'tcx>(
11341134
|diag| {
11351135
multispan_sugg(
11361136
diag,
1137-
"consider using an iterator".to_string(),
1137+
"consider using an iterator",
11381138
vec![
11391139
(pat.span, format!("({}, <item>)", ident.name)),
11401140
(
@@ -1163,7 +1163,7 @@ fn check_for_loop_range<'a, 'tcx>(
11631163
|diag| {
11641164
multispan_sugg(
11651165
diag,
1166-
"consider using an iterator".to_string(),
1166+
"consider using an iterator",
11671167
vec![(pat.span, "<item>".to_string()), (arg.span, repl)],
11681168
);
11691169
},
@@ -1462,7 +1462,7 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
14621462
let map = sugg::Sugg::hir(cx, arg, "map");
14631463
multispan_sugg(
14641464
diag,
1465-
"use the corresponding method".into(),
1465+
"use the corresponding method",
14661466
vec![
14671467
(pat_span, snippet(cx, new_pat_span, kind).into_owned()),
14681468
(arg_span, format!("{}.{}s{}()", map.maybe_par(), kind, mutbl)),

clippy_lints/src/matches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>
820820

821821
span_lint_and_then(cx, MATCH_REF_PATS, expr.span, title, |diag| {
822822
if !expr.span.from_expansion() {
823-
multispan_sugg(diag, msg.to_owned(), suggs);
823+
multispan_sugg(diag, msg, suggs);
824824
}
825825
});
826826
}

0 commit comments

Comments
 (0)