Skip to content

Commit 54bdb9c

Browse files
Merge #3939
3939: Fix non canonicallized path from metadata r=matklad a=edwin0cheng Crate root path obtained from cargo-metadata may contains non-canonicalized path (e.g. `/foo/../libcore/tests/lib.rs`), such that `vfs::load` will find a incorrect root. This PR try to fix that by canonicalize it before passing to vfs. Co-authored-by: Edwin Cheng <[email protected]>
2 parents beb755c + 73e5122 commit 54bdb9c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

crates/rust-analyzer/src/cli/load_cargo.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ pub(crate) fn load(
152152
&extern_source_roots,
153153
proc_macro_client,
154154
&mut |path: &Path| {
155-
let vfs_file = vfs.load(path);
155+
// Some path from metadata will be non canonicalized, e.g. /foo/../bar/lib.rs
156+
let path = path.canonicalize().ok()?;
157+
let vfs_file = vfs.load(&path);
156158
log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
157159
vfs_file.map(vfs_file_to_id)
158160
},

crates/rust-analyzer/src/world.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ impl WorldState {
139139
// Create crate graph from all the workspaces
140140
let mut crate_graph = CrateGraph::default();
141141
let mut load = |path: &std::path::Path| {
142-
let vfs_file = vfs.load(path);
142+
// Some path from metadata will be non canonicalized, e.g. /foo/../bar/lib.rs
143+
let path = path.canonicalize().ok()?;
144+
let vfs_file = vfs.load(&path);
143145
vfs_file.map(|f| FileId(f.0))
144146
};
145147

0 commit comments

Comments
 (0)