diff options
Diffstat (limited to 'crates/ide_assists/src/handlers')
9 files changed, 66 insertions, 121 deletions
diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index d4748ef3a..accc345fc 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs | |||
@@ -103,8 +103,9 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
103 | let scope = match scope.clone() { | 103 | let scope = match scope.clone() { |
104 | ImportScope::File(it) => ImportScope::File(builder.make_mut(it)), | 104 | ImportScope::File(it) => ImportScope::File(builder.make_mut(it)), |
105 | ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)), | 105 | ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)), |
106 | ImportScope::Block(it) => ImportScope::Block(builder.make_mut(it)), | ||
106 | }; | 107 | }; |
107 | insert_use(&scope, mod_path_to_ast(&import.import_path), ctx.config.insert_use); | 108 | insert_use(&scope, mod_path_to_ast(&import.import_path), &ctx.config.insert_use); |
108 | }, | 109 | }, |
109 | ); | 110 | ); |
110 | } | 111 | } |
diff --git a/crates/ide_assists/src/handlers/convert_into_to_from.rs b/crates/ide_assists/src/handlers/convert_into_to_from.rs index 79a0c4879..2d8b936cd 100644 --- a/crates/ide_assists/src/handlers/convert_into_to_from.rs +++ b/crates/ide_assists/src/handlers/convert_into_to_from.rs | |||
@@ -13,10 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
13 | // Converts an Into impl to an equivalent From impl. | 13 | // Converts an Into impl to an equivalent From impl. |
14 | // | 14 | // |
15 | // ``` | 15 | // ``` |
16 | // # //- /lib.rs crate:core | 16 | // # //- minicore: from |
17 | // # pub mod convert { pub trait Into<T> { pub fn into(self) -> T; } } | ||
18 | // # //- /lib.rs crate:main deps:core | ||
19 | // # use core::convert::Into; | ||
20 | // impl $0Into<Thing> for usize { | 17 | // impl $0Into<Thing> for usize { |
21 | // fn into(self) -> Thing { | 18 | // fn into(self) -> Thing { |
22 | // Thing { | 19 | // Thing { |
@@ -28,7 +25,6 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
28 | // ``` | 25 | // ``` |
29 | // -> | 26 | // -> |
30 | // ``` | 27 | // ``` |
31 | // # use core::convert::Into; | ||
32 | // impl From<usize> for Thing { | 28 | // impl From<usize> for Thing { |
33 | // fn from(val: usize) -> Self { | 29 | // fn from(val: usize) -> Self { |
34 | // Thing { | 30 | // Thing { |
diff --git a/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs b/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs index 7fd73d4c7..70754adf9 100644 --- a/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs +++ b/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs | |||
@@ -11,14 +11,10 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
11 | // Converts an Iterator::for_each function into a for loop. | 11 | // Converts an Iterator::for_each function into a for loop. |
12 | // | 12 | // |
13 | // ``` | 13 | // ``` |
14 | // # //- /lib.rs crate:core | 14 | // # //- minicore: iterators |
15 | // # pub mod iter { pub mod traits { pub mod iterator { pub trait Iterator {} } } } | 15 | // # use core::iter; |
16 | // # pub struct SomeIter; | ||
17 | // # impl self::iter::traits::iterator::Iterator for SomeIter {} | ||
18 | // # //- /lib.rs crate:main deps:core | ||
19 | // # use core::SomeIter; | ||
20 | // fn main() { | 16 | // fn main() { |
21 | // let iter = SomeIter; | 17 | // let iter = iter::repeat((9, 2)); |
22 | // iter.for_each$0(|(x, y)| { | 18 | // iter.for_each$0(|(x, y)| { |
23 | // println!("x: {}, y: {}", x, y); | 19 | // println!("x: {}, y: {}", x, y); |
24 | // }); | 20 | // }); |
@@ -26,9 +22,9 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
26 | // ``` | 22 | // ``` |
27 | // -> | 23 | // -> |
28 | // ``` | 24 | // ``` |
29 | // # use core::SomeIter; | 25 | // # use core::iter; |
30 | // fn main() { | 26 | // fn main() { |
31 | // let iter = SomeIter; | 27 | // let iter = iter::repeat((9, 2)); |
32 | // for (x, y) in iter { | 28 | // for (x, y) in iter { |
33 | // println!("x: {}, y: {}", x, y); | 29 | // println!("x: {}, y: {}", x, y); |
34 | // } | 30 | // } |
diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs index 43e83d683..ac7f0959b 100644 --- a/crates/ide_assists/src/handlers/extract_function.rs +++ b/crates/ide_assists/src/handlers/extract_function.rs | |||
@@ -831,7 +831,6 @@ fn path_element_of_reference( | |||
831 | })?; | 831 | })?; |
832 | stdx::always!( | 832 | stdx::always!( |
833 | matches!(path, ast::Expr::PathExpr(_) | ast::Expr::MacroCall(_)), | 833 | matches!(path, ast::Expr::PathExpr(_) | ast::Expr::MacroCall(_)), |
834 | |||
835 | "unexpected expression type for variable usage: {:?}", | 834 | "unexpected expression type for variable usage: {:?}", |
836 | path | 835 | path |
837 | ); | 836 | ); |
@@ -2991,11 +2990,7 @@ mod bar { | |||
2991 | check_assist( | 2990 | check_assist( |
2992 | extract_function, | 2991 | extract_function, |
2993 | r#" | 2992 | r#" |
2994 | enum Option<T> { | 2993 | //- minicore: option |
2995 | #[lang = "None"] None, | ||
2996 | #[lang = "Some"] Some(T), | ||
2997 | } | ||
2998 | use Option::*; | ||
2999 | fn foo() { | 2994 | fn foo() { |
3000 | loop { | 2995 | loop { |
3001 | let n = 1; | 2996 | let n = 1; |
@@ -3007,11 +3002,6 @@ fn foo() { | |||
3007 | } | 3002 | } |
3008 | "#, | 3003 | "#, |
3009 | r#" | 3004 | r#" |
3010 | enum Option<T> { | ||
3011 | #[lang = "None"] None, | ||
3012 | #[lang = "Some"] Some(T), | ||
3013 | } | ||
3014 | use Option::*; | ||
3015 | fn foo() { | 3005 | fn foo() { |
3016 | loop { | 3006 | loop { |
3017 | let n = 1; | 3007 | let n = 1; |
diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs index 6c6ff16c2..430710448 100644 --- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -236,7 +236,7 @@ fn apply_references( | |||
236 | import: Option<(ImportScope, hir::ModPath)>, | 236 | import: Option<(ImportScope, hir::ModPath)>, |
237 | ) { | 237 | ) { |
238 | if let Some((scope, path)) = import { | 238 | if let Some((scope, path)) = import { |
239 | insert_use(&scope, mod_path_to_ast(&path), insert_use_cfg); | 239 | insert_use(&scope, mod_path_to_ast(&path), &insert_use_cfg); |
240 | } | 240 | } |
241 | // deep clone to prevent cycle | 241 | // deep clone to prevent cycle |
242 | let path = make::path_from_segments(iter::once(segment.clone_subtree()), false); | 242 | let path = make::path_from_segments(iter::once(segment.clone_subtree()), false); |
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#" |
484 | enum Option<T> { Some(T), None } | 484 | //- minicore: option |
485 | use Option::*; | ||
486 | |||
487 | fn main() { | 485 | fn main() { |
488 | match None$0 { | 486 | match None$0 { |
489 | None => {} | 487 | None => {} |
490 | } | 488 | } |
491 | } | 489 | } |
492 | "#, | 490 | "#, |
493 | r#" | 491 | r#" |
494 | enum Option<T> { Some(T), None } | ||
495 | use Option::*; | ||
496 | |||
497 | fn main() { | 492 | fn 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#" |
265 | enum Option<T> { Some(T), None } | 265 | //- minicore: option |
266 | use Option::*; | ||
267 | |||
268 | fn foo(x: Option<i32>) { | 266 | fn 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#" |
277 | enum Option<T> { Some(T), None } | ||
278 | use Option::*; | ||
279 | |||
280 | fn foo(x: Option<i32>) { | 275 | fn 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#" |
295 | enum Option<T> { Some(T), None } | 290 | //- minicore: option |
296 | use Option::*; | ||
297 | |||
298 | fn foo(x: Option<i32>) { | 291 | fn 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#" |
307 | enum Option<T> { Some(T), None } | ||
308 | use Option::*; | ||
309 | |||
310 | fn foo(x: Option<i32>) { | 300 | fn 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#" |
325 | enum Result<T, E> { Ok(T), Err(E) } | 315 | //- minicore: result |
326 | use Result::*; | ||
327 | |||
328 | fn foo(x: Result<i32, ()>) { | 316 | fn 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#" |
337 | enum Result<T, E> { Ok(T), Err(E) } | ||
338 | use Result::*; | ||
339 | |||
340 | fn foo(x: Result<i32, ()>) { | 325 | fn 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#" |
355 | enum Result<T, E> { Ok(T), Err(E) } | 340 | //- minicore: result |
356 | use Result::*; | ||
357 | |||
358 | fn foo(x: Result<i32, ()>) { | 341 | fn 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#" |
367 | enum Result<T, E> { Ok(T), Err(E) } | ||
368 | use Result::*; | ||
369 | |||
370 | fn foo(x: Result<i32, ()>) { | 350 | fn 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#" |
491 | enum Option<T> { Some(T), None } | 471 | //- minicore: option |
492 | use Option::*; | ||
493 | |||
494 | fn foo(x: Option<i32>) { | 472 | fn 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#" |
502 | enum Option<T> { Some(T), None } | ||
503 | use Option::*; | ||
504 | |||
505 | fn foo(x: Option<i32>) { | 480 | fn 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#" |
521 | enum Result<T, E> { Ok(T), Err(E) } | 496 | //- minicore: result |
522 | use Result::*; | ||
523 | |||
524 | fn foo(x: Result<i32, ()>) { | 497 | fn 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#" |
532 | enum Result<T, E> { Ok(T), Err(E) } | ||
533 | use Result::*; | ||
534 | |||
535 | fn foo(x: Result<i32, ()>) { | 505 | fn 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_qualified_name_with_use.rs b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs index 39f5eb4ff..26778ee74 100644 --- a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs | |||
@@ -32,7 +32,6 @@ pub(crate) fn replace_qualified_name_with_use( | |||
32 | 32 | ||
33 | let target = path.syntax().text_range(); | 33 | let target = path.syntax().text_range(); |
34 | let scope = ImportScope::find_insert_use_container_with_macros(path.syntax(), &ctx.sema)?; | 34 | let scope = ImportScope::find_insert_use_container_with_macros(path.syntax(), &ctx.sema)?; |
35 | let syntax = scope.as_syntax_node(); | ||
36 | acc.add( | 35 | acc.add( |
37 | AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite), | 36 | AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite), |
38 | "Replace qualified path with use", | 37 | "Replace qualified path with use", |
@@ -40,11 +39,13 @@ pub(crate) fn replace_qualified_name_with_use( | |||
40 | |builder| { | 39 | |builder| { |
41 | // Now that we've brought the name into scope, re-qualify all paths that could be | 40 | // Now that we've brought the name into scope, re-qualify all paths that could be |
42 | // affected (that is, all paths inside the node we added the `use` to). | 41 | // affected (that is, all paths inside the node we added the `use` to). |
43 | let syntax = builder.make_syntax_mut(syntax.clone()); | 42 | let scope = match scope { |
44 | if let Some(ref import_scope) = ImportScope::from(syntax.clone()) { | 43 | ImportScope::File(it) => ImportScope::File(builder.make_mut(it)), |
45 | shorten_paths(&syntax, &path.clone_for_update()); | 44 | ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)), |
46 | insert_use(import_scope, path, ctx.config.insert_use); | 45 | ImportScope::Block(it) => ImportScope::Block(builder.make_mut(it)), |
47 | } | 46 | }; |
47 | shorten_paths(scope.as_syntax_node(), &path.clone_for_update()); | ||
48 | insert_use(&scope, path, &ctx.config.insert_use); | ||
48 | }, | 49 | }, |
49 | ) | 50 | ) |
50 | } | 51 | } |
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..f39c48d8f 100644 --- a/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs +++ b/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs | |||
@@ -20,17 +20,16 @@ use ide_db::ty_filter::TryEnum; | |||
20 | // Replaces `unwrap` with a `match` expression. Works for Result and Option. | 20 | // Replaces `unwrap` with a `match` expression. Works for Result and Option. |
21 | // | 21 | // |
22 | // ``` | 22 | // ``` |
23 | // enum Result<T, E> { Ok(T), Err(E) } | 23 | // # //- minicore: result |
24 | // fn main() { | 24 | // fn main() { |
25 | // let x: Result<i32, i32> = Result::Ok(92); | 25 | // let x: Result<i32, i32> = Ok(92); |
26 | // let y = x.$0unwrap(); | 26 | // let y = x.$0unwrap(); |
27 | // } | 27 | // } |
28 | // ``` | 28 | // ``` |
29 | // -> | 29 | // -> |
30 | // ``` | 30 | // ``` |
31 | // enum Result<T, E> { Ok(T), Err(E) } | ||
32 | // fn main() { | 31 | // fn main() { |
33 | // let x: Result<i32, i32> = Result::Ok(92); | 32 | // let x: Result<i32, i32> = Ok(92); |
34 | // let y = match x { | 33 | // let y = match x { |
35 | // Ok(it) => it, | 34 | // Ok(it) => it, |
36 | // $0_ => unreachable!(), | 35 | // $0_ => unreachable!(), |
@@ -97,25 +96,24 @@ mod tests { | |||
97 | fn test_replace_result_unwrap_with_match() { | 96 | fn test_replace_result_unwrap_with_match() { |
98 | check_assist( | 97 | check_assist( |
99 | replace_unwrap_with_match, | 98 | replace_unwrap_with_match, |
100 | r" | 99 | r#" |
101 | enum Result<T, E> { Ok(T), Err(E) } | 100 | //- minicore: result |
102 | fn i<T>(a: T) -> T { a } | 101 | fn i<T>(a: T) -> T { a } |
103 | fn main() { | 102 | fn main() { |
104 | let x: Result<i32, i32> = Result::Ok(92); | 103 | let x: Result<i32, i32> = Ok(92); |
105 | let y = i(x).$0unwrap(); | 104 | let y = i(x).$0unwrap(); |
106 | } | 105 | } |
107 | ", | 106 | "#, |
108 | r" | 107 | r#" |
109 | enum Result<T, E> { Ok(T), Err(E) } | ||
110 | fn i<T>(a: T) -> T { a } | 108 | fn i<T>(a: T) -> T { a } |
111 | fn main() { | 109 | fn main() { |
112 | let x: Result<i32, i32> = Result::Ok(92); | 110 | let x: Result<i32, i32> = Ok(92); |
113 | let y = match i(x) { | 111 | let y = match i(x) { |
114 | Ok(it) => it, | 112 | Ok(it) => it, |
115 | $0_ => unreachable!(), | 113 | $0_ => unreachable!(), |
116 | }; | 114 | }; |
117 | } | 115 | } |
118 | ", | 116 | "#, |
119 | ) | 117 | ) |
120 | } | 118 | } |
121 | 119 | ||
@@ -123,25 +121,24 @@ fn main() { | |||
123 | fn test_replace_option_unwrap_with_match() { | 121 | fn test_replace_option_unwrap_with_match() { |
124 | check_assist( | 122 | check_assist( |
125 | replace_unwrap_with_match, | 123 | replace_unwrap_with_match, |
126 | r" | 124 | r#" |
127 | enum Option<T> { Some(T), None } | 125 | //- minicore: option |
128 | fn i<T>(a: T) -> T { a } | 126 | fn i<T>(a: T) -> T { a } |
129 | fn main() { | 127 | fn main() { |
130 | let x = Option::Some(92); | 128 | let x = Some(92); |
131 | let y = i(x).$0unwrap(); | 129 | let y = i(x).$0unwrap(); |
132 | } | 130 | } |
133 | ", | 131 | "#, |
134 | r" | 132 | r#" |
135 | enum Option<T> { Some(T), None } | ||
136 | fn i<T>(a: T) -> T { a } | 133 | fn i<T>(a: T) -> T { a } |
137 | fn main() { | 134 | fn main() { |
138 | let x = Option::Some(92); | 135 | let x = Some(92); |
139 | let y = match i(x) { | 136 | let y = match i(x) { |
140 | Some(it) => it, | 137 | Some(it) => it, |
141 | $0_ => unreachable!(), | 138 | $0_ => unreachable!(), |
142 | }; | 139 | }; |
143 | } | 140 | } |
144 | ", | 141 | "#, |
145 | ); | 142 | ); |
146 | } | 143 | } |
147 | 144 | ||
@@ -149,25 +146,24 @@ fn main() { | |||
149 | fn test_replace_result_unwrap_with_match_chaining() { | 146 | fn test_replace_result_unwrap_with_match_chaining() { |
150 | check_assist( | 147 | check_assist( |
151 | replace_unwrap_with_match, | 148 | replace_unwrap_with_match, |
152 | r" | 149 | r#" |
153 | enum Result<T, E> { Ok(T), Err(E) } | 150 | //- minicore: result |
154 | fn i<T>(a: T) -> T { a } | 151 | fn i<T>(a: T) -> T { a } |
155 | fn main() { | 152 | fn main() { |
156 | let x: Result<i32, i32> = Result::Ok(92); | 153 | let x: Result<i32, i32> = Ok(92); |
157 | let y = i(x).$0unwrap().count_zeroes(); | 154 | let y = i(x).$0unwrap().count_zeroes(); |
158 | } | 155 | } |
159 | ", | 156 | "#, |
160 | r" | 157 | r#" |
161 | enum Result<T, E> { Ok(T), Err(E) } | ||
162 | fn i<T>(a: T) -> T { a } | 158 | fn i<T>(a: T) -> T { a } |
163 | fn main() { | 159 | fn main() { |
164 | let x: Result<i32, i32> = Result::Ok(92); | 160 | let x: Result<i32, i32> = Ok(92); |
165 | let y = match i(x) { | 161 | let y = match i(x) { |
166 | Ok(it) => it, | 162 | Ok(it) => it, |
167 | $0_ => unreachable!(), | 163 | $0_ => unreachable!(), |
168 | }.count_zeroes(); | 164 | }.count_zeroes(); |
169 | } | 165 | } |
170 | ", | 166 | "#, |
171 | ) | 167 | ) |
172 | } | 168 | } |
173 | 169 | ||
@@ -175,14 +171,14 @@ fn main() { | |||
175 | fn replace_unwrap_with_match_target() { | 171 | fn replace_unwrap_with_match_target() { |
176 | check_assist_target( | 172 | check_assist_target( |
177 | replace_unwrap_with_match, | 173 | replace_unwrap_with_match, |
178 | r" | 174 | r#" |
179 | enum Option<T> { Some(T), None } | 175 | //- minicore: option |
180 | fn i<T>(a: T) -> T { a } | 176 | fn i<T>(a: T) -> T { a } |
181 | fn main() { | 177 | fn main() { |
182 | let x = Option::Some(92); | 178 | let x = Some(92); |
183 | let y = i(x).$0unwrap(); | 179 | let y = i(x).$0unwrap(); |
184 | } | 180 | } |
185 | ", | 181 | "#, |
186 | r"i(x).unwrap()", | 182 | r"i(x).unwrap()", |
187 | ); | 183 | ); |
188 | } | 184 | } |