Skip to content

Commit 7579417

Browse files
committed
fix: strip local rustc sysroot path from file path
close #21 (comment)
1 parent 35b7054 commit 7579417

File tree

5 files changed

+1115
-1105
lines changed

5 files changed

+1115
-1105
lines changed

src/functions/mod.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,21 @@ fn cmp_callees(a: &Instance, b: &Instance, tcx: TyCtxt, src_map: &SourceMap) ->
141141

142142
fn file_path(inst: &Instance) -> String {
143143
use std::sync::LazyLock;
144-
static PWD: LazyLock<String> = LazyLock::new(|| {
145-
let mut path = std::env::current_dir().unwrap().into_os_string().into_string().unwrap();
146-
path.push('/');
147-
path
144+
static PREFIXES: LazyLock<[String; 2]> = LazyLock::new(|| {
145+
let mut pwd = std::env::current_dir().unwrap().into_os_string().into_string().unwrap();
146+
pwd.push('/');
147+
148+
let out = std::process::Command::new("rustc").arg("--print=sysroot").output().unwrap();
149+
let sysroot = std::str::from_utf8(&out.stdout).unwrap().trim();
150+
let sysroot = format!("{sysroot}/lib/rustlib/src/rust/");
151+
[pwd, sysroot]
148152
});
153+
149154
let file = inst.def.span().get_filename();
150-
file.strip_prefix(&*PWD).map(String::from).unwrap_or(file)
155+
for prefix in &*PREFIXES {
156+
if let Some(file) = file.strip_prefix(prefix) {
157+
return file.to_owned();
158+
}
159+
}
160+
file
151161
}

0 commit comments

Comments
 (0)