diff options
26 files changed, 67 insertions, 68 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 09d74b9e7..956cbe162 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs | |||
@@ -87,12 +87,18 @@ salsa::query_group! { | |||
87 | } | 87 | } |
88 | } | 88 | } |
89 | 89 | ||
90 | #[derive(Default, Debug, PartialEq, Eq)] | 90 | #[derive(Default, Debug, Eq)] |
91 | pub(crate) struct FileSet { | 91 | pub(crate) struct FileSet { |
92 | pub(crate) files: FxHashSet<FileId>, | 92 | pub(crate) files: FxHashSet<FileId>, |
93 | pub(crate) resolver: FileResolverImp, | 93 | pub(crate) resolver: FileResolverImp, |
94 | } | 94 | } |
95 | 95 | ||
96 | impl PartialEq for FileSet { | ||
97 | fn eq(&self, other: &FileSet) -> bool { | ||
98 | self.files == other.files && self.resolver == other.resolver | ||
99 | } | ||
100 | } | ||
101 | |||
96 | impl Hash for FileSet { | 102 | impl Hash for FileSet { |
97 | fn hash<H: Hasher>(&self, hasher: &mut H) { | 103 | fn hash<H: Hasher>(&self, hasher: &mut H) { |
98 | let mut files = self.files.iter().cloned().collect::<Vec<_>>(); | 104 | let mut files = self.files.iter().cloned().collect::<Vec<_>>(); |
diff --git a/crates/ra_analysis/src/descriptors.rs b/crates/ra_analysis/src/descriptors.rs index 310bf1585..92da26493 100644 --- a/crates/ra_analysis/src/descriptors.rs +++ b/crates/ra_analysis/src/descriptors.rs | |||
@@ -22,7 +22,7 @@ impl ModuleDescriptor { | |||
22 | } | 22 | } |
23 | } | 23 | } |
24 | 24 | ||
25 | fn modules<'a>(root: ast::Root<'a>) -> impl Iterator<Item = (SmolStr, ast::Module<'a>)> { | 25 | fn modules(root: ast::Root<'_>) -> impl Iterator<Item = (SmolStr, ast::Module<'_>)> { |
26 | root.modules().filter_map(|module| { | 26 | root.modules().filter_map(|module| { |
27 | let name = module.name()?.text(); | 27 | let name = module.name()?.text(); |
28 | if !module.has_semi() { | 28 | if !module.has_semi() { |
@@ -184,8 +184,7 @@ impl Link { | |||
184 | root: ast::Root<'a>, | 184 | root: ast::Root<'a>, |
185 | ) -> ast::Module<'a> { | 185 | ) -> ast::Module<'a> { |
186 | modules(root) | 186 | modules(root) |
187 | .filter(|(name, _)| name == &tree.link(self).name) | 187 | .find(|(name, _)| name == &tree.link(self).name) |
188 | .next() | ||
189 | .unwrap() | 188 | .unwrap() |
190 | .1 | 189 | .1 |
191 | } | 190 | } |
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 32e9bb6d7..196627539 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -426,12 +426,12 @@ impl AnalysisImpl { | |||
426 | .text() | 426 | .text() |
427 | .slice(range_search) | 427 | .slice(range_search) |
428 | .to_string() | 428 | .to_string() |
429 | .matches(",") | 429 | .matches(',') |
430 | .count(); | 430 | .count(); |
431 | 431 | ||
432 | // If we have a method call eat the first param since it's just self. | 432 | // If we have a method call eat the first param since it's just self. |
433 | if has_self { | 433 | if has_self { |
434 | commas = commas + 1; | 434 | commas += 1; |
435 | } | 435 | } |
436 | 436 | ||
437 | current_parameter = Some(commas); | 437 | current_parameter = Some(commas); |
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs index 9ee1df281..9d8df25c3 100644 --- a/crates/ra_editor/src/extend_selection.rs +++ b/crates/ra_editor/src/extend_selection.rs | |||
@@ -63,7 +63,7 @@ fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRa | |||
63 | let prefix = TextRange::from_to(ws.range().start(), offset) - ws.range().start(); | 63 | let prefix = TextRange::from_to(ws.range().start(), offset) - ws.range().start(); |
64 | let ws_suffix = &ws_text.as_str()[suffix]; | 64 | let ws_suffix = &ws_text.as_str()[suffix]; |
65 | let ws_prefix = &ws_text.as_str()[prefix]; | 65 | let ws_prefix = &ws_text.as_str()[prefix]; |
66 | if ws_text.contains("\n") && !ws_suffix.contains("\n") { | 66 | if ws_text.contains('\n') && !ws_suffix.contains('\n') { |
67 | if let Some(node) = ws.next_sibling() { | 67 | if let Some(node) = ws.next_sibling() { |
68 | let start = match ws_prefix.rfind('\n') { | 68 | let start = match ws_prefix.rfind('\n') { |
69 | Some(idx) => ws.range().start() + TextUnit::from((idx + 1) as u32), | 69 | Some(idx) => ws.range().start() + TextUnit::from((idx + 1) as u32), |
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs index e5bc0c4ee..d0d4ed3d3 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs | |||
@@ -38,12 +38,12 @@ pub fn folding_ranges(file: &File) -> Vec<Fold> { | |||
38 | continue; | 38 | continue; |
39 | } | 39 | } |
40 | if node.kind() == COMMENT { | 40 | if node.kind() == COMMENT { |
41 | contiguous_range_for_comment(node, &mut visited_comments).map(|range| { | 41 | if let Some(range) = contiguous_range_for_comment(node, &mut visited_comments) { |
42 | res.push(Fold { | 42 | res.push(Fold { |
43 | range, | 43 | range, |
44 | kind: FoldKind::Comment, | 44 | kind: FoldKind::Comment, |
45 | }) | 45 | }) |
46 | }); | 46 | } |
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
diff --git a/crates/ra_editor/src/line_index.rs b/crates/ra_editor/src/line_index.rs index da0f2a7f7..9abbb0d09 100644 --- a/crates/ra_editor/src/line_index.rs +++ b/crates/ra_editor/src/line_index.rs | |||
@@ -29,10 +29,10 @@ impl LineIndex { | |||
29 | let line = self.newlines.upper_bound(&offset) - 1; | 29 | let line = self.newlines.upper_bound(&offset) - 1; |
30 | let line_start_offset = self.newlines[line]; | 30 | let line_start_offset = self.newlines[line]; |
31 | let col = offset - line_start_offset; | 31 | let col = offset - line_start_offset; |
32 | return LineCol { | 32 | LineCol { |
33 | line: line as u32, | 33 | line: line as u32, |
34 | col, | 34 | col, |
35 | }; | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
38 | pub fn offset(&self, line_col: LineCol) -> TextUnit { | 38 | pub fn offset(&self, line_col: LineCol) -> TextUnit { |
diff --git a/crates/ra_editor/src/scope/mod_scope.rs b/crates/ra_editor/src/scope/mod_scope.rs index 8d7e408f8..956ee0e2f 100644 --- a/crates/ra_editor/src/scope/mod_scope.rs +++ b/crates/ra_editor/src/scope/mod_scope.rs | |||
@@ -22,14 +22,14 @@ impl ModuleScope { | |||
22 | let mut entries = Vec::new(); | 22 | let mut entries = Vec::new(); |
23 | for item in items { | 23 | for item in items { |
24 | let entry = match item { | 24 | let entry = match item { |
25 | ast::ModuleItem::StructDef(item) => Entry::new(item), | 25 | ast::ModuleItem::StructDef(item) => Entry::new_item(item), |
26 | ast::ModuleItem::EnumDef(item) => Entry::new(item), | 26 | ast::ModuleItem::EnumDef(item) => Entry::new_item(item), |
27 | ast::ModuleItem::FnDef(item) => Entry::new(item), | 27 | ast::ModuleItem::FnDef(item) => Entry::new_item(item), |
28 | ast::ModuleItem::ConstDef(item) => Entry::new(item), | 28 | ast::ModuleItem::ConstDef(item) => Entry::new_item(item), |
29 | ast::ModuleItem::StaticDef(item) => Entry::new(item), | 29 | ast::ModuleItem::StaticDef(item) => Entry::new_item(item), |
30 | ast::ModuleItem::TraitDef(item) => Entry::new(item), | 30 | ast::ModuleItem::TraitDef(item) => Entry::new_item(item), |
31 | ast::ModuleItem::TypeDef(item) => Entry::new(item), | 31 | ast::ModuleItem::TypeDef(item) => Entry::new_item(item), |
32 | ast::ModuleItem::Module(item) => Entry::new(item), | 32 | ast::ModuleItem::Module(item) => Entry::new_item(item), |
33 | ast::ModuleItem::UseItem(item) => { | 33 | ast::ModuleItem::UseItem(item) => { |
34 | if let Some(tree) = item.use_tree() { | 34 | if let Some(tree) = item.use_tree() { |
35 | collect_imports(tree, &mut entries); | 35 | collect_imports(tree, &mut entries); |
@@ -50,7 +50,7 @@ impl ModuleScope { | |||
50 | } | 50 | } |
51 | 51 | ||
52 | impl Entry { | 52 | impl Entry { |
53 | fn new<'a>(item: impl ast::NameOwner<'a>) -> Option<Entry> { | 53 | fn new_item<'a>(item: impl ast::NameOwner<'a>) -> Option<Entry> { |
54 | let name = item.name()?; | 54 | let name = item.name()?; |
55 | Some(Entry { | 55 | Some(Entry { |
56 | node: name.syntax().owned(), | 56 | node: name.syntax().owned(), |
diff --git a/crates/ra_editor/src/symbols.rs b/crates/ra_editor/src/symbols.rs index c3c66680d..0bab9dd67 100644 --- a/crates/ra_editor/src/symbols.rs +++ b/crates/ra_editor/src/symbols.rs | |||
@@ -54,15 +54,15 @@ pub fn file_structure(file: &File) -> Vec<StructureNode> { | |||
54 | let mut res = Vec::new(); | 54 | let mut res = Vec::new(); |
55 | let mut stack = Vec::new(); | 55 | let mut stack = Vec::new(); |
56 | 56 | ||
57 | |||
57 | for event in file.syntax().preorder() { | 58 | for event in file.syntax().preorder() { |
58 | match event { | 59 | match event { |
59 | WalkEvent::Enter(node) => match structure_node(node) { | 60 | WalkEvent::Enter(node) => { |
60 | Some(mut symbol) => { | 61 | if let Some(mut symbol) = structure_node(node) { |
61 | symbol.parent = stack.last().map(|&n| n); | 62 | symbol.parent = stack.last().map(|&n| n); |
62 | stack.push(res.len()); | 63 | stack.push(res.len()); |
63 | res.push(symbol); | 64 | res.push(symbol); |
64 | } | 65 | } |
65 | None => (), | ||
66 | }, | 66 | }, |
67 | WalkEvent::Leave(node) => { | 67 | WalkEvent::Leave(node) => { |
68 | if structure_node(node).is_some() { | 68 | if structure_node(node).is_some() { |
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs index 50b52e7a1..5a457d148 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs | |||
@@ -58,7 +58,7 @@ pub fn join_lines(file: &File, range: TextRange) -> LocalEdit { | |||
58 | pub fn on_enter(file: &File, offset: TextUnit) -> Option<LocalEdit> { | 58 | pub fn on_enter(file: &File, offset: TextUnit) -> Option<LocalEdit> { |
59 | let comment = find_leaf_at_offset(file.syntax(), offset) | 59 | let comment = find_leaf_at_offset(file.syntax(), offset) |
60 | .left_biased() | 60 | .left_biased() |
61 | .and_then(|it| ast::Comment::cast(it))?; | 61 | .and_then(ast::Comment::cast)?; |
62 | 62 | ||
63 | if let ast::CommentFlavor::Multiline = comment.flavor() { | 63 | if let ast::CommentFlavor::Multiline = comment.flavor() { |
64 | return None; | 64 | return None; |
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 8325e8c1e..bc0cf7c68 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -65,7 +65,7 @@ impl ConvWith for TextUnit { | |||
65 | fn conv_with(self, line_index: &LineIndex) -> Position { | 65 | fn conv_with(self, line_index: &LineIndex) -> Position { |
66 | let line_col = line_index.line_col(self); | 66 | let line_col = line_index.line_col(self); |
67 | // TODO: UTF-16 | 67 | // TODO: UTF-16 |
68 | Position::new(line_col.line as u64, u32::from(line_col.col) as u64) | 68 | Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col))) |
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
@@ -192,7 +192,7 @@ impl TryConvWith for SourceChange { | |||
192 | .map(|it| it.edits.as_slice()) | 192 | .map(|it| it.edits.as_slice()) |
193 | .unwrap_or(&[]); | 193 | .unwrap_or(&[]); |
194 | let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits); | 194 | let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits); |
195 | let position = Position::new(line_col.line as u64, u32::from(line_col.col) as u64); | 195 | let position = Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col))); |
196 | Some(TextDocumentPositionParams { | 196 | Some(TextDocumentPositionParams { |
197 | text_document: TextDocumentIdentifier::new(pos.file_id.try_conv_with(world)?), | 197 | text_document: TextDocumentIdentifier::new(pos.file_id.try_conv_with(world)?), |
198 | position, | 198 | position, |
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 9f62347f1..c07eb0140 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -18,7 +18,7 @@ fn main() -> Result<()> { | |||
18 | .directory("log") | 18 | .directory("log") |
19 | .start()?; | 19 | .start()?; |
20 | info!("lifecycle: server started"); | 20 | info!("lifecycle: server started"); |
21 | match ::std::panic::catch_unwind(|| main_inner()) { | 21 | match ::std::panic::catch_unwind(main_inner) { |
22 | Ok(res) => { | 22 | Ok(res) => { |
23 | info!("lifecycle: terminating process with {:?}", res); | 23 | info!("lifecycle: terminating process with {:?}", res); |
24 | res | 24 | res |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index f5dff4c80..11f34eb93 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -154,8 +154,8 @@ pub fn handle_workspace_symbol( | |||
154 | world: ServerWorld, | 154 | world: ServerWorld, |
155 | params: req::WorkspaceSymbolParams, | 155 | params: req::WorkspaceSymbolParams, |
156 | ) -> Result<Option<Vec<SymbolInformation>>> { | 156 | ) -> Result<Option<Vec<SymbolInformation>>> { |
157 | let all_symbols = params.query.contains("#"); | 157 | let all_symbols = params.query.contains('#'); |
158 | let libs = params.query.contains("*"); | 158 | let libs = params.query.contains('*'); |
159 | let query = { | 159 | let query = { |
160 | let query: String = params | 160 | let query: String = params |
161 | .query | 161 | .query |
@@ -279,8 +279,8 @@ pub fn handle_runnables( | |||
279 | .filter_map(|ws| { | 279 | .filter_map(|ws| { |
280 | let tgt = ws.target_by_root(path)?; | 280 | let tgt = ws.target_by_root(path)?; |
281 | Some(( | 281 | Some(( |
282 | tgt.package(ws).name(ws).clone(), | 282 | tgt.package(ws).name(ws), |
283 | tgt.name(ws).clone(), | 283 | tgt.name(ws), |
284 | tgt.kind(ws), | 284 | tgt.kind(ws), |
285 | )) | 285 | )) |
286 | }) | 286 | }) |
diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs index 04e2ef9c8..cabb336a3 100644 --- a/crates/ra_lsp_server/src/project_model.rs +++ b/crates/ra_lsp_server/src/project_model.rs | |||
@@ -173,7 +173,6 @@ pub fn workspace_loader() -> (Worker<PathBuf, Result<CargoWorkspace>>, ThreadWat | |||
173 | 1, | 173 | 1, |
174 | |input_receiver, output_sender| { | 174 | |input_receiver, output_sender| { |
175 | input_receiver | 175 | input_receiver |
176 | .into_iter() | ||
177 | .map(|path| CargoWorkspace::from_cargo_metadata(path.as_path())) | 176 | .map(|path| CargoWorkspace::from_cargo_metadata(path.as_path())) |
178 | .for_each(|it| output_sender.send(it)) | 177 | .for_each(|it| output_sender.send(it)) |
179 | }, | 178 | }, |
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 35ff65ea1..69b2a1cd1 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -73,9 +73,7 @@ impl ServerWorldState { | |||
73 | events | 73 | events |
74 | .into_iter() | 74 | .into_iter() |
75 | .map(|event| { | 75 | .map(|event| { |
76 | let text = match event.kind { | 76 | let FileEventKind::Add(text) = event.kind; |
77 | FileEventKind::Add(text) => text, | ||
78 | }; | ||
79 | (event.path, text) | 77 | (event.path, text) |
80 | }) | 78 | }) |
81 | .map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text)) | 79 | .map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text)) |
diff --git a/crates/ra_lsp_server/src/thread_watcher.rs b/crates/ra_lsp_server/src/thread_watcher.rs index 51b35fa66..5143c77ae 100644 --- a/crates/ra_lsp_server/src/thread_watcher.rs +++ b/crates/ra_lsp_server/src/thread_watcher.rs | |||
@@ -17,8 +17,7 @@ impl<I, O> Worker<I, O> { | |||
17 | I: Send + 'static, | 17 | I: Send + 'static, |
18 | O: Send + 'static, | 18 | O: Send + 'static, |
19 | { | 19 | { |
20 | let ((inp, out), inp_r, out_s) = worker_chan(buf); | 20 | let (worker, inp_r, out_s) = worker_chan(buf); |
21 | let worker = Worker { inp, out }; | ||
22 | let watcher = ThreadWatcher::spawn(name, move || f(inp_r, out_s)); | 21 | let watcher = ThreadWatcher::spawn(name, move || f(inp_r, out_s)); |
23 | (worker, watcher) | 22 | (worker, watcher) |
24 | } | 23 | } |
@@ -67,11 +66,14 @@ impl ThreadWatcher { | |||
67 | /// Sets up worker channels in a deadlock-avoind way. | 66 | /// Sets up worker channels in a deadlock-avoind way. |
68 | /// If one sets both input and output buffers to a fixed size, | 67 | /// If one sets both input and output buffers to a fixed size, |
69 | /// a worker might get stuck. | 68 | /// a worker might get stuck. |
70 | fn worker_chan<I, O>(buf: usize) -> ((Sender<I>, Receiver<O>), Receiver<I>, Sender<O>) { | 69 | fn worker_chan<I, O>(buf: usize) -> (Worker<I, O>, Receiver<I>, Sender<O>) { |
71 | let (input_sender, input_receiver) = bounded::<I>(buf); | 70 | let (input_sender, input_receiver) = bounded::<I>(buf); |
72 | let (output_sender, output_receiver) = unbounded::<O>(); | 71 | let (output_sender, output_receiver) = unbounded::<O>(); |
73 | ( | 72 | ( |
74 | (input_sender, output_receiver), | 73 | Worker { |
74 | inp: input_sender, | ||
75 | out: output_receiver, | ||
76 | }, | ||
75 | input_receiver, | 77 | input_receiver, |
76 | output_sender, | 78 | output_sender, |
77 | ) | 79 | ) |
diff --git a/crates/ra_lsp_server/src/vfs.rs b/crates/ra_lsp_server/src/vfs.rs index 417a3c19a..6e317d854 100644 --- a/crates/ra_lsp_server/src/vfs.rs +++ b/crates/ra_lsp_server/src/vfs.rs | |||
@@ -24,7 +24,6 @@ pub fn roots_loader() -> (Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, ThreadWatc | |||
24 | 128, | 24 | 128, |
25 | |input_receiver, output_sender| { | 25 | |input_receiver, output_sender| { |
26 | input_receiver | 26 | input_receiver |
27 | .into_iter() | ||
28 | .map(|path| { | 27 | .map(|path| { |
29 | debug!("loading {} ...", path.as_path().display()); | 28 | debug!("loading {} ...", path.as_path().display()); |
30 | let events = load_root(path.as_path()); | 29 | let events = load_root(path.as_path()); |
diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs index 9d2014bc7..d82c42b3e 100644 --- a/crates/ra_syntax/src/algo/mod.rs +++ b/crates/ra_syntax/src/algo/mod.rs | |||
@@ -30,7 +30,8 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse | |||
30 | let left = children.next().unwrap(); | 30 | let left = children.next().unwrap(); |
31 | let right = children.next(); | 31 | let right = children.next(); |
32 | assert!(children.next().is_none()); | 32 | assert!(children.next().is_none()); |
33 | return if let Some(right) = right { | 33 | |
34 | if let Some(right) = right { | ||
34 | match ( | 35 | match ( |
35 | find_leaf_at_offset(left, offset), | 36 | find_leaf_at_offset(left, offset), |
36 | find_leaf_at_offset(right, offset), | 37 | find_leaf_at_offset(right, offset), |
@@ -42,10 +43,10 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse | |||
42 | } | 43 | } |
43 | } else { | 44 | } else { |
44 | find_leaf_at_offset(left, offset) | 45 | find_leaf_at_offset(left, offset) |
45 | }; | 46 | } |
46 | } | 47 | } |
47 | 48 | ||
48 | #[derive(Clone, Copy, Debug)] | 49 | #[derive(Clone, Debug)] |
49 | pub enum LeafAtOffset<'a> { | 50 | pub enum LeafAtOffset<'a> { |
50 | None, | 51 | None, |
51 | Single(SyntaxNodeRef<'a>), | 52 | Single(SyntaxNodeRef<'a>), |
diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs index 34958b6cb..900426a8a 100644 --- a/crates/ra_syntax/src/ast/mod.rs +++ b/crates/ra_syntax/src/ast/mod.rs | |||
@@ -259,9 +259,8 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { | |||
259 | type Item = N; | 259 | type Item = N; |
260 | fn next(&mut self) -> Option<N> { | 260 | fn next(&mut self) -> Option<N> { |
261 | loop { | 261 | loop { |
262 | match N::cast(self.inner.next()?) { | 262 | if let Some(n) = N::cast(self.inner.next()?) { |
263 | Some(n) => return Some(n), | 263 | return Some(n); |
264 | None => (), | ||
265 | } | 264 | } |
266 | } | 265 | } |
267 | } | 266 | } |
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs index 11f766d33..04087fd60 100644 --- a/crates/ra_syntax/src/grammar/expressions/atom.rs +++ b/crates/ra_syntax/src/grammar/expressions/atom.rs | |||
@@ -62,9 +62,8 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![ | |||
62 | const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; | 62 | const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; |
63 | 63 | ||
64 | pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { | 64 | pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { |
65 | match literal(p) { | 65 | if let Some(m) = literal(p) { |
66 | Some(m) => return Some(m), | 66 | return Some(m); |
67 | None => (), | ||
68 | } | 67 | } |
69 | if paths::is_path_start(p) || p.at(L_ANGLE) { | 68 | if paths::is_path_start(p) || p.at(L_ANGLE) { |
70 | return Some(path_expr(p, r)); | 69 | return Some(path_expr(p, r)); |
diff --git a/crates/ra_syntax/src/grammar/items/mod.rs b/crates/ra_syntax/src/grammar/items/mod.rs index dc4742bce..06c6b5e6e 100644 --- a/crates/ra_syntax/src/grammar/items/mod.rs +++ b/crates/ra_syntax/src/grammar/items/mod.rs | |||
@@ -352,7 +352,7 @@ fn macro_call(p: &mut Parser) -> BlockLike { | |||
352 | pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { | 352 | pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { |
353 | p.expect(EXCL); | 353 | p.expect(EXCL); |
354 | p.eat(IDENT); | 354 | p.eat(IDENT); |
355 | let flavor = match p.current() { | 355 | match p.current() { |
356 | L_CURLY => { | 356 | L_CURLY => { |
357 | token_tree(p); | 357 | token_tree(p); |
358 | BlockLike::Block | 358 | BlockLike::Block |
@@ -365,9 +365,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { | |||
365 | p.error("expected `{`, `[`, `(`"); | 365 | p.error("expected `{`, `[`, `(`"); |
366 | BlockLike::NotBlock | 366 | BlockLike::NotBlock |
367 | } | 367 | } |
368 | }; | 368 | } |
369 | |||
370 | flavor | ||
371 | } | 369 | } |
372 | 370 | ||
373 | pub(crate) fn token_tree(p: &mut Parser) { | 371 | pub(crate) fn token_tree(p: &mut Parser) { |
diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs index 9d35dbb3d..10fa0e0be 100644 --- a/crates/ra_syntax/src/grammar/patterns.rs +++ b/crates/ra_syntax/src/grammar/patterns.rs | |||
@@ -49,9 +49,8 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { | |||
49 | // "hello" => (), | 49 | // "hello" => (), |
50 | // } | 50 | // } |
51 | // } | 51 | // } |
52 | match expressions::literal(p) { | 52 | if let Some(m) = expressions::literal(p) { |
53 | Some(m) => return Some(m), | 53 | return Some(m); |
54 | None => (), | ||
55 | } | 54 | } |
56 | 55 | ||
57 | let m = match la0 { | 56 | let m = match la0 { |
diff --git a/crates/ra_syntax/src/lexer/ptr.rs b/crates/ra_syntax/src/lexer/ptr.rs index fa79d8862..4c291b9c4 100644 --- a/crates/ra_syntax/src/lexer/ptr.rs +++ b/crates/ra_syntax/src/lexer/ptr.rs | |||
@@ -31,7 +31,7 @@ impl<'s> Ptr<'s> { | |||
31 | /// For example, 0 will return the current token, 1 will return the next, etc. | 31 | /// For example, 0 will return the current token, 1 will return the next, etc. |
32 | pub fn nth(&self, n: u32) -> Option<char> { | 32 | pub fn nth(&self, n: u32) -> Option<char> { |
33 | let mut chars = self.chars().peekable(); | 33 | let mut chars = self.chars().peekable(); |
34 | chars.by_ref().skip(n as usize).next() | 34 | chars.by_ref().nth(n as usize) |
35 | } | 35 | } |
36 | 36 | ||
37 | /// Checks whether the current character is `c`. | 37 | /// Checks whether the current character is `c`. |
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index a0014e016..eae01b1d5 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs | |||
@@ -98,17 +98,18 @@ fn is_contextual_kw(text: &str) -> bool { | |||
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | fn find_reparsable_node<'node>( | 101 | type ParseFn = fn(&mut Parser); |
102 | node: SyntaxNodeRef<'node>, | 102 | fn find_reparsable_node( |
103 | node: SyntaxNodeRef<'_>, | ||
103 | range: TextRange, | 104 | range: TextRange, |
104 | ) -> Option<(SyntaxNodeRef<'node>, fn(&mut Parser))> { | 105 | ) -> Option<(SyntaxNodeRef<'_>, ParseFn)> { |
105 | let node = algo::find_covering_node(node, range); | 106 | let node = algo::find_covering_node(node, range); |
106 | return node | 107 | return node |
107 | .ancestors() | 108 | .ancestors() |
108 | .filter_map(|node| reparser(node).map(|r| (node, r))) | 109 | .filter_map(|node| reparser(node).map(|r| (node, r))) |
109 | .next(); | 110 | .next(); |
110 | 111 | ||
111 | fn reparser(node: SyntaxNodeRef) -> Option<fn(&mut Parser)> { | 112 | fn reparser(node: SyntaxNodeRef) -> Option<ParseFn> { |
112 | let res = match node.kind() { | 113 | let res = match node.kind() { |
113 | BLOCK => grammar::block, | 114 | BLOCK => grammar::block, |
114 | NAMED_FIELD_DEF_LIST => grammar::named_field_def_list, | 115 | NAMED_FIELD_DEF_LIST => grammar::named_field_def_list, |
@@ -134,7 +135,7 @@ fn find_reparsable_node<'node>( | |||
134 | } | 135 | } |
135 | 136 | ||
136 | fn is_balanced(tokens: &[Token]) -> bool { | 137 | fn is_balanced(tokens: &[Token]) -> bool { |
137 | if tokens.len() == 0 | 138 | if tokens.is_empty() |
138 | || tokens.first().unwrap().kind != L_CURLY | 139 | || tokens.first().unwrap().kind != L_CURLY |
139 | || tokens.last().unwrap().kind != R_CURLY | 140 | || tokens.last().unwrap().kind != R_CURLY |
140 | { | 141 | { |
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index 7d0ef2fa2..8ee02724d 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs | |||
@@ -5,7 +5,7 @@ use std::fmt::Write; | |||
5 | 5 | ||
6 | /// Parse a file and create a string representation of the resulting parse tree. | 6 | /// Parse a file and create a string representation of the resulting parse tree. |
7 | pub fn dump_tree(syntax: SyntaxNodeRef) -> String { | 7 | pub fn dump_tree(syntax: SyntaxNodeRef) -> String { |
8 | let mut errors: Vec<_> = syntax.root_data().iter().cloned().collect(); | 8 | let mut errors: Vec<_> = syntax.root_data().to_vec(); |
9 | errors.sort_by_key(|e| e.offset); | 9 | errors.sort_by_key(|e| e.offset); |
10 | let mut err_pos = 0; | 10 | let mut err_pos = 0; |
11 | let mut level = 0; | 11 | let mut level = 0; |
@@ -42,7 +42,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String { | |||
42 | writeln!(buf, "err: `{}`", err.msg).unwrap(); | 42 | writeln!(buf, "err: `{}`", err.msg).unwrap(); |
43 | } | 43 | } |
44 | 44 | ||
45 | return buf; | 45 | buf |
46 | } | 46 | } |
47 | 47 | ||
48 | pub fn check_fuzz_invariants(text: &str) { | 48 | pub fn check_fuzz_invariants(text: &str) { |
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 444745be5..7c5410d3c 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs | |||
@@ -50,7 +50,7 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> { | |||
50 | block.map(|(_, line)| line).chain(::std::iter::once("")), | 50 | block.map(|(_, line)| line).chain(::std::iter::once("")), |
51 | "\n", | 51 | "\n", |
52 | ); | 52 | ); |
53 | assert!(!text.trim().is_empty() && text.ends_with("\n")); | 53 | assert!(!text.trim().is_empty() && text.ends_with('\n')); |
54 | res.push((start_line, Test { name, text })) | 54 | res.push((start_line, Test { name, text })) |
55 | } | 55 | } |
56 | res | 56 | res |
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 152298014..fdb443690 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs | |||
@@ -112,9 +112,8 @@ fn existing_tests(dir: &Path) -> Result<HashMap<String, (PathBuf, Test)>> { | |||
112 | name: name.clone(), | 112 | name: name.clone(), |
113 | text, | 113 | text, |
114 | }; | 114 | }; |
115 | match res.insert(name, (path, test)) { | 115 | if let Some(old) = res.insert(name, (path, test)) { |
116 | Some(old) => println!("Duplicate test: {:?}", old), | 116 | println!("Duplicate test: {:?}", old); |
117 | None => (), | ||
118 | } | 117 | } |
119 | } | 118 | } |
120 | Ok(res) | 119 | Ok(res) |