Skip to content

Commit f4d2ddc

Browse files
committed
Rename lint map_unwrap to map_unwrap_or and register lints as renamed
1 parent adbdf75 commit f4d2ddc

File tree

7 files changed

+36
-25
lines changed

7 files changed

+36
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ Released 2018-09-13
14301430
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
14311431
[`map_entry`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
14321432
[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
1433-
[`map_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap
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

clippy_lints/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
673673
&methods::ITER_SKIP_NEXT,
674674
&methods::MANUAL_SATURATING_ARITHMETIC,
675675
&methods::MAP_FLATTEN,
676-
&methods::MAP_UNWRAP,
676+
&methods::MAP_UNWRAP_OR,
677677
&methods::NEW_RET_NO_SELF,
678678
&methods::OK_EXPECT,
679679
&methods::OPTION_AND_THEN_SOME,
@@ -1145,7 +1145,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11451145
LintId::of(&methods::FIND_MAP),
11461146
LintId::of(&methods::INEFFICIENT_TO_STRING),
11471147
LintId::of(&methods::MAP_FLATTEN),
1148-
LintId::of(&methods::MAP_UNWRAP),
1148+
LintId::of(&methods::MAP_UNWRAP_OR),
11491149
LintId::of(&misc::USED_UNDERSCORE_BINDING),
11501150
LintId::of(&misc_early::UNSEPARATED_LITERAL_SUFFIX),
11511151
LintId::of(&mut_mut::MUT_MUT),
@@ -1785,6 +1785,17 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
17851785
ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
17861786
ls.register_renamed("clippy::cyclomatic_complexity", "clippy::cognitive_complexity");
17871787
ls.register_renamed("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes");
1788+
ls.register_renamed("clippy::block_in_if_condition_expr", "clippy::block_in_if_condition");
1789+
ls.register_renamed("clippy::block_in_if_condition_stmt", "clippy::block_in_if_condition");
1790+
ls.register_renamed("clippy::option_map_unwrap_or", "clippy::map_unwrap_or");
1791+
ls.register_renamed("clippy::option_map_unwrap_or_else", "clippy::map_unwrap_or");
1792+
ls.register_renamed("clippy::result_map_unwrap_or_else", "clippy::map_unwrap_or");
1793+
ls.register_renamed("clippy::option_unwrap_used", "clippy::unwrap_used");
1794+
ls.register_renamed("clippy::result_unwrap_used", "clippy::unwrap_used");
1795+
ls.register_renamed("clippy::option_expect_used", "clippy::expect_used");
1796+
ls.register_renamed("clippy::result_expect_used", "clippy::expect_used");
1797+
ls.register_renamed("clippy::for_loop_over_option", "clippy::for_loop_over_fallible");
1798+
ls.register_renamed("clippy::for_loop_over_result", "clippy::for_loop_over_fallible");
17881799
}
17891800

17901801
// only exists to let the dogfood integration test works.

clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ declare_clippy_lint! {
255255
/// // Good
256256
/// x.map_or_else(some_function, |a| a + 1);
257257
/// ```
258-
pub MAP_UNWRAP,
258+
pub MAP_UNWRAP_OR,
259259
pedantic,
260260
"using `.map(f).unwrap_or(a)` or `.map(f).unwrap_or_else(func)`, which are more succinctly expressed as `map_or(a, f)` or `map_or_else(a, f)`"
261261
}
@@ -1240,7 +1240,7 @@ declare_lint_pass!(Methods => [
12401240
WRONG_SELF_CONVENTION,
12411241
WRONG_PUB_SELF_CONVENTION,
12421242
OK_EXPECT,
1243-
MAP_UNWRAP,
1243+
MAP_UNWRAP_OR,
12441244
RESULT_MAP_OR_INTO_OPTION,
12451245
OPTION_MAP_OR_NONE,
12461246
OPTION_AND_THEN_SOME,
@@ -2512,7 +2512,7 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
25122512
if same_span && !multiline {
25132513
span_lint_and_note(
25142514
cx,
2515-
MAP_UNWRAP,
2515+
MAP_UNWRAP_OR,
25162516
expr.span,
25172517
msg,
25182518
None,
@@ -2522,7 +2522,7 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
25222522
),
25232523
);
25242524
} else if same_span && multiline {
2525-
span_lint(cx, MAP_UNWRAP, expr.span, msg);
2525+
span_lint(cx, MAP_UNWRAP_OR, expr.span, msg);
25262526
};
25272527
}
25282528
}

clippy_lints/src/methods/option_map_unwrap_or.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::hir::map::Map;
99
use rustc_span::source_map::Span;
1010
use rustc_span::symbol::Symbol;
1111

12-
use super::MAP_UNWRAP;
12+
use super::MAP_UNWRAP_OR;
1313

1414
/// lint use of `map().unwrap_or()` for `Option`s
1515
pub(super) fn lint<'a, 'tcx>(
@@ -66,7 +66,7 @@ pub(super) fn lint<'a, 'tcx>(
6666
arg, suggest
6767
);
6868

69-
span_lint_and_then(cx, MAP_UNWRAP, expr.span, msg, |diag| {
69+
span_lint_and_then(cx, MAP_UNWRAP_OR, expr.span, msg, |diag| {
7070
let map_arg_span = map_args[1].span;
7171

7272
let mut suggestion = vec![

src/lintlist/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
11381138
module: "methods",
11391139
},
11401140
Lint {
1141-
name: "map_unwrap",
1141+
name: "map_unwrap_or",
11421142
group: "pedantic",
11431143
desc: "using `.map(f).unwrap_or(a)` or `.map(f).unwrap_or_else(func)`, which are more succinctly expressed as `map_or(a, f)` or `map_or_else(a, f)`",
11441144
deprecation: None,

tests/ui/map_unwrap.rs renamed to tests/ui/map_unwrap_or.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// FIXME: Add "run-rustfix" once it's supported for multipart suggestions
22
// aux-build:option_helpers.rs
33

4-
#![warn(clippy::map_unwrap)]
4+
#![warn(clippy::map_unwrap_or)]
55

66
#[macro_use]
77
extern crate option_helpers;

tests/ui/map_unwrap.stderr renamed to tests/ui/map_unwrap_or.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead
2-
--> $DIR/map_unwrap.rs:17:13
2+
--> $DIR/map_unwrap_or.rs:17:13
33
|
44
LL | let _ = opt.map(|x| x + 1)
55
| _____________^
66
LL | | // Should lint even though this call is on a separate line.
77
LL | | .unwrap_or(0);
88
| |_____________________^
99
|
10-
= note: `-D clippy::map-unwrap` implied by `-D warnings`
10+
= note: `-D clippy::map-unwrap-or` implied by `-D warnings`
1111
help: use `map_or(a, f)` instead
1212
|
1313
LL | let _ = opt.map_or(0, |x| x + 1);
1414
| ^^^^^^ ^^ --
1515

1616
error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead
17-
--> $DIR/map_unwrap.rs:21:13
17+
--> $DIR/map_unwrap_or.rs:21:13
1818
|
1919
LL | let _ = opt.map(|x| {
2020
| _____________^
@@ -32,7 +32,7 @@ LL | );
3232
|
3333

3434
error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead
35-
--> $DIR/map_unwrap.rs:25:13
35+
--> $DIR/map_unwrap_or.rs:25:13
3636
|
3737
LL | let _ = opt.map(|x| x + 1)
3838
| _____________^
@@ -49,7 +49,7 @@ LL | }, |x| x + 1);
4949
|
5050

5151
error: called `map(f).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead
52-
--> $DIR/map_unwrap.rs:30:13
52+
--> $DIR/map_unwrap_or.rs:30:13
5353
|
5454
LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -60,7 +60,7 @@ LL | let _ = opt.and_then(|x| Some(x + 1));
6060
| ^^^^^^^^ --
6161

6262
error: called `map(f).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead
63-
--> $DIR/map_unwrap.rs:32:13
63+
--> $DIR/map_unwrap_or.rs:32:13
6464
|
6565
LL | let _ = opt.map(|x| {
6666
| _____________^
@@ -78,7 +78,7 @@ LL | );
7878
|
7979

8080
error: called `map(f).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(f)` instead
81-
--> $DIR/map_unwrap.rs:36:13
81+
--> $DIR/map_unwrap_or.rs:36:13
8282
|
8383
LL | let _ = opt
8484
| _____________^
@@ -92,7 +92,7 @@ LL | .and_then(|x| Some(x + 1));
9292
| ^^^^^^^^ --
9393

9494
error: called `map(f).unwrap_or(a)` on an `Option` value. This can be done more directly by calling `map_or(a, f)` instead
95-
--> $DIR/map_unwrap.rs:47:13
95+
--> $DIR/map_unwrap_or.rs:47:13
9696
|
9797
LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
9898
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -103,7 +103,7 @@ LL | let _ = Some("prefix").map_or(id, |p| format!("{}.", p));
103103
| ^^^^^^ ^^^ --
104104

105105
error: called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling `map_or_else(g, f)` instead
106-
--> $DIR/map_unwrap.rs:51:13
106+
--> $DIR/map_unwrap_or.rs:51:13
107107
|
108108
LL | let _ = opt.map(|x| x + 1)
109109
| _____________^
@@ -114,7 +114,7 @@ LL | | .unwrap_or_else(|| 0);
114114
= note: replace `map(|x| x + 1).unwrap_or_else(|| 0)` with `map_or_else(|| 0, |x| x + 1)`
115115

116116
error: called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling `map_or_else(g, f)` instead
117-
--> $DIR/map_unwrap.rs:55:13
117+
--> $DIR/map_unwrap_or.rs:55:13
118118
|
119119
LL | let _ = opt.map(|x| {
120120
| _____________^
@@ -124,7 +124,7 @@ LL | | ).unwrap_or_else(|| 0);
124124
| |__________________________^
125125

126126
error: called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling `map_or_else(g, f)` instead
127-
--> $DIR/map_unwrap.rs:59:13
127+
--> $DIR/map_unwrap_or.rs:59:13
128128
|
129129
LL | let _ = opt.map(|x| x + 1)
130130
| _____________^
@@ -134,23 +134,23 @@ LL | | );
134134
| |_________^
135135

136136
error: called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling `.map_or_else(g, f)` instead
137-
--> $DIR/map_unwrap.rs:88:13
137+
--> $DIR/map_unwrap_or.rs:88:13
138138
|
139139
LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); // should lint even though this call is on a separate line
140140
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141141
|
142142
= note: replace `map(|x| x + 1).unwrap_or_else(|e| 0)` with `map_or_else(|e| 0, |x| x + 1)`
143143

144144
error: called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling `.map_or_else(g, f)` instead
145-
--> $DIR/map_unwrap.rs:90:13
145+
--> $DIR/map_unwrap_or.rs:90:13
146146
|
147147
LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0);
148148
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149149
|
150150
= note: replace `map(|x| x + 1).unwrap_or_else(|e| 0)` with `map_or_else(|e| 0, |x| x + 1)`
151151

152152
error: called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling `.map_or_else(g, f)` instead
153-
--> $DIR/map_unwrap.rs:91:13
153+
--> $DIR/map_unwrap_or.rs:91:13
154154
|
155155
LL | let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0);
156156
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)