Skip to content

Commit 66d8ef9

Browse files
Merge pull request #95 from yihong0618/hy/check_vaild_first_for_relative_pos_range
fix: check vaild frist when relative_pos_range close #94
2 parents ced7658 + 0cc9f8e commit 66d8ef9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

rapx/src/utils/log.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ pub fn span_to_line_number(span: Span) -> usize {
135135
#[inline]
136136
// this function computes the relative pos range of two spans which could be generated from two dirrerent files or not intersect with each other
137137
pub unsafe fn relative_pos_range(span: Span, sub_span: Span) -> Range<usize> {
138-
let start_pos = span.lo();
139-
let lo = (sub_span.lo() - start_pos).to_usize(); //unsafe: overflow
140-
let hi = (sub_span.hi() - start_pos).to_usize();
138+
if sub_span.lo() < span.lo() || sub_span.hi() > span.hi() {
139+
return 0..0;
140+
}
141+
let offset = span.lo();
142+
let lo = (sub_span.lo() - offset).to_usize();
143+
let hi = (sub_span.hi() - offset).to_usize();
141144
lo..hi
142145
}
143146

0 commit comments

Comments
 (0)