aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorkjeremy <[email protected]>2020-01-13 16:27:06 +0000
committerkjeremy <[email protected]>2020-01-13 16:27:06 +0000
commita82c679c97af1e0aabe9eb375573d5d23fc75391 (patch)
tree59ff0d52538586ceecc8feb11cf1634418c886d7 /crates
parent5621f90071f576a8989cd09f98eb0fc6c9b7a612 (diff)
Some clippy lints
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/assists/add_custom_impl.rs2
-rw-r--r--crates/ra_cli/src/main.rs2
-rw-r--r--crates/ra_ide/src/call_hierarchy.rs2
-rw-r--r--crates/ra_ide/src/call_info.rs59
-rw-r--r--crates/ra_ide/src/completion/complete_path.rs2
-rw-r--r--crates/ra_ide/src/extend_selection.rs2
-rw-r--r--crates/ra_ide/src/references.rs13
-rw-r--r--crates/ra_ide/src/references/search_scope.rs3
-rw-r--r--crates/ra_parser/src/grammar/paths.rs2
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs4
10 files changed, 45 insertions, 46 deletions
diff --git a/crates/ra_assists/src/assists/add_custom_impl.rs b/crates/ra_assists/src/assists/add_custom_impl.rs
index 037306fd6..9b8955710 100644
--- a/crates/ra_assists/src/assists/add_custom_impl.rs
+++ b/crates/ra_assists/src/assists/add_custom_impl.rs
@@ -10,7 +10,7 @@ use ra_syntax::{
10 TextRange, TextUnit, 10 TextRange, TextUnit,
11}; 11};
12 12
13const DERIVE_TRAIT: &'static str = "derive"; 13const DERIVE_TRAIT: &str = "derive";
14 14
15// Assist: add_custom_impl 15// Assist: add_custom_impl
16// 16//
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index 3808590ab..806612c2c 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -22,7 +22,7 @@ pub enum Verbosity {
22} 22}
23 23
24impl Verbosity { 24impl Verbosity {
25 fn is_verbose(&self) -> bool { 25 fn is_verbose(self) -> bool {
26 match self { 26 match self {
27 Verbosity::Verbose => true, 27 Verbosity::Verbose => true,
28 _ => false, 28 _ => false,
diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs
index 1cb712e32..aa5d60c7b 100644
--- a/crates/ra_ide/src/call_hierarchy.rs
+++ b/crates/ra_ide/src/call_hierarchy.rs
@@ -121,7 +121,7 @@ pub(crate) fn outgoing_calls(db: &RootDatabase, position: FilePosition) -> Optio
121 Some(macro_def.to_nav(db)) 121 Some(macro_def.to_nav(db))
122 } 122 }
123 } { 123 } {
124 Some((func_target.clone(), name_ref.value.text_range())) 124 Some((func_target, name_ref.value.text_range()))
125 } else { 125 } else {
126 None 126 None
127 } 127 }
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index a7023529b..14f5ead6b 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -1,10 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2
3use hir::db::AstDatabase; 2use hir::db::AstDatabase;
4use ra_syntax::{ 3use ra_syntax::{
5 ast::{self, ArgListOwner}, 4 ast::{self, ArgListOwner},
6 match_ast, AstNode, SyntaxNode, 5 match_ast, AstNode, SyntaxNode,
7}; 6};
7use std::cmp::Ordering;
8use test_utils::tested_by; 8use test_utils::tested_by;
9 9
10use crate::{ 10use crate::{
@@ -51,36 +51,39 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
51 // If we have a calling expression let's find which argument we are on 51 // If we have a calling expression let's find which argument we are on
52 let num_params = call_info.parameters().len(); 52 let num_params = call_info.parameters().len();
53 53
54 if num_params == 1 { 54 match num_params.cmp(&1) {
55 if !has_self { 55 Ordering::Less => {}
56 call_info.active_parameter = Some(0); 56 Ordering::Equal => {
57 } 57 if !has_self {
58 } else if num_params > 1 { 58 call_info.active_parameter = Some(0);
59 // Count how many parameters into the call we are.
60 if let Some(arg_list) = calling_node.arg_list() {
61 // Number of arguments specified at the call site
62 let num_args_at_callsite = arg_list.args().count();
63
64 let arg_list_range = arg_list.syntax().text_range();
65 if !arg_list_range.contains_inclusive(position.offset) {
66 tested_by!(call_info_bad_offset);
67 return None;
68 } 59 }
60 }
61 Ordering::Greater => {
62 if let Some(arg_list) = calling_node.arg_list() {
63 // Number of arguments specified at the call site
64 let num_args_at_callsite = arg_list.args().count();
65
66 let arg_list_range = arg_list.syntax().text_range();
67 if !arg_list_range.contains_inclusive(position.offset) {
68 tested_by!(call_info_bad_offset);
69 return None;
70 }
69 71
70 let mut param = std::cmp::min( 72 let mut param = std::cmp::min(
71 num_args_at_callsite, 73 num_args_at_callsite,
72 arg_list 74 arg_list
73 .args() 75 .args()
74 .take_while(|arg| arg.syntax().text_range().end() < position.offset) 76 .take_while(|arg| arg.syntax().text_range().end() < position.offset)
75 .count(), 77 .count(),
76 ); 78 );
77 79
78 // If we are in a method account for `self` 80 // If we are in a method account for `self`
79 if has_self { 81 if has_self {
80 param += 1; 82 param += 1;
81 } 83 }
82 84
83 call_info.active_parameter = Some(param); 85 call_info.active_parameter = Some(param);
86 }
84 } 87 }
85 } 88 }
86 89
diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs
index cc1f7c830..0dce9dc2d 100644
--- a/crates/ra_ide/src/completion/complete_path.rs
+++ b/crates/ra_ide/src/completion/complete_path.rs
@@ -26,7 +26,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
26 } 26 }
27 if let ScopeDef::Unknown = def { 27 if let ScopeDef::Unknown = def {
28 if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { 28 if let Some(name_ref) = ctx.name_ref_syntax.as_ref() {
29 if &name_ref.syntax().text() == name.to_string().as_str() { 29 if name_ref.syntax().text() == name.to_string().as_str() {
30 // for `use self::foo<|>`, don't suggest `foo` as a completion 30 // for `use self::foo<|>`, don't suggest `foo` as a completion
31 tested_by!(dont_complete_current_use); 31 tested_by!(dont_complete_current_use);
32 continue; 32 continue;
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index 70b6fde82..930e0c4c2 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -339,7 +339,7 @@ mod tests {
339 let (cursor, before) = extract_offset(before); 339 let (cursor, before) = extract_offset(before);
340 let (analysis, file_id) = single_file(&before); 340 let (analysis, file_id) = single_file(&before);
341 let range = TextRange::offset_len(cursor, 0.into()); 341 let range = TextRange::offset_len(cursor, 0.into());
342 let mut frange = FileRange { file_id: file_id, range }; 342 let mut frange = FileRange { file_id, range };
343 343
344 for &after in afters { 344 for &after in afters {
345 frange.range = analysis.extend_selection(frange).unwrap(); 345 frange.range = analysis.extend_selection(frange).unwrap();
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index 4e52e0e7b..2c753dade 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -166,7 +166,7 @@ pub(crate) fn find_all_refs(
166 Some(RangeInfo::new(range, ReferenceSearchResult { declaration, references })) 166 Some(RangeInfo::new(range, ReferenceSearchResult { declaration, references }))
167} 167}
168 168
169fn find_name<'a>( 169fn find_name(
170 db: &RootDatabase, 170 db: &RootDatabase,
171 syntax: &SyntaxNode, 171 syntax: &SyntaxNode,
172 position: FilePosition, 172 position: FilePosition,
@@ -253,13 +253,10 @@ fn decl_access(
253 let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?; 253 let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?;
254 if let Some(_) = stmt.initializer() { 254 if let Some(_) = stmt.initializer() {
255 let pat = stmt.pat()?; 255 let pat = stmt.pat()?;
256 match pat { 256 if let ast::Pat::BindPat(it) = pat {
257 ast::Pat::BindPat(it) => { 257 if it.name()?.text().as_str() == name {
258 if it.name()?.text().as_str() == name { 258 return Some(ReferenceAccess::Write);
259 return Some(ReferenceAccess::Write);
260 }
261 } 259 }
262 _ => {}
263 } 260 }
264 } 261 }
265 262
@@ -286,7 +283,7 @@ fn reference_access(kind: &NameKind, name_ref: &ast::NameRef) -> Option<Referenc
286 } 283 }
287 } 284 }
288 } 285 }
289 return Some(ReferenceAccess::Read); 286 Some(ReferenceAccess::Read)
290 }, 287 },
291 _ => {None} 288 _ => {None}
292 } 289 }
diff --git a/crates/ra_ide/src/references/search_scope.rs b/crates/ra_ide/src/references/search_scope.rs
index 241dd358f..f8211a746 100644
--- a/crates/ra_ide/src/references/search_scope.rs
+++ b/crates/ra_ide/src/references/search_scope.rs
@@ -82,8 +82,7 @@ impl NameDefinition {
82 return SearchScope::new(res); 82 return SearchScope::new(res);
83 } 83 }
84 84
85 let vis = 85 let vis = self.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or_default();
86 self.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or("".to_string());
87 86
88 if vis.as_str() == "pub(super)" { 87 if vis.as_str() == "pub(super)" {
89 if let Some(parent_module) = self.container.parent(db) { 88 if let Some(parent_module) = self.container.parent(db) {
diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs
index ca8e075a1..e125c6b9c 100644
--- a/crates/ra_parser/src/grammar/paths.rs
+++ b/crates/ra_parser/src/grammar/paths.rs
@@ -94,7 +94,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
94 94
95fn opt_path_type_args(p: &mut Parser, mode: Mode) { 95fn opt_path_type_args(p: &mut Parser, mode: Mode) {
96 match mode { 96 match mode {
97 Mode::Use => return, 97 Mode::Use => {}
98 Mode::Type => { 98 Mode::Type => {
99 // test path_fn_trait_args 99 // test path_fn_trait_args
100 // type F = Box<Fn(x: i32) -> ()>; 100 // type F = Box<Fn(x: i32) -> ()>;
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 3dfecfe76..6da4b1309 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -127,8 +127,8 @@ pub enum BinOp {
127} 127}
128 128
129impl BinOp { 129impl BinOp {
130 pub fn is_assignment(&self) -> bool { 130 pub fn is_assignment(self) -> bool {
131 match *self { 131 match self {
132 BinOp::Assignment 132 BinOp::Assignment
133 | BinOp::AddAssign 133 | BinOp::AddAssign
134 | BinOp::DivAssign 134 | BinOp::DivAssign