@@ -21,7 +21,7 @@ pub struct InlayHintsConfig {
21
21
pub parameter_hints : bool ,
22
22
pub chaining_hints : bool ,
23
23
pub reborrow_hints : ReborrowHints ,
24
- pub closure_return_type_hints : bool ,
24
+ pub closure_return_type_hints : ClosureReturnTypeHints ,
25
25
pub binding_mode_hints : bool ,
26
26
pub lifetime_elision_hints : LifetimeElisionHints ,
27
27
pub param_names_for_lifetime_elision_hints : bool ,
@@ -31,6 +31,13 @@ pub struct InlayHintsConfig {
31
31
pub closing_brace_hints_min_lines : Option < usize > ,
32
32
}
33
33
34
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
35
+ pub enum ClosureReturnTypeHints {
36
+ Always ,
37
+ WithBlock ,
38
+ Never ,
39
+ }
40
+
34
41
#[ derive( Clone , Debug , PartialEq , Eq ) ]
35
42
pub enum LifetimeElisionHints {
36
43
Always ,
@@ -86,7 +93,7 @@ pub enum InlayTooltip {
86
93
//
87
94
// Optionally, one can enable additional hints for
88
95
//
89
- // * return types of closure expressions with blocks
96
+ // * return types of closure expressions
90
97
// * elided lifetimes
91
98
// * compiler inserted reborrows
92
99
//
@@ -460,15 +467,17 @@ fn closure_ret_hints(
460
467
file_id : FileId ,
461
468
closure : ast:: ClosureExpr ,
462
469
) -> Option < ( ) > {
463
- if ! config. closure_return_type_hints {
470
+ if config. closure_return_type_hints == ClosureReturnTypeHints :: Never {
464
471
return None ;
465
472
}
466
473
467
474
if closure. ret_type ( ) . is_some ( ) {
468
475
return None ;
469
476
}
470
477
471
- if !closure_has_block_body ( & closure) {
478
+ if !closure_has_block_body ( & closure)
479
+ && config. closure_return_type_hints == ClosureReturnTypeHints :: WithBlock
480
+ {
472
481
return None ;
473
482
}
474
483
@@ -1092,13 +1101,15 @@ mod tests {
1092
1101
use crate :: inlay_hints:: ReborrowHints ;
1093
1102
use crate :: { fixture, inlay_hints:: InlayHintsConfig , LifetimeElisionHints } ;
1094
1103
1104
+ use super :: ClosureReturnTypeHints ;
1105
+
1095
1106
const DISABLED_CONFIG : InlayHintsConfig = InlayHintsConfig {
1096
1107
render_colons : false ,
1097
1108
type_hints : false ,
1098
1109
parameter_hints : false ,
1099
1110
chaining_hints : false ,
1100
1111
lifetime_elision_hints : LifetimeElisionHints :: Never ,
1101
- closure_return_type_hints : false ,
1112
+ closure_return_type_hints : ClosureReturnTypeHints :: Never ,
1102
1113
reborrow_hints : ReborrowHints :: Always ,
1103
1114
binding_mode_hints : false ,
1104
1115
hide_named_constructor_hints : false ,
@@ -1112,7 +1123,7 @@ mod tests {
1112
1123
parameter_hints : true ,
1113
1124
chaining_hints : true ,
1114
1125
reborrow_hints : ReborrowHints :: Always ,
1115
- closure_return_type_hints : true ,
1126
+ closure_return_type_hints : ClosureReturnTypeHints :: WithBlock ,
1116
1127
binding_mode_hints : true ,
1117
1128
lifetime_elision_hints : LifetimeElisionHints :: Always ,
1118
1129
..DISABLED_CONFIG
@@ -2054,6 +2065,23 @@ fn main() {
2054
2065
) ;
2055
2066
}
2056
2067
2068
+ #[ test]
2069
+ fn return_type_hints_for_closure_without_block ( ) {
2070
+ check_with_config (
2071
+ InlayHintsConfig {
2072
+ closure_return_type_hints : ClosureReturnTypeHints :: Always ,
2073
+ ..DISABLED_CONFIG
2074
+ } ,
2075
+ r#"
2076
+ fn main() {
2077
+ let a = || { 0 };
2078
+ //^^ i32
2079
+ let b = || 0;
2080
+ //^^ i32
2081
+ }"# ,
2082
+ ) ;
2083
+ }
2084
+
2057
2085
#[ test]
2058
2086
fn skip_closure_type_hints ( ) {
2059
2087
check_with_config (
0 commit comments