aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-18 21:49:31 +0100
committerGitHub <[email protected]>2021-06-18 21:49:31 +0100
commit664912fbf83718508156fc09d2a0ff2448de175a (patch)
tree8cac1ee23ff3232ccc30eb174da908cecf34df8f /crates
parent71490ed84b7fbfabecdf44b25d48ff8aafc4c601 (diff)
parent90da9fc9b302de46097065f0d6428ad33c292217 (diff)
Merge #9332
9332: minor: use minicore r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/inlay_hints.rs21
-rw-r--r--crates/ide_assists/src/handlers/fill_match_arms.rs11
-rw-r--r--crates/ide_assists/src/handlers/replace_if_let_with_match.rs66
-rw-r--r--crates/ide_assists/src/handlers/replace_unwrap_with_match.rs53
-rw-r--r--crates/ide_completion/src/completions/postfix.rs27
-rw-r--r--crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs76
-rw-r--r--crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs86
-rw-r--r--crates/test_utils/src/minicore.rs26
8 files changed, 109 insertions, 257 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index 335d57a0d..95f9edce4 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -661,9 +661,7 @@ fn main() {
661 fn function_call_parameter_hint() { 661 fn function_call_parameter_hint() {
662 check_params( 662 check_params(
663 r#" 663 r#"
664enum Option<T> { None, Some(T) } 664//- minicore: option
665use Option::*;
666
667struct FileId {} 665struct FileId {}
668struct SmolStr {} 666struct SmolStr {}
669 667
@@ -872,7 +870,6 @@ fn main() {
872 check_types( 870 check_types(
873 r#" 871 r#"
874//- minicore: fn, sized 872//- minicore: fn, sized
875
876fn foo() -> impl Fn() { loop {} } 873fn foo() -> impl Fn() { loop {} }
877fn foo1() -> impl Fn(f64) { loop {} } 874fn foo1() -> impl Fn(f64) { loop {} }
878fn foo2() -> impl Fn(f64, f64) { loop {} } 875fn foo2() -> impl Fn(f64, f64) { loop {} }
@@ -908,9 +905,7 @@ fn main() {
908 fn unit_structs_have_no_type_hints() { 905 fn unit_structs_have_no_type_hints() {
909 check_types( 906 check_types(
910 r#" 907 r#"
911enum Result<T, E> { Ok(T), Err(E) } 908//- minicore: result
912use Result::*;
913
914struct SyntheticSyntax; 909struct SyntheticSyntax;
915 910
916fn main() { 911fn main() {
@@ -962,9 +957,7 @@ fn main() {
962 fn if_expr() { 957 fn if_expr() {
963 check_types( 958 check_types(
964 r#" 959 r#"
965enum Option<T> { None, Some(T) } 960//- minicore: option
966use Option::*;
967
968struct Test { a: Option<u32>, b: u8 } 961struct Test { a: Option<u32>, b: u8 }
969 962
970fn main() { 963fn main() {
@@ -994,9 +987,7 @@ fn main() {
994 fn while_expr() { 987 fn while_expr() {
995 check_types( 988 check_types(
996 r#" 989 r#"
997enum Option<T> { None, Some(T) } 990//- minicore: option
998use Option::*;
999
1000struct Test { a: Option<u32>, b: u8 } 991struct Test { a: Option<u32>, b: u8 }
1001 992
1002fn main() { 993fn main() {
@@ -1012,9 +1003,7 @@ fn main() {
1012 fn match_arm_list() { 1003 fn match_arm_list() {
1013 check_types( 1004 check_types(
1014 r#" 1005 r#"
1015enum Option<T> { None, Some(T) } 1006//- minicore: option
1016use Option::*;
1017
1018struct Test { a: Option<u32>, b: u8 } 1007struct Test { a: Option<u32>, b: u8 }
1019 1008
1020fn main() { 1009fn main() {
diff --git a/crates/ide_assists/src/handlers/fill_match_arms.rs b/crates/ide_assists/src/handlers/fill_match_arms.rs
index cd0f6dba9..318faa0fc 100644
--- a/crates/ide_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ide_assists/src/handlers/fill_match_arms.rs
@@ -481,26 +481,21 @@ fn main() {
481 check_assist( 481 check_assist(
482 fill_match_arms, 482 fill_match_arms,
483 r#" 483 r#"
484enum Option<T> { Some(T), None } 484//- minicore: option
485use Option::*;
486
487fn main() { 485fn main() {
488 match None$0 { 486 match None$0 {
489 None => {} 487 None => {}
490 } 488 }
491} 489}
492 "#, 490"#,
493 r#" 491 r#"
494enum Option<T> { Some(T), None }
495use Option::*;
496
497fn main() { 492fn main() {
498 match None { 493 match None {
499 None => {} 494 None => {}
500 Some(${0:_}) => todo!(), 495 Some(${0:_}) => todo!(),
501 } 496 }
502} 497}
503 "#, 498"#,
504 ); 499 );
505 } 500 }
506 501
diff --git a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs
index 9404aa26d..f37aa0d53 100644
--- a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs
+++ b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs
@@ -262,9 +262,7 @@ impl VariantData {
262 check_assist( 262 check_assist(
263 replace_if_let_with_match, 263 replace_if_let_with_match,
264 r#" 264 r#"
265enum Option<T> { Some(T), None } 265//- minicore: option
266use Option::*;
267
268fn foo(x: Option<i32>) { 266fn foo(x: Option<i32>) {
269 $0if let Some(x) = x { 267 $0if let Some(x) = x {
270 println!("{}", x) 268 println!("{}", x)
@@ -272,18 +270,15 @@ fn foo(x: Option<i32>) {
272 println!("none") 270 println!("none")
273 } 271 }
274} 272}
275 "#, 273"#,
276 r#" 274 r#"
277enum Option<T> { Some(T), None }
278use Option::*;
279
280fn foo(x: Option<i32>) { 275fn foo(x: Option<i32>) {
281 match x { 276 match x {
282 Some(x) => println!("{}", x), 277 Some(x) => println!("{}", x),
283 None => println!("none"), 278 None => println!("none"),
284 } 279 }
285} 280}
286 "#, 281"#,
287 ); 282 );
288 } 283 }
289 284
@@ -292,9 +287,7 @@ fn foo(x: Option<i32>) {
292 check_assist( 287 check_assist(
293 replace_if_let_with_match, 288 replace_if_let_with_match,
294 r#" 289 r#"
295enum Option<T> { Some(T), None } 290//- minicore: option
296use Option::*;
297
298fn foo(x: Option<i32>) { 291fn foo(x: Option<i32>) {
299 $0if let None = x { 292 $0if let None = x {
300 println!("none") 293 println!("none")
@@ -302,18 +295,15 @@ fn foo(x: Option<i32>) {
302 println!("some") 295 println!("some")
303 } 296 }
304} 297}
305 "#, 298"#,
306 r#" 299 r#"
307enum Option<T> { Some(T), None }
308use Option::*;
309
310fn foo(x: Option<i32>) { 300fn foo(x: Option<i32>) {
311 match x { 301 match x {
312 None => println!("none"), 302 None => println!("none"),
313 Some(_) => println!("some"), 303 Some(_) => println!("some"),
314 } 304 }
315} 305}
316 "#, 306"#,
317 ); 307 );
318 } 308 }
319 309
@@ -322,9 +312,7 @@ fn foo(x: Option<i32>) {
322 check_assist( 312 check_assist(
323 replace_if_let_with_match, 313 replace_if_let_with_match,
324 r#" 314 r#"
325enum Result<T, E> { Ok(T), Err(E) } 315//- minicore: result
326use Result::*;
327
328fn foo(x: Result<i32, ()>) { 316fn foo(x: Result<i32, ()>) {
329 $0if let Ok(x) = x { 317 $0if let Ok(x) = x {
330 println!("{}", x) 318 println!("{}", x)
@@ -332,18 +320,15 @@ fn foo(x: Result<i32, ()>) {
332 println!("none") 320 println!("none")
333 } 321 }
334} 322}
335 "#, 323"#,
336 r#" 324 r#"
337enum Result<T, E> { Ok(T), Err(E) }
338use Result::*;
339
340fn foo(x: Result<i32, ()>) { 325fn foo(x: Result<i32, ()>) {
341 match x { 326 match x {
342 Ok(x) => println!("{}", x), 327 Ok(x) => println!("{}", x),
343 Err(_) => println!("none"), 328 Err(_) => println!("none"),
344 } 329 }
345} 330}
346 "#, 331"#,
347 ); 332 );
348 } 333 }
349 334
@@ -352,9 +337,7 @@ fn foo(x: Result<i32, ()>) {
352 check_assist( 337 check_assist(
353 replace_if_let_with_match, 338 replace_if_let_with_match,
354 r#" 339 r#"
355enum Result<T, E> { Ok(T), Err(E) } 340//- minicore: result
356use Result::*;
357
358fn foo(x: Result<i32, ()>) { 341fn foo(x: Result<i32, ()>) {
359 $0if let Err(x) = x { 342 $0if let Err(x) = x {
360 println!("{}", x) 343 println!("{}", x)
@@ -362,18 +345,15 @@ fn foo(x: Result<i32, ()>) {
362 println!("ok") 345 println!("ok")
363 } 346 }
364} 347}
365 "#, 348"#,
366 r#" 349 r#"
367enum Result<T, E> { Ok(T), Err(E) }
368use Result::*;
369
370fn foo(x: Result<i32, ()>) { 350fn foo(x: Result<i32, ()>) {
371 match x { 351 match x {
372 Err(x) => println!("{}", x), 352 Err(x) => println!("{}", x),
373 Ok(_) => println!("ok"), 353 Ok(_) => println!("ok"),
374 } 354 }
375} 355}
376 "#, 356"#,
377 ); 357 );
378 } 358 }
379 359
@@ -488,20 +468,15 @@ impl VariantData {
488 check_assist( 468 check_assist(
489 replace_match_with_if_let, 469 replace_match_with_if_let,
490 r#" 470 r#"
491enum Option<T> { Some(T), None } 471//- minicore: option
492use Option::*;
493
494fn foo(x: Option<i32>) { 472fn foo(x: Option<i32>) {
495 $0match x { 473 $0match x {
496 Some(x) => println!("{}", x), 474 Some(x) => println!("{}", x),
497 None => println!("none"), 475 None => println!("none"),
498 } 476 }
499} 477}
500 "#, 478"#,
501 r#" 479 r#"
502enum Option<T> { Some(T), None }
503use Option::*;
504
505fn foo(x: Option<i32>) { 480fn foo(x: Option<i32>) {
506 if let Some(x) = x { 481 if let Some(x) = x {
507 println!("{}", x) 482 println!("{}", x)
@@ -509,7 +484,7 @@ fn foo(x: Option<i32>) {
509 println!("none") 484 println!("none")
510 } 485 }
511} 486}
512 "#, 487"#,
513 ); 488 );
514 } 489 }
515 490
@@ -518,20 +493,15 @@ fn foo(x: Option<i32>) {
518 check_assist( 493 check_assist(
519 replace_match_with_if_let, 494 replace_match_with_if_let,
520 r#" 495 r#"
521enum Result<T, E> { Ok(T), Err(E) } 496//- minicore: result
522use Result::*;
523
524fn foo(x: Result<i32, ()>) { 497fn foo(x: Result<i32, ()>) {
525 $0match x { 498 $0match x {
526 Ok(x) => println!("{}", x), 499 Ok(x) => println!("{}", x),
527 Err(_) => println!("none"), 500 Err(_) => println!("none"),
528 } 501 }
529} 502}
530 "#, 503"#,
531 r#" 504 r#"
532enum Result<T, E> { Ok(T), Err(E) }
533use Result::*;
534
535fn foo(x: Result<i32, ()>) { 505fn foo(x: Result<i32, ()>) {
536 if let Ok(x) = x { 506 if let Ok(x) = x {
537 println!("{}", x) 507 println!("{}", x)
@@ -539,7 +509,7 @@ fn foo(x: Result<i32, ()>) {
539 println!("none") 509 println!("none")
540 } 510 }
541} 511}
542 "#, 512"#,
543 ); 513 );
544 } 514 }
545 515
diff --git a/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs b/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs
index a3bfa221c..7e57353c6 100644
--- a/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs
+++ b/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs
@@ -97,25 +97,24 @@ mod tests {
97 fn test_replace_result_unwrap_with_match() { 97 fn test_replace_result_unwrap_with_match() {
98 check_assist( 98 check_assist(
99 replace_unwrap_with_match, 99 replace_unwrap_with_match,
100 r" 100 r#"
101enum Result<T, E> { Ok(T), Err(E) } 101//- minicore: result
102fn i<T>(a: T) -> T { a } 102fn i<T>(a: T) -> T { a }
103fn main() { 103fn main() {
104 let x: Result<i32, i32> = Result::Ok(92); 104 let x: Result<i32, i32> = Ok(92);
105 let y = i(x).$0unwrap(); 105 let y = i(x).$0unwrap();
106} 106}
107 ", 107"#,
108 r" 108 r#"
109enum Result<T, E> { Ok(T), Err(E) }
110fn i<T>(a: T) -> T { a } 109fn i<T>(a: T) -> T { a }
111fn main() { 110fn main() {
112 let x: Result<i32, i32> = Result::Ok(92); 111 let x: Result<i32, i32> = Ok(92);
113 let y = match i(x) { 112 let y = match i(x) {
114 Ok(it) => it, 113 Ok(it) => it,
115 $0_ => unreachable!(), 114 $0_ => unreachable!(),
116 }; 115 };
117} 116}
118 ", 117"#,
119 ) 118 )
120 } 119 }
121 120
@@ -123,25 +122,24 @@ fn main() {
123 fn test_replace_option_unwrap_with_match() { 122 fn test_replace_option_unwrap_with_match() {
124 check_assist( 123 check_assist(
125 replace_unwrap_with_match, 124 replace_unwrap_with_match,
126 r" 125 r#"
127enum Option<T> { Some(T), None } 126//- minicore: option
128fn i<T>(a: T) -> T { a } 127fn i<T>(a: T) -> T { a }
129fn main() { 128fn main() {
130 let x = Option::Some(92); 129 let x = Some(92);
131 let y = i(x).$0unwrap(); 130 let y = i(x).$0unwrap();
132} 131}
133 ", 132"#,
134 r" 133 r#"
135enum Option<T> { Some(T), None }
136fn i<T>(a: T) -> T { a } 134fn i<T>(a: T) -> T { a }
137fn main() { 135fn main() {
138 let x = Option::Some(92); 136 let x = Some(92);
139 let y = match i(x) { 137 let y = match i(x) {
140 Some(it) => it, 138 Some(it) => it,
141 $0_ => unreachable!(), 139 $0_ => unreachable!(),
142 }; 140 };
143} 141}
144 ", 142"#,
145 ); 143 );
146 } 144 }
147 145
@@ -149,25 +147,24 @@ fn main() {
149 fn test_replace_result_unwrap_with_match_chaining() { 147 fn test_replace_result_unwrap_with_match_chaining() {
150 check_assist( 148 check_assist(
151 replace_unwrap_with_match, 149 replace_unwrap_with_match,
152 r" 150 r#"
153enum Result<T, E> { Ok(T), Err(E) } 151//- minicore: result
154fn i<T>(a: T) -> T { a } 152fn i<T>(a: T) -> T { a }
155fn main() { 153fn main() {
156 let x: Result<i32, i32> = Result::Ok(92); 154 let x: Result<i32, i32> = Ok(92);
157 let y = i(x).$0unwrap().count_zeroes(); 155 let y = i(x).$0unwrap().count_zeroes();
158} 156}
159 ", 157"#,
160 r" 158 r#"
161enum Result<T, E> { Ok(T), Err(E) }
162fn i<T>(a: T) -> T { a } 159fn i<T>(a: T) -> T { a }
163fn main() { 160fn main() {
164 let x: Result<i32, i32> = Result::Ok(92); 161 let x: Result<i32, i32> = Ok(92);
165 let y = match i(x) { 162 let y = match i(x) {
166 Ok(it) => it, 163 Ok(it) => it,
167 $0_ => unreachable!(), 164 $0_ => unreachable!(),
168 }.count_zeroes(); 165 }.count_zeroes();
169} 166}
170 ", 167"#,
171 ) 168 )
172 } 169 }
173 170
@@ -175,14 +172,14 @@ fn main() {
175 fn replace_unwrap_with_match_target() { 172 fn replace_unwrap_with_match_target() {
176 check_assist_target( 173 check_assist_target(
177 replace_unwrap_with_match, 174 replace_unwrap_with_match,
178 r" 175 r#"
179enum Option<T> { Some(T), None } 176//- minicore: option
180fn i<T>(a: T) -> T { a } 177fn i<T>(a: T) -> T { a }
181fn main() { 178fn main() {
182 let x = Option::Some(92); 179 let x = Some(92);
183 let y = i(x).$0unwrap(); 180 let y = i(x).$0unwrap();
184} 181}
185 ", 182"#,
186 r"i(x).unwrap()", 183 r"i(x).unwrap()",
187 ); 184 );
188 } 185 }
diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs
index c3c7e4589..4e20ec003 100644
--- a/crates/ide_completion/src/completions/postfix.rs
+++ b/crates/ide_completion/src/completions/postfix.rs
@@ -436,18 +436,15 @@ fn main() {
436 check_edit( 436 check_edit(
437 "ifl", 437 "ifl",
438 r#" 438 r#"
439enum Option<T> { Some(T), None } 439//- minicore: option
440
441fn main() { 440fn main() {
442 let bar = Option::Some(true); 441 let bar = Some(true);
443 bar.$0 442 bar.$0
444} 443}
445"#, 444"#,
446 r#" 445 r#"
447enum Option<T> { Some(T), None }
448
449fn main() { 446fn main() {
450 let bar = Option::Some(true); 447 let bar = Some(true);
451 if let Some($1) = bar { 448 if let Some($1) = bar {
452 $0 449 $0
453} 450}
@@ -461,18 +458,15 @@ fn main() {
461 check_edit( 458 check_edit(
462 "match", 459 "match",
463 r#" 460 r#"
464enum Result<T, E> { Ok(T), Err(E) } 461//- minicore: result
465
466fn main() { 462fn main() {
467 let bar = Result::Ok(true); 463 let bar = Ok(true);
468 bar.$0 464 bar.$0
469} 465}
470"#, 466"#,
471 r#" 467 r#"
472enum Result<T, E> { Ok(T), Err(E) }
473
474fn main() { 468fn main() {
475 let bar = Result::Ok(true); 469 let bar = Ok(true);
476 match bar { 470 match bar {
477 Ok(${1:_}) => {$2}, 471 Ok(${1:_}) => {$2},
478 Err(${3:_}) => {$0}, 472 Err(${3:_}) => {$0},
@@ -515,18 +509,15 @@ fn main() {
515 check_edit( 509 check_edit(
516 "ifl", 510 "ifl",
517 r#" 511 r#"
518enum Option<T> { Some(T), None } 512//- minicore: option
519
520fn main() { 513fn main() {
521 let bar = &Option::Some(true); 514 let bar = &Some(true);
522 bar.$0 515 bar.$0
523} 516}
524"#, 517"#,
525 r#" 518 r#"
526enum Option<T> { Some(T), None }
527
528fn main() { 519fn main() {
529 let bar = &Option::Some(true); 520 let bar = &Some(true);
530 if let Some($1) = bar { 521 if let Some($1) = bar {
531 $0 522 $0
532} 523}
diff --git a/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs b/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs
index 63de54570..c0edcd7d3 100644
--- a/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs
+++ b/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs
@@ -49,26 +49,15 @@ mod tests {
49 fn test_wrap_return_type_option() { 49 fn test_wrap_return_type_option() {
50 check_fix( 50 check_fix(
51 r#" 51 r#"
52//- /main.rs crate:main deps:core 52//- minicore: option, result
53use core::option::Option::{self, Some, None};
54
55fn div(x: i32, y: i32) -> Option<i32> { 53fn div(x: i32, y: i32) -> Option<i32> {
56 if y == 0 { 54 if y == 0 {
57 return None; 55 return None;
58 } 56 }
59 x / y$0 57 x / y$0
60} 58}
61//- /core/lib.rs crate:core
62pub mod result {
63 pub enum Result<T, E> { Ok(T), Err(E) }
64}
65pub mod option {
66 pub enum Option<T> { Some(T), None }
67}
68"#, 59"#,
69 r#" 60 r#"
70use core::option::Option::{self, Some, None};
71
72fn div(x: i32, y: i32) -> Option<i32> { 61fn div(x: i32, y: i32) -> Option<i32> {
73 if y == 0 { 62 if y == 0 {
74 return None; 63 return None;
@@ -83,26 +72,15 @@ fn div(x: i32, y: i32) -> Option<i32> {
83 fn test_wrap_return_type() { 72 fn test_wrap_return_type() {
84 check_fix( 73 check_fix(
85 r#" 74 r#"
86//- /main.rs crate:main deps:core 75//- minicore: option, result
87use core::result::Result::{self, Ok, Err};
88
89fn div(x: i32, y: i32) -> Result<i32, ()> { 76fn div(x: i32, y: i32) -> Result<i32, ()> {
90 if y == 0 { 77 if y == 0 {
91 return Err(()); 78 return Err(());
92 } 79 }
93 x / y$0 80 x / y$0
94} 81}
95//- /core/lib.rs crate:core
96pub mod result {
97 pub enum Result<T, E> { Ok(T), Err(E) }
98}
99pub mod option {
100 pub enum Option<T> { Some(T), None }
101}
102"#, 82"#,
103 r#" 83 r#"
104use core::result::Result::{self, Ok, Err};
105
106fn div(x: i32, y: i32) -> Result<i32, ()> { 84fn div(x: i32, y: i32) -> Result<i32, ()> {
107 if y == 0 { 85 if y == 0 {
108 return Err(()); 86 return Err(());
@@ -117,26 +95,15 @@ fn div(x: i32, y: i32) -> Result<i32, ()> {
117 fn test_wrap_return_type_handles_generic_functions() { 95 fn test_wrap_return_type_handles_generic_functions() {
118 check_fix( 96 check_fix(
119 r#" 97 r#"
120//- /main.rs crate:main deps:core 98//- minicore: option, result
121use core::result::Result::{self, Ok, Err};
122
123fn div<T>(x: T) -> Result<T, i32> { 99fn div<T>(x: T) -> Result<T, i32> {
124 if x == 0 { 100 if x == 0 {
125 return Err(7); 101 return Err(7);
126 } 102 }
127 $0x 103 $0x
128} 104}
129//- /core/lib.rs crate:core
130pub mod result {
131 pub enum Result<T, E> { Ok(T), Err(E) }
132}
133pub mod option {
134 pub enum Option<T> { Some(T), None }
135}
136"#, 105"#,
137 r#" 106 r#"
138use core::result::Result::{self, Ok, Err};
139
140fn div<T>(x: T) -> Result<T, i32> { 107fn div<T>(x: T) -> Result<T, i32> {
141 if x == 0 { 108 if x == 0 {
142 return Err(7); 109 return Err(7);
@@ -151,9 +118,7 @@ fn div<T>(x: T) -> Result<T, i32> {
151 fn test_wrap_return_type_handles_type_aliases() { 118 fn test_wrap_return_type_handles_type_aliases() {
152 check_fix( 119 check_fix(
153 r#" 120 r#"
154//- /main.rs crate:main deps:core 121//- minicore: option, result
155use core::result::Result::{self, Ok, Err};
156
157type MyResult<T> = Result<T, ()>; 122type MyResult<T> = Result<T, ()>;
158 123
159fn div(x: i32, y: i32) -> MyResult<i32> { 124fn div(x: i32, y: i32) -> MyResult<i32> {
@@ -162,17 +127,8 @@ fn div(x: i32, y: i32) -> MyResult<i32> {
162 } 127 }
163 x $0/ y 128 x $0/ y
164} 129}
165//- /core/lib.rs crate:core
166pub mod result {
167 pub enum Result<T, E> { Ok(T), Err(E) }
168}
169pub mod option {
170 pub enum Option<T> { Some(T), None }
171}
172"#, 130"#,
173 r#" 131 r#"
174use core::result::Result::{self, Ok, Err};
175
176type MyResult<T> = Result<T, ()>; 132type MyResult<T> = Result<T, ()>;
177 133
178fn div(x: i32, y: i32) -> MyResult<i32> { 134fn div(x: i32, y: i32) -> MyResult<i32> {
@@ -189,18 +145,8 @@ fn div(x: i32, y: i32) -> MyResult<i32> {
189 fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { 145 fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() {
190 check_diagnostics( 146 check_diagnostics(
191 r#" 147 r#"
192//- /main.rs crate:main deps:core 148//- minicore: option, result
193use core::result::Result::{self, Ok, Err};
194
195fn foo() -> Result<(), i32> { 0 } 149fn foo() -> Result<(), i32> { 0 }
196
197//- /core/lib.rs crate:core
198pub mod result {
199 pub enum Result<T, E> { Ok(T), Err(E) }
200}
201pub mod option {
202 pub enum Option<T> { Some(T), None }
203}
204"#, 150"#,
205 ); 151 );
206 } 152 }
@@ -209,20 +155,10 @@ pub mod option {
209 fn test_wrap_return_type_not_applicable_when_return_type_is_not_result_or_option() { 155 fn test_wrap_return_type_not_applicable_when_return_type_is_not_result_or_option() {
210 check_diagnostics( 156 check_diagnostics(
211 r#" 157 r#"
212//- /main.rs crate:main deps:core 158//- minicore: option, result
213use core::result::Result::{self, Ok, Err};
214
215enum SomeOtherEnum { Ok(i32), Err(String) } 159enum SomeOtherEnum { Ok(i32), Err(String) }
216 160
217fn foo() -> SomeOtherEnum { 0 } 161fn foo() -> SomeOtherEnum { 0 }
218
219//- /core/lib.rs crate:core
220pub mod result {
221 pub enum Result<T, E> { Ok(T), Err(E) }
222}
223pub mod option {
224 pub enum Option<T> { Some(T), None }
225}
226"#, 162"#,
227 ); 163 );
228 } 164 }
diff --git a/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs b/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs
index cd87a10bb..839ceac03 100644
--- a/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs
+++ b/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs
@@ -55,44 +55,16 @@ fn fixes(
55 55
56#[cfg(test)] 56#[cfg(test)]
57mod tests { 57mod tests {
58 use crate::tests::check_fix; 58 use crate::tests::{check_diagnostics, check_fix};
59
60 // Register the required standard library types to make the tests work
61 #[track_caller]
62 fn check_diagnostics(ra_fixture: &str) {
63 let prefix = r#"
64//- /main.rs crate:main deps:core
65use core::iter::Iterator;
66use core::option::Option::{self, Some, None};
67"#;
68 let suffix = r#"
69//- /core/lib.rs crate:core
70pub mod option {
71 pub enum Option<T> { Some(T), None }
72}
73pub mod iter {
74 pub trait Iterator {
75 type Item;
76 fn filter_map<B, F>(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option<B> { FilterMap }
77 fn next(&mut self) -> Option<Self::Item>;
78 }
79 pub struct FilterMap {}
80 impl Iterator for FilterMap {
81 type Item = i32;
82 fn next(&mut self) -> i32 { 7 }
83 }
84}
85"#;
86 crate::tests::check_diagnostics(&format!("{}{}{}", prefix, ra_fixture, suffix))
87 }
88 59
89 #[test] 60 #[test]
90 fn replace_filter_map_next_with_find_map2() { 61 fn replace_filter_map_next_with_find_map2() {
91 check_diagnostics( 62 check_diagnostics(
92 r#" 63 r#"
93 fn foo() { 64//- minicore: iterators
94 let m = [1, 2, 3].iter().filter_map(|x| Some(92)).next(); 65fn foo() {
95 } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 💡 weak: replace filter_map(..).next() with find_map(..) 66 let m = core::iter::repeat(()).filter_map(|()| Some(92)).next();
67} //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 💡 weak: replace filter_map(..).next() with find_map(..)
96"#, 68"#,
97 ); 69 );
98 } 70 }
@@ -101,11 +73,11 @@ pub mod iter {
101 fn replace_filter_map_next_with_find_map_no_diagnostic_without_next() { 73 fn replace_filter_map_next_with_find_map_no_diagnostic_without_next() {
102 check_diagnostics( 74 check_diagnostics(
103 r#" 75 r#"
76//- minicore: iterators
104fn foo() { 77fn foo() {
105 let m = [1, 2, 3] 78 let m = core::iter::repeat(())
106 .iter() 79 .filter_map(|()| Some(92))
107 .filter_map(|x| Some(92)) 80 .count();
108 .len();
109} 81}
110"#, 82"#,
111 ); 83 );
@@ -115,12 +87,12 @@ fn foo() {
115 fn replace_filter_map_next_with_find_map_no_diagnostic_with_intervening_methods() { 87 fn replace_filter_map_next_with_find_map_no_diagnostic_with_intervening_methods() {
116 check_diagnostics( 88 check_diagnostics(
117 r#" 89 r#"
90//- minicore: iterators
118fn foo() { 91fn foo() {
119 let m = [1, 2, 3] 92 let m = core::iter::repeat(())
120 .iter() 93 .filter_map(|()| Some(92))
121 .filter_map(|x| Some(92))
122 .map(|x| x + 2) 94 .map(|x| x + 2)
123 .len(); 95 .next();
124} 96}
125"#, 97"#,
126 ); 98 );
@@ -130,10 +102,10 @@ fn foo() {
130 fn replace_filter_map_next_with_find_map_no_diagnostic_if_not_in_chain() { 102 fn replace_filter_map_next_with_find_map_no_diagnostic_if_not_in_chain() {
131 check_diagnostics( 103 check_diagnostics(
132 r#" 104 r#"
105//- minicore: iterators
133fn foo() { 106fn foo() {
134 let m = [1, 2, 3] 107 let m = core::iter::repeat(())
135 .iter() 108 .filter_map(|()| Some(92));
136 .filter_map(|x| Some(92));
137 let n = m.next(); 109 let n = m.next();
138} 110}
139"#, 111"#,
@@ -144,34 +116,14 @@ fn foo() {
144 fn replace_with_wind_map() { 116 fn replace_with_wind_map() {
145 check_fix( 117 check_fix(
146 r#" 118 r#"
147//- /main.rs crate:main deps:core 119//- minicore: iterators
148use core::iter::Iterator;
149use core::option::Option::{self, Some, None};
150fn foo() { 120fn foo() {
151 let m = [1, 2, 3].iter().$0filter_map(|x| Some(92)).next(); 121 let m = core::iter::repeat(()).$0filter_map(|()| Some(92)).next();
152}
153//- /core/lib.rs crate:core
154pub mod option {
155 pub enum Option<T> { Some(T), None }
156}
157pub mod iter {
158 pub trait Iterator {
159 type Item;
160 fn filter_map<B, F>(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option<B> { FilterMap }
161 fn next(&mut self) -> Option<Self::Item>;
162 }
163 pub struct FilterMap {}
164 impl Iterator for FilterMap {
165 type Item = i32;
166 fn next(&mut self) -> i32 { 7 }
167 }
168} 122}
169"#, 123"#,
170 r#" 124 r#"
171use core::iter::Iterator;
172use core::option::Option::{self, Some, None};
173fn foo() { 125fn foo() {
174 let m = [1, 2, 3].iter().find_map(|x| Some(92)); 126 let m = core::iter::repeat(()).find_map(|()| Some(92));
175} 127}
176"#, 128"#,
177 ) 129 )
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs
index 71f07d38a..ce6ad8541 100644
--- a/crates/test_utils/src/minicore.rs
+++ b/crates/test_utils/src/minicore.rs
@@ -22,7 +22,7 @@
22//! option: 22//! option:
23//! result: 23//! result:
24//! iterator: option 24//! iterator: option
25//! iterators: iterator 25//! iterators: iterator, fn
26//! default: sized 26//! default: sized
27//! clone: sized 27//! clone: sized
28//! copy: clone 28//! copy: clone
@@ -390,7 +390,6 @@ pub mod iter {
390 iter: I, 390 iter: I,
391 n: usize, 391 n: usize,
392 } 392 }
393
394 impl<I> Iterator for Take<I> 393 impl<I> Iterator for Take<I>
395 where 394 where
396 I: Iterator, 395 I: Iterator,
@@ -401,6 +400,22 @@ pub mod iter {
401 loop {} 400 loop {}
402 } 401 }
403 } 402 }
403
404 pub struct FilterMap<I, F> {
405 iter: I,
406 f: F,
407 }
408 impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
409 where
410 F: FnMut(I::Item) -> Option<B>,
411 {
412 type Item = B;
413
414 #[inline]
415 fn next(&mut self) -> Option<B> {
416 loop {}
417 }
418 }
404 } 419 }
405 pub use self::adapters::Take; 420 pub use self::adapters::Take;
406 421
@@ -448,6 +463,13 @@ pub mod iter {
448 fn take(self, n: usize) -> crate::iter::Take<Self> { 463 fn take(self, n: usize) -> crate::iter::Take<Self> {
449 loop {} 464 loop {}
450 } 465 }
466 fn filter_map<B, F>(self, f: F) -> crate::iter::FilterMap<Self, F>
467 where
468 Self: Sized,
469 F: FnMut(Self::Item) -> Option<B>,
470 {
471 loop {}
472 }
451 // endregion:iterators 473 // endregion:iterators
452 } 474 }
453 impl<I: Iterator + ?Sized> Iterator for &mut I { 475 impl<I: Iterator + ?Sized> Iterator for &mut I {