]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_span/src/lib.rs
Rollup merge of #102125 - notriddle:notriddle/content-item-info, r=GuillaumeGomez
[rust.git] / compiler / rustc_span / src / lib.rs
index ada3bae61502f3eab2db96ea9f9762b7ac080b7d..6ce75492caff3a6861fd89e726eff163da69ffa8 100644 (file)
@@ -1631,10 +1631,9 @@ pub fn count_lines(&self) -> usize {
     /// number. If the source_file is empty or the position is located before the
     /// first line, `None` is returned.
     pub fn lookup_line(&self, pos: BytePos) -> Option<usize> {
-        self.lines(|lines| match lines.binary_search(&pos) {
-            Ok(idx) => Some(idx),
-            Err(0) => None,
-            Err(idx) => Some(idx - 1),
+        self.lines(|lines| match lines.partition_point(|x| x <= &pos) {
+            0 => None,
+            i => Some(i - 1),
         })
     }