aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/coercion.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-20 17:58:59 +0000
committerGitHub <[email protected]>2019-12-20 17:58:59 +0000
commit979cbb496e88f91d21a1f12cbf959fc0032bd0cd (patch)
tree0b00ef7d63064a4f60e03427abf0803bb17b4596 /crates/ra_hir_ty/src/tests/coercion.rs
parent1d7931e5ffeb2d65ebcc14a63da1b84cc131bfb8 (diff)
parent44b00aed4a7d7e329fcbfa95a8685437cfb06e41 (diff)
Merge #2619
2619: Coerce closures to fn pointers r=flodiebold a=flodiebold E.g. `let x: fn(A) -> B = |x| { y };` Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests/coercion.rs')
-rw-r--r--crates/ra_hir_ty/src/tests/coercion.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs
index 793c23e41..7e99a42ed 100644
--- a/crates/ra_hir_ty/src/tests/coercion.rs
+++ b/crates/ra_hir_ty/src/tests/coercion.rs
@@ -487,3 +487,42 @@ fn foo() {
487 "### 487 "###
488 ); 488 );
489} 489}
490
491#[test]
492fn coerce_fn_item_to_fn_ptr() {
493 assert_snapshot!(
494 infer_with_mismatches(r#"
495fn foo(x: u32) -> isize { 1 }
496fn test() {
497 let f: fn(u32) -> isize = foo;
498}
499"#, true),
500 @r###"
501 [8; 9) 'x': u32
502 [25; 30) '{ 1 }': isize
503 [27; 28) '1': isize
504 [41; 79) '{ ...foo; }': ()
505 [51; 52) 'f': fn(u32) -> isize
506 [73; 76) 'foo': fn foo(u32) -> isize
507 "###
508 );
509}
510
511#[test]
512fn coerce_closure_to_fn_ptr() {
513 assert_snapshot!(
514 infer_with_mismatches(r#"
515fn test() {
516 let f: fn(u32) -> isize = |x| { 1 };
517}
518"#, true),
519 @r###"
520 [11; 55) '{ ...1 }; }': ()
521 [21; 22) 'f': fn(u32) -> isize
522 [43; 52) '|x| { 1 }': |u32| -> isize
523 [44; 45) 'x': u32
524 [47; 52) '{ 1 }': isize
525 [49; 50) '1': isize
526 "###
527 );
528}