10440: Fix Clippy warnings and replace some `if let`s with `match` r=Veykril a=arzg

I decided to try fixing a bunch of Clippy warnings. I am aware of this project’s opinion of Clippy (I have read both [rust-lang/clippy#5537](https://github.com/rust-lang/rust-clippy/issues/5537) and [rust-analyzer/rowan#57 (comment)](https://github.com/rust-analyzer/rowan/pull/57#discussion_r415676159)), so I totally understand if part of or the entirety of this PR is rejected. In particular, I can see how the semicolons and `if let` vs `match` commits provide comparatively little benefit when compared to the ensuing churn.

I tried to separate each kind of change into its own commit to make it easier to discard certain changes. I also only applied Clippy suggestions where I thought they provided a definite improvement to the code (apart from semicolons, which is IMO more of a formatting/consistency question than a linting question). In the end I accumulated a list of 28 Clippy lints I ignored entirely.

Sidenote: I should really have asked about this on Zulip before going through all 1,555 `if let`s in the codebase to decide which ones definitely look better as `match` :P

Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
This commit is contained in:
bors[bot] 2021-10-05 08:58:40 +00:00 committed by GitHub
commit 86c534f244
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
95 changed files with 399 additions and 478 deletions

View file

@ -509,10 +509,9 @@ impl<'a> CompletionContext<'a> {
.and_then(|pat| self.sema.type_of_pat(&pat))
.or_else(|| it.initializer().and_then(|it| self.sema.type_of_expr(&it)))
.map(TypeInfo::original);
let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() {
ident.name().map(NameOrNameRef::Name)
} else {
None
let name = match it.pat() {
Some(ast::Pat::IdentPat(ident)) => ident.name().map(NameOrNameRef::Name),
Some(_) | None => None,
};
(ty, name)

View file

@ -74,10 +74,9 @@ impl<'a> FunctionRender<'a> {
fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem {
let params = self.params();
let call = if let Some(receiver) = &self.receiver {
format!("{}.{}", receiver, &self.name)
} else {
self.name.clone()
let call = match &self.receiver {
Some(receiver) => format!("{}.{}", receiver, &self.name),
None => self.name.clone(),
};
let mut item =
CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), call.clone());

View file

@ -63,10 +63,9 @@ fn build_completion(
.set_documentation(ctx.docs(def))
.set_deprecated(ctx.is_deprecated(def))
.detail(&pat);
if let Some(snippet_cap) = ctx.snippet_cap() {
item.insert_snippet(snippet_cap, pat);
} else {
item.insert_text(pat);
match ctx.snippet_cap() {
Some(snippet_cap) => item.insert_snippet(snippet_cap, pat),
None => item.insert_text(pat),
};
item.build()
}

View file

@ -38,10 +38,9 @@ fn build_completion(
.set_documentation(ctx.docs(def))
.set_deprecated(ctx.is_deprecated(def))
.detail(&literal);
if let Some(snippet_cap) = ctx.snippet_cap() {
item.insert_snippet(snippet_cap, literal);
} else {
item.insert_text(literal);
match ctx.snippet_cap() {
Some(snippet_cap) => item.insert_snippet(snippet_cap, literal),
None => item.insert_text(literal),
};
item.build()
}