@@ -21,7 +21,7 @@ pub struct InlayHintsConfig {
2121 pub parameter_hints : bool ,
2222 pub chaining_hints : bool ,
2323 pub reborrow_hints : ReborrowHints ,
24- pub closure_return_type_hints : bool ,
24+ pub closure_return_type_hints : ClosureReturnTypeHints ,
2525 pub binding_mode_hints : bool ,
2626 pub lifetime_elision_hints : LifetimeElisionHints ,
2727 pub param_names_for_lifetime_elision_hints : bool ,
@@ -31,6 +31,13 @@ pub struct InlayHintsConfig {
3131 pub closing_brace_hints_min_lines : Option < usize > ,
3232}
3333
34+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
35+ pub enum ClosureReturnTypeHints {
36+ Always ,
37+ WithBlock ,
38+ Never ,
39+ }
40+
3441#[ derive( Clone , Debug , PartialEq , Eq ) ]
3542pub enum LifetimeElisionHints {
3643 Always ,
@@ -86,7 +93,7 @@ pub enum InlayTooltip {
8693//
8794// Optionally, one can enable additional hints for
8895//
89- // * return types of closure expressions with blocks
96+ // * return types of closure expressions
9097// * elided lifetimes
9198// * compiler inserted reborrows
9299//
@@ -460,15 +467,17 @@ fn closure_ret_hints(
460467 file_id : FileId ,
461468 closure : ast:: ClosureExpr ,
462469) -> Option < ( ) > {
463- if ! config. closure_return_type_hints {
470+ if config. closure_return_type_hints == ClosureReturnTypeHints :: Never {
464471 return None ;
465472 }
466473
467474 if closure. ret_type ( ) . is_some ( ) {
468475 return None ;
469476 }
470477
471- if !closure_has_block_body ( & closure) {
478+ if !closure_has_block_body ( & closure)
479+ && config. closure_return_type_hints == ClosureReturnTypeHints :: WithBlock
480+ {
472481 return None ;
473482 }
474483
@@ -1092,13 +1101,15 @@ mod tests {
10921101 use crate :: inlay_hints:: ReborrowHints ;
10931102 use crate :: { fixture, inlay_hints:: InlayHintsConfig , LifetimeElisionHints } ;
10941103
1104+ use super :: ClosureReturnTypeHints ;
1105+
10951106 const DISABLED_CONFIG : InlayHintsConfig = InlayHintsConfig {
10961107 render_colons : false ,
10971108 type_hints : false ,
10981109 parameter_hints : false ,
10991110 chaining_hints : false ,
11001111 lifetime_elision_hints : LifetimeElisionHints :: Never ,
1101- closure_return_type_hints : false ,
1112+ closure_return_type_hints : ClosureReturnTypeHints :: Never ,
11021113 reborrow_hints : ReborrowHints :: Always ,
11031114 binding_mode_hints : false ,
11041115 hide_named_constructor_hints : false ,
@@ -1112,7 +1123,7 @@ mod tests {
11121123 parameter_hints : true ,
11131124 chaining_hints : true ,
11141125 reborrow_hints : ReborrowHints :: Always ,
1115- closure_return_type_hints : true ,
1126+ closure_return_type_hints : ClosureReturnTypeHints :: WithBlock ,
11161127 binding_mode_hints : true ,
11171128 lifetime_elision_hints : LifetimeElisionHints :: Always ,
11181129 ..DISABLED_CONFIG
@@ -2054,6 +2065,23 @@ fn main() {
20542065 ) ;
20552066 }
20562067
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+
20572085 #[ test]
20582086 fn skip_closure_type_hints ( ) {
20592087 check_with_config (
0 commit comments