Skip to content

Commit 98ac5f1

Browse files
Rename into manual_unwrap_or_default
1 parent b0f358f commit 98ac5f1

8 files changed

+19
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5377,6 +5377,7 @@ Released 2018-09-13
53775377
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
53785378
[`manual_try_fold`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold
53795379
[`manual_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or
5380+
[`manual_unwrap_or_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or_default
53805381
[`manual_while_let_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_while_let_some
53815382
[`many_single_char_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names
53825383
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
@@ -5390,7 +5391,6 @@ Released 2018-09-13
53905391
[`match_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_bool
53915392
[`match_like_matches_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro
53925393
[`match_on_vec_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_on_vec_items
5393-
[`match_option_and_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_option_and_default
53945394
[`match_overlapping_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_overlapping_arm
53955395
[`match_ref_pats`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats
53965396
[`match_result_ok`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_result_ok

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
310310
crate::manual_slice_size_calculation::MANUAL_SLICE_SIZE_CALCULATION_INFO,
311311
crate::manual_string_new::MANUAL_STRING_NEW_INFO,
312312
crate::manual_strip::MANUAL_STRIP_INFO,
313+
crate::manual_unwrap_or_default::MANUAL_UNWRAP_OR_DEFAULT_INFO,
313314
crate::map_unit_fn::OPTION_MAP_UNIT_FN_INFO,
314315
crate::map_unit_fn::RESULT_MAP_UNIT_FN_INFO,
315-
crate::match_option_and_default::MATCH_OPTION_AND_DEFAULT_INFO,
316316
crate::match_result_ok::MATCH_RESULT_OK_INFO,
317317
crate::matches::COLLAPSIBLE_MATCH_INFO,
318318
crate::matches::INFALLIBLE_DESTRUCTURING_MATCH_INFO,

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ mod manual_retain;
211211
mod manual_slice_size_calculation;
212212
mod manual_string_new;
213213
mod manual_strip;
214+
mod manual_unwrap_or_default;
214215
mod map_unit_fn;
215-
mod match_option_and_default;
216216
mod match_result_ok;
217217
mod matches;
218218
mod mem_replace;
@@ -1123,7 +1123,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
11231123
store.register_early_pass(|| Box::new(multiple_bound_locations::MultipleBoundLocations));
11241124
store.register_late_pass(|_| Box::new(assigning_clones::AssigningClones));
11251125
store.register_late_pass(|_| Box::new(zero_repeat_side_effects::ZeroRepeatSideEffects));
1126-
store.register_late_pass(|_| Box::new(match_option_and_default::MatchOptionAndDefault));
1126+
store.register_late_pass(|_| Box::new(manual_unwrap_or_default::ManualUnwrapOrDefault));
11271127
// add lints here, do not remove this comment, it's used in `new_lint`
11281128
}
11291129

clippy_lints/src/match_option_and_default.rs renamed to clippy_lints/src/manual_unwrap_or_default.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ declare_clippy_lint! {
4242
/// let y: Vec<String> = x.unwrap_or_default();
4343
/// ```
4444
#[clippy::version = "1.78.0"]
45-
pub MATCH_OPTION_AND_DEFAULT,
45+
pub MANUAL_UNWRAP_OR_DEFAULT,
4646
suspicious,
4747
"check if a `match` or `if let` can be simplified with `unwrap_or_default`"
4848
}
4949

50-
declare_lint_pass!(MatchOptionAndDefault => [MATCH_OPTION_AND_DEFAULT]);
50+
declare_lint_pass!(ManualUnwrapOrDefault => [MANUAL_UNWRAP_OR_DEFAULT]);
5151

5252
fn get_some<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>) -> Option<HirId> {
5353
if let PatKind::TupleStruct(QPath::Resolved(_, path), &[pat], _) = pat.kind
@@ -123,13 +123,12 @@ fn handle_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
123123
&& local_id == binding_id
124124
// We now check the `None` arm is calling a method equivalent to `Default::default`.
125125
&& let body_none = body_none.peel_blocks()
126-
&& let ExprKind::Call(_, &[]) = body_none.kind
127126
&& is_default_equivalent(cx, body_none)
128127
&& let Some(match_expr_snippet) = snippet_opt(cx, match_expr.span)
129128
{
130129
span_lint_and_sugg(
131130
cx,
132-
MATCH_OPTION_AND_DEFAULT,
131+
MANUAL_UNWRAP_OR_DEFAULT,
133132
expr.span,
134133
"match can be simplified with `.unwrap_or_default()`",
135134
"replace it with",
@@ -155,13 +154,12 @@ fn handle_if_let<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
155154
&& local_id == binding_id
156155
// We now check the `None` arm is calling a method equivalent to `Default::default`.
157156
&& let body_else = else_expr.peel_blocks()
158-
&& let ExprKind::Call(_, &[]) = body_else.kind
159157
&& is_default_equivalent(cx, body_else)
160158
&& let Some(if_let_expr_snippet) = snippet_opt(cx, let_.init.span)
161159
{
162160
span_lint_and_sugg(
163161
cx,
164-
MATCH_OPTION_AND_DEFAULT,
162+
MANUAL_UNWRAP_OR_DEFAULT,
165163
expr.span,
166164
"if let can be simplified with `.unwrap_or_default()`",
167165
"replace it with",
@@ -171,7 +169,7 @@ fn handle_if_let<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
171169
}
172170
}
173171

174-
impl<'tcx> LateLintPass<'tcx> for MatchOptionAndDefault {
172+
impl<'tcx> LateLintPass<'tcx> for ManualUnwrapOrDefault {
175173
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
176174
if expr.span.from_expansion() {
177175
return;

tests/ui/match_option_and_default.fixed renamed to tests/ui/manual_unwrap_or_default.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::match_option_and_default)]
1+
#![warn(clippy::manual_unwrap_or_default)]
22
#![allow(clippy::unnecessary_literal_unwrap)]
33

44
fn main() {

tests/ui/match_option_and_default.rs renamed to tests/ui/manual_unwrap_or_default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::match_option_and_default)]
1+
#![warn(clippy::manual_unwrap_or_default)]
22
#![allow(clippy::unnecessary_literal_unwrap)]
33

44
fn main() {

tests/ui/match_option_and_default.stderr renamed to tests/ui/manual_unwrap_or_default.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: match can be simplified with `.unwrap_or_default()`
2-
--> tests/ui/match_option_and_default.rs:6:5
2+
--> tests/ui/manual_unwrap_or_default.rs:6:5
33
|
44
LL | / match x {
55
LL | |
@@ -8,11 +8,11 @@ LL | | None => Vec::default(),
88
LL | | };
99
| |_____^ help: replace it with: `x.unwrap_or_default()`
1010
|
11-
= note: `-D clippy::match-option-and-default` implied by `-D warnings`
12-
= help: to override `-D warnings` add `#[allow(clippy::match_option_and_default)]`
11+
= note: `-D clippy::manual-unwrap-or-default` implied by `-D warnings`
12+
= help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or_default)]`
1313

1414
error: match can be simplified with `.unwrap_or_default()`
15-
--> tests/ui/match_option_and_default.rs:13:5
15+
--> tests/ui/manual_unwrap_or_default.rs:13:5
1616
|
1717
LL | / match x {
1818
LL | |
@@ -22,7 +22,7 @@ LL | | };
2222
| |_____^ help: replace it with: `x.unwrap_or_default()`
2323

2424
error: match can be simplified with `.unwrap_or_default()`
25-
--> tests/ui/match_option_and_default.rs:20:5
25+
--> tests/ui/manual_unwrap_or_default.rs:20:5
2626
|
2727
LL | / match x {
2828
LL | |
@@ -32,7 +32,7 @@ LL | | };
3232
| |_____^ help: replace it with: `x.unwrap_or_default()`
3333

3434
error: match can be simplified with `.unwrap_or_default()`
35-
--> tests/ui/match_option_and_default.rs:27:5
35+
--> tests/ui/manual_unwrap_or_default.rs:27:5
3636
|
3737
LL | / match x {
3838
LL | |
@@ -42,7 +42,7 @@ LL | | };
4242
| |_____^ help: replace it with: `x.unwrap_or_default()`
4343

4444
error: if let can be simplified with `.unwrap_or_default()`
45-
--> tests/ui/match_option_and_default.rs:34:5
45+
--> tests/ui/manual_unwrap_or_default.rs:34:5
4646
|
4747
LL | / if let Some(v) = x {
4848
LL | |

tests/ui/option_option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@compile-flags: -Zdeduplicate-diagnostics=yes
22

33
#![deny(clippy::option_option)]
4-
#![allow(clippy::unnecessary_wraps, clippy::match_option_and_default)]
4+
#![allow(clippy::unnecessary_wraps, clippy::manual_unwrap_or_default)]
55

66
const C: Option<Option<i32>> = None;
77
//~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if

0 commit comments

Comments
 (0)