diff --git a/crates/ra_arena/src/lib.rs b/crates/ra_arena/src/lib.rs index 3b7cb77b181..3ec8d3b60b6 100644 --- a/crates/ra_arena/src/lib.rs +++ b/crates/ra_arena/src/lib.rs @@ -79,7 +79,7 @@ impl Arena { self.data.push(value); ID::from_raw(id) } - pub fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator + ExactSizeIterator { self.data.iter().enumerate().map(|(idx, value)| (ID::from_raw(RawId(idx as u32)), value)) } } diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 8e830c8b858..9a38d43d2ae 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -269,7 +269,7 @@ fn main_loop_inner( && pending_libraries.is_empty() && in_flight_libraries == 0 { - let n_packages: usize = state.workspaces.iter().map(|it| it.count()).sum(); + let n_packages: usize = state.workspaces.iter().map(|it| it.n_packages()).sum(); if state.options.show_workspace_loaded { let msg = format!("workspace loaded, {} rust packages", n_packages); show_message(req::MessageType::Info, msg, msg_sender); diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 1d775591046..b57cdf925a7 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -211,7 +211,7 @@ impl WorldSnapshot { } else { res.push_str("workspaces:\n"); for w in self.workspaces.iter() { - res += &format!("{} packages loaded\n", w.count()); + res += &format!("{} packages loaded\n", w.n_packages()); } } res.push_str("\nanalysis:\n"); diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 2b06e9e372c..712d8818f8a 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -167,7 +167,7 @@ impl CargoWorkspace { Ok(CargoWorkspace { packages, targets, workspace_root: meta.workspace_root }) } - pub fn packages<'a>(&'a self) -> impl Iterator + 'a { + pub fn packages<'a>(&'a self) -> impl Iterator + ExactSizeIterator + 'a { self.packages.iter().map(|(id, _pkg)| id) } diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 647a1f36585..8e81396d445 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -112,8 +112,7 @@ impl ProjectWorkspace { roots } ProjectWorkspace::Cargo { cargo, sysroot } => { - let mut roots = - Vec::with_capacity(cargo.packages().count() + sysroot.crates().count()); + let mut roots = Vec::with_capacity(cargo.packages().len() + sysroot.crates().len()); for pkg in cargo.packages() { let root = pkg.root(&cargo).to_path_buf(); let member = pkg.is_member(&cargo); @@ -127,10 +126,12 @@ impl ProjectWorkspace { } } - pub fn count(&self) -> usize { + pub fn n_packages(&self) -> usize { match self { ProjectWorkspace::Json { project } => project.crates.len(), - ProjectWorkspace::Cargo { cargo, .. } => cargo.packages().count(), + ProjectWorkspace::Cargo { cargo, sysroot } => { + cargo.packages().len() + sysroot.crates().len() + } } } diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 4f6e880dd47..3f34d51ccb9 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs @@ -28,7 +28,7 @@ impl Sysroot { self.by_name("std") } - pub fn crates<'a>(&'a self) -> impl Iterator + 'a { + pub fn crates<'a>(&'a self) -> impl Iterator + ExactSizeIterator + 'a { self.crates.iter().map(|(id, _data)| id) }