Merge #10440
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:
commit
86c534f244
95 changed files with 399 additions and 478 deletions
|
|
@ -292,10 +292,9 @@ impl TryToNav for hir::Impl {
|
|||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
||||
let src = self.source(db)?;
|
||||
let derive_attr = self.is_builtin_derive(db);
|
||||
let frange = if let Some(item) = &derive_attr {
|
||||
item.syntax().original_file_range(db)
|
||||
} else {
|
||||
src.syntax().original_file_range(db)
|
||||
let frange = match &derive_attr {
|
||||
Some(item) => item.syntax().original_file_range(db),
|
||||
None => src.syntax().original_file_range(db),
|
||||
};
|
||||
let focus_range = if derive_attr.is_some() {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -136,10 +136,9 @@ fn remove_newline(
|
|||
}
|
||||
T!['}'] => {
|
||||
// Removes: comma, newline (incl. surrounding whitespace)
|
||||
let space = if let Some(left) = prev.prev_sibling_or_token() {
|
||||
compute_ws(left.kind(), next.kind())
|
||||
} else {
|
||||
" "
|
||||
let space = match prev.prev_sibling_or_token() {
|
||||
Some(left) => compute_ws(left.kind(), next.kind()),
|
||||
None => " ",
|
||||
};
|
||||
edit.replace(
|
||||
TextRange::new(prev.text_range().start(), token.text_range().end()),
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ fn rename_to_self(sema: &Semantics<RootDatabase>, local: hir::Local) -> RenameRe
|
|||
_ => bail!("Cannot rename local to self outside of function"),
|
||||
};
|
||||
|
||||
if let Some(_) = fn_def.self_param(sema.db) {
|
||||
if fn_def.self_param(sema.db).is_some() {
|
||||
bail!("Method already has a self parameter");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,10 +103,9 @@ impl StaticIndex<'_> {
|
|||
for token in tokens {
|
||||
let range = token.text_range();
|
||||
let node = token.parent().unwrap();
|
||||
let def = if let Some(x) = get_definition(&sema, token.clone()) {
|
||||
x
|
||||
} else {
|
||||
continue;
|
||||
let def = match get_definition(&sema, token.clone()) {
|
||||
Some(x) => x,
|
||||
None => continue,
|
||||
};
|
||||
let id = if let Some(x) = self.def_map.get(&def) {
|
||||
*x
|
||||
|
|
@ -124,10 +123,9 @@ impl StaticIndex<'_> {
|
|||
let token = self.tokens.get_mut(id).unwrap();
|
||||
token.references.push(ReferenceData {
|
||||
range: FileRange { range, file_id },
|
||||
is_definition: if let Some(x) = def.try_to_nav(self.db) {
|
||||
x.file_id == file_id && x.focus_or_full_range() == range
|
||||
} else {
|
||||
false
|
||||
is_definition: match def.try_to_nav(self.db) {
|
||||
Some(x) => x.file_id == file_id && x.focus_or_full_range() == range,
|
||||
None => false,
|
||||
},
|
||||
});
|
||||
result.tokens.push((range, id));
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ fn traverse(
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(_) = macro_highlighter.highlight(element_to_highlight.clone()) {
|
||||
if macro_highlighter.highlight(element_to_highlight.clone()).is_some() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue