Skip to content

Commit 0d19ee1

Browse files
committed
Simplify
1 parent 66bcdcb commit 0d19ee1

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

crates/project_model/src/workspace.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,19 @@ impl ProjectWorkspace {
200200
let mut crate_graph = CrateGraph::default();
201201
match self {
202202
ProjectWorkspace::Json { project, sysroot } => {
203-
let sysroot_dps = sysroot
203+
let sysroot_deps = sysroot
204204
.as_ref()
205205
.map(|sysroot| sysroot_to_crate_graph(&mut crate_graph, sysroot, target, load));
206206

207207
let mut cfg_cache: FxHashMap<Option<&str>, Vec<CfgFlag>> = FxHashMap::default();
208-
let crates: FxHashMap<_, _> = project
208+
let crates: FxHashMap<CrateId, CrateId> = project
209209
.crates()
210210
.filter_map(|(crate_id, krate)| {
211211
let file_path = &krate.root_module;
212-
let file_id = match load(&file_path) {
213-
Some(id) => id,
214-
None => {
215-
log::error!("failed to load crate root {}", file_path.display());
216-
return None;
217-
}
218-
};
219-
212+
let file_id = load(&file_path)?;
213+
Some((crate_id, krate, file_id))
214+
})
215+
.map(|(crate_id, krate, file_id)| {
220216
let env = krate.env.clone().into_iter().collect();
221217
let proc_macro = krate
222218
.proc_macro_dylib_path
@@ -230,8 +226,7 @@ impl ProjectWorkspace {
230226

231227
let mut cfg_options = CfgOptions::default();
232228
cfg_options.extend(target_cfgs.iter().chain(krate.cfg.iter()).cloned());
233-
234-
Some((
229+
(
235230
crate_id,
236231
crate_graph.add_crate_root(
237232
file_id,
@@ -241,21 +236,20 @@ impl ProjectWorkspace {
241236
env,
242237
proc_macro.unwrap_or_default(),
243238
),
244-
))
239+
)
245240
})
246241
.collect();
247242

248243
for (from, krate) in project.crates() {
249244
if let Some(&from) = crates.get(&from) {
250-
if let Some((public_deps, _proc_macro)) = &sysroot_dps {
245+
if let Some((public_deps, _proc_macro)) = &sysroot_deps {
251246
for (name, to) in public_deps.iter() {
252247
add_dep(&mut crate_graph, from, name.clone(), *to)
253248
}
254249
}
255250

256251
for dep in &krate.deps {
257-
let to_crate_id = dep.crate_id;
258-
if let Some(&to) = crates.get(&to_crate_id) {
252+
if let Some(&to) = crates.get(&dep.crate_id) {
259253
add_dep(&mut crate_graph, from, dep.name.clone(), to)
260254
}
261255
}

crates/rust-analyzer/src/reload.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ impl GlobalState {
203203
let contents = loader.handle.load_sync(path);
204204
vfs.set_file_contents(vfs_path.clone(), contents);
205205
}
206-
vfs.file_id(&vfs_path)
206+
let res = vfs.file_id(&vfs_path);
207+
if res.is_none() {
208+
log::error!("failed to load {}", path.display())
209+
}
210+
res
207211
};
208212
for ws in workspaces.iter() {
209213
crate_graph.extend(ws.to_crate_graph(

0 commit comments

Comments
 (0)