mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-14 06:15:27 +00:00
redundant_pattern_matching
This commit is contained in:
parent
5a62a0db46
commit
71d4dba960
17 changed files with 39 additions and 46 deletions
|
@ -177,7 +177,6 @@ needless_doctest_main = "allow"
|
||||||
new_without_default = "allow"
|
new_without_default = "allow"
|
||||||
non_canonical_clone_impl = "allow"
|
non_canonical_clone_impl = "allow"
|
||||||
non_canonical_partial_ord_impl = "allow"
|
non_canonical_partial_ord_impl = "allow"
|
||||||
redundant_pattern_matching = "allow"
|
|
||||||
search_is_some = "allow"
|
search_is_some = "allow"
|
||||||
self_named_constructors = "allow"
|
self_named_constructors = "allow"
|
||||||
single_match = "allow"
|
single_match = "allow"
|
||||||
|
|
|
@ -331,7 +331,7 @@ impl CrateData {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(_) = opts.next() {
|
if opts.next().is_some() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub(super) fn lower_path(ctx: &LowerCtx<'_>, mut path: ast::Path) -> Option<Path
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.map(Interned::new);
|
.map(Interned::new);
|
||||||
if let Some(_) = args {
|
if args.is_some() {
|
||||||
generic_args.resize(segments.len(), None);
|
generic_args.resize(segments.len(), None);
|
||||||
generic_args.push(args);
|
generic_args.push(args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1043,7 +1043,7 @@ impl HirDisplay for Ty {
|
||||||
f.start_location_link(t.into());
|
f.start_location_link(t.into());
|
||||||
}
|
}
|
||||||
write!(f, "Future")?;
|
write!(f, "Future")?;
|
||||||
if let Some(_) = future_trait {
|
if future_trait.is_some() {
|
||||||
f.end_location_link();
|
f.end_location_link();
|
||||||
}
|
}
|
||||||
write!(f, "<")?;
|
write!(f, "<")?;
|
||||||
|
@ -1051,7 +1051,7 @@ impl HirDisplay for Ty {
|
||||||
f.start_location_link(t.into());
|
f.start_location_link(t.into());
|
||||||
}
|
}
|
||||||
write!(f, "Output")?;
|
write!(f, "Output")?;
|
||||||
if let Some(_) = output {
|
if output.is_some() {
|
||||||
f.end_location_link();
|
f.end_location_link();
|
||||||
}
|
}
|
||||||
write!(f, " = ")?;
|
write!(f, " = ")?;
|
||||||
|
@ -1520,7 +1520,7 @@ fn write_bounds_like_dyn_trait(
|
||||||
}
|
}
|
||||||
write!(f, "Sized")?;
|
write!(f, "Sized")?;
|
||||||
}
|
}
|
||||||
if let Some(_) = sized_trait {
|
if sized_trait.is_some() {
|
||||||
f.end_location_link();
|
f.end_location_link();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -439,7 +439,7 @@ impl InferenceContext<'_> {
|
||||||
ty
|
ty
|
||||||
}
|
}
|
||||||
&Expr::Continue { label } => {
|
&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 {
|
self.push_diagnostic(InferenceDiagnostic::BreakOutsideOfLoop {
|
||||||
expr: tgt_expr,
|
expr: tgt_expr,
|
||||||
is_break: false,
|
is_break: false,
|
||||||
|
|
|
@ -1335,7 +1335,7 @@ fn named_associated_type_shorthand_candidates<R>(
|
||||||
),
|
),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
if let Some(_) = res {
|
if res.is_some() {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
// Handle `Self::Type` referring to own associated type in trait definitions
|
// Handle `Self::Type` referring to own associated type in trait definitions
|
||||||
|
|
|
@ -2217,7 +2217,7 @@ impl Evaluator<'_> {
|
||||||
let generic_args = generic_args.clone();
|
let generic_args = generic_args.clone();
|
||||||
match def {
|
match def {
|
||||||
CallableDefId::FunctionId(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(
|
return self.exec_fn_trait(
|
||||||
def,
|
def,
|
||||||
args,
|
args,
|
||||||
|
|
|
@ -614,7 +614,7 @@ impl SourceAnalyzer {
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
})();
|
})();
|
||||||
if let Some(_) = resolved {
|
if resolved.is_some() {
|
||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,7 +659,7 @@ impl SourceAnalyzer {
|
||||||
if let Some(name_ref) = path.as_single_name_ref() {
|
if let Some(name_ref) = path.as_single_name_ref() {
|
||||||
let builtin =
|
let builtin =
|
||||||
BuiltinAttr::by_name(db, self.resolver.krate().into(), &name_ref.text());
|
BuiltinAttr::by_name(db, self.resolver.krate().into(), &name_ref.text());
|
||||||
if let Some(_) = builtin {
|
if builtin.is_some() {
|
||||||
return builtin.map(PathResolution::BuiltinAttr);
|
return builtin.map(PathResolution::BuiltinAttr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ pub(super) fn find_importable_node(
|
||||||
{
|
{
|
||||||
ImportAssets::for_method_call(&method_under_caret, &ctx.sema)
|
ImportAssets::for_method_call(&method_under_caret, &ctx.sema)
|
||||||
.zip(Some(method_under_caret.syntax().clone().into()))
|
.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
|
None
|
||||||
} else if let Some(pat) = ctx
|
} else if let Some(pat) = ctx
|
||||||
.find_node_at_offset_with_descend::<ast::IdentPat>()
|
.find_node_at_offset_with_descend::<ast::IdentPat>()
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
|
||||||
let name = nominal.name()?;
|
let name = nominal.name()?;
|
||||||
let target = nominal.syntax().text_range();
|
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;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
||||||
let name = nominal.name()?;
|
let name = nominal.name()?;
|
||||||
let target = nominal.syntax().text_range();
|
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;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub(crate) fn replace_turbofish_with_explicit_type(
|
||||||
return None;
|
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.
|
// If there's no colon in a let statement, then there is no explicit type.
|
||||||
// let x = fn::<...>();
|
// let x = fn::<...>();
|
||||||
let ident_range = let_stmt.pat()?.syntax().text_range();
|
let ident_range = let_stmt.pat()?.syntax().text_range();
|
||||||
|
|
|
@ -37,16 +37,14 @@ pub(crate) fn unnecessary_async(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
// Do nothing if the function isn't async.
|
// Do nothing if the function isn't async.
|
||||||
if let None = function.async_token() {
|
function.async_token()?;
|
||||||
return None;
|
|
||||||
}
|
|
||||||
// Do nothing if the function has an `await` expression in its body.
|
// Do nothing if the function has an `await` expression in its body.
|
||||||
if function.body()?.syntax().descendants().find_map(ast::AwaitExpr::cast).is_some() {
|
if function.body()?.syntax().descendants().find_map(ast::AwaitExpr::cast).is_some() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
// Do nothing if the method is a member of trait.
|
// 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_) = function.syntax().ancestors().nth(2).and_then(ast::Impl::cast) {
|
||||||
if let Some(_) = impl_.trait_() {
|
if impl_.trait_().is_some() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_trait_impl = matches!(kind, Some(ItemListKind::TraitImpl(_)));
|
||||||
let in_inherent_impl = matches!(kind, Some(ItemListKind::Impl));
|
let in_inherent_impl = matches!(kind, Some(ItemListKind::Impl));
|
||||||
let no_qualifiers = ctx.qualifier_ctx.vis_node.is_none();
|
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 !in_trait_impl {
|
||||||
if ctx.qualifier_ctx.unsafe_tok.is_some() {
|
if ctx.qualifier_ctx.unsafe_tok.is_some() {
|
||||||
|
|
|
@ -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> {
|
fn fold_range_for_multiline_match_arm(match_arm: ast::MatchArm) -> Option<TextRange> {
|
||||||
if let Some(_) = fold_kind(match_arm.expr()?.syntax().kind()) {
|
if fold_kind(match_arm.expr()?.syntax().kind()).is_some() {
|
||||||
return None;
|
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)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -98,15 +98,13 @@ pub(super) fn hints(
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
let mut potential_lt_refs = potential_lt_refs.iter().filter(|&&(.., is_elided)| is_elided);
|
let mut potential_lt_refs = potential_lt_refs.iter().filter(|&&(.., is_elided)| is_elided);
|
||||||
if let Some(_) = &self_param {
|
if self_param.is_some() && potential_lt_refs.next().is_some() {
|
||||||
if let Some(_) = potential_lt_refs.next() {
|
allocated_lifetimes.push(if config.param_names_for_lifetime_elision_hints {
|
||||||
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 can't be used as a lifetime, so no need to check for collisions
|
"'self".into()
|
||||||
"'self".into()
|
} else {
|
||||||
} else {
|
gen_idx_name()
|
||||||
gen_idx_name()
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
potential_lt_refs.for_each(|(name, ..)| {
|
potential_lt_refs.for_each(|(name, ..)| {
|
||||||
let name = match name {
|
let name = match name {
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub(super) fn hints(
|
||||||
if let Some(name) = param {
|
if let Some(name) = param {
|
||||||
if let hir::CallableKind::Function(f) = callable.kind() {
|
if let hir::CallableKind::Function(f) = callable.kind() {
|
||||||
// assert the file is cached so we can map out of macros
|
// 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());
|
linked_location = sema.original_range_opt(name.syntax());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ impl GlobalState {
|
||||||
status.health = lsp_ext::Health::Warning;
|
status.health = lsp_ext::Health::Warning;
|
||||||
message.push_str("Proc-macros have changed and need to be rebuilt.\n\n");
|
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;
|
status.health = lsp_ext::Health::Warning;
|
||||||
message.push_str("Failed to run build scripts of some packages.\n\n");
|
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;
|
status.health = lsp_ext::Health::Error;
|
||||||
message.push_str("Failed to load workspaces.");
|
message.push_str("Failed to load workspaces.");
|
||||||
|
|
||||||
|
@ -364,15 +364,13 @@ impl GlobalState {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(_) = self.fetch_workspace_error() {
|
if self.fetch_workspace_error().is_err() && !self.workspaces.is_empty() {
|
||||||
if !self.workspaces.is_empty() {
|
if *force_reload_crate_graph {
|
||||||
if *force_reload_crate_graph {
|
self.recreate_crate_graph(cause);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
// It only makes sense to switch to a partially broken workspace
|
||||||
|
// if we don't have any workspace at all yet.
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let workspaces =
|
let workspaces =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue