diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-04 23:14:46 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-04 23:14:46 +0100 |
commit | 5deb907b4321d8328978d3322b0826b781814452 (patch) | |
tree | 2baa3b75b1ef62c02617c37ba9b800c41a3dd102 /crates/ra_ide_api | |
parent | 8bd0e844247dc28d6ceb24b00f3cc3396bd5bf03 (diff) | |
parent | aa30c4909ebb1e85f1591f465c9e2875aa4d394e (diff) |
Merge #1374
1374: Implement `cargo lint` and fix some clippy errors r=alanhdu a=alanhdu
This creates a `cargo lint` command that runs clippy with certain lints disabled. I've also gone ahead and fixed some of the lint errors, although there are many more still to go.
cc #848
Co-authored-by: Alan Du <[email protected]>
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 7 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_pattern.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_scope.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/extend_selection.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/folding_ranges.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/line_index.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/line_index_utils.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide_api/src/typing.rs | 2 |
11 files changed, 27 insertions, 23 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 5d43282fd..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<Cal | |||
21 | let function = match calling_node { | 21 | let function = match calling_node { |
22 | FnCallNode::CallExpr(expr) => { | 22 | FnCallNode::CallExpr(expr) => { |
23 | //FIXME: apply subst | 23 | //FIXME: apply subst |
24 | let (callable_def, _subst) = | 24 | let (callable_def, _subst) = analyzer.type_of(db, expr.expr()?)?.as_callable()?; |
25 | analyzer.type_of(db, expr.expr()?.into())?.as_callable()?; | ||
26 | match callable_def { | 25 | match callable_def { |
27 | hir::CallableDef::Function(it) => it, | 26 | hir::CallableDef::Function(it) => it, |
28 | //FIXME: handle other callables | 27 | //FIXME: handle other callables |
@@ -64,7 +63,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal | |||
64 | 63 | ||
65 | // If we are in a method account for `self` | 64 | // If we are in a method account for `self` |
66 | if has_self { | 65 | if has_self { |
67 | param = param + 1; | 66 | param += 1; |
68 | } | 67 | } |
69 | 68 | ||
70 | call_info.active_parameter = Some(param); | 69 | call_info.active_parameter = Some(param); |
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) { | |||
16 | 16 | ||
17 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { | 17 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { |
18 | for receiver in receiver.autoderef(ctx.db) { | 18 | for receiver in receiver.autoderef(ctx.db) { |
19 | match receiver { | 19 | if let Ty::Apply(a_ty) = receiver { |
20 | Ty::Apply(a_ty) => match a_ty.ctor { | 20 | match a_ty.ctor { |
21 | TypeCtor::Adt(AdtDef::Struct(s)) => { | 21 | TypeCtor::Adt(AdtDef::Struct(s)) => { |
22 | for field in s.fields(ctx.db) { | 22 | for field in s.fields(ctx.db) { |
23 | acc.add_field(ctx, field, &a_ty.parameters); | 23 | acc.add_field(ctx, field, &a_ty.parameters); |
@@ -30,8 +30,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
30 | } | 30 | } |
31 | } | 31 | } |
32 | _ => {} | 32 | _ => {} |
33 | }, | 33 | } |
34 | _ => {} | ||
35 | }; | 34 | }; |
36 | } | 35 | } |
37 | } | 36 | } |
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) { | |||
10 | let names = ctx.analyzer.all_names(ctx.db); | 10 | let names = ctx.analyzer.all_names(ctx.db); |
11 | for (name, res) in names.into_iter() { | 11 | for (name, res) in names.into_iter() { |
12 | let r = res.as_ref(); | 12 | let r = res.as_ref(); |
13 | let def = match r.take_types().or(r.take_values()) { | 13 | let def = match r.take_types().or_else(|| r.take_values()) { |
14 | Some(hir::Resolution::Def(def)) => def, | 14 | Some(hir::Resolution::Def(def)) => def, |
15 | _ => continue, | 15 | _ => continue, |
16 | }; | 16 | }; |
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) { | |||
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | fn build_import_label(name: &str, path: &Vec<SmolStr>) -> String { | 52 | fn build_import_label(name: &str, path: &[SmolStr]) -> String { |
53 | let mut buf = String::with_capacity(64); | 53 | let mut buf = String::with_capacity(64); |
54 | buf.push_str(name); | 54 | buf.push_str(name); |
55 | buf.push_str(" ("); | 55 | buf.push_str(" ("); |
@@ -58,7 +58,7 @@ fn build_import_label(name: &str, path: &Vec<SmolStr>) -> String { | |||
58 | buf | 58 | buf |
59 | } | 59 | } |
60 | 60 | ||
61 | fn fmt_import_path(path: &Vec<SmolStr>, buf: &mut String) { | 61 | fn fmt_import_path(path: &[SmolStr], buf: &mut String) { |
62 | let mut segments = path.iter(); | 62 | let mut segments = path.iter(); |
63 | if let Some(s) = segments.next() { | 63 | if let Some(s) = segments.next() { |
64 | buf.push_str(&s); | 64 | buf.push_str(&s); |
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( | |||
109 | 109 | ||
110 | acc.push(Diagnostic { | 110 | acc.push(Diagnostic { |
111 | range, | 111 | range, |
112 | message: format!("Unnecessary braces in use statement"), | 112 | message: "Unnecessary braces in use statement".to_string(), |
113 | severity: Severity::WeakWarning, | 113 | severity: Severity::WeakWarning, |
114 | fix: Some(SourceChange::source_file_edit( | 114 | fix: Some(SourceChange::source_file_edit( |
115 | "Remove unnecessary braces", | 115 | "Remove unnecessary braces", |
@@ -155,7 +155,7 @@ fn check_struct_shorthand_initialization( | |||
155 | 155 | ||
156 | acc.push(Diagnostic { | 156 | acc.push(Diagnostic { |
157 | range: named_field.syntax().range(), | 157 | range: named_field.syntax().range(), |
158 | message: format!("Shorthand struct initialization"), | 158 | message: "Shorthand struct initialization".to_string(), |
159 | severity: Severity::WeakWarning, | 159 | severity: Severity::WeakWarning, |
160 | fix: Some(SourceChange::source_file_edit( | 160 | fix: Some(SourceChange::source_file_edit( |
161 | "use struct shorthand initialization", | 161 | "use struct shorthand initialization", |
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( | |||
95 | } | 95 | } |
96 | 96 | ||
97 | let start_idx = before.rfind(non_word_char)? as u32; | 97 | let start_idx = before.rfind(non_word_char)? as u32; |
98 | let end_idx = after.find(non_word_char).unwrap_or(after.len()) as u32; | 98 | let end_idx = after.find(non_word_char).unwrap_or_else(|| after.len()) as u32; |
99 | 99 | ||
100 | let from: TextUnit = (start_idx + 1).into(); | 100 | let from: TextUnit = (start_idx + 1).into(); |
101 | let to: TextUnit = (cursor_position + end_idx).into(); | 101 | let to: TextUnit = (cursor_position + end_idx).into(); |
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 { | |||
205 | "The amount of fold kinds is different than the expected amount" | 205 | "The amount of fold kinds is different than the expected amount" |
206 | ); | 206 | ); |
207 | for ((fold, range), fold_kind) in | 207 | for ((fold, range), fold_kind) in |
208 | folds.into_iter().zip(ranges.into_iter()).zip(fold_kinds.into_iter()) | 208 | folds.iter().zip(ranges.into_iter()).zip(fold_kinds.iter()) |
209 | { | 209 | { |
210 | assert_eq!(fold.range.start(), range.start()); | 210 | assert_eq!(fold.range.start(), range.start()); |
211 | assert_eq!(fold.range.end(), range.end()); | 211 | assert_eq!(fold.range.end(), range.end()); |
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 { | |||
18 | exact: bool, | 18 | exact: bool, |
19 | } | 19 | } |
20 | 20 | ||
21 | impl Default for HoverResult { | ||
22 | fn default() -> Self { | ||
23 | HoverResult::new() | ||
24 | } | ||
25 | } | ||
26 | |||
21 | impl HoverResult { | 27 | impl HoverResult { |
22 | pub fn new() -> HoverResult { | 28 | pub fn new() -> HoverResult { |
23 | HoverResult { | 29 | HoverResult { |
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 { | |||
41 | newlines.push(curr_row); | 41 | newlines.push(curr_row); |
42 | 42 | ||
43 | // Save any utf-16 characters seen in the previous line | 43 | // Save any utf-16 characters seen in the previous line |
44 | if utf16_chars.len() > 0 { | 44 | if !utf16_chars.is_empty() { |
45 | utf16_lines.insert(line, utf16_chars); | 45 | utf16_lines.insert(line, utf16_chars); |
46 | utf16_chars = Vec::new(); | 46 | utf16_chars = Vec::new(); |
47 | } | 47 | } |
@@ -61,7 +61,7 @@ impl LineIndex { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | // Save any utf-16 characters seen in the last line | 63 | // Save any utf-16 characters seen in the last line |
64 | if utf16_chars.len() > 0 { | 64 | if !utf16_chars.is_empty() { |
65 | utf16_lines.insert(line, utf16_chars); | 65 | utf16_lines.insert(line, utf16_chars); |
66 | } | 66 | } |
67 | 67 | ||
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> { | |||
133 | } | 133 | } |
134 | 134 | ||
135 | fn next_steps(&mut self, step: &Step) -> NextSteps { | 135 | fn next_steps(&mut self, step: &Step) -> NextSteps { |
136 | let step_pos = match step { | 136 | let step_pos = match *step { |
137 | &Step::Newline(n) => n, | 137 | Step::Newline(n) => n, |
138 | &Step::Utf16Char(r) => r.end(), | 138 | Step::Utf16Char(r) => r.end(), |
139 | }; | 139 | }; |
140 | let res = match &mut self.current { | 140 | let res = match &mut self.current { |
141 | Some(edit) => { | 141 | Some(edit) => { |
@@ -181,9 +181,9 @@ impl<'a> Edits<'a> { | |||
181 | if self.acc_diff == 0 { | 181 | if self.acc_diff == 0 { |
182 | x.clone() | 182 | x.clone() |
183 | } else { | 183 | } else { |
184 | match x { | 184 | match *x { |
185 | &Step::Newline(n) => Step::Newline(self.translate(n)), | 185 | Step::Newline(n) => Step::Newline(self.translate(n)), |
186 | &Step::Utf16Char(r) => Step::Utf16Char(self.translate_range(r)), | 186 | Step::Utf16Char(r) => Step::Utf16Char(self.translate_range(r)), |
187 | } | 187 | } |
188 | } | 188 | } |
189 | } | 189 | } |
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< | |||
110 | let mut edit = TextEditBuilder::default(); | 110 | let mut edit = TextEditBuilder::default(); |
111 | edit.replace( | 111 | edit.replace( |
112 | TextRange::from_to(position.offset - current_indent_len, position.offset), | 112 | TextRange::from_to(position.offset - current_indent_len, position.offset), |
113 | target_indent.into(), | 113 | target_indent, |
114 | ); | 114 | ); |
115 | 115 | ||
116 | let res = SourceChange::source_file_edit_from("reindent dot", position.file_id, edit.finish()) | 116 | let res = SourceChange::source_file_edit_from("reindent dot", position.file_id, edit.finish()) |