aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-05-25 13:24:08 +0100
committerFlorian Diebold <[email protected]>2021-05-25 13:29:53 +0100
commit35c948ff4a36b9c031bda96f79b8bf9e0d5bda26 (patch)
treee335ab0ab7271234b269974f92b591ea22174abd /crates/hir_ty/src
parent835cf55887527bd1953cb7004259214f7c215095 (diff)
Fix lowering of FnOnce() without return type
This should result in an implicit `-> ()`, not leaving out the binding.
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r--crates/hir_ty/src/tests/traits.rs32
1 files changed, 27 insertions, 5 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index a5a2df54c..714f12937 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -3041,7 +3041,7 @@ fn infer_fn_trait_arg() {
3041 3041
3042#[test] 3042#[test]
3043fn infer_box_fn_arg() { 3043fn infer_box_fn_arg() {
3044 // The type mismatch is a bug 3044 // The type mismatch is because we don't define Unsize and CoerceUnsized
3045 check_infer_with_mismatches( 3045 check_infer_with_mismatches(
3046 r#" 3046 r#"
3047//- /lib.rs deps:std 3047//- /lib.rs deps:std
@@ -3095,16 +3095,16 @@ fn foo() {
3095 478..576 '{ ...&s); }': () 3095 478..576 '{ ...&s); }': ()
3096 488..489 's': Option<i32> 3096 488..489 's': Option<i32>
3097 492..504 'Option::None': Option<i32> 3097 492..504 'Option::None': Option<i32>
3098 514..515 'f': Box<dyn FnOnce(&Option<i32>)> 3098 514..515 'f': Box<dyn FnOnce(&Option<i32>) -> ()>
3099 549..562 'box (|ps| {})': Box<|{unknown}| -> ()> 3099 549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
3100 554..561 '|ps| {}': |{unknown}| -> () 3100 554..561 '|ps| {}': |{unknown}| -> ()
3101 555..557 'ps': {unknown} 3101 555..557 'ps': {unknown}
3102 559..561 '{}': () 3102 559..561 '{}': ()
3103 568..569 'f': Box<dyn FnOnce(&Option<i32>)> 3103 568..569 'f': Box<dyn FnOnce(&Option<i32>) -> ()>
3104 568..573 'f(&s)': FnOnce::Output<dyn FnOnce(&Option<i32>), (&Option<i32>,)> 3104 568..573 'f(&s)': ()
3105 570..572 '&s': &Option<i32> 3105 570..572 '&s': &Option<i32>
3106 571..572 's': Option<i32> 3106 571..572 's': Option<i32>
3107 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()> 3107 549..562: expected Box<dyn FnOnce(&Option<i32>) -> ()>, got Box<|{unknown}| -> ()>
3108 "#]], 3108 "#]],
3109 ); 3109 );
3110} 3110}
@@ -3571,3 +3571,25 @@ fn main() {
3571 "#]], 3571 "#]],
3572 ) 3572 )
3573} 3573}
3574
3575#[test]
3576fn fn_returning_unit() {
3577 check_infer_with_mismatches(
3578 r#"
3579#[lang = "fn_once"]
3580trait FnOnce<Args> {
3581 type Output;
3582}
3583
3584fn test<F: FnOnce()>(f: F) {
3585 let _: () = f();
3586}"#,
3587 expect![[r#"
3588 82..83 'f': F
3589 88..112 '{ ...f(); }': ()
3590 98..99 '_': ()
3591 106..107 'f': F
3592 106..109 'f()': ()
3593 "#]],
3594 );
3595}