@@ -75,7 +75,7 @@ impl Function {
7575 let attrs = KANI_TOOL_ATTRS . iter ( ) . flat_map ( |v| inst_def. tool_attrs ( v) ) . collect ( ) ;
7676
7777 let span = inst_def. span ( ) ;
78- let file = span . get_filename ( ) ;
78+ let file = file_path ( & inst ) ;
7979
8080 let fn_def = ty_to_fndef ( inst. ty ( ) ) ?;
8181 let body = fn_def. body ( ) ?;
@@ -127,8 +127,8 @@ fn source_code_of_body(inst: &Instance, tcx: TyCtxt, src_map: &SourceMap) -> Opt
127127}
128128
129129fn cmp_callees ( a : & Instance , b : & Instance , tcx : TyCtxt , src_map : & SourceMap ) -> Ordering {
130- let filename_a = a . def . span ( ) . get_filename ( ) ;
131- let filename_b = b . def . span ( ) . get_filename ( ) ;
130+ let filename_a = file_path ( a ) ;
131+ let filename_b = file_path ( b ) ;
132132 match filename_a. cmp ( & filename_b) {
133133 Ordering :: Equal => ( ) ,
134134 ord => return ord,
@@ -138,3 +138,24 @@ fn cmp_callees(a: &Instance, b: &Instance, tcx: TyCtxt, src_map: &SourceMap) ->
138138 let body_b = source_code_of_body ( b, tcx, src_map) ;
139139 body_a. cmp ( & body_b)
140140}
141+
142+ fn file_path ( inst : & Instance ) -> String {
143+ use std:: sync:: LazyLock ;
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]
152+ } ) ;
153+
154+ let file = inst. def . span ( ) . get_filename ( ) ;
155+ for prefix in & * PREFIXES {
156+ if let Some ( file) = file. strip_prefix ( prefix) {
157+ return file. to_owned ( ) ;
158+ }
159+ }
160+ file
161+ }
0 commit comments