redundant_pattern_matching

This commit is contained in:
Johann Hemmann 2024-01-19 16:51:08 +01:00
parent 5a62a0db46
commit 71d4dba960
17 changed files with 39 additions and 46 deletions

View file

@ -177,7 +177,6 @@ needless_doctest_main = "allow"
new_without_default = "allow"
non_canonical_clone_impl = "allow"
non_canonical_partial_ord_impl = "allow"
redundant_pattern_matching = "allow"
search_is_some = "allow"
self_named_constructors = "allow"
single_match = "allow"

View file

@ -331,7 +331,7 @@ impl CrateData {
return false;
}
if let Some(_) = opts.next() {
if opts.next().is_some() {
return false;
}
}

View file

@ -53,7 +53,7 @@ pub(super) fn lower_path(ctx: &LowerCtx<'_>, mut path: ast::Path) -> Option<Path
)
})
.map(Interned::new);
if let Some(_) = args {
if args.is_some() {
generic_args.resize(segments.len(), None);
generic_args.push(args);
}

View file

@ -1043,7 +1043,7 @@ impl HirDisplay for Ty {
f.start_location_link(t.into());
}
write!(f, "Future")?;
if let Some(_) = future_trait {
if future_trait.is_some() {
f.end_location_link();
}
write!(f, "<")?;
@ -1051,7 +1051,7 @@ impl HirDisplay for Ty {
f.start_location_link(t.into());
}
write!(f, "Output")?;
if let Some(_) = output {
if output.is_some() {
f.end_location_link();
}
write!(f, " = ")?;
@ -1520,7 +1520,7 @@ fn write_bounds_like_dyn_trait(
}
write!(f, "Sized")?;
}
if let Some(_) = sized_trait {
if sized_trait.is_some() {
f.end_location_link();
}
}

View file

@ -439,7 +439,7 @@ impl InferenceContext<'_> {
ty
}
&Expr::Continue { label } => {
if let None = find_continuable(&mut self.breakables, label) {
if find_continuable(&mut self.breakables, label).is_none() {
self.push_diagnostic(InferenceDiagnostic::BreakOutsideOfLoop {
expr: tgt_expr,
is_break: false,

View file

@ -1335,7 +1335,7 @@ fn named_associated_type_shorthand_candidates<R>(
),
_ => None,
});
if let Some(_) = res {
if res.is_some() {
return res;
}
// Handle `Self::Type` referring to own associated type in trait definitions

View file

@ -2217,7 +2217,7 @@ impl Evaluator<'_> {
let generic_args = generic_args.clone();
match def {
CallableDefId::FunctionId(def) => {
if let Some(_) = self.detect_fn_trait(def) {
if self.detect_fn_trait(def).is_some() {
return self.exec_fn_trait(
def,
args,

View file

@ -614,7 +614,7 @@ impl SourceAnalyzer {
}
None
})();
if let Some(_) = resolved {
if resolved.is_some() {
return resolved;
}
@ -659,7 +659,7 @@ impl SourceAnalyzer {
if let Some(name_ref) = path.as_single_name_ref() {
let builtin =
BuiltinAttr::by_name(db, self.resolver.krate().into(), &name_ref.text());
if let Some(_) = builtin {
if builtin.is_some() {
return builtin.map(PathResolution::BuiltinAttr);
}

View file

@ -198,7 +198,7 @@ pub(super) fn find_importable_node(
{
ImportAssets::for_method_call(&method_under_caret, &ctx.sema)
.zip(Some(method_under_caret.syntax().clone().into()))
} else if let Some(_) = ctx.find_node_at_offset_with_descend::<ast::Param>() {
} else if ctx.find_node_at_offset_with_descend::<ast::Param>().is_some() {
None
} else if let Some(pat) = ctx
.find_node_at_offset_with_descend::<ast::IdentPat>()

View file

@ -29,7 +29,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
let name = nominal.name()?;
let target = nominal.syntax().text_range();
if let Some(_) = ctx.find_node_at_offset::<ast::RecordFieldList>() {
if ctx.find_node_at_offset::<ast::RecordFieldList>().is_some() {
return None;
}
@ -77,7 +77,7 @@ pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let name = nominal.name()?;
let target = nominal.syntax().text_range();
if let Some(_) = ctx.find_node_at_offset::<ast::RecordFieldList>() {
if ctx.find_node_at_offset::<ast::RecordFieldList>().is_some() {
return None;
}

View file

@ -69,7 +69,7 @@ pub(crate) fn replace_turbofish_with_explicit_type(
return None;
}
if let None = let_stmt.colon_token() {
if let_stmt.colon_token().is_none() {
// If there's no colon in a let statement, then there is no explicit type.
// let x = fn::<...>();
let ident_range = let_stmt.pat()?.syntax().text_range();

View file

@ -37,16 +37,14 @@ pub(crate) fn unnecessary_async(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
return None;
}
// Do nothing if the function isn't async.
if let None = function.async_token() {
return None;
}
function.async_token()?;
// Do nothing if the function has an `await` expression in its body.
if function.body()?.syntax().descendants().find_map(ast::AwaitExpr::cast).is_some() {
return None;
}
// Do nothing if the method is a member of trait.
if let Some(impl_) = function.syntax().ancestors().nth(2).and_then(ast::Impl::cast) {
if let Some(_) = impl_.trait_() {
if impl_.trait_().is_some() {
return None;
}
}

View file

@ -80,7 +80,7 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option
let in_trait_impl = matches!(kind, Some(ItemListKind::TraitImpl(_)));
let in_inherent_impl = matches!(kind, Some(ItemListKind::Impl));
let no_qualifiers = ctx.qualifier_ctx.vis_node.is_none();
let in_block = matches!(kind, None);
let in_block = kind.is_none();
if !in_trait_impl {
if ctx.qualifier_ctx.unsafe_tok.is_some() {

View file

@ -271,13 +271,13 @@ fn fold_range_for_where_clause(where_clause: ast::WhereClause) -> Option<TextRan
}
fn fold_range_for_multiline_match_arm(match_arm: ast::MatchArm) -> Option<TextRange> {
if let Some(_) = fold_kind(match_arm.expr()?.syntax().kind()) {
return None;
if fold_kind(match_arm.expr()?.syntax().kind()).is_some() {
None
} else if match_arm.expr()?.syntax().text().contains_char('\n') {
Some(match_arm.expr()?.syntax().text_range())
} else {
None
}
if match_arm.expr()?.syntax().text().contains_char('\n') {
return Some(match_arm.expr()?.syntax().text_range());
}
None
}
#[cfg(test)]

View file

@ -98,15 +98,13 @@ pub(super) fn hints(
};
{
let mut potential_lt_refs = potential_lt_refs.iter().filter(|&&(.., is_elided)| is_elided);
if let Some(_) = &self_param {
if let Some(_) = potential_lt_refs.next() {
allocated_lifetimes.push(if config.param_names_for_lifetime_elision_hints {
// self can't be used as a lifetime, so no need to check for collisions
"'self".into()
} else {
gen_idx_name()
});
}
if self_param.is_some() && potential_lt_refs.next().is_some() {
allocated_lifetimes.push(if config.param_names_for_lifetime_elision_hints {
// self can't be used as a lifetime, so no need to check for collisions
"'self".into()
} else {
gen_idx_name()
});
}
potential_lt_refs.for_each(|(name, ..)| {
let name = match name {

View file

@ -47,7 +47,7 @@ pub(super) fn hints(
if let Some(name) = param {
if let hir::CallableKind::Function(f) = callable.kind() {
// assert the file is cached so we can map out of macros
if let Some(_) = sema.source(f) {
if sema.source(f).is_some() {
linked_location = sema.original_range_opt(name.syntax());
}
}

View file

@ -109,7 +109,7 @@ impl GlobalState {
status.health = lsp_ext::Health::Warning;
message.push_str("Proc-macros have changed and need to be rebuilt.\n\n");
}
if let Err(_) = self.fetch_build_data_error() {
if self.fetch_build_data_error().is_err() {
status.health = lsp_ext::Health::Warning;
message.push_str("Failed to run build scripts of some packages.\n\n");
}
@ -173,7 +173,7 @@ impl GlobalState {
}
}
if let Err(_) = self.fetch_workspace_error() {
if self.fetch_workspace_error().is_err() {
status.health = lsp_ext::Health::Error;
message.push_str("Failed to load workspaces.");
@ -364,15 +364,13 @@ impl GlobalState {
return;
};
if let Err(_) = self.fetch_workspace_error() {
if !self.workspaces.is_empty() {
if *force_reload_crate_graph {
self.recreate_crate_graph(cause);
}
// It only makes sense to switch to a partially broken workspace
// if we don't have any workspace at all yet.
return;
if self.fetch_workspace_error().is_err() && !self.workspaces.is_empty() {
if *force_reload_crate_graph {
self.recreate_crate_graph(cause);
}
// It only makes sense to switch to a partially broken workspace
// if we don't have any workspace at all yet.
return;
}
let workspaces =