Skip to content

Commit 71d4dba

Browse files
committed
redundant_pattern_matching
1 parent 5a62a0d commit 71d4dba

File tree

17 files changed

+39
-46
lines changed

17 files changed

+39
-46
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ needless_doctest_main = "allow"
177177
new_without_default = "allow"
178178
non_canonical_clone_impl = "allow"
179179
non_canonical_partial_ord_impl = "allow"
180-
redundant_pattern_matching = "allow"
181180
search_is_some = "allow"
182181
self_named_constructors = "allow"
183182
single_match = "allow"

crates/base-db/src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl CrateData {
331331
return false;
332332
}
333333

334-
if let Some(_) = opts.next() {
334+
if opts.next().is_some() {
335335
return false;
336336
}
337337
}

crates/hir-def/src/path/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(super) fn lower_path(ctx: &LowerCtx<'_>, mut path: ast::Path) -> Option<Path
5353
)
5454
})
5555
.map(Interned::new);
56-
if let Some(_) = args {
56+
if args.is_some() {
5757
generic_args.resize(segments.len(), None);
5858
generic_args.push(args);
5959
}

crates/hir-ty/src/display.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,15 +1043,15 @@ impl HirDisplay for Ty {
10431043
f.start_location_link(t.into());
10441044
}
10451045
write!(f, "Future")?;
1046-
if let Some(_) = future_trait {
1046+
if future_trait.is_some() {
10471047
f.end_location_link();
10481048
}
10491049
write!(f, "<")?;
10501050
if let Some(t) = output {
10511051
f.start_location_link(t.into());
10521052
}
10531053
write!(f, "Output")?;
1054-
if let Some(_) = output {
1054+
if output.is_some() {
10551055
f.end_location_link();
10561056
}
10571057
write!(f, " = ")?;
@@ -1520,7 +1520,7 @@ fn write_bounds_like_dyn_trait(
15201520
}
15211521
write!(f, "Sized")?;
15221522
}
1523-
if let Some(_) = sized_trait {
1523+
if sized_trait.is_some() {
15241524
f.end_location_link();
15251525
}
15261526
}

crates/hir-ty/src/infer/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl InferenceContext<'_> {
439439
ty
440440
}
441441
&Expr::Continue { label } => {
442-
if let None = find_continuable(&mut self.breakables, label) {
442+
if find_continuable(&mut self.breakables, label).is_none() {
443443
self.push_diagnostic(InferenceDiagnostic::BreakOutsideOfLoop {
444444
expr: tgt_expr,
445445
is_break: false,

crates/hir-ty/src/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ fn named_associated_type_shorthand_candidates<R>(
13351335
),
13361336
_ => None,
13371337
});
1338-
if let Some(_) = res {
1338+
if res.is_some() {
13391339
return res;
13401340
}
13411341
// Handle `Self::Type` referring to own associated type in trait definitions

crates/hir-ty/src/mir/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,7 @@ impl Evaluator<'_> {
22172217
let generic_args = generic_args.clone();
22182218
match def {
22192219
CallableDefId::FunctionId(def) => {
2220-
if let Some(_) = self.detect_fn_trait(def) {
2220+
if self.detect_fn_trait(def).is_some() {
22212221
return self.exec_fn_trait(
22222222
def,
22232223
args,

crates/hir/src/source_analyzer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl SourceAnalyzer {
614614
}
615615
None
616616
})();
617-
if let Some(_) = resolved {
617+
if resolved.is_some() {
618618
return resolved;
619619
}
620620

@@ -659,7 +659,7 @@ impl SourceAnalyzer {
659659
if let Some(name_ref) = path.as_single_name_ref() {
660660
let builtin =
661661
BuiltinAttr::by_name(db, self.resolver.krate().into(), &name_ref.text());
662-
if let Some(_) = builtin {
662+
if builtin.is_some() {
663663
return builtin.map(PathResolution::BuiltinAttr);
664664
}
665665

crates/ide-assists/src/handlers/auto_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub(super) fn find_importable_node(
198198
{
199199
ImportAssets::for_method_call(&method_under_caret, &ctx.sema)
200200
.zip(Some(method_under_caret.syntax().clone().into()))
201-
} else if let Some(_) = ctx.find_node_at_offset_with_descend::<ast::Param>() {
201+
} else if ctx.find_node_at_offset_with_descend::<ast::Param>().is_some() {
202202
None
203203
} else if let Some(pat) = ctx
204204
.find_node_at_offset_with_descend::<ast::IdentPat>()

crates/ide-assists/src/handlers/generate_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
2929
let name = nominal.name()?;
3030
let target = nominal.syntax().text_range();
3131

32-
if let Some(_) = ctx.find_node_at_offset::<ast::RecordFieldList>() {
32+
if ctx.find_node_at_offset::<ast::RecordFieldList>().is_some() {
3333
return None;
3434
}
3535

@@ -77,7 +77,7 @@ pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) ->
7777
let name = nominal.name()?;
7878
let target = nominal.syntax().text_range();
7979

80-
if let Some(_) = ctx.find_node_at_offset::<ast::RecordFieldList>() {
80+
if ctx.find_node_at_offset::<ast::RecordFieldList>().is_some() {
8181
return None;
8282
}
8383

crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub(crate) fn replace_turbofish_with_explicit_type(
6969
return None;
7070
}
7171

72-
if let None = let_stmt.colon_token() {
72+
if let_stmt.colon_token().is_none() {
7373
// If there's no colon in a let statement, then there is no explicit type.
7474
// let x = fn::<...>();
7575
let ident_range = let_stmt.pat()?.syntax().text_range();

crates/ide-assists/src/handlers/unnecessary_async.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ pub(crate) fn unnecessary_async(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
3737
return None;
3838
}
3939
// Do nothing if the function isn't async.
40-
if let None = function.async_token() {
41-
return None;
42-
}
40+
function.async_token()?;
4341
// Do nothing if the function has an `await` expression in its body.
4442
if function.body()?.syntax().descendants().find_map(ast::AwaitExpr::cast).is_some() {
4543
return None;
4644
}
4745
// Do nothing if the method is a member of trait.
4846
if let Some(impl_) = function.syntax().ancestors().nth(2).and_then(ast::Impl::cast) {
49-
if let Some(_) = impl_.trait_() {
47+
if impl_.trait_().is_some() {
5048
return None;
5149
}
5250
}

crates/ide-completion/src/completions/item_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option
8080
let in_trait_impl = matches!(kind, Some(ItemListKind::TraitImpl(_)));
8181
let in_inherent_impl = matches!(kind, Some(ItemListKind::Impl));
8282
let no_qualifiers = ctx.qualifier_ctx.vis_node.is_none();
83-
let in_block = matches!(kind, None);
83+
let in_block = kind.is_none();
8484

8585
if !in_trait_impl {
8686
if ctx.qualifier_ctx.unsafe_tok.is_some() {

crates/ide/src/folding_ranges.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,13 @@ fn fold_range_for_where_clause(where_clause: ast::WhereClause) -> Option<TextRan
271271
}
272272

273273
fn fold_range_for_multiline_match_arm(match_arm: ast::MatchArm) -> Option<TextRange> {
274-
if let Some(_) = fold_kind(match_arm.expr()?.syntax().kind()) {
275-
return None;
276-
}
277-
if match_arm.expr()?.syntax().text().contains_char('\n') {
278-
return Some(match_arm.expr()?.syntax().text_range());
274+
if fold_kind(match_arm.expr()?.syntax().kind()).is_some() {
275+
None
276+
} else if match_arm.expr()?.syntax().text().contains_char('\n') {
277+
Some(match_arm.expr()?.syntax().text_range())
278+
} else {
279+
None
279280
}
280-
None
281281
}
282282

283283
#[cfg(test)]

crates/ide/src/inlay_hints/fn_lifetime_fn.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,13 @@ pub(super) fn hints(
9898
};
9999
{
100100
let mut potential_lt_refs = potential_lt_refs.iter().filter(|&&(.., is_elided)| is_elided);
101-
if let Some(_) = &self_param {
102-
if let Some(_) = potential_lt_refs.next() {
103-
allocated_lifetimes.push(if config.param_names_for_lifetime_elision_hints {
104-
// self can't be used as a lifetime, so no need to check for collisions
105-
"'self".into()
106-
} else {
107-
gen_idx_name()
108-
});
109-
}
101+
if self_param.is_some() && potential_lt_refs.next().is_some() {
102+
allocated_lifetimes.push(if config.param_names_for_lifetime_elision_hints {
103+
// self can't be used as a lifetime, so no need to check for collisions
104+
"'self".into()
105+
} else {
106+
gen_idx_name()
107+
});
110108
}
111109
potential_lt_refs.for_each(|(name, ..)| {
112110
let name = match name {

crates/ide/src/inlay_hints/param_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub(super) fn hints(
4747
if let Some(name) = param {
4848
if let hir::CallableKind::Function(f) = callable.kind() {
4949
// assert the file is cached so we can map out of macros
50-
if let Some(_) = sema.source(f) {
50+
if sema.source(f).is_some() {
5151
linked_location = sema.original_range_opt(name.syntax());
5252
}
5353
}

crates/rust-analyzer/src/reload.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl GlobalState {
109109
status.health = lsp_ext::Health::Warning;
110110
message.push_str("Proc-macros have changed and need to be rebuilt.\n\n");
111111
}
112-
if let Err(_) = self.fetch_build_data_error() {
112+
if self.fetch_build_data_error().is_err() {
113113
status.health = lsp_ext::Health::Warning;
114114
message.push_str("Failed to run build scripts of some packages.\n\n");
115115
}
@@ -173,7 +173,7 @@ impl GlobalState {
173173
}
174174
}
175175

176-
if let Err(_) = self.fetch_workspace_error() {
176+
if self.fetch_workspace_error().is_err() {
177177
status.health = lsp_ext::Health::Error;
178178
message.push_str("Failed to load workspaces.");
179179

@@ -364,15 +364,13 @@ impl GlobalState {
364364
return;
365365
};
366366

367-
if let Err(_) = self.fetch_workspace_error() {
368-
if !self.workspaces.is_empty() {
369-
if *force_reload_crate_graph {
370-
self.recreate_crate_graph(cause);
371-
}
372-
// It only makes sense to switch to a partially broken workspace
373-
// if we don't have any workspace at all yet.
374-
return;
367+
if self.fetch_workspace_error().is_err() && !self.workspaces.is_empty() {
368+
if *force_reload_crate_graph {
369+
self.recreate_crate_graph(cause);
375370
}
371+
// It only makes sense to switch to a partially broken workspace
372+
// if we don't have any workspace at all yet.
373+
return;
376374
}
377375

378376
let workspaces =

0 commit comments

Comments
 (0)