From ecd420636efe54657ae742ce960ce061740ef108 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 3 Jun 2019 10:01:10 -0400 Subject: Fix clippy::single_match --- crates/ra_ide_api/src/completion/complete_dot.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 5bf289c63..0822a0e7e 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -16,8 +16,8 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { for receiver in receiver.autoderef(ctx.db) { - match receiver { - Ty::Apply(a_ty) => match a_ty.ctor { + if let Ty::Apply(a_ty) = receiver { + match a_ty.ctor { TypeCtor::Adt(AdtDef::Struct(s)) => { for field in s.fields(ctx.db) { acc.add_field(ctx, field, &a_ty.parameters); @@ -30,8 +30,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) } } _ => {} - }, - _ => {} + } }; } } -- cgit v1.2.3 From b9af1d7c428bac3e2efb69e0dadda72938ce3b3c Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 3 Jun 2019 10:07:00 -0400 Subject: Fix clippy::match_ref_pats --- crates/ra_ide_api/src/line_index_utils.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/line_index_utils.rs b/crates/ra_ide_api/src/line_index_utils.rs index 799a920ad..a03467011 100644 --- a/crates/ra_ide_api/src/line_index_utils.rs +++ b/crates/ra_ide_api/src/line_index_utils.rs @@ -133,9 +133,9 @@ impl<'a> Edits<'a> { } fn next_steps(&mut self, step: &Step) -> NextSteps { - let step_pos = match step { - &Step::Newline(n) => n, - &Step::Utf16Char(r) => r.end(), + let step_pos = match *step { + Step::Newline(n) => n, + Step::Utf16Char(r) => r.end(), }; let res = match &mut self.current { Some(edit) => { @@ -181,9 +181,9 @@ impl<'a> Edits<'a> { if self.acc_diff == 0 { x.clone() } else { - match x { - &Step::Newline(n) => Step::Newline(self.translate(n)), - &Step::Utf16Char(r) => Step::Utf16Char(self.translate_range(r)), + match *x { + Step::Newline(n) => Step::Newline(self.translate(n)), + Step::Utf16Char(r) => Step::Utf16Char(self.translate_range(r)), } } } -- cgit v1.2.3 From fafca4cb11c0580ff10111d3ca44d4569932b125 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 4 Jun 2019 01:51:25 -0400 Subject: Fix clippy::ptr_arg --- crates/ra_ide_api/src/completion/complete_scope.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 2473e58b4..0f8cfaae8 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -49,7 +49,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { } } -fn build_import_label(name: &str, path: &Vec) -> String { +fn build_import_label(name: &str, path: &[SmolStr]) -> String { let mut buf = String::with_capacity(64); buf.push_str(name); buf.push_str(" ("); @@ -58,7 +58,7 @@ fn build_import_label(name: &str, path: &Vec) -> String { buf } -fn fmt_import_path(path: &Vec, buf: &mut String) { +fn fmt_import_path(path: &[SmolStr], buf: &mut String) { let mut segments = path.iter(); if let Some(s) = segments.next() { buf.push_str(&s); -- cgit v1.2.3 From 619a61529878f82daf7aed571bc4f6a10bd6dd9f Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 4 Jun 2019 02:28:22 -0400 Subject: Fix clippy::len_zero --- crates/ra_ide_api/src/line_index.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/line_index.rs b/crates/ra_ide_api/src/line_index.rs index fd33d6767..087dfafed 100644 --- a/crates/ra_ide_api/src/line_index.rs +++ b/crates/ra_ide_api/src/line_index.rs @@ -41,7 +41,7 @@ impl LineIndex { newlines.push(curr_row); // Save any utf-16 characters seen in the previous line - if utf16_chars.len() > 0 { + if !utf16_chars.is_empty() { utf16_lines.insert(line, utf16_chars); utf16_chars = Vec::new(); } @@ -61,7 +61,7 @@ impl LineIndex { } // Save any utf-16 characters seen in the last line - if utf16_chars.len() > 0 { + if !utf16_chars.is_empty() { utf16_lines.insert(line, utf16_chars); } -- cgit v1.2.3 From fb592d76aa24e8fe74694038c283f56ea83ab568 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 4 Jun 2019 02:28:50 -0400 Subject: Fix clippy::into_iter_on_ref --- crates/ra_ide_api/src/folding_ranges.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/folding_ranges.rs b/crates/ra_ide_api/src/folding_ranges.rs index b50bbee38..4400ff232 100644 --- a/crates/ra_ide_api/src/folding_ranges.rs +++ b/crates/ra_ide_api/src/folding_ranges.rs @@ -205,7 +205,7 @@ mod tests { "The amount of fold kinds is different than the expected amount" ); for ((fold, range), fold_kind) in - folds.into_iter().zip(ranges.into_iter()).zip(fold_kinds.into_iter()) + folds.iter().zip(ranges.into_iter()).zip(fold_kinds.iter()) { assert_eq!(fold.range.start(), range.start()); assert_eq!(fold.range.end(), range.end()); -- cgit v1.2.3 From 21d7964bc3f0b923aac081d9ab854c3fc0c8b0b7 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 4 Jun 2019 02:29:50 -0400 Subject: Fix clippy::useless_format --- crates/ra_ide_api/src/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index a2a8c1e4f..35b3d77df 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs @@ -109,7 +109,7 @@ fn check_unnecessary_braces_in_use_statement( acc.push(Diagnostic { range, - message: format!("Unnecessary braces in use statement"), + message: "Unnecessary braces in use statement".to_string(), severity: Severity::WeakWarning, fix: Some(SourceChange::source_file_edit( "Remove unnecessary braces", @@ -155,7 +155,7 @@ fn check_struct_shorthand_initialization( acc.push(Diagnostic { range: named_field.syntax().range(), - message: format!("Shorthand struct initialization"), + message: "Shorthand struct initialization".to_string(), severity: Severity::WeakWarning, fix: Some(SourceChange::source_file_edit( "use struct shorthand initialization", -- cgit v1.2.3 From 6939011b273c8ac63a29faed6febef5a94035d40 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 4 Jun 2019 02:31:17 -0400 Subject: Fix clippy::assign_op_pattern --- crates/ra_ide_api/src/call_info.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 5d43282fd..0d1f92ca6 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -64,7 +64,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option Date: Tue, 4 Jun 2019 02:32:02 -0400 Subject: Fix clippy::new_without_default --- crates/ra_ide_api/src/hover.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 9c35db2a4..f56965ef5 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -18,6 +18,12 @@ pub struct HoverResult { exact: bool, } +impl Default for HoverResult { + fn default() -> Self { + HoverResult::new() + } +} + impl HoverResult { pub fn new() -> HoverResult { HoverResult { -- cgit v1.2.3 From 40424d4222d4630bc53294d10f1718f2d3d300de Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 3 Jun 2019 10:21:08 -0400 Subject: Fix clippy::identity_conversion --- crates/ra_ide_api/src/call_info.rs | 3 +-- crates/ra_ide_api/src/typing.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 0d1f92ca6..bd08e183d 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -21,8 +21,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option { //FIXME: apply subst - let (callable_def, _subst) = - analyzer.type_of(db, expr.expr()?.into())?.as_callable()?; + let (callable_def, _subst) = analyzer.type_of(db, expr.expr()?)?.as_callable()?; match callable_def { hir::CallableDef::Function(it) => it, //FIXME: handle other callables diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index 63bc0cf88..3e35d8352 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs @@ -110,7 +110,7 @@ pub(crate) fn on_dot_typed(db: &RootDatabase, position: FilePosition) -> Option< let mut edit = TextEditBuilder::default(); edit.replace( TextRange::from_to(position.offset - current_indent_len, position.offset), - target_indent.into(), + target_indent, ); let res = SourceChange::source_file_edit_from("reindent dot", position.file_id, edit.finish()) -- cgit v1.2.3 From b28ca32db22d5e2ed34db556c6fd50a5fc2d679c Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 3 Jun 2019 10:27:51 -0400 Subject: Fix clippy::or_fun_call --- crates/ra_ide_api/src/completion/complete_pattern.rs | 2 +- crates/ra_ide_api/src/extend_selection.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs index 74833a756..6655a05a7 100644 --- a/crates/ra_ide_api/src/completion/complete_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_pattern.rs @@ -10,7 +10,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { let names = ctx.analyzer.all_names(ctx.db); for (name, res) in names.into_iter() { let r = res.as_ref(); - let def = match r.take_types().or(r.take_values()) { + let def = match r.take_types().or_else(|| r.take_values()) { Some(hir::Resolution::Def(def)) => def, _ => continue, }; diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 00c445310..a713b762c 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs @@ -95,7 +95,7 @@ fn extend_single_word_in_comment_or_string( } let start_idx = before.rfind(non_word_char)? as u32; - let end_idx = after.find(non_word_char).unwrap_or(after.len()) as u32; + let end_idx = after.find(non_word_char).unwrap_or_else(|| after.len()) as u32; let from: TextUnit = (start_idx + 1).into(); let to: TextUnit = (cursor_position + end_idx).into(); -- cgit v1.2.3