aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-17 09:30:08 +0100
committerGitHub <[email protected]>2021-06-17 09:30:08 +0100
commitb5830fbf9222b9a83309dc61fe1df480b0c3b153 (patch)
treeb927b06a3f866f6ebac907d7714fa05af7422d4e
parent7b4f5c0262bbdf7e9db81734eb9c82dd04eb82cb (diff)
parentc42cdff3d2ed2e30add09dd0d602181b6f83534d (diff)
Merge #9306
9306: internal: minimize minicore r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/ide/src/inlay_hints.rs31
-rw-r--r--crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs78
-rw-r--r--crates/test_utils/src/fixture.rs2
-rw-r--r--crates/test_utils/src/minicore.rs39
4 files changed, 80 insertions, 70 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index 9cd33d0e4..335d57a0d 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -434,7 +434,6 @@ fn get_callable(
434#[cfg(test)] 434#[cfg(test)]
435mod tests { 435mod tests {
436 use expect_test::{expect, Expect}; 436 use expect_test::{expect, Expect};
437 use ide_db::helpers::FamousDefs;
438 use test_utils::extract_annotations; 437 use test_utils::extract_annotations;
439 438
440 use crate::{fixture, inlay_hints::InlayHintsConfig}; 439 use crate::{fixture, inlay_hints::InlayHintsConfig};
@@ -487,8 +486,6 @@ mod tests {
487 } 486 }
488 487
489 fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) { 488 fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) {
490 let ra_fixture =
491 format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);
492 let (analysis, file_id) = fixture::file(&ra_fixture); 489 let (analysis, file_id) = fixture::file(&ra_fixture);
493 let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); 490 let expected = extract_annotations(&*analysis.file_text(file_id).unwrap());
494 let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); 491 let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap();
@@ -498,8 +495,6 @@ mod tests {
498 } 495 }
499 496
500 fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) { 497 fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) {
501 let ra_fixture =
502 format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);
503 let (analysis, file_id) = fixture::file(&ra_fixture); 498 let (analysis, file_id) = fixture::file(&ra_fixture);
504 let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); 499 let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap();
505 expect.assert_debug_eq(&inlay_hints) 500 expect.assert_debug_eq(&inlay_hints)
@@ -823,6 +818,7 @@ fn main() {
823 fn shorten_iterators_in_associated_params() { 818 fn shorten_iterators_in_associated_params() {
824 check_types( 819 check_types(
825 r#" 820 r#"
821//- minicore: iterators
826use core::iter; 822use core::iter;
827 823
828pub struct SomeIter<T> {} 824pub struct SomeIter<T> {}
@@ -875,7 +871,7 @@ fn main() {
875 fn fn_hints() { 871 fn fn_hints() {
876 check_types( 872 check_types(
877 r#" 873 r#"
878trait Sized {} 874//- minicore: fn, sized
879 875
880fn foo() -> impl Fn() { loop {} } 876fn foo() -> impl Fn() { loop {} }
881fn foo1() -> impl Fn(f64) { loop {} } 877fn foo1() -> impl Fn(f64) { loop {} }
@@ -1073,6 +1069,7 @@ fn main() {
1073 fn complete_for_hint() { 1069 fn complete_for_hint() {
1074 check_types( 1070 check_types(
1075 r#" 1071 r#"
1072//- minicore: iterator
1076pub struct Vec<T> {} 1073pub struct Vec<T> {}
1077 1074
1078impl<T> Vec<T> { 1075impl<T> Vec<T> {
@@ -1129,6 +1126,7 @@ fn main() {
1129 fn shorten_iterator_hints() { 1126 fn shorten_iterator_hints() {
1130 check_types( 1127 check_types(
1131 r#" 1128 r#"
1129//- minicore: iterators
1132use core::iter; 1130use core::iter;
1133 1131
1134struct MyIter; 1132struct MyIter;
@@ -1230,12 +1228,12 @@ fn main() {
1230 expect![[r#" 1228 expect![[r#"
1231 [ 1229 [
1232 InlayHint { 1230 InlayHint {
1233 range: 148..173, 1231 range: 147..172,
1234 kind: ChainingHint, 1232 kind: ChainingHint,
1235 label: "B", 1233 label: "B",
1236 }, 1234 },
1237 InlayHint { 1235 InlayHint {
1238 range: 148..155, 1236 range: 147..154,
1239 kind: ChainingHint, 1237 kind: ChainingHint,
1240 label: "A", 1238 label: "A",
1241 }, 1239 },
@@ -1290,12 +1288,12 @@ fn main() {
1290 expect![[r#" 1288 expect![[r#"
1291 [ 1289 [
1292 InlayHint { 1290 InlayHint {
1293 range: 144..191, 1291 range: 143..190,
1294 kind: ChainingHint, 1292 kind: ChainingHint,
1295 label: "C", 1293 label: "C",
1296 }, 1294 },
1297 InlayHint { 1295 InlayHint {
1298 range: 144..180, 1296 range: 143..179,
1299 kind: ChainingHint, 1297 kind: ChainingHint,
1300 label: "B", 1298 label: "B",
1301 }, 1299 },
@@ -1335,12 +1333,12 @@ fn main() {
1335 expect![[r#" 1333 expect![[r#"
1336 [ 1334 [
1337 InlayHint { 1335 InlayHint {
1338 range: 247..284, 1336 range: 246..283,
1339 kind: ChainingHint, 1337 kind: ChainingHint,
1340 label: "B<X<i32, bool>>", 1338 label: "B<X<i32, bool>>",
1341 }, 1339 },
1342 InlayHint { 1340 InlayHint {
1343 range: 247..266, 1341 range: 246..265,
1344 kind: ChainingHint, 1342 kind: ChainingHint,
1345 label: "A<X<i32, bool>>", 1343 label: "A<X<i32, bool>>",
1346 }, 1344 },
@@ -1359,6 +1357,7 @@ fn main() {
1359 max_length: None, 1357 max_length: None,
1360 }, 1358 },
1361 r#" 1359 r#"
1360//- minicore: iterators
1362use core::iter; 1361use core::iter;
1363 1362
1364struct MyIter; 1363struct MyIter;
@@ -1381,22 +1380,22 @@ fn main() {
1381 expect![[r#" 1380 expect![[r#"
1382 [ 1381 [
1383 InlayHint { 1382 InlayHint {
1384 range: 175..242, 1383 range: 174..241,
1385 kind: ChainingHint, 1384 kind: ChainingHint,
1386 label: "impl Iterator<Item = ()>", 1385 label: "impl Iterator<Item = ()>",
1387 }, 1386 },
1388 InlayHint { 1387 InlayHint {
1389 range: 175..225, 1388 range: 174..224,
1390 kind: ChainingHint, 1389 kind: ChainingHint,
1391 label: "impl Iterator<Item = ()>", 1390 label: "impl Iterator<Item = ()>",
1392 }, 1391 },
1393 InlayHint { 1392 InlayHint {
1394 range: 175..207, 1393 range: 174..206,
1395 kind: ChainingHint, 1394 kind: ChainingHint,
1396 label: "impl Iterator<Item = ()>", 1395 label: "impl Iterator<Item = ()>",
1397 }, 1396 },
1398 InlayHint { 1397 InlayHint {
1399 range: 175..190, 1398 range: 174..189,
1400 kind: ChainingHint, 1399 kind: ChainingHint,
1401 label: "&mut MyIter", 1400 label: "&mut MyIter",
1402 }, 1401 },
diff --git a/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs b/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs
index 8e571723d..5f2aa016f 100644
--- a/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs
+++ b/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs
@@ -186,18 +186,14 @@ fn main() {
186 fn test_for_borrowed() { 186 fn test_for_borrowed() {
187 check_assist( 187 check_assist(
188 replace_for_loop_with_for_each, 188 replace_for_loop_with_for_each,
189 r" 189 r#"
190//- minicore: iterator 190//- minicore: iterators
191struct Iter; 191use core::iter::{Repeat, repeat};
192impl Iterator for Iter {
193 type Item = usize;
194 fn next(&mut self) -> Option<Self::Item> { None }
195}
196 192
197struct S; 193struct S;
198impl S { 194impl S {
199 fn iter(&self) -> Iter { Iter } 195 fn iter(&self) -> Repeat<i32> { repeat(92) }
200 fn iter_mut(&mut self) -> Iter { Iter } 196 fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) }
201} 197}
202 198
203fn main() { 199fn main() {
@@ -206,18 +202,14 @@ fn main() {
206 let a = v * 2; 202 let a = v * 2;
207 } 203 }
208} 204}
209", 205"#,
210 r" 206 r#"
211struct Iter; 207use core::iter::{Repeat, repeat};
212impl Iterator for Iter {
213 type Item = usize;
214 fn next(&mut self) -> Option<Self::Item> { None }
215}
216 208
217struct S; 209struct S;
218impl S { 210impl S {
219 fn iter(&self) -> Iter { Iter } 211 fn iter(&self) -> Repeat<i32> { repeat(92) }
220 fn iter_mut(&mut self) -> Iter { Iter } 212 fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) }
221} 213}
222 214
223fn main() { 215fn main() {
@@ -226,7 +218,7 @@ fn main() {
226 let a = v * 2; 218 let a = v * 2;
227 }); 219 });
228} 220}
229", 221"#,
230 ) 222 )
231 } 223 }
232 224
@@ -259,18 +251,14 @@ fn main() {
259 fn test_for_borrowed_mut() { 251 fn test_for_borrowed_mut() {
260 check_assist( 252 check_assist(
261 replace_for_loop_with_for_each, 253 replace_for_loop_with_for_each,
262 r" 254 r#"
263//- minicore: iterator 255//- minicore: iterators
264struct Iter; 256use core::iter::{Repeat, repeat};
265impl Iterator for Iter {
266 type Item = usize;
267 fn next(&mut self) -> Option<Self::Item> { None }
268}
269 257
270struct S; 258struct S;
271impl S { 259impl S {
272 fn iter(&self) -> Iter { Iter } 260 fn iter(&self) -> Repeat<i32> { repeat(92) }
273 fn iter_mut(&mut self) -> Iter { Iter } 261 fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) }
274} 262}
275 263
276fn main() { 264fn main() {
@@ -279,18 +267,14 @@ fn main() {
279 let a = v * 2; 267 let a = v * 2;
280 } 268 }
281} 269}
282", 270"#,
283 r" 271 r#"
284struct Iter; 272use core::iter::{Repeat, repeat};
285impl Iterator for Iter {
286 type Item = usize;
287 fn next(&mut self) -> Option<Self::Item> { None }
288}
289 273
290struct S; 274struct S;
291impl S { 275impl S {
292 fn iter(&self) -> Iter { Iter } 276 fn iter(&self) -> Repeat<i32> { repeat(92) }
293 fn iter_mut(&mut self) -> Iter { Iter } 277 fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) }
294} 278}
295 279
296fn main() { 280fn main() {
@@ -299,7 +283,7 @@ fn main() {
299 let a = v * 2; 283 let a = v * 2;
300 }); 284 });
301} 285}
302", 286"#,
303 ) 287 )
304 } 288 }
305 289
@@ -332,28 +316,16 @@ fn main() {
332 check_assist( 316 check_assist(
333 replace_for_loop_with_for_each, 317 replace_for_loop_with_for_each,
334 r#" 318 r#"
335//- minicore: iterator 319//- minicore: iterators
336struct Iter;
337impl Iterator for Iter {
338 type Item = usize;
339 fn next(&mut self) -> Option<Self::Item> { None }
340}
341
342fn main() { 320fn main() {
343 for$0 a in Iter.take(1) { 321 for$0 a in core::iter::repeat(92).take(1) {
344 println!("{}", a); 322 println!("{}", a);
345 } 323 }
346} 324}
347"#, 325"#,
348 r#" 326 r#"
349struct Iter;
350impl Iterator for Iter {
351 type Item = usize;
352 fn next(&mut self) -> Option<Self::Item> { None }
353}
354
355fn main() { 327fn main() {
356 Iter.take(1).for_each(|a| { 328 core::iter::repeat(92).take(1).for_each(|a| {
357 println!("{}", a); 329 println!("{}", a);
358 }); 330 });
359} 331}
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs
index 005a5c092..8d8f3b560 100644
--- a/crates/test_utils/src/fixture.rs
+++ b/crates/test_utils/src/fixture.rs
@@ -154,7 +154,7 @@ impl Fixture {
154 let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); 154 let components = meta.split_ascii_whitespace().collect::<Vec<_>>();
155 155
156 let path = components[0].to_string(); 156 let path = components[0].to_string();
157 assert!(path.starts_with('/')); 157 assert!(path.starts_with('/'), "fixture path does not start with `/`: {:?}", path);
158 158
159 let mut krate = None; 159 let mut krate = None;
160 let mut deps = Vec::new(); 160 let mut deps = Vec::new();
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs
index 2f0da7fe5..e6d2301c7 100644
--- a/crates/test_utils/src/minicore.rs
+++ b/crates/test_utils/src/minicore.rs
@@ -21,6 +21,7 @@
21//! option: 21//! option:
22//! result: 22//! result:
23//! iterator: option 23//! iterator: option
24//! iterators: iterator
24 25
25pub mod marker { 26pub mod marker {
26 // region:sized 27 // region:sized
@@ -209,6 +210,7 @@ pub mod task {
209 210
210// region:iterator 211// region:iterator
211pub mod iter { 212pub mod iter {
213 // region:iterators
212 mod adapters { 214 mod adapters {
213 pub struct Take<I> { 215 pub struct Take<I> {
214 iter: I, 216 iter: I,
@@ -228,6 +230,29 @@ pub mod iter {
228 } 230 }
229 pub use self::adapters::Take; 231 pub use self::adapters::Take;
230 232
233 mod sources {
234 mod repeat {
235 pub fn repeat<T>(elt: T) -> Repeat<T> {
236 loop {}
237 }
238
239 pub struct Repeat<A> {
240 element: A,
241 }
242
243 impl<A> Iterator for Repeat<A> {
244 type Item = A;
245
246 fn next(&mut self) -> Option<A> {
247 loop {}
248 }
249 }
250 }
251 pub use self::repeat::{repeat, Repeat};
252 }
253 pub use self::sources::{repeat, Repeat};
254 // endregion:iterators
255
231 mod traits { 256 mod traits {
232 mod iterator { 257 mod iterator {
233 use super::super::Take; 258 use super::super::Take;
@@ -239,9 +264,23 @@ pub mod iter {
239 fn nth(&mut self, n: usize) -> Option<Self::Item> { 264 fn nth(&mut self, n: usize) -> Option<Self::Item> {
240 loop {} 265 loop {}
241 } 266 }
267 fn by_ref(&mut self) -> &mut Self
268 where
269 Self: Sized,
270 {
271 self
272 }
273 // region:iterators
242 fn take(self, n: usize) -> crate::iter::Take<Self> { 274 fn take(self, n: usize) -> crate::iter::Take<Self> {
243 loop {} 275 loop {}
244 } 276 }
277 // endregion:iterators
278 }
279 impl<I: Iterator + ?Sized> Iterator for &mut I {
280 type Item = I::Item;
281 fn next(&mut self) -> Option<I::Item> {
282 (**self).next()
283 }
245 } 284 }
246 } 285 }
247 pub use self::iterator::Iterator; 286 pub use self::iterator::Iterator;