Skip to content

Commit ce06f8d

Browse files
bors[bot]matkladJonas Schievink
authored
Merge #5072 #5073
5072: Cleanup r=matklad a=matklad bors r+ 🤖 5073: `iterate_method_candidates`: Address review comments r=jonas-schievink a=jonas-schievink bors r+ Co-authored-by: Aleksey Kladov <[email protected]> Co-authored-by: Jonas Schievink <[email protected]>
3 parents 38cd1b7 + 12831b7 + c441306 commit ce06f8d

File tree

5 files changed

+35
-28
lines changed

5 files changed

+35
-28
lines changed

crates/ra_hir_ty/src/method_resolution.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,15 @@ pub fn iterate_method_candidates<T>(
281281
name,
282282
mode,
283283
&mut |ty, item| {
284+
assert!(slot.is_none());
284285
slot = callback(ty, item);
285286
slot.is_some()
286287
},
287288
);
288289
slot
289290
}
290291

291-
pub fn iterate_method_candidates_impl(
292+
fn iterate_method_candidates_impl(
292293
ty: &Canonical<Ty>,
293294
db: &dyn HirDatabase,
294295
env: Arc<TraitEnvironment>,

crates/rust-analyzer/src/diagnostics.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub(crate) mod to_proto;
33

44
use std::{collections::HashMap, mem, sync::Arc};
55

6-
use lsp_types::{Diagnostic, Range};
76
use ra_ide::FileId;
87
use rustc_hash::FxHashSet;
98

@@ -19,15 +18,15 @@ pub struct DiagnosticsConfig {
1918

2019
#[derive(Debug, Default, Clone)]
2120
pub(crate) struct DiagnosticCollection {
22-
pub(crate) native: HashMap<FileId, Vec<Diagnostic>>,
23-
pub(crate) check: HashMap<FileId, Vec<Diagnostic>>,
21+
pub(crate) native: HashMap<FileId, Vec<lsp_types::Diagnostic>>,
22+
pub(crate) check: HashMap<FileId, Vec<lsp_types::Diagnostic>>,
2423
pub(crate) check_fixes: CheckFixes,
2524
changes: FxHashSet<FileId>,
2625
}
2726

2827
#[derive(Debug, Clone)]
2928
pub(crate) struct Fix {
30-
pub(crate) range: Range,
29+
pub(crate) range: lsp_types::Range,
3130
pub(crate) action: lsp_ext::CodeAction,
3231
}
3332

@@ -40,7 +39,7 @@ impl DiagnosticCollection {
4039
pub(crate) fn add_check_diagnostic(
4140
&mut self,
4241
file_id: FileId,
43-
diagnostic: Diagnostic,
42+
diagnostic: lsp_types::Diagnostic,
4443
fixes: Vec<lsp_ext::CodeAction>,
4544
) {
4645
let diagnostics = self.check.entry(file_id).or_default();
@@ -59,12 +58,19 @@ impl DiagnosticCollection {
5958
self.changes.insert(file_id);
6059
}
6160

62-
pub(crate) fn set_native_diagnostics(&mut self, file_id: FileId, diagnostics: Vec<Diagnostic>) {
61+
pub(crate) fn set_native_diagnostics(
62+
&mut self,
63+
file_id: FileId,
64+
diagnostics: Vec<lsp_types::Diagnostic>,
65+
) {
6366
self.native.insert(file_id, diagnostics);
6467
self.changes.insert(file_id);
6568
}
6669

67-
pub(crate) fn diagnostics_for(&self, file_id: FileId) -> impl Iterator<Item = &Diagnostic> {
70+
pub(crate) fn diagnostics_for(
71+
&self,
72+
file_id: FileId,
73+
) -> impl Iterator<Item = &lsp_types::Diagnostic> {
6874
let native = self.native.get(&file_id).into_iter().flatten();
6975
let check = self.check.get(&file_id).into_iter().flatten();
7076
native.chain(check)
@@ -78,7 +84,7 @@ impl DiagnosticCollection {
7884
}
7985
}
8086

81-
fn are_diagnostics_equal(left: &Diagnostic, right: &Diagnostic) -> bool {
87+
fn are_diagnostics_equal(left: &lsp_types::Diagnostic, right: &lsp_types::Diagnostic) -> bool {
8288
left.source == right.source
8389
&& left.severity == right.severity
8490
&& left.range == right.range

crates/rust-analyzer/src/diagnostics/to_proto.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ fn map_rust_child_diagnostic(
167167

168168
#[derive(Debug)]
169169
pub(crate) struct MappedRustDiagnostic {
170-
pub location: Location,
171-
pub diagnostic: Diagnostic,
172-
pub fixes: Vec<lsp_ext::CodeAction>,
170+
pub(crate) location: Location,
171+
pub(crate) diagnostic: Diagnostic,
172+
pub(crate) fixes: Vec<lsp_ext::CodeAction>,
173173
}
174174

175175
/// Converts a Rust root diagnostic to LSP form

crates/rust-analyzer/src/global_state.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,7 @@ impl Drop for GlobalState {
195195

196196
impl GlobalStateSnapshot {
197197
pub(crate) fn url_to_file_id(&self, url: &Url) -> Result<FileId> {
198-
let path = from_proto::abs_path(url)?;
199-
let path = path.into();
200-
let res =
201-
self.vfs.read().0.file_id(&path).ok_or_else(|| format!("file not found: {}", path))?;
202-
Ok(res)
198+
url_to_file_id(&self.vfs.read().0, url)
203199
}
204200

205201
pub(crate) fn file_id_to_url(&self, id: FileId) -> Url {
@@ -239,3 +235,9 @@ pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url {
239235
let path = path.as_path().unwrap();
240236
url_from_abs_path(&path)
241237
}
238+
239+
pub(crate) fn url_to_file_id(vfs: &vfs::Vfs, url: &Url) -> Result<FileId> {
240+
let path = from_proto::vfs_path(url)?;
241+
let res = vfs.file_id(&path).ok_or_else(|| format!("file not found: {}", path))?;
242+
Ok(res)
243+
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
config::Config,
1717
dispatch::{NotificationDispatcher, RequestDispatcher},
1818
from_proto,
19-
global_state::{file_id_to_url, GlobalState, Status},
19+
global_state::{file_id_to_url, url_to_file_id, GlobalState, Status},
2020
handlers, lsp_ext,
2121
lsp_utils::{apply_document_changes, is_canceled, notification_is, notification_new},
2222
Result,
@@ -200,18 +200,16 @@ impl GlobalState {
200200
&workspace_root,
201201
);
202202
for diag in diagnostics {
203-
let path = from_proto::vfs_path(&diag.location.uri)?;
204-
let file_id = match self.vfs.read().0.file_id(&path) {
205-
Some(file) => FileId(file.0),
206-
None => {
207-
log::error!(
208-
"File with cargo diagnostic not found in VFS: {}",
209-
path
210-
);
211-
return Ok(());
203+
match url_to_file_id(&self.vfs.read().0, &diag.location.uri) {
204+
Ok(file_id) => self.diagnostics.add_check_diagnostic(
205+
file_id,
206+
diag.diagnostic,
207+
diag.fixes,
208+
),
209+
Err(err) => {
210+
log::error!("File with cargo diagnostic not found in VFS: {}", err);
212211
}
213212
};
214-
self.diagnostics.add_check_diagnostic(file_id, diag.diagnostic, diag.fixes)
215213
}
216214
}
217215

0 commit comments

Comments
 (0)