@@ -3,7 +3,7 @@ use std::path::{Component, Path};
3
3
4
4
use crate :: prelude:: * ;
5
5
6
- use rustc_span:: FileName ;
6
+ use rustc_span:: { FileName , SourceFileAndLine } ;
7
7
8
8
use cranelift_codegen:: binemit:: CodeOffset ;
9
9
@@ -139,25 +139,32 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
139
139
rustc_span:: hygiene:: walk_chain ( span, function_span. ctxt ( ) )
140
140
} ;
141
141
142
- let loc = tcx. sess . source_map ( ) . lookup_char_pos ( span. lo ( ) ) ;
142
+ let ( file, line, col) = match tcx. sess . source_map ( ) . lookup_line ( span. lo ( ) ) {
143
+ Ok ( SourceFileAndLine { sf : file, line } ) => {
144
+ let line_pos = file. line_begin_pos ( span. lo ( ) ) ;
145
+
146
+ ( file, u64:: try_from ( line) . unwrap ( ) + 1 , u64:: from ( ( span. lo ( ) - line_pos) . to_u32 ( ) ) + 1 )
147
+ }
148
+ Err ( file) => ( file, 0 , 0 )
149
+ } ;
143
150
144
151
// line_program_add_file is very slow.
145
152
// Optimize for the common case of the current file not being changed.
146
153
let current_file_changed = if let Some ( last_file) = & mut last_file {
147
154
// If the allocations are not equal, then the files may still be equal, but that
148
155
// is not a problem, as this is just an optimization.
149
- !Lrc :: ptr_eq ( last_file, & loc . file )
156
+ !Lrc :: ptr_eq ( last_file, & file)
150
157
} else {
151
158
true
152
159
} ;
153
160
if current_file_changed {
154
- let file_id = line_program_add_file ( line_program, line_strings, & loc . file . name ) ;
161
+ let file_id = line_program_add_file ( line_program, line_strings, & file. name ) ;
155
162
line_program. row ( ) . file = file_id;
156
- last_file = Some ( loc . file . clone ( ) ) ;
163
+ last_file = Some ( file. clone ( ) ) ;
157
164
}
158
165
159
- line_program. row ( ) . line = loc . line as u64 ;
160
- line_program. row ( ) . column = loc . col . to_u32 ( ) as u64 + 1 ;
166
+ line_program. row ( ) . line = line;
167
+ line_program. row ( ) . column = col;
161
168
line_program. generate_row ( ) ;
162
169
} ;
163
170
0 commit comments