Skip to content

Commit b37b709

Browse files
bors[bot]matkladSomeoneToIgnore
authored
Merge #8718
8718: 1.52.0 r=SomeoneToIgnore a=matklad A lot of APIs we use in this release! Co-authored-by: Aleksey Kladov <[email protected]> Co-authored-by: Kirill Bulatov <[email protected]>
2 parents 3b4d5df + 607d8a2 commit b37b709

File tree

7 files changed

+16
-90
lines changed

7 files changed

+16
-90
lines changed

crates/ide_completion/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl<'a> CompletionContext<'a> {
381381
let def = self.sema.to_def(&it);
382382
(def.map(|def| def.ret_type(self.db)), None)
383383
},
384-
ast::Stmt(it) => (None, None),
384+
ast::Stmt(_it) => (None, None),
385385
_ => {
386386
match node.parent() {
387387
Some(n) => {

crates/ide_db/src/line_index.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use std::iter;
44

55
use rustc_hash::FxHashMap;
6-
use stdx::partition_point;
76
use syntax::{TextRange, TextSize};
87

98
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -97,7 +96,7 @@ impl LineIndex {
9796
}
9897

9998
pub fn line_col(&self, offset: TextSize) -> LineCol {
100-
let line = partition_point(&self.newlines, |&it| it <= offset) - 1;
99+
let line = self.newlines.partition_point(|&it| it <= offset) - 1;
101100
let line_start_offset = self.newlines[line];
102101
let col = offset - line_start_offset;
103102
LineCol { line: line as u32, col: col.into() }
@@ -118,8 +117,8 @@ impl LineIndex {
118117
}
119118

120119
pub fn lines(&self, range: TextRange) -> impl Iterator<Item = TextRange> + '_ {
121-
let lo = partition_point(&self.newlines, |&it| it < range.start());
122-
let hi = partition_point(&self.newlines, |&it| it <= range.end());
120+
let lo = self.newlines.partition_point(|&it| it < range.start());
121+
let hi = self.newlines.partition_point(|&it| it <= range.end());
123122
let all = iter::once(range.start())
124123
.chain(self.newlines[lo..hi].iter().copied())
125124
.chain(iter::once(range.end()));

crates/project_model/src/cfg_flag.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use std::str::FromStr;
55

66
use cfg::CfgOptions;
7-
use stdx::split_once;
87

98
#[derive(Clone, Eq, PartialEq, Debug)]
109
pub enum CfgFlag {
@@ -15,7 +14,7 @@ pub enum CfgFlag {
1514
impl FromStr for CfgFlag {
1615
type Err = String;
1716
fn from_str(s: &str) -> Result<Self, Self::Err> {
18-
let res = match split_once(s, '=') {
17+
let res = match s.split_once('=') {
1918
Some((key, value)) => {
2019
if !(value.starts_with('"') && value.ends_with('"')) {
2120
return Err(format!("Invalid cfg ({:?}), value should be in quotes", s));

crates/stdx/src/lib.rs

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,6 @@ pub fn replace(buf: &mut String, from: char, to: &str) {
6565
*buf = buf.replace(from, to)
6666
}
6767

68-
// https://github.com/rust-lang/rust/issues/74773
69-
pub fn split_once(haystack: &str, delim: char) -> Option<(&str, &str)> {
70-
let mut split = haystack.splitn(2, delim);
71-
let prefix = split.next()?;
72-
let suffix = split.next()?;
73-
Some((prefix, suffix))
74-
}
75-
pub fn rsplit_once(haystack: &str, delim: char) -> Option<(&str, &str)> {
76-
let mut split = haystack.rsplitn(2, delim);
77-
let suffix = split.next()?;
78-
let prefix = split.next()?;
79-
Some((prefix, suffix))
80-
}
81-
8268
pub fn trim_indent(mut text: &str) -> String {
8369
if text.starts_with('\n') {
8470
text = &text[1..];
@@ -89,7 +75,7 @@ pub fn trim_indent(mut text: &str) -> String {
8975
.map(|it| it.len() - it.trim_start().len())
9076
.min()
9177
.unwrap_or(0);
92-
lines_with_ends(text)
78+
text.split_inclusive('\n')
9379
.map(
9480
|line| {
9581
if line.len() <= indent {
@@ -102,70 +88,12 @@ pub fn trim_indent(mut text: &str) -> String {
10288
.collect()
10389
}
10490

105-
pub fn lines_with_ends(text: &str) -> LinesWithEnds {
106-
LinesWithEnds { text }
107-
}
108-
109-
pub struct LinesWithEnds<'a> {
110-
text: &'a str,
111-
}
112-
113-
impl<'a> Iterator for LinesWithEnds<'a> {
114-
type Item = &'a str;
115-
fn next(&mut self) -> Option<&'a str> {
116-
if self.text.is_empty() {
117-
return None;
118-
}
119-
let idx = self.text.find('\n').map_or(self.text.len(), |it| it + 1);
120-
let (res, next) = self.text.split_at(idx);
121-
self.text = next;
122-
Some(res)
123-
}
124-
}
125-
126-
/// Returns `idx` such that:
127-
///
128-
/// ```text
129-
/// ∀ x in slice[..idx]: pred(x)
130-
/// && ∀ x in slice[idx..]: !pred(x)
131-
/// ```
132-
///
133-
/// https://github.com/rust-lang/rust/issues/73831
134-
pub fn partition_point<T, P>(slice: &[T], mut pred: P) -> usize
135-
where
136-
P: FnMut(&T) -> bool,
137-
{
138-
let mut left = 0;
139-
let mut right = slice.len();
140-
141-
while left != right {
142-
let mid = left + (right - left) / 2;
143-
// SAFETY:
144-
// When left < right, left <= mid < right.
145-
// Therefore left always increases and right always decreases,
146-
// and either of them is selected.
147-
// In both cases left <= right is satisfied.
148-
// Therefore if left < right in a step,
149-
// left <= right is satisfied in the next step.
150-
// Therefore as long as left != right, 0 <= left < right <= len is satisfied
151-
// and if this case 0 <= mid < len is satisfied too.
152-
let value = unsafe { slice.get_unchecked(mid) };
153-
if pred(value) {
154-
left = mid + 1;
155-
} else {
156-
right = mid;
157-
}
158-
}
159-
160-
left
161-
}
162-
16391
pub fn equal_range_by<T, F>(slice: &[T], mut key: F) -> ops::Range<usize>
16492
where
16593
F: FnMut(&T) -> Ordering,
16694
{
167-
let start = partition_point(slice, |it| key(it) == Ordering::Less);
168-
let len = partition_point(&slice[start..], |it| key(it) == Ordering::Equal);
95+
let start = slice.partition_point(|it| key(it) == Ordering::Less);
96+
let len = slice[start..].partition_point(|it| key(it) == Ordering::Equal);
16997
start..start + len
17098
}
17199

crates/test_utils/src/fixture.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
//! ```
6363
6464
use rustc_hash::FxHashMap;
65-
use stdx::{lines_with_ends, split_once, trim_indent};
65+
use stdx::trim_indent;
6666

6767
#[derive(Debug, Eq, PartialEq)]
6868
pub struct Fixture {
@@ -93,7 +93,7 @@ impl Fixture {
9393

9494
let default = if ra_fixture.contains("//-") { None } else { Some("//- /main.rs") };
9595

96-
for (ix, line) in default.into_iter().chain(lines_with_ends(&fixture)).enumerate() {
96+
for (ix, line) in default.into_iter().chain(fixture.split_inclusive('\n')).enumerate() {
9797
if line.contains("//-") {
9898
assert!(
9999
line.starts_with("//-"),
@@ -133,22 +133,22 @@ impl Fixture {
133133
let mut env = FxHashMap::default();
134134
let mut introduce_new_source_root = false;
135135
for component in components[1..].iter() {
136-
let (key, value) = split_once(component, ':').unwrap();
136+
let (key, value) = component.split_once(':').unwrap();
137137
match key {
138138
"crate" => krate = Some(value.to_string()),
139139
"deps" => deps = value.split(',').map(|it| it.to_string()).collect(),
140140
"edition" => edition = Some(value.to_string()),
141141
"cfg" => {
142142
for entry in value.split(',') {
143-
match split_once(entry, '=') {
143+
match entry.split_once('=') {
144144
Some((k, v)) => cfg_key_values.push((k.to_string(), v.to_string())),
145145
None => cfg_atoms.push(entry.to_string()),
146146
}
147147
}
148148
}
149149
"env" => {
150150
for key in value.split(',') {
151-
if let Some((k, v)) = split_once(key, '=') {
151+
if let Some((k, v)) = key.split_once('=') {
152152
env.insert(k.into(), v.into());
153153
}
154154
}

crates/test_utils/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::{
1717
};
1818

1919
use profile::StopWatch;
20-
use stdx::{is_ci, lines_with_ends};
20+
use stdx::is_ci;
2121
use text_size::{TextRange, TextSize};
2222

2323
pub use dissimilar::diff as __diff;
@@ -181,7 +181,7 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
181181
let mut prev_line_start: Option<TextSize> = None;
182182
let mut line_start: TextSize = 0.into();
183183
let mut prev_line_annotations: Vec<(TextSize, usize)> = Vec::new();
184-
for line in lines_with_ends(text) {
184+
for line in text.split_inclusive('\n') {
185185
let mut this_line_annotations = Vec::new();
186186
if let Some(idx) = line.find("//") {
187187
let annotation_offset = TextSize::of(&line[..idx + "//".len()]);

xtask/src/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use xshell::{cmd, pushd};
88
use crate::flags;
99

1010
// Latest stable, feel free to send a PR if this lags behind.
11-
const REQUIRED_RUST_VERSION: u32 = 51;
11+
const REQUIRED_RUST_VERSION: u32 = 52;
1212

1313
impl flags::Install {
1414
pub(crate) fn run(self) -> Result<()> {

0 commit comments

Comments
 (0)