diff options
author | Maan2003 <[email protected]> | 2021-06-13 04:54:16 +0100 |
---|---|---|
committer | Maan2003 <[email protected]> | 2021-06-13 04:54:16 +0100 |
commit | c9b4ac5be4daaabc062ab1ee663eba8594750003 (patch) | |
tree | 6090c8c38c735875c916255920525cf5fff45c75 /crates/rust-analyzer | |
parent | d6737e55fb49d286b5e646f57975b27b2c95ce92 (diff) |
clippy::redudant_borrow
Diffstat (limited to 'crates/rust-analyzer')
-rw-r--r-- | crates/rust-analyzer/src/cargo_target_spec.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/load_cargo.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/diagnostics.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/diagnostics/to_proto.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 10 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 8 | ||||
-rw-r--r-- | crates/rust-analyzer/src/lsp_utils.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 10 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/slow-tests/main.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/slow-tests/support.rs | 2 |
11 files changed, 26 insertions, 26 deletions
diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs index f4cd43448..5d8547152 100644 --- a/crates/rust-analyzer/src/cargo_target_spec.rs +++ b/crates/rust-analyzer/src/cargo_target_spec.rs | |||
@@ -123,7 +123,7 @@ impl CargoTargetSpec { | |||
123 | let res = CargoTargetSpec { | 123 | let res = CargoTargetSpec { |
124 | workspace_root: cargo_ws.workspace_root().to_path_buf(), | 124 | workspace_root: cargo_ws.workspace_root().to_path_buf(), |
125 | cargo_toml: package_data.manifest.clone(), | 125 | cargo_toml: package_data.manifest.clone(), |
126 | package: cargo_ws.package_flag(&package_data), | 126 | package: cargo_ws.package_flag(package_data), |
127 | target: target_data.name.clone(), | 127 | target: target_data.name.clone(), |
128 | target_kind: target_data.kind, | 128 | target_kind: target_data.kind, |
129 | }; | 129 | }; |
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 19cb1c046..b5f5519b4 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs | |||
@@ -126,7 +126,7 @@ fn load_crate_graph( | |||
126 | } | 126 | } |
127 | } | 127 | } |
128 | } | 128 | } |
129 | let source_roots = source_root_config.partition(&vfs); | 129 | let source_roots = source_root_config.partition(vfs); |
130 | analysis_change.set_roots(source_roots); | 130 | analysis_change.set_roots(source_roots); |
131 | 131 | ||
132 | analysis_change.set_crate_graph(crate_graph); | 132 | analysis_change.set_crate_graph(crate_graph); |
diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs index d4b9db362..2f63c26ce 100644 --- a/crates/rust-analyzer/src/diagnostics.rs +++ b/crates/rust-analyzer/src/diagnostics.rs | |||
@@ -47,7 +47,7 @@ impl DiagnosticCollection { | |||
47 | ) { | 47 | ) { |
48 | let diagnostics = self.check.entry(file_id).or_default(); | 48 | let diagnostics = self.check.entry(file_id).or_default(); |
49 | for existing_diagnostic in diagnostics.iter() { | 49 | for existing_diagnostic in diagnostics.iter() { |
50 | if are_diagnostics_equal(&existing_diagnostic, &diagnostic) { | 50 | if are_diagnostics_equal(existing_diagnostic, &diagnostic) { |
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | } | 53 | } |
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 82dd0da9a..8594d923c 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs | |||
@@ -224,7 +224,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
224 | 224 | ||
225 | let mut message = rd.message.clone(); | 225 | let mut message = rd.message.clone(); |
226 | for child in &rd.children { | 226 | for child in &rd.children { |
227 | let child = map_rust_child_diagnostic(config, workspace_root, &child); | 227 | let child = map_rust_child_diagnostic(config, workspace_root, child); |
228 | match child { | 228 | match child { |
229 | MappedRustChildDiagnostic::SubDiagnostic(sub) => { | 229 | MappedRustChildDiagnostic::SubDiagnostic(sub) => { |
230 | subdiagnostics.push(sub); | 230 | subdiagnostics.push(sub); |
@@ -268,7 +268,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
268 | primary_spans | 268 | primary_spans |
269 | .iter() | 269 | .iter() |
270 | .flat_map(|primary_span| { | 270 | .flat_map(|primary_span| { |
271 | let primary_location = primary_location(config, workspace_root, &primary_span); | 271 | let primary_location = primary_location(config, workspace_root, primary_span); |
272 | 272 | ||
273 | let mut message = message.clone(); | 273 | let mut message = message.clone(); |
274 | if needs_primary_span_label { | 274 | if needs_primary_span_label { |
@@ -298,7 +298,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
298 | // generated that code. | 298 | // generated that code. |
299 | let is_in_macro_call = i != 0; | 299 | let is_in_macro_call = i != 0; |
300 | 300 | ||
301 | let secondary_location = location(config, workspace_root, &span); | 301 | let secondary_location = location(config, workspace_root, span); |
302 | if secondary_location == primary_location { | 302 | if secondary_location == primary_location { |
303 | continue; | 303 | continue; |
304 | } | 304 | } |
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 582a89667..583900cfe 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -194,7 +194,7 @@ impl GlobalState { | |||
194 | change.change_file(file.file_id, text); | 194 | change.change_file(file.file_id, text); |
195 | } | 195 | } |
196 | if has_fs_changes { | 196 | if has_fs_changes { |
197 | let roots = self.source_root_config.partition(&vfs); | 197 | let roots = self.source_root_config.partition(vfs); |
198 | change.set_roots(roots); | 198 | change.set_roots(roots); |
199 | } | 199 | } |
200 | change | 200 | change |
@@ -291,7 +291,7 @@ impl GlobalStateSnapshot { | |||
291 | } | 291 | } |
292 | 292 | ||
293 | pub(crate) fn url_file_version(&self, url: &Url) -> Option<i32> { | 293 | pub(crate) fn url_file_version(&self, url: &Url) -> Option<i32> { |
294 | let path = from_proto::vfs_path(&url).ok()?; | 294 | let path = from_proto::vfs_path(url).ok()?; |
295 | Some(self.mem_docs.get(&path)?.version) | 295 | Some(self.mem_docs.get(&path)?.version) |
296 | } | 296 | } |
297 | 297 | ||
@@ -300,7 +300,7 @@ impl GlobalStateSnapshot { | |||
300 | base.pop(); | 300 | base.pop(); |
301 | let path = base.join(&path.path).unwrap(); | 301 | let path = base.join(&path.path).unwrap(); |
302 | let path = path.as_path().unwrap(); | 302 | let path = path.as_path().unwrap(); |
303 | url_from_abs_path(&path) | 303 | url_from_abs_path(path) |
304 | } | 304 | } |
305 | 305 | ||
306 | pub(crate) fn cargo_target_for_crate_root( | 306 | pub(crate) fn cargo_target_for_crate_root( |
@@ -312,7 +312,7 @@ impl GlobalStateSnapshot { | |||
312 | let path = path.as_path()?; | 312 | let path = path.as_path()?; |
313 | self.workspaces.iter().find_map(|ws| match ws { | 313 | self.workspaces.iter().find_map(|ws| match ws { |
314 | ProjectWorkspace::Cargo { cargo, .. } => { | 314 | ProjectWorkspace::Cargo { cargo, .. } => { |
315 | cargo.target_by_root(&path).map(|it| (cargo, it)) | 315 | cargo.target_by_root(path).map(|it| (cargo, it)) |
316 | } | 316 | } |
317 | ProjectWorkspace::Json { .. } => None, | 317 | ProjectWorkspace::Json { .. } => None, |
318 | ProjectWorkspace::DetachedFiles { .. } => None, | 318 | ProjectWorkspace::DetachedFiles { .. } => None, |
@@ -323,7 +323,7 @@ impl GlobalStateSnapshot { | |||
323 | pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url { | 323 | pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url { |
324 | let path = vfs.file_path(id); | 324 | let path = vfs.file_path(id); |
325 | let path = path.as_path().unwrap(); | 325 | let path = path.as_path().unwrap(); |
326 | url_from_abs_path(&path) | 326 | url_from_abs_path(path) |
327 | } | 327 | } |
328 | 328 | ||
329 | pub(crate) fn url_to_file_id(vfs: &vfs::Vfs, url: &Url) -> Result<FileId> { | 329 | pub(crate) fn url_to_file_id(vfs: &vfs::Vfs, url: &Url) -> Result<FileId> { |
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 40dd0da3e..59339d401 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -1396,7 +1396,7 @@ pub(crate) fn handle_semantic_tokens_full_delta( | |||
1396 | 1396 | ||
1397 | if let Some(prev_id) = &cached_tokens.result_id { | 1397 | if let Some(prev_id) = &cached_tokens.result_id { |
1398 | if *prev_id == params.previous_result_id { | 1398 | if *prev_id == params.previous_result_id { |
1399 | let delta = to_proto::semantic_token_delta(&cached_tokens, &semantic_tokens); | 1399 | let delta = to_proto::semantic_token_delta(cached_tokens, &semantic_tokens); |
1400 | *cached_tokens = semantic_tokens; | 1400 | *cached_tokens = semantic_tokens; |
1401 | return Ok(Some(delta.into())); | 1401 | return Ok(Some(delta.into())); |
1402 | } | 1402 | } |
@@ -1540,7 +1540,7 @@ fn runnable_action_links( | |||
1540 | snap: &GlobalStateSnapshot, | 1540 | snap: &GlobalStateSnapshot, |
1541 | runnable: Runnable, | 1541 | runnable: Runnable, |
1542 | ) -> Option<lsp_ext::CommandLinkGroup> { | 1542 | ) -> Option<lsp_ext::CommandLinkGroup> { |
1543 | let cargo_spec = CargoTargetSpec::for_file(&snap, runnable.nav.file_id).ok()?; | 1543 | let cargo_spec = CargoTargetSpec::for_file(snap, runnable.nav.file_id).ok()?; |
1544 | let hover_config = snap.config.hover(); | 1544 | let hover_config = snap.config.hover(); |
1545 | if !hover_config.runnable() || should_skip_target(&runnable, cargo_spec.as_ref()) { | 1545 | if !hover_config.runnable() || should_skip_target(&runnable, cargo_spec.as_ref()) { |
1546 | return None; | 1546 | return None; |
@@ -1624,7 +1624,7 @@ fn run_rustfmt( | |||
1624 | text_document: TextDocumentIdentifier, | 1624 | text_document: TextDocumentIdentifier, |
1625 | range: Option<lsp_types::Range>, | 1625 | range: Option<lsp_types::Range>, |
1626 | ) -> Result<Option<Vec<lsp_types::TextEdit>>> { | 1626 | ) -> Result<Option<Vec<lsp_types::TextEdit>>> { |
1627 | let file_id = from_proto::file_id(&snap, &text_document.uri)?; | 1627 | let file_id = from_proto::file_id(snap, &text_document.uri)?; |
1628 | let file = snap.analysis.file_text(file_id)?; | 1628 | let file = snap.analysis.file_text(file_id)?; |
1629 | let crate_ids = snap.analysis.crate_for(file_id)?; | 1629 | let crate_ids = snap.analysis.crate_for(file_id)?; |
1630 | 1630 | ||
@@ -1671,7 +1671,7 @@ fn run_rustfmt( | |||
1671 | .into()); | 1671 | .into()); |
1672 | } | 1672 | } |
1673 | 1673 | ||
1674 | let frange = from_proto::file_range(&snap, text_document, range)?; | 1674 | let frange = from_proto::file_range(snap, text_document, range)?; |
1675 | let start_line = line_index.index.line_col(frange.range.start()).line; | 1675 | let start_line = line_index.index.line_col(frange.range.start()).line; |
1676 | let end_line = line_index.index.line_col(frange.range.end()).line; | 1676 | let end_line = line_index.index.line_col(frange.range.end()).line; |
1677 | 1677 | ||
diff --git a/crates/rust-analyzer/src/lsp_utils.rs b/crates/rust-analyzer/src/lsp_utils.rs index 8000b5490..087c26a71 100644 --- a/crates/rust-analyzer/src/lsp_utils.rs +++ b/crates/rust-analyzer/src/lsp_utils.rs | |||
@@ -124,7 +124,7 @@ pub(crate) fn apply_document_changes( | |||
124 | match change.range { | 124 | match change.range { |
125 | Some(range) => { | 125 | Some(range) => { |
126 | if !index_valid.covers(range.end.line) { | 126 | if !index_valid.covers(range.end.line) { |
127 | line_index.index = Arc::new(ide::LineIndex::new(&old_text)); | 127 | line_index.index = Arc::new(ide::LineIndex::new(old_text)); |
128 | } | 128 | } |
129 | index_valid = IndexValid::UpToLineExclusive(range.start.line); | 129 | index_valid = IndexValid::UpToLineExclusive(range.start.line); |
130 | let range = from_proto::text_range(&line_index, range); | 130 | let range = from_proto::text_range(&line_index, range); |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 31d8ea9e7..fa5fc6fbf 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -740,7 +740,7 @@ impl GlobalState { | |||
740 | let subscriptions = self | 740 | let subscriptions = self |
741 | .mem_docs | 741 | .mem_docs |
742 | .keys() | 742 | .keys() |
743 | .map(|path| self.vfs.read().0.file_id(&path).unwrap()) | 743 | .map(|path| self.vfs.read().0.file_id(path).unwrap()) |
744 | .collect::<Vec<_>>(); | 744 | .collect::<Vec<_>>(); |
745 | 745 | ||
746 | log::trace!("updating notifications for {:?}", subscriptions); | 746 | log::trace!("updating notifications for {:?}", subscriptions); |
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 7428a3043..e53cd3c7b 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs | |||
@@ -405,7 +405,7 @@ pub(crate) fn semantic_tokens( | |||
405 | text_range = | 405 | text_range = |
406 | TextRange::new(text_range.start(), text_range.end() - TextSize::of('\n')); | 406 | TextRange::new(text_range.start(), text_range.end() - TextSize::of('\n')); |
407 | } | 407 | } |
408 | let range = range(&line_index, text_range); | 408 | let range = range(line_index, text_range); |
409 | builder.push(range, token_index, modifier_bitset); | 409 | builder.push(range, token_index, modifier_bitset); |
410 | } | 410 | } |
411 | } | 411 | } |
@@ -781,7 +781,7 @@ pub(crate) fn snippet_workspace_edit( | |||
781 | document_changes.extend_from_slice(&ops); | 781 | document_changes.extend_from_slice(&ops); |
782 | } | 782 | } |
783 | for (file_id, edit) in source_change.source_file_edits { | 783 | for (file_id, edit) in source_change.source_file_edits { |
784 | let edit = snippet_text_document_edit(&snap, source_change.is_snippet, file_id, edit)?; | 784 | let edit = snippet_text_document_edit(snap, source_change.is_snippet, file_id, edit)?; |
785 | document_changes.push(lsp_ext::SnippetDocumentChangeOperation::Edit(edit)); | 785 | document_changes.push(lsp_ext::SnippetDocumentChangeOperation::Edit(edit)); |
786 | } | 786 | } |
787 | let mut workspace_edit = lsp_ext::SnippetWorkspaceEdit { | 787 | let mut workspace_edit = lsp_ext::SnippetWorkspaceEdit { |
@@ -957,7 +957,7 @@ pub(crate) fn code_lens( | |||
957 | let annotation_range = range(&line_index, annotation.range); | 957 | let annotation_range = range(&line_index, annotation.range); |
958 | 958 | ||
959 | let action = run.action(); | 959 | let action = run.action(); |
960 | let r = runnable(&snap, run)?; | 960 | let r = runnable(snap, run)?; |
961 | 961 | ||
962 | let command = if debug { | 962 | let command = if debug { |
963 | command::debug_single(&r) | 963 | command::debug_single(&r) |
@@ -1236,12 +1236,12 @@ fn main() { | |||
1236 | assert_eq!(folds.len(), 4); | 1236 | assert_eq!(folds.len(), 4); |
1237 | 1237 | ||
1238 | let line_index = LineIndex { | 1238 | let line_index = LineIndex { |
1239 | index: Arc::new(ide::LineIndex::new(&text)), | 1239 | index: Arc::new(ide::LineIndex::new(text)), |
1240 | endings: LineEndings::Unix, | 1240 | endings: LineEndings::Unix, |
1241 | encoding: OffsetEncoding::Utf16, | 1241 | encoding: OffsetEncoding::Utf16, |
1242 | }; | 1242 | }; |
1243 | let converted: Vec<lsp_types::FoldingRange> = | 1243 | let converted: Vec<lsp_types::FoldingRange> = |
1244 | folds.into_iter().map(|it| folding_range(&text, &line_index, true, it)).collect(); | 1244 | folds.into_iter().map(|it| folding_range(text, &line_index, true, it)).collect(); |
1245 | 1245 | ||
1246 | let expected_lines = [(0, 2), (4, 10), (5, 6), (7, 9)]; | 1246 | let expected_lines = [(0, 2), (4, 10), (5, 6), (7, 9)]; |
1247 | assert_eq!(converted.len(), expected_lines.len()); | 1247 | assert_eq!(converted.len(), expected_lines.len()); |
diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs index 9e89209ea..3585132d4 100644 --- a/crates/rust-analyzer/tests/slow-tests/main.rs +++ b/crates/rust-analyzer/tests/slow-tests/main.rs | |||
@@ -493,7 +493,7 @@ fn preserves_dos_line_endings() { | |||
493 | } | 493 | } |
494 | 494 | ||
495 | let server = Project::with_fixture( | 495 | let server = Project::with_fixture( |
496 | &" | 496 | " |
497 | //- /Cargo.toml | 497 | //- /Cargo.toml |
498 | [package] | 498 | [package] |
499 | name = \"foo\" | 499 | name = \"foo\" |
@@ -758,7 +758,7 @@ pub fn foo(_input: TokenStream) -> TokenStream { | |||
758 | ```rust | 758 | ```rust |
759 | fn bar() | 759 | fn bar() |
760 | ```"#]] | 760 | ```"#]] |
761 | .assert_eq(&value); | 761 | .assert_eq(value); |
762 | } | 762 | } |
763 | 763 | ||
764 | #[test] | 764 | #[test] |
@@ -795,7 +795,7 @@ fn main() {} | |||
795 | 795 | ||
796 | "#; | 796 | "#; |
797 | let server = | 797 | let server = |
798 | Project::with_fixture(&code).tmp_dir(tmp_dir).server().wait_until_workspace_is_loaded(); | 798 | Project::with_fixture(code).tmp_dir(tmp_dir).server().wait_until_workspace_is_loaded(); |
799 | 799 | ||
800 | //rename same level file | 800 | //rename same level file |
801 | server.request::<WillRenameFiles>( | 801 | server.request::<WillRenameFiles>( |
diff --git a/crates/rust-analyzer/tests/slow-tests/support.rs b/crates/rust-analyzer/tests/slow-tests/support.rs index 75e677762..e22c295f9 100644 --- a/crates/rust-analyzer/tests/slow-tests/support.rs +++ b/crates/rust-analyzer/tests/slow-tests/support.rs | |||
@@ -323,7 +323,7 @@ fn find_mismatch<'a>(expected: &'a Value, actual: &'a Value) -> Option<(&'a Valu | |||
323 | 323 | ||
324 | if !l.is_empty() { | 324 | if !l.is_empty() { |
325 | assert!(!r.is_empty()); | 325 | assert!(!r.is_empty()); |
326 | Some((&l[0], &r[0])) | 326 | Some((l[0], r[0])) |
327 | } else { | 327 | } else { |
328 | assert_eq!(r.len(), 0); | 328 | assert_eq!(r.len(), 0); |
329 | None | 329 | None |