internal: use API stabilized in 1.52

This commit is contained in:
Aleksey Kladov 2021-05-04 14:10:49 +03:00 committed by Kirill Bulatov
parent 3b4d5df840
commit 6a16ec52aa
7 changed files with 16 additions and 90 deletions

View file

@ -3,7 +3,6 @@
use std::iter;
use rustc_hash::FxHashMap;
use stdx::partition_point;
use syntax::{TextRange, TextSize};
#[derive(Clone, Debug, PartialEq, Eq)]
@ -97,7 +96,7 @@ impl LineIndex {
}
pub fn line_col(&self, offset: TextSize) -> LineCol {
let line = partition_point(&self.newlines, |&it| it <= offset) - 1;
let line = self.newlines.partition_point(|&it| it <= offset) - 1;
let line_start_offset = self.newlines[line];
let col = offset - line_start_offset;
LineCol { line: line as u32, col: col.into() }
@ -118,8 +117,8 @@ impl LineIndex {
}
pub fn lines(&self, range: TextRange) -> impl Iterator<Item = TextRange> + '_ {
let lo = partition_point(&self.newlines, |&it| it < range.start());
let hi = partition_point(&self.newlines, |&it| it <= range.end());
let lo = self.newlines.partition_point(|&it| it < range.start());
let hi = self.newlines.partition_point(|&it| it <= range.end());
let all = iter::once(range.start())
.chain(self.newlines[lo..hi].iter().copied())
.chain(iter::once(range.end()));